Revision: 1174
http://www.exim.org/viewvc/pcre2?view=rev&revision=1174
Author: zherczeg
Date: 2019-10-01 14:46:41 +0100 (Tue, 01 Oct 2019)
Log Message:
-----------
Better description for jit-sealloc option and early check for executable memory.
Modified Paths:
--------------
code/trunk/CMakeLists.txt
code/trunk/README
code/trunk/configure.ac
code/trunk/src/pcre2_jit_compile.c
Modified: code/trunk/CMakeLists.txt
===================================================================
--- code/trunk/CMakeLists.txt 2019-09-26 16:10:30 UTC (rev 1173)
+++ code/trunk/CMakeLists.txt 2019-10-01 13:46:41 UTC (rev 1174)
@@ -178,7 +178,7 @@
"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.")
Modified: code/trunk/README
===================================================================
--- code/trunk/README 2019-09-26 16:10:30 UTC (rev 1173)
+++ code/trunk/README 2019-10-01 13:46:41 UTC (rev 1174)
@@ -164,9 +164,11 @@
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
Modified: code/trunk/configure.ac
===================================================================
--- code/trunk/configure.ac 2019-09-26 16:10:30 UTC (rev 1173)
+++ code/trunk/configure.ac 2019-10-01 13:46:41 UTC (rev 1174)
@@ -161,7 +161,7 @@
# 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)
Modified: code/trunk/src/pcre2_jit_compile.c
===================================================================
--- code/trunk/src/pcre2_jit_compile.c 2019-09-26 16:10:30 UTC (rev 1173)
+++ code/trunk/src/pcre2_jit_compile.c 2019-10-01 13:46:41 UTC (rev 1174)
@@ -13740,6 +13740,8 @@
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
@@ -13746,6 +13748,25 @@
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;