summaryrefslogtreecommitdiff
path: root/src/lj_mcode.c
diff options
context:
space:
mode:
authorMike Pall <mike>2010-02-27 19:53:14 +0100
committerMike Pall <mike>2010-02-27 20:18:11 +0100
commitec78d3177e1b24c24a89f0e83c19eb3e3e0f8023 (patch)
tree81d6af7daf9c7fa3e973cc3d8d7861a09880b05c /src/lj_mcode.c
parent52b7651327b2aec4f12ae47f3ce5b56b1fb55996 (diff)
downloadluajit-ec78d3177e1b24c24a89f0e83c19eb3e3e0f8023.tar.gz
luajit-ec78d3177e1b24c24a89f0e83c19eb3e3e0f8023.tar.bz2
luajit-ec78d3177e1b24c24a89f0e83c19eb3e3e0f8023.zip
Correctly align and free allocated machine code areas.
Bump default mcode area size to 64K for x64.
Diffstat (limited to 'src/lj_mcode.c')
-rw-r--r--src/lj_mcode.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lj_mcode.c b/src/lj_mcode.c
index e9921601..be3ea1c0 100644
--- a/src/lj_mcode.c
+++ b/src/lj_mcode.c
@@ -110,10 +110,10 @@ static void mcode_free(jit_State *J, void *p, size_t sz)
110/* Get memory within relative jump distance of our code in 64 bit mode. */ 110/* Get memory within relative jump distance of our code in 64 bit mode. */
111static void *mcode_alloc(jit_State *J, size_t sz, int prot) 111static void *mcode_alloc(jit_State *J, size_t sz, int prot)
112{ 112{
113 /* Target an address in the static assembler code. 113 /* Target an address in the static assembler code (64K aligned).
114 ** Try addresses within a distance of target-1GB+1MB .. target+1GB-1MB. 114 ** Try addresses within a distance of target-1GB+1MB .. target+1GB-1MB.
115 */ 115 */
116 uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler; 116 uintptr_t target = (uintptr_t)(void *)lj_vm_exit_handler & ~(uintptr_t)0xffff;
117 const uintptr_t range = (1u<<31) - (1u << 21); 117 const uintptr_t range = (1u<<31) - (1u << 21);
118 int i; 118 int i;
119 /* First try a contiguous area below the last one. */ 119 /* First try a contiguous area below the last one. */
@@ -128,7 +128,7 @@ static void *mcode_alloc(jit_State *J, size_t sz, int prot)
128 uintptr_t hint; 128 uintptr_t hint;
129 void *p; 129 void *p;
130 do { 130 do {
131 hint = LJ_PRNG_BITS(J, 15) << 16; 131 hint = LJ_PRNG_BITS(J, 15) << 16; /* 64K aligned. */
132 } while (!(hint + sz < range && 132 } while (!(hint + sz < range &&
133 target + hint - (range>>1) < (uintptr_t)1<<47)); 133 target + hint - (range>>1) < (uintptr_t)1<<47));
134 p = mcode_alloc_at(J, target + hint - (range>>1), sz, prot); 134 p = mcode_alloc_at(J, target + hint - (range>>1), sz, prot);