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)



On Sep 8, 2009, at 12:55 AM, Andrew Haley wrote:


Sure, its overkill, but it'll still work.

There are stuff from <mntent.h> that's not available on darwin, so, it seems like we can only mmap.

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?

Try it. If it works, we can check it in. The alternative is to write a bunch of special case code for Snow Leopard. I'm happy either way; your call.


I tried this patch (against 3.0.8) and after running the autotools,
reconfiguring, and building, it seems to work for my system (Ikarus
Scheme <http://ikarus-scheme.org/>).  Basically, in closure.c, all
the stuff about temporary files is used iff FFI_MMAP_EXEC_SELINUX is
set (not darwin) or else dlmmap would just do mmap and return the
pointer (unchecked).  Also, configure.ac sets FFI_MMAP_EXEC_WRIT
explicitly on darwin10, making it go through the mmap-only path.

Let me know if this is good enough (or not).

Aziz,,,

=== modified file 'configure.ac'
--- configure.ac	2009-09-07 22:56:10 +0000
+++ configure.ac	2009-09-07 22:57:36 +0000
@@ -260,6 +260,16 @@
     fi
 fi

+case "$target" in
+  i?86-apple-darwin10*)
+    AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
+              [Cannot use malloc on this target, so, we revert to
+               alternative means])
+    ;;
+esac
+
+
+
 AC_CACHE_CHECK([whether .eh_frame section should be read-only],
     libffi_cv_ro_eh_frame, [
 	libffi_cv_ro_eh_frame=no

=== modified file 'src/closures.c'
--- src/closures.c	2009-09-07 22:56:10 +0000
+++ src/closures.c	2009-09-07 23:08:05 +0000
@@ -93,7 +93,6 @@
 #include <unistd.h>
 #include <string.h>
 #include <stdio.h>
-#include <mntent.h>
 #include <sys/param.h>
 #include <pthread.h>

@@ -105,6 +104,7 @@
 #if FFI_MMAP_EXEC_SELINUX
 #include <sys/statfs.h>
 #include <stdlib.h>
+#include <mntent.h>

static int selinux_enabled = -1;

@@ -180,6 +180,7 @@
 #undef mmap
 #undef munmap

+#if FFI_MMAP_EXEC_SELINUX
/* A mutex used to synchronize access to *exec* variables in this file. */
static pthread_mutex_t open_temp_exec_file_mutex = PTHREAD_MUTEX_INITIALIZER;


@@ -444,6 +445,27 @@

   return dlmmap_locked (start, length, prot, flags, offset);
 }
+#else
+
+static void *
+dlmmap (void *start, size_t length, int prot,
+	int flags, int fd, off_t offset)
+{
+
+  assert (start == NULL && length % malloc_getpagesize == 0
+	  && prot == (PROT_READ | PROT_WRITE)
+	  && flags == (MAP_PRIVATE | MAP_ANONYMOUS)
+	  && fd == -1 && offset == 0);
+
+#if FFI_CLOSURE_TEST
+  printf ("mapping in %zi\n", length);
+#endif
+
+  return mmap (start, length, prot | PROT_EXEC, flags, fd, offset);
+}
+
+#endif
+

 /* Release memory at the given address, as well as the corresponding
    executable page if it's separate.  */




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