summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzherczeg <zherczeg@6239d852-aaf2-0410-a92c-79f79f948069>2019-10-01 13:46:41 +0000
committerzherczeg <zherczeg@6239d852-aaf2-0410-a92c-79f79f948069>2019-10-01 13:46:41 +0000
commit9b6f404956f56fb01a1645a4e3c21bc239b77d50 (patch)
tree11e6f33d9fb736fa8c61de9dcb562b4f9d7b43c7
parentfea6c5222cfeb954313108bdef5cf6f7d47e675e (diff)
downloadpcre2-9b6f404956f56fb01a1645a4e3c21bc239b77d50.tar.gz
Better description for jit-sealloc option and early check for executable memory.
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@1174 6239d852-aaf2-0410-a92c-79f79f948069
-rw-r--r--CMakeLists.txt2
-rw-r--r--README8
-rw-r--r--configure.ac2
-rw-r--r--src/pcre2_jit_compile.c21
4 files changed, 28 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4737687..9a3e5da 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -178,7 +178,7 @@ SET(PCRE2_SUPPORT_JIT OFF CACHE BOOL
"Enable support for Just-in-time compiling.")
SET(PCRE2_SUPPORT_JIT_SEALLOC OFF CACHE BOOL
- "Enable SELinux compatible execmem allocator in JIT.")
+ "Enable SELinux compatible execmem allocator in JIT (experimental).")
SET(PCRE2GREP_SUPPORT_JIT ON CACHE BOOL
"Enable use of Just-in-time compiling in pcre2grep.")
diff --git a/README b/README
index ff9a6af..329e856 100644
--- a/README
+++ b/README
@@ -164,9 +164,11 @@ library. They are also documented in the pcre2build man page.
will be a compile time error. If in doubt, use --enable-jit=auto, which
enables JIT only if the current hardware is supported.
-. If you are enabling JIT under SELinux you may also want to add
- --enable-jit-sealloc, which enables the use of an execmem allocator in JIT
- that is compatible with SELinux. This has no effect if JIT is not enabled.
+. If you are enabling JIT under SELinux environment you may also want to add
+ --enable-jit-sealloc, which enables the use of an executable memory allocator
+ that is compatible with SELinux. Warning: this allocator is experimental!
+ It does not support fork() operation and may crash when no disk space is
+ available. This option has no effect if JIT is disabled.
. If you do not want to make use of the default support for UTF-8 Unicode
character strings in the 8-bit library, UTF-16 Unicode character strings in
diff --git a/configure.ac b/configure.ac
index 35b947b..170cde8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -161,7 +161,7 @@ fi
# Handle --enable-jit-sealloc (disabled by default)
AC_ARG_ENABLE(jit-sealloc,
AS_HELP_STRING([--enable-jit-sealloc],
- [enable SELinux compatible execmem allocator in JIT]),
+ [enable SELinux compatible execmem allocator in JIT (experimental)]),
, enable_jit_sealloc=no)
# Handle --disable-pcre2grep-jit (enabled by default)
diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c
index 6dace1f..9f32795 100644
--- a/src/pcre2_jit_compile.c
+++ b/src/pcre2_jit_compile.c
@@ -13740,12 +13740,33 @@ Returns: 0: success or (*NOJIT) was used
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
pcre2_jit_compile(pcre2_code *code, uint32_t options)
{
+static int executable_allocator_is_working = 0;
+
pcre2_real_code *re = (pcre2_real_code *)code;
#ifdef SUPPORT_JIT
executable_functions *functions = (executable_functions *)re->executable_jit;
#endif
+if (executable_allocator_is_working == 0)
+ {
+ /* Checks whether the executable allocator is working. This check
+ might run multiple times in multi-threaded environments, but the result
+ should not be affected by it. */
+ void *ptr = SLJIT_MALLOC_EXEC(32);
+
+ executable_allocator_is_working = -1;
+
+ if (ptr != NULL)
+ {
+ SLJIT_FREE_EXEC(((sljit_u8*)(ptr)) + SLJIT_EXEC_OFFSET(ptr));
+ executable_allocator_is_working = 1;
+ }
+ }
+
+if (executable_allocator_is_working < 0)
+ return PCRE2_ERROR_NOMEMORY;
+
if (code == NULL)
return PCRE2_ERROR_NULL;