[Pcre-svn] [1178] code/trunk/src: JIT compiler update and di…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [1178] code/trunk/src: JIT compiler update and disable wrong assert.
Revision: 1178
          http://www.exim.org/viewvc/pcre2?view=rev&revision=1178
Author:   zherczeg
Date:     2019-10-16 13:50:55 +0100 (Wed, 16 Oct 2019)
Log Message:
-----------
JIT compiler update and disable wrong assert.


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


Modified: code/trunk/src/pcre2_jit_compile.c
===================================================================
--- code/trunk/src/pcre2_jit_compile.c    2019-10-15 15:23:31 UTC (rev 1177)
+++ code/trunk/src/pcre2_jit_compile.c    2019-10-16 12:50:55 UTC (rev 1178)
@@ -1050,8 +1050,8 @@
   return cc + 1 + 2 + cc[1];


default:
- /* All opcodes are supported now! */
- SLJIT_UNREACHABLE();
+ /* Unsupported opcodes: OP_ASSERT_NA and OP_ASSERTBACK_NA */
+ /* SLJIT_UNREACHABLE(); */
return NULL;
}
}

Modified: code/trunk/src/sljit/sljitExecAllocator.c
===================================================================
--- code/trunk/src/sljit/sljitExecAllocator.c    2019-10-15 15:23:31 UTC (rev 1177)
+++ code/trunk/src/sljit/sljitExecAllocator.c    2019-10-16 12:50:55 UTC (rev 1178)
@@ -118,10 +118,20 @@
     if (map_jit_flag == -1) {
         struct utsname name;


+        map_jit_flag = 0;
         uname(&name);


         /* Kernel version for 10.14.0 (Mojave) */
-        map_jit_flag = (atoi(name.release) >= 18) ? MAP_JIT : 0;
+        if (atoi(name.release) >= 18) {
+            /* Only use MAP_JIT if a hardened runtime is used, because MAP_JIT is incompatible with fork(). */
+            void *ptr = mmap(NULL, getpagesize(), PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+
+            if (ptr == MAP_FAILED) {
+                map_jit_flag = MAP_JIT;
+            } else {
+                munmap(ptr, getpagesize());
+            }
+        }
     }


     return map_jit_flag;
@@ -137,6 +147,7 @@
 static SLJIT_INLINE void* alloc_chunk(sljit_uw size)
 {
     void *retval;
+    const int prot = PROT_READ | PROT_WRITE | PROT_EXEC;


#ifdef MAP_ANON

@@ -146,16 +157,25 @@
     flags |= get_map_jit_flag();
 #endif


-    retval = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, flags, -1, 0);
+    retval = mmap(NULL, size, prot, flags, -1, 0);
 #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);
+    retval = mmap(NULL, size, prot, MAP_PRIVATE, dev_zero, 0);
 #endif /* MAP_ANON */


-    return (retval != MAP_FAILED) ? retval : NULL;
+    if (retval == MAP_FAILED)
+        retval = NULL;
+    else {
+        if (mprotect(retval, size, prot) < 0) {
+            munmap(retval, size);
+            retval = NULL;
+        }
+    }
+
+    return retval;
 }


static SLJIT_INLINE void free_chunk(void *chunk, sljit_uw size)

Modified: code/trunk/src/sljit/sljitUtils.c
===================================================================
--- code/trunk/src/sljit/sljitUtils.c    2019-10-15 15:23:31 UTC (rev 1177)
+++ code/trunk/src/sljit/sljitUtils.c    2019-10-16 12:50:55 UTC (rev 1178)
@@ -154,7 +154,13 @@
 #include "windows.h"
 #else
 /* Provides mmap function. */
+#include <sys/types.h>
 #include <sys/mman.h>
+#ifndef MAP_ANON
+#ifdef MAP_ANONYMOUS
+#define MAP_ANON MAP_ANONYMOUS
+#endif
+#endif
 /* For detecting the page size. */
 #include <unistd.h>