diff options
author | Mike Dalessio <mike.dalessio@gmail.com> | 2021-02-11 12:13:14 -0500 |
---|---|---|
committer | Alan Wu <XrXr@users.noreply.github.com> | 2021-10-20 18:19:29 -0400 |
commit | 7a75e9bbaf47ce597361f7a9e7c8550a5d7e15ed (patch) | |
tree | c38f9d105976abe727ee42b50a19d74913610033 | |
parent | 05d36f31ca919a2cc1c2db210dd70639457dca35 (diff) |
ujit_asm: if mmap() fails with the address hint, try without
valgrind doesn't seem to support the address hint, and so the fallback
to using NULL will allow valgrind to run.
-rw-r--r-- | ujit_asm.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/ujit_asm.c b/ujit_asm.c index a5d7f480bc..c580414539 100644 --- a/ujit_asm.c +++ b/ujit_asm.c @@ -137,9 +137,19 @@ uint8_t* alloc_exec_mem(uint32_t mem_size) 0 ); + if (mem_block == MAP_FAILED) { + mem_block = (uint8_t*)mmap( + NULL, // try again without the address hint (e.g., valgrind) + mem_size, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_PRIVATE | MAP_ANONYMOUS, + -1, + 0 + ); + } + // Check that the memory mapping was successful - if (mem_block == MAP_FAILED) - { + if (mem_block == MAP_FAILED) { fprintf(stderr, "mmap call failed\n"); exit(-1); } |