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)
Interesting also is that there is a manpage[*] on darwin that says:
...
Some architectures do not allow the execution of data by
default. In such cases, it is necessary to manually alter
the permissions of the page that contains closure prior to
its execution.
...
// Allocate a page to hold the closure with read and write
permissions.
if ((closure = mmap(NULL, sizeof(ffi_closure), PROT_READ |
PROT_WRITE,
MAP_ANON | MAP_PRIVATE, -1, )) == (void*)-1)
{ ...
// Prepare the ffi_cif structure.
if ((status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI,
2, &ffi_type_uint8, arg_types)) != FFI_OK)
{ ...
// Prepare the ffi_closure structure.
if ((status = ffi_prep_closure(closure, &cif, foo_closure,
NULL)) != FFI_OK)
{ ...
// Ensure that the closure will execute on all architectures.
if (mprotect(closure, sizeof(closure), PROT_READ |
PROT_EXEC) == -1)
{ ...
// The closure is now ready to be executed, and can be saved
for later
// execution if desired.
...
Aziz,,,
[*] http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man3/ffi_prep_closure.3.html