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: Andrew Haley <aph at redhat dot com>
- To: Abdulaziz Ghuloum <aghuloum at gmail dot com>
- Cc: libffi-discuss at sourceware dot org
- Date: Mon, 07 Sep 2009 09:49:59 +0100
- Subject: Re: Protection errors on Mac OS X 10.6 (Snow Leopard)
- References: <478412E4-92D6-4353-9FE6-705C1832D7E6@gmail.com>
Abdulaziz Ghuloum wrote:
> 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?
Not quite. libffi should not attempt to alter the protection of
pages returned by malloc(). Instead, ffi_closure_alloc() allocates
a chunk of memory with the correct permissions. On some systems,
memory returned by malloc is writable and executable so we just use
it, but on other systems FFI_MMAP_EXEC_WRIT is set to show that
we must do something special.
Go into closures.c, find the definition of FFI_MMAP_EXEC_WRIT for
your system, and set it accordingly.
Andrew.