[Pcre-svn] [1046] code/trunk: Improve MAP_JIT flag usage on …

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [1046] code/trunk: Improve MAP_JIT flag usage on MacOS.
Revision: 1046
          http://www.exim.org/viewvc/pcre2?view=rev&revision=1046
Author:   zherczeg
Date:     2018-11-25 17:11:52 +0000 (Sun, 25 Nov 2018)
Log Message:
-----------
Improve MAP_JIT flag usage on MacOS. Patch by Rich Siegel.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/src/sljit/sljitExecAllocator.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2018-11-24 16:31:10 UTC (rev 1045)
+++ code/trunk/ChangeLog    2018-11-25 17:11:52 UTC (rev 1046)
@@ -83,7 +83,9 @@
 20. Added "fork" support for VMS to pcre2grep, for running an external program 
 via a string callout.


+21. Improve MAP_JIT flag usage on MacOS. Patch by Rich Siegel.

+
Version 10.32 10-September-2018
-------------------------------


Modified: code/trunk/src/sljit/sljitExecAllocator.c
===================================================================
--- code/trunk/src/sljit/sljitExecAllocator.c    2018-11-24 16:31:10 UTC (rev 1045)
+++ code/trunk/src/sljit/sljitExecAllocator.c    2018-11-25 17:11:52 UTC (rev 1046)
@@ -94,6 +94,38 @@


#else

+#ifdef MAP_JIT
+
+static SLJIT_INLINE int get_map_jit_flag()
+{
+#ifdef TARGET_OS_MAC
+    /* On macOS systems, returns MAP_JIT if it is defined _and_ we're running on a version
+       of macOS where it's OK to have more than one JIT block. On non-macOS systems, returns
+       MAP_JIT if it is defined. */
+
+    static dispatch_once_t _inited;
+    static int map_jit_flag;
+
+    dispatch_once(&_inited,
+        ^() {
+            struct utsname name;
+
+            uname(&name);
+
+            /* Kernel version for 10.14.0 (Mojave) */
+            if (atoi(name.release) >= 18)
+                map_jit_flag = MAP_JIT;
+        }
+    );
+
+    return map_jit_flag;
+#else /* !TARGET_OS_MAC */
+    return MAP_JIT;
+#endif /* TARGET_OS_MAC */
+}
+
+#endif /* MAP_JIT */
+
 static SLJIT_INLINE void* alloc_chunk(sljit_uw size)
 {
     void *retval;
@@ -103,17 +135,17 @@
     int flags = MAP_PRIVATE | MAP_ANON;


 #ifdef MAP_JIT
-    flags |= MAP_JIT;
+    flags |= get_map_jit_flag();
 #endif


     retval = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, flags, -1, 0);
-#else
+#else /* !MAP_ANON */
     if (dev_zero < 0) {
         if (open_dev_zero())
             return NULL;
     }
     retval = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, dev_zero, 0);
-#endif
+#endif /* MAP_ANON */


     return (retval != MAP_FAILED) ? retval : NULL;
 }