This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Protection errors on Mac OS X 10.6 (Snow Leopard)



On Sep 7, 2009, at 11:49 AM, Andrew Haley wrote:


libffi should not attempt to alter the protection of
pages returned by malloc().

This is fine as a policy.


Instead, ffi_closure_alloc() allocates
a chunk of memory with the correct permissions.

Okay.


On some systems,
memory returned by malloc is writable and executable so we just use
it,

Right.


but on other systems FFI_MMAP_EXEC_WRIT is set to show that
we must do something special.

Hmm. The documentation about FFI_MMAP_EXEC_WRIT says:


/* This macro indicates it may be forbidden to map anonymous memory
   with both write and execute permission. [...]

This is not the situation under Snow Leopard.  Here, you *can*
map anonymous memory with both write and execute permissions.
It's just that you have to mmap it with the correct PROT flags
(or mmap it first and mprotect it later).  So, you cannot use
malloc (since the protection on malloced memory is READ|WRITE)
but you can use mmap without needing to do all of:

                                      [...] Code compiled when this
   option is defined will attempt to map such pages once, but if it
   fails, it falls back to creating a temporary file in a writable and
   executable filesystem and mapping pages from it into separate
   locations in the virtual memory space, one location writable and
   another executable. */

Go into closures.c, find the definition of FFI_MMAP_EXEC_WRIT for
your system, and set it accordingly.

I can do that on my computer, yes. But what about people who use my program that depends on libffi? I cannot expect them to have to patch and recompile libffi just to use my program, right?

Aziz,,,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]