From cb6566caf17869070d4d0dbdc0d856c2dc67b48d Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sun, 3 Jan 2021 00:39:25 -0800 Subject: [PATCH] Switch to mmap w/ executable memory. --- ueforth/common/core.h | 4 ++-- ueforth/posix/posix_main.c | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ueforth/common/core.h b/ueforth/common/core.h index 6283194..d51cf05 100644 --- a/ueforth/common/core.h +++ b/ueforth/common/core.h @@ -96,8 +96,8 @@ static cell_t *eval1(cell_t *sp, cell_t *call) { return sp; } -static void ueforth(const char *src, cell_t src_len) { - g_sys.heap = malloc(HEAP_SIZE); +static void ueforth(void *heap, const char *src, cell_t src_len) { + g_sys.heap = (cell_t *) heap; register cell_t *sp = g_sys.heap; g_sys.heap += STACK_SIZE; register cell_t *rp = g_sys.heap; g_sys.heap += STACK_SIZE; register cell_t tos = 0, *ip, t, w; diff --git a/ueforth/posix/posix_main.c b/ueforth/posix/posix_main.c index d52d395..8e70117 100644 --- a/ueforth/posix/posix_main.c +++ b/ueforth/posix/posix_main.c @@ -1,9 +1,8 @@ #include -#include +#include #include "common/opcodes.h" -#define HEAP_SIZE (10 * 1024 * 1024) #define STACK_SIZE (16 * 1024) #define PLATFORM_OPCODE_LIST \ @@ -23,6 +22,9 @@ #include "gen/posix_boot.h" +#define HEAP_SIZE (10 * 1024 * 1024) + int main(int argc, char *argv[]) { - ueforth(boot, sizeof(boot)); + void *heap = mmap(0, HEAP_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + ueforth(heap, boot, sizeof(boot)); }