diff options
Diffstat (limited to '')
-rw-r--r-- | src/lj_mcode.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/lj_mcode.c b/src/lj_mcode.c index b34d7c85..b3efbc55 100644 --- a/src/lj_mcode.c +++ b/src/lj_mcode.c | |||
@@ -97,10 +97,15 @@ static int mcode_setprot(void *p, size_t sz, DWORD prot) | |||
97 | #define MCPROT_RW (PROT_READ|PROT_WRITE) | 97 | #define MCPROT_RW (PROT_READ|PROT_WRITE) |
98 | #define MCPROT_RX (PROT_READ|PROT_EXEC) | 98 | #define MCPROT_RX (PROT_READ|PROT_EXEC) |
99 | #define MCPROT_RWX (PROT_READ|PROT_WRITE|PROT_EXEC) | 99 | #define MCPROT_RWX (PROT_READ|PROT_WRITE|PROT_EXEC) |
100 | #ifdef PROT_MPROTECT | ||
101 | #define MCPROT_CREATE (PROT_MPROTECT(MCPROT_RWX)) | ||
102 | #else | ||
103 | #define MCPROT_CREATE 0 | ||
104 | #endif | ||
100 | 105 | ||
101 | static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot) | 106 | static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot) |
102 | { | 107 | { |
103 | void *p = mmap((void *)hint, sz, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); | 108 | void *p = mmap((void *)hint, sz, prot|MCPROT_CREATE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); |
104 | if (p == MAP_FAILED) { | 109 | if (p == MAP_FAILED) { |
105 | if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL); | 110 | if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL); |
106 | p = NULL; | 111 | p = NULL; |
@@ -238,7 +243,7 @@ static void *mcode_alloc(jit_State *J, size_t sz) | |||
238 | /* All memory addresses are reachable by relative jumps. */ | 243 | /* All memory addresses are reachable by relative jumps. */ |
239 | static void *mcode_alloc(jit_State *J, size_t sz) | 244 | static void *mcode_alloc(jit_State *J, size_t sz) |
240 | { | 245 | { |
241 | #if defined(__OpenBSD__) || LJ_TARGET_UWP | 246 | #if defined(__OpenBSD__) || defined(__NetBSD__) || LJ_TARGET_UWP |
242 | /* Allow better executable memory allocation for OpenBSD W^X mode. */ | 247 | /* Allow better executable memory allocation for OpenBSD W^X mode. */ |
243 | void *p = mcode_alloc_at(J, 0, sz, MCPROT_RUN); | 248 | void *p = mcode_alloc_at(J, 0, sz, MCPROT_RUN); |
244 | if (p && mcode_setprot(p, sz, MCPROT_GEN)) { | 249 | if (p && mcode_setprot(p, sz, MCPROT_GEN)) { |