Skip to content

Commit 7f71ad0

Browse files
author
zherczeg
committed
Improve MAP_JIT flag usage on MacOS. Patch by Rich Siegel.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1742 2f5784b3-3f2a-0410-8824-cb99058d5e15
1 parent a65e1b6 commit 7f71ad0

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ minimum of zero, an incorrect "match must start with this character" could be
4545
recorded. Example: /(?&xxx)*ABC(?<xxx>XYZ)/ would (incorrectly) expect 'A' to
4646
be the first character of a match.
4747

48+
9. Improve MAP_JIT flag usage on MacOS. Patch by Rich Siegel.
49+
4850

4951
Version 8.42 20-March-2018
5052
--------------------------

sljit/sljitExecAllocator.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,38 @@ static SLJIT_INLINE void free_chunk(void *chunk, sljit_uw size)
9494

9595
#else
9696

97+
#ifdef MAP_JIT
98+
99+
static SLJIT_INLINE int get_map_jit_flag()
100+
{
101+
#ifdef TARGET_OS_MAC
102+
/* On macOS systems, returns MAP_JIT if it is defined _and_ we're running on a version
103+
of macOS where it's OK to have more than one JIT block. On non-macOS systems, returns
104+
MAP_JIT if it is defined. */
105+
106+
static dispatch_once_t _inited;
107+
static int map_jit_flag;
108+
109+
dispatch_once(&_inited,
110+
^() {
111+
struct utsname name;
112+
113+
uname(&name);
114+
115+
/* Kernel version for 10.14.0 (Mojave) */
116+
if (atoi(name.release) >= 18)
117+
map_jit_flag = MAP_JIT;
118+
}
119+
);
120+
121+
return map_jit_flag;
122+
#else /* !TARGET_OS_MAC */
123+
return MAP_JIT;
124+
#endif /* TARGET_OS_MAC */
125+
}
126+
127+
#endif /* MAP_JIT */
128+
97129
static SLJIT_INLINE void* alloc_chunk(sljit_uw size)
98130
{
99131
void *retval;
@@ -103,17 +135,17 @@ static SLJIT_INLINE void* alloc_chunk(sljit_uw size)
103135
int flags = MAP_PRIVATE | MAP_ANON;
104136

105137
#ifdef MAP_JIT
106-
flags |= MAP_JIT;
138+
flags |= get_map_jit_flag();
107139
#endif
108140

109141
retval = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, flags, -1, 0);
110-
#else
142+
#else /* !MAP_ANON */
111143
if (dev_zero < 0) {
112144
if (open_dev_zero())
113145
return NULL;
114146
}
115147
retval = mmap(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, dev_zero, 0);
116-
#endif
148+
#endif /* MAP_ANON */
117149

118150
return (retval != MAP_FAILED) ? retval : NULL;
119151
}

0 commit comments

Comments
 (0)