diff options
author | Mike Pall <mike> | 2015-01-17 12:55:04 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2015-01-17 12:55:04 +0100 |
commit | b876d6dadaaff8f1deb91c54513a1e59e40b2ef2 (patch) | |
tree | c34e9b4e1123f5af48938fc84bd6dbf9f3af1c1b | |
parent | 86913b9bbf75c78a5dcfa2bf6071db8db7df7c51 (diff) | |
download | luajit-b876d6dadaaff8f1deb91c54513a1e59e40b2ef2.tar.gz luajit-b876d6dadaaff8f1deb91c54513a1e59e40b2ef2.tar.bz2 luajit-b876d6dadaaff8f1deb91c54513a1e59e40b2ef2.zip |
OpenBSD/x86: Better executable memory allocation for W^X mode.
-rw-r--r-- | src/lj_mcode.c | 17 |
1 files 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) | |||
145 | 145 | ||
146 | /* -- MCode area protection ----------------------------------------------- */ | 146 | /* -- MCode area protection ----------------------------------------------- */ |
147 | 147 | ||
148 | /* Define this ONLY if the page protection twiddling becomes a bottleneck. */ | 148 | /* Define this ONLY if page protection twiddling becomes a bottleneck. */ |
149 | #ifdef LUAJIT_UNPROTECT_MCODE | 149 | #ifdef LUAJIT_UNPROTECT_MCODE |
150 | 150 | ||
151 | /* It's generally considered to be a potential security risk to have | 151 | /* 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) | |||
252 | #else | 252 | #else |
253 | 253 | ||
254 | /* All memory addresses are reachable by relative jumps. */ | 254 | /* All memory addresses are reachable by relative jumps. */ |
255 | #define mcode_alloc(J, sz) mcode_alloc_at((J), 0, (sz), MCPROT_GEN) | 255 | static void *mcode_alloc(jit_State *J, size_t sz) |
256 | { | ||
257 | #ifdef __OpenBSD__ | ||
258 | /* Allow better executable memory allocation for OpenBSD W^X mode. */ | ||
259 | void *p = mcode_alloc_at(J, 0, sz, MCPROT_RUN); | ||
260 | if (p && mcode_setprot(p, sz, MCPROT_GEN)) { | ||
261 | mcode_free(J, p, sz); | ||
262 | return NULL; | ||
263 | } | ||
264 | return p; | ||
265 | #else | ||
266 | return mcode_alloc_at(J, 0, sz, MCPROT_GEN); | ||
267 | #endif | ||
268 | } | ||
256 | 269 | ||
257 | #endif | 270 | #endif |
258 | 271 | ||