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)


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.


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