mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
NetBSD: Use PROT_MPROTECT() and disable getentropy().
Note: this is not an officially supported target. Contributed by David Carlier.
This commit is contained in:
parent
9442226825
commit
3217240b47
@ -256,6 +256,11 @@ static void *callback_mcode_init(global_State *g, uint32_t *page)
|
|||||||
#ifndef MAP_ANONYMOUS
|
#ifndef MAP_ANONYMOUS
|
||||||
#define MAP_ANONYMOUS MAP_ANON
|
#define MAP_ANONYMOUS MAP_ANON
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef PROT_MPROTECT
|
||||||
|
#define CCPROT_CREATE (PROT_MPROTECT(PROT_EXEC))
|
||||||
|
#else
|
||||||
|
#define CCPROT_CREATE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -271,7 +276,7 @@ static void callback_mcode_new(CTState *cts)
|
|||||||
if (!p)
|
if (!p)
|
||||||
lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);
|
lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);
|
||||||
#elif LJ_TARGET_POSIX
|
#elif LJ_TARGET_POSIX
|
||||||
p = mmap(NULL, sz, (PROT_READ|PROT_WRITE), MAP_PRIVATE|MAP_ANONYMOUS,
|
p = mmap(NULL, sz, (PROT_READ|PROT_WRITE|CCPROT_CREATE), MAP_PRIVATE|MAP_ANONYMOUS,
|
||||||
-1, 0);
|
-1, 0);
|
||||||
if (p == MAP_FAILED)
|
if (p == MAP_FAILED)
|
||||||
lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);
|
lj_err_caller(cts->L, LJ_ERR_FFI_CBACKOV);
|
||||||
|
@ -97,10 +97,15 @@ static int mcode_setprot(void *p, size_t sz, DWORD prot)
|
|||||||
#define MCPROT_RW (PROT_READ|PROT_WRITE)
|
#define MCPROT_RW (PROT_READ|PROT_WRITE)
|
||||||
#define MCPROT_RX (PROT_READ|PROT_EXEC)
|
#define MCPROT_RX (PROT_READ|PROT_EXEC)
|
||||||
#define MCPROT_RWX (PROT_READ|PROT_WRITE|PROT_EXEC)
|
#define MCPROT_RWX (PROT_READ|PROT_WRITE|PROT_EXEC)
|
||||||
|
#ifdef PROT_MPROTECT
|
||||||
|
#define MCPROT_CREATE (PROT_MPROTECT(MCPROT_RWX))
|
||||||
|
#else
|
||||||
|
#define MCPROT_CREATE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot)
|
static void *mcode_alloc_at(jit_State *J, uintptr_t hint, size_t sz, int prot)
|
||||||
{
|
{
|
||||||
void *p = mmap((void *)hint, sz, prot, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
void *p = mmap((void *)hint, sz, prot|MCPROT_CREATE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
||||||
if (p == MAP_FAILED) {
|
if (p == MAP_FAILED) {
|
||||||
if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL);
|
if (!hint) lj_trace_err(J, LJ_TRERR_MCODEAL);
|
||||||
p = NULL;
|
p = NULL;
|
||||||
@ -238,7 +243,7 @@ static void *mcode_alloc(jit_State *J, size_t sz)
|
|||||||
/* All memory addresses are reachable by relative jumps. */
|
/* All memory addresses are reachable by relative jumps. */
|
||||||
static void *mcode_alloc(jit_State *J, size_t sz)
|
static void *mcode_alloc(jit_State *J, size_t sz)
|
||||||
{
|
{
|
||||||
#if defined(__OpenBSD__) || LJ_TARGET_UWP
|
#if defined(__OpenBSD__) || defined(__NetBSD__) || LJ_TARGET_UWP
|
||||||
/* Allow better executable memory allocation for OpenBSD W^X mode. */
|
/* Allow better executable memory allocation for OpenBSD W^X mode. */
|
||||||
void *p = mcode_alloc_at(J, 0, sz, MCPROT_RUN);
|
void *p = mcode_alloc_at(J, 0, sz, MCPROT_RUN);
|
||||||
if (p && mcode_setprot(p, sz, MCPROT_GEN)) {
|
if (p && mcode_setprot(p, sz, MCPROT_GEN)) {
|
||||||
|
@ -121,7 +121,7 @@ static PRGR libfunc_rgr;
|
|||||||
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
|
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
|
||||||
#define LJ_TARGET_HAS_GETENTROPY 1
|
#define LJ_TARGET_HAS_GETENTROPY 1
|
||||||
#endif
|
#endif
|
||||||
#elif LJ_TARGET_BSD || LJ_TARGET_SOLARIS || LJ_TARGET_CYGWIN
|
#elif (LJ_TARGET_BSD && !defined(__NetBSD__)) || LJ_TARGET_SOLARIS || LJ_TARGET_CYGWIN
|
||||||
#define LJ_TARGET_HAS_GETENTROPY 1
|
#define LJ_TARGET_HAS_GETENTROPY 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user