summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gen_x86.c1
-rw-r--r--mem.c6
2 files changed, 4 insertions, 3 deletions
diff --git a/gen_x86.c b/gen_x86.c
index 2da8055..2840ba0 100644
--- a/gen_x86.c
+++ b/gen_x86.c
@@ -207,7 +207,6 @@ void check_alloc_code(code_info *code, uint32_t inst_size)
//new chunk is not contiguous with the current one
jmp_nocheck(code, next_code);
code->cur = next_code;
- code->last = next_code + size/sizeof(RESERVE_WORDS);
}
code->last = next_code + size/sizeof(code_word) - RESERVE_WORDS;
}
diff --git a/mem.c b/mem.c
index f3442bf..8f0094b 100644
--- a/mem.c
+++ b/mem.c
@@ -30,8 +30,10 @@ void * alloc_code(size_t *size)
if (ret) {
return ret;
}
- *size += PAGE_SIZE - (*size & (PAGE_SIZE - 1));
- ret = mmap(NULL, *size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
+ if (*size & (PAGE_SIZE -1)) {
+ *size += PAGE_SIZE - (*size & (PAGE_SIZE - 1));
+ }
+ ret = mmap(next, *size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
if (ret == MAP_FAILED) {
perror("alloc_code");
return NULL;