Aaron Bieber <aa...@bolddaemon.com> writes: Accidently only sent this to tedu@ :P
Ted Unangst <t...@tedunangst.com> writes: On i386, it's better for a jit to ask for exec memory upfront, so uvm knows to place it in the exec segment. Otherwise, if you mmap non-exec and mprotect it, you wind up with a high mapping and the segment must be enlarged to cover the whole process. I sent Mike a slightly different diff; this is what he ended up committing to git. I think we should add it to the port. Here is the diff. I don't currently have an i386 box to test, so if someone could try it, that would be awesome :D OK? Index: Makefile =================================================================== RCS file: /cvs/ports/lang/luajit/Makefile,v retrieving revision 1.14 diff -u -p -r1.14 Makefile --- Makefile 2 Jun 2014 19:43:50 -0000 1.14 +++ Makefile 19 Jan 2015 17:23:40 -0000 @@ -11,7 +11,7 @@ COMMENT = just-in-time compiler for Lua V = 2.0.3 DISTNAME = LuaJIT-${V} PKGNAME = ${DISTNAME:L} -REVISION = 1 +REVISION = 2 CATEGORIES = lang Index: patches/patch-src_lj_mcode_c =================================================================== RCS file: patches/patch-src_lj_mcode_c diff -N patches/patch-src_lj_mcode_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-src_lj_mcode_c 19 Jan 2015 17:23:40 -0000 @@ -0,0 +1,34 @@ +$OpenBSD$ +--- src/lj_mcode.c.orig Wed Mar 12 06:10:00 2014 ++++ src/lj_mcode.c Mon Jan 19 10:21:45 2015 +@@ -145,7 +145,7 @@ static void mcode_free(jit_State *J, void *p, size_t s + + /* -- 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 +