This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
Protection errors on Mac OS X 10.6 (Snow Leopard)
- From: Abdulaziz Ghuloum <aghuloum at gmail dot com>
- To: libffi-discuss at sourceware dot org
- Cc: Abdulaziz Ghuloum <aghuloum at gmail dot com>
- Date: Sat, 5 Sep 2009 05:59:35 +0300
- Subject: Protection errors on Mac OS X 10.6 (Snow Leopard)
Greetings,
On Snow Leopard, libffi-3.0.8 causes kernel protection errors
when trying to call the codeloc returned by ffi_closure_alloc.
Seems like libffi should be calling
mprotect(addr, size, PROT_READ|PROT_WRITE|PROT_EXEC)
after assembling the piece of code at run time, or better yet
it should allocate codes in a specially designated area of
memory (instead of calling malloc directly which IIUC is what
libffi does).
Here's a log of GDB. First, it shows the error where I try
to continue only to get the same error (not unexpected).
I then manually set the protection bits on the page of the
faulting address, and violla, the program continues to
termination.
Does this sound like the correct analysis of the situation?
Aziz,,,
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x0000000100105b90
0x0000000100105b90 in ?? ()
(gdb) continue
Continuing.
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x0000000100105b90
0x0000000100105b90 in ?? ()
(gdb) continue
Continuing.
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x0000000100105b90
0x0000000100105b90 in ?? ()
(gdb) call (int) mprotect ((char *)0x0000000100105000, (size_t)4096,
(int)7)
$1 = 0
(gdb) continue
Continuing.
Program exited normally.
(gdb)