Commit e4a91de766acc47f6c50f13cc11719a65e23ecba

Anthony Green 2009-10-05T00:16:17

From Abdulaziz Ghuloum. Adds special case for Snow Leopard.

diff --git a/configure b/configure
index 53c6059..aa9c0a4 100755
--- a/configure
+++ b/configure
@@ -22797,6 +22797,16 @@ _ACEOF
     fi
 fi
 
+case "$target" in
+    i?86-apple-darwin10*)
+
+cat >>confdefs.h <<\_ACEOF
+#define FFI_MMAP_EXEC_WRIT 1
+_ACEOF
+
+    ;;
+esac
+
 { $as_echo "$as_me:$LINENO: checking whether .eh_frame section should be read-only" >&5
 $as_echo_n "checking whether .eh_frame section should be read-only... " >&6; }
 if test "${libffi_cv_ro_eh_frame+set}" = set; then
diff --git a/configure.ac b/configure.ac
index aeaa555..de438d7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -273,6 +273,14 @@ if test x$TARGET = xX86 || test x$TARGET = xX86_WIN32 || test x$TARGET = xX86_64
     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
diff --git a/src/closures.c b/src/closures.c
index f07ad06..afa2cf6 100644
--- a/src/closures.c
+++ b/src/closures.c
@@ -209,6 +209,7 @@ static int dlmunmap(void *, size_t);
 
 #if !(defined(X86_WIN32) || defined(X86_WIN64)) || defined (__CYGWIN__)
 
+#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;
 
@@ -478,6 +479,27 @@ dlmmap (void *start, size_t length, int prot,
   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.  */
 static int