On linux x86_64, to set up an address space with 32-bit pointers only, I use the function (In Rust):
let big_heap = libc::mmap(std::ptr_null_mut() as *mut libc::c_void,
MAX_HEAP_SIZE, libc::PROT_READ | libc::PROT_WRITE,
libc::MAP_PRIVATE | libc::MAP_32BIT | libc::MAP_ANONYMOUS, -1, 0);
Or alternatively pass a 32 bit value as the first argument to mmap
and use libc::MAP_FIXED
.
There seems to be no libc::MAP_32BIT
on macOS. I tried setting the first argument to some constant and with MAP_FIXED
, sometimes it works, sometimes it crashes with failure to create memory.
Is there any way to reserve an address space safely and that resides in 32-bits on macOS? I considered allocating a 64-bit value, and using 32-bit offsets from this value, but it produces unacceptable runtime overhead, having to pass the base pointer around everywhere.