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

Page principale
Supprimer ce message
Auteur: Subversion repository
Date:  
À: pcre-svn
Sujet: [Pcre-svn] [1742] code/trunk: Improve MAP_JIT flag usage on MacOS.
Revision: 1742
          http://vcs.pcre.org/viewvc?view=rev&revision=1742
Author:   zherczeg
Date:     2018-11-25 17:09:20 +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/sljit/sljitExecAllocator.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2018-10-20 09:38:44 UTC (rev 1741)
+++ code/trunk/ChangeLog    2018-11-25 17:09:20 UTC (rev 1742)
@@ -45,7 +45,9 @@
 recorded. Example: /(?&xxx)*ABC(?<xxx>XYZ)/ would (incorrectly) expect 'A' to 
 be the first character of a match. 


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

+
Version 8.42 20-March-2018
--------------------------


Modified: code/trunk/sljit/sljitExecAllocator.c
===================================================================
--- code/trunk/sljit/sljitExecAllocator.c    2018-10-20 09:38:44 UTC (rev 1741)
+++ code/trunk/sljit/sljitExecAllocator.c    2018-11-25 17:09:20 UTC (rev 1742)
@@ -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;
 }