[Pcre-svn] [1305] code/trunk/src/sljit: JIT compiler update.

Kezdőlap
Üzenet törlése
Szerző: Subversion repository
Dátum:  
Címzett: pcre-svn
Tárgy: [Pcre-svn] [1305] code/trunk/src/sljit: JIT compiler update.
Revision: 1305
          http://www.exim.org/viewvc/pcre2?view=rev&revision=1305
Author:   zherczeg
Date:     2021-04-26 06:56:04 +0100 (Mon, 26 Apr 2021)
Log Message:
-----------
JIT compiler update.


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


Modified: code/trunk/src/sljit/sljitExecAllocator.c
===================================================================
--- code/trunk/src/sljit/sljitExecAllocator.c    2021-02-19 12:05:57 UTC (rev 1304)
+++ code/trunk/src/sljit/sljitExecAllocator.c    2021-04-26 05:56:04 UTC (rev 1305)
@@ -166,23 +166,28 @@
 static SLJIT_INLINE void* alloc_chunk(sljit_uw size)
 {
     void *retval;
-    const int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
+    int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
+    int flags = MAP_PRIVATE;
+    int fd = -1;


+#ifdef PROT_MAX
+    prot |= PROT_MAX(prot);
+#endif
+
 #ifdef MAP_ANON
-    int flags = MAP_PRIVATE | MAP_ANON | SLJIT_MAP_JIT;
-
-    retval = mmap(NULL, size, prot, flags, -1, 0);
+    flags |= MAP_ANON | SLJIT_MAP_JIT;
 #else /* !MAP_ANON */
     if (SLJIT_UNLIKELY((dev_zero < 0) && open_dev_zero()))
         return NULL;


-    retval = mmap(NULL, size, prot, MAP_PRIVATE, dev_zero, 0);
+    fd = dev_zero;
 #endif /* MAP_ANON */


+    retval = mmap(NULL, size, prot, flags, fd, 0);
     if (retval == MAP_FAILED)
         return NULL;


-    if (mprotect(retval, size, prot) < 0) {
+    if (mprotect(retval, size, PROT_READ | PROT_WRITE | PROT_EXEC) < 0) {
         munmap(retval, size);
         return NULL;
     }


Modified: code/trunk/src/sljit/sljitUtils.c
===================================================================
--- code/trunk/src/sljit/sljitUtils.c    2021-02-19 12:05:57 UTC (rev 1304)
+++ code/trunk/src/sljit/sljitUtils.c    2021-04-26 05:56:04 UTC (rev 1305)
@@ -48,7 +48,7 @@
 static SLJIT_INLINE void allocator_grab_lock(void)
 {
     HANDLE lock;
-    if (SLJIT_UNLIKELY(!allocator_lock)) {
+    if (SLJIT_UNLIKELY(!InterlockedCompareExchangePointer(&allocator_lock, NULL, NULL))) {
         lock = CreateMutex(NULL, FALSE, NULL);
         if (InterlockedCompareExchangePointer(&allocator_lock, lock, NULL))
             CloseHandle(lock);
@@ -146,9 +146,13 @@
 #include <unistd.h>


 static SLJIT_INLINE sljit_sw get_page_alignment(void) {
-    static sljit_sw sljit_page_align;
-    if (!sljit_page_align) {
+    static sljit_sw sljit_page_align = -1;
+    if (sljit_page_align < 0) {
+#ifdef _SC_PAGESIZE
         sljit_page_align = sysconf(_SC_PAGESIZE);
+#else
+        sljit_page_align = getpagesize();
+#endif
         /* Should never happen. */
         if (sljit_page_align < 0)
             sljit_page_align = 4096;


Modified: code/trunk/src/sljit/sljitWXExecAllocator.c
===================================================================
--- code/trunk/src/sljit/sljitWXExecAllocator.c    2021-02-19 12:05:57 UTC (rev 1304)
+++ code/trunk/src/sljit/sljitWXExecAllocator.c    2021-04-26 05:56:04 UTC (rev 1305)
@@ -121,14 +121,18 @@
     static pthread_mutex_t se_lock = PTHREAD_MUTEX_INITIALIZER;
 #endif
     static int se_protected = !SLJIT_PROT_WX;
+    int prot = PROT_READ | PROT_WRITE | SLJIT_PROT_WX;
     sljit_uw* ptr;


     if (SLJIT_UNLIKELY(se_protected < 0))
         return NULL;


+#ifdef PROT_MAX
+    prot |= PROT_MAX(PROT_READ | PROT_WRITE | PROT_EXEC);
+#endif
+
     size += sizeof(sljit_uw);
-    ptr = (sljit_uw*)mmap(NULL, size, PROT_READ | PROT_WRITE | SLJIT_PROT_WX,
-                MAP_PRIVATE | MAP_ANON, -1, 0);
+    ptr = (sljit_uw*)mmap(NULL, size, prot, MAP_PRIVATE | MAP_ANON, -1, 0);


     if (ptr == MAP_FAILED)
         return NULL;