gpsp/memmap.c
David Guillen Fandos 3a7fedb8fb Simplify MMAP machinery for Win/Lin/Mac/Android
This gets rid of the bloated memmap_win32.c in favour of a much simpler
wrapper. This will be needed in the future since the wrapper does not
support MAP_FIXED maps (necessary for some platforms)
2021-11-05 18:23:05 +01:00

35 lines
634 B
C

#include "memmap.h"
#ifdef MMAP_JIT_CACHE
#ifdef WIN32
#include <windows.h>
#include <io.h>
void *map_jit_block(unsigned size) {
return VirtualAlloc(0, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
}
void unmap_jit_block(void *bufptr, unsigned size) {
VirtualFree(bufptr, 0, MEM_RELEASE);
}
#else
#include <sys/mman.h>
// Posix implementation
void *map_jit_block(unsigned size) {
return mmap(0, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0);
}
void unmap_jit_block(void *bufptr, unsigned size) {
munmap(bufptr, size);
}
#endif /* WIN32 */
#endif /* MMAP_JIT_CACHE */