From b876d6dadaaff8f1deb91c54513a1e59e40b2ef2 Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sat, 17 Jan 2015 12:55:04 +0100 Subject: [PATCH 1/2] OpenBSD/x86: Better executable memory allocation for W^X mode. --- src/lj_mcode.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lj_mcode.c b/src/lj_mcode.c index f8f8406a..d95ebeb1 100644 --- a/src/lj_mcode.c +++ b/src/lj_mcode.c @@ -145,7 +145,7 @@ static void mcode_free(jit_State *J, void *p, size_t sz) /* -- MCode area protection ----------------------------------------------- */ -/* Define this ONLY if the page protection twiddling becomes a bottleneck. */ +/* Define this ONLY if page protection twiddling becomes a bottleneck. */ #ifdef LUAJIT_UNPROTECT_MCODE /* It's generally considered to be a potential security risk to have @@ -252,7 +252,20 @@ static void *mcode_alloc(jit_State *J, size_t sz) #else /* All memory addresses are reachable by relative jumps. */ -#define mcode_alloc(J, sz) mcode_alloc_at((J), 0, (sz), MCPROT_GEN) +static void *mcode_alloc(jit_State *J, size_t sz) +{ +#ifdef __OpenBSD__ + /* Allow better executable memory allocation for OpenBSD W^X mode. */ + void *p = mcode_alloc_at(J, 0, sz, MCPROT_RUN); + if (p && mcode_setprot(p, sz, MCPROT_GEN)) { + mcode_free(J, p, sz); + return NULL; + } + return p; +#else + return mcode_alloc_at(J, 0, sz, MCPROT_GEN); +#endif +} #endif From 7f013005f61b82300d4ec591fd4cec59a74d62ff Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sat, 17 Jan 2015 14:50:41 +0100 Subject: [PATCH 2/2] Don't compile IR_RETF after CALLT to ff with-side effects. --- src/lj_record.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lj_record.c b/src/lj_record.c index 19f17639..843108c8 100644 --- a/src/lj_record.c +++ b/src/lj_record.c @@ -745,6 +745,8 @@ void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults) } else if (J->parent == 0 && !bc_isret(bc_op(J->cur.startins))) { /* Return to lower frame would leave the loop in a root trace. */ lj_trace_err(J, LJ_TRERR_LLEAVE); + } else if (J->needsnap) { /* Tailcalled to ff with side-effects. */ + lj_trace_err(J, LJ_TRERR_NYIRETL); /* No way to insert snapshot here. */ } else { /* Return to lower frame. Guard for the target we return to. */ TRef trpt = lj_ir_kgc(J, obj2gco(pt), IRT_PROTO); TRef trpc = lj_ir_kptr(J, (void *)frame_pc(frame));