diff options
author | Mike Pall <mike> | 2021-03-29 10:41:52 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2021-03-29 10:41:52 +0200 |
commit | 3217240b4767d481f7dd5e7036721aec643a1f11 (patch) | |
tree | 9d3a196c6cc520d09f99f5cf4e1719911d663b17 | |
parent | 9442226825e8e5be38474492adf7742dd47a4902 (diff) | |
download | luajit-3217240b4767d481f7dd5e7036721aec643a1f11.tar.gz luajit-3217240b4767d481f7dd5e7036721aec643a1f11.tar.bz2 luajit-3217240b4767d481f7dd5e7036721aec643a1f11.zip |
NetBSD: Use PROT_MPROTECT() and disable getentropy().
Note: this is not an officially supported target.
Contributed by David Carlier.
-rw-r--r-- | src/lj_ccallback.c | 7 | ||||
-rw-r--r-- | src/lj_mcode.c | 9 | ||||
-rw-r--r-- | src/lj_prng.c | 2 |
3 files changed, 14 insertions, 4 deletions
diff --git a/src/lj_ccallback.c b/src/lj_ccallback.c index 9de86258..8d6cb737 100644 --- a/src/lj_ccallback.c +++ b/src/lj_ccallback.c | |||
@@ -256,6 +256,11 @@ static void *callback_mcode_init(global_State *g, uint32_t *page) | |||
256 | #ifndef MAP_ANONYMOUS | 256 | #ifndef MAP_ANONYMOUS |
257 | #define MAP_ANONYMOUS MAP_ANON | 257 | #define MAP_ANONYMOUS MAP_ANON |
258 | #endif | 258 | #endif |
259 | #ifdef PROT_MPROTECT | ||
260 | #define CCPROT_CREATE (PROT_MPROTECT(PROT_EXEC)) | ||
261 | #else | ||
262 | #define CCPROT_CREATE 0 | ||
263 | #endif | ||
259 | 264 | ||
260 | #endif | 265 | #endif |
261 | 266 | ||
@@ -271,7 +276,7 @@ static void callback_mcode_new(CTState *cts) | |||
271 | if (!p) | 276 | if (!p) |
272 | lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV); | 277 | lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV); |
273 | #elif LJ_TARGET_POSIX | 278 | #elif LJ_TARGET_POSIX |
274 | p = mmap(NULL, sz, (PROT_READ|PROT_WRITE), MAP_PRIVATE|MAP_ANONYMOUS, | 279 | p = mmap(NULL, sz, (PROT_READ|PROT_WRITE|CCPROT_CREATE), MAP_PRIVATE|MAP_ANONYMOUS, |
275 | -1, 0); | 280 | -1, 0); |
276 | if (p == MAP_FAILED) | 281 | if (p == MAP_FAILED) |
277 | lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV); | 282 | lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV); |
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)) { |
diff --git a/src/lj_prng.c b/src/lj_prng.c index 0c4a5cf0..a390662d 100644 --- a/src/lj_prng.c +++ b/src/lj_prng.c | |||
@@ -121,7 +121,7 @@ static PRGR libfunc_rgr; | |||
121 | #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 | 121 | #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 |
122 | #define LJ_TARGET_HAS_GETENTROPY 1 | 122 | #define LJ_TARGET_HAS_GETENTROPY 1 |
123 | #endif | 123 | #endif |
124 | #elif LJ_TARGET_BSD || LJ_TARGET_SOLARIS || LJ_TARGET_CYGWIN | 124 | #elif (LJ_TARGET_BSD && !defined(__NetBSD__)) || LJ_TARGET_SOLARIS || LJ_TARGET_CYGWIN |
125 | #define LJ_TARGET_HAS_GETENTROPY 1 | 125 | #define LJ_TARGET_HAS_GETENTROPY 1 |
126 | #endif | 126 | #endif |
127 | 127 | ||