From 274dececcc084ba86026d8ac3f18edf915f79f24 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Thu, 4 May 2017 21:00:25 -0700 Subject: Fix some inconsequential issues in code for executable memory allocation noticed while tracking down a different issue --- gen_x86.c | 1 - mem.c | 6 ++++-- 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; -- cgit v1.2.3