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

This commit is contained in:
Zoltán Herczeg 2018-11-25 17:11:52 +00:00
parent 8187224514
commit 57f1eca640
2 changed files with 37 additions and 3 deletions

View File

@ -83,6 +83,8 @@ compiler complains).
20. Added "fork" support for VMS to pcre2grep, for running an external program 20. Added "fork" support for VMS to pcre2grep, for running an external program
via a string callout. via a string callout.
21. Improve MAP_JIT flag usage on MacOS. Patch by Rich Siegel.
Version 10.32 10-September-2018 Version 10.32 10-September-2018
------------------------------- -------------------------------

View File

@ -94,6 +94,38 @@ static SLJIT_INLINE void free_chunk(void *chunk, sljit_uw size)
#else #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) static SLJIT_INLINE void* alloc_chunk(sljit_uw size)
{ {
void *retval; void *retval;
@ -103,17 +135,17 @@ static SLJIT_INLINE void* alloc_chunk(sljit_uw size)
int flags = MAP_PRIVATE | MAP_ANON; int flags = MAP_PRIVATE | MAP_ANON;
#ifdef MAP_JIT #ifdef MAP_JIT
flags |= MAP_JIT; flags |= get_map_jit_flag();
#endif #endif
retval = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, flags, -1, 0); retval = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, flags, -1, 0);
#else #else /* !MAP_ANON */
if (dev_zero < 0) { if (dev_zero < 0) {
if (open_dev_zero()) if (open_dev_zero())
return NULL; return NULL;
} }
retval = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, dev_zero, 0); 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; return (retval != MAP_FAILED) ? retval : NULL;
} }