This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Re: Protection errors on Mac OS X 10.6 (Snow Leopard)
- From: Abdulaziz Ghuloum <aghuloum at gmail dot com>
- To: Andrew Haley <aph at redhat dot com>
- Cc: Abdulaziz Ghuloum <aghuloum at gmail dot com>, libffi-discuss at sourceware dot org
- Date: Tue, 8 Sep 2009 00:49:15 +0300
- Subject: Re: Protection errors on Mac OS X 10.6 (Snow Leopard)
- References: <478412E4-92D6-4353-9FE6-705C1832D7E6@gmail.com> <4AA4C937.2090601@redhat.com>
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,,,