Fix plat_mmap on FreeBSD (#1980)

* Fix plat_mmap on FreeBSD

* Same for old codegen backend

* ...and for new codegen backend
This commit is contained in:
Cacodemon345
2022-01-07 14:58:59 +06:00
committed by GitHub
parent 95c223e9cc
commit 2da187c0bd
3 changed files with 5 additions and 5 deletions

View File

@@ -67,7 +67,7 @@ void codegen_init()
#if _WIN64 #if _WIN64
codeblock = VirtualAlloc(NULL, BLOCK_SIZE * sizeof(codeblock_t), MEM_COMMIT, PAGE_EXECUTE_READWRITE); codeblock = VirtualAlloc(NULL, BLOCK_SIZE * sizeof(codeblock_t), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
#elif defined(__unix__) || defined(__APPLE__) #elif defined(__unix__) || defined(__APPLE__)
codeblock = mmap(NULL, BLOCK_SIZE * sizeof(codeblock_t), PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, 0, 0); codeblock = mmap(NULL, BLOCK_SIZE * sizeof(codeblock_t), PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
#else #else
codeblock = malloc(BLOCK_SIZE * sizeof(codeblock_t)); codeblock = malloc(BLOCK_SIZE * sizeof(codeblock_t));
#endif #endif

View File

@@ -39,9 +39,9 @@ void codegen_allocator_init()
/* TODO: check deployment target: older Intel-based versions of macOS don't play /* TODO: check deployment target: older Intel-based versions of macOS don't play
nice with MAP_JIT. */ nice with MAP_JIT. */
#elif defined(__APPLE__) && defined(MAP_JIT) #elif defined(__APPLE__) && defined(MAP_JIT)
mem_block_alloc = mmap(0, MEM_BLOCK_NR * MEM_BLOCK_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE|MAP_JIT, 0, 0); mem_block_alloc = mmap(0, MEM_BLOCK_NR * MEM_BLOCK_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE|MAP_JIT, -1, 0);
#else #else
mem_block_alloc = mmap(0, MEM_BLOCK_NR * MEM_BLOCK_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, 0, 0); mem_block_alloc = mmap(0, MEM_BLOCK_NR * MEM_BLOCK_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
#endif #endif
for (c = 0; c < MEM_BLOCK_NR; c++) for (c = 0; c < MEM_BLOCK_NR; c++)

View File

@@ -374,9 +374,9 @@ void *
plat_mmap(size_t size, uint8_t executable) plat_mmap(size_t size, uint8_t executable)
{ {
#if defined __APPLE__ && defined MAP_JIT #if defined __APPLE__ && defined MAP_JIT
void *ret = mmap(0, size, PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0), MAP_ANON | MAP_PRIVATE | (executable ? MAP_JIT : 0), 0, 0); void *ret = mmap(0, size, PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0), MAP_ANON | MAP_PRIVATE | (executable ? MAP_JIT : 0), -1, 0);
#else #else
void *ret = mmap(0, size, PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0), MAP_ANON | MAP_PRIVATE, 0, 0); void *ret = mmap(0, size, PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0), MAP_ANON | MAP_PRIVATE, -1, 0);
#endif #endif
return (ret < 0) ? NULL : ret; return (ret < 0) ? NULL : ret;
} }