0

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.

stevenkucera
  • 3,855
  • 2
  • 18
  • 13
  • Does this answer your question? [How to 'malloc' within first 4GB on x86\_64](https://stackoverflow.com/questions/28661393/how-to-malloc-within-first-4gb-on-x86-64) – Inline Apr 15 '21 at 08:40

1 Answers1

0

For what it's worth, MAP_32BIT actually does exist on macOS since Catalina. It was seemingly gated behind an entitlement before 10.15.4, but should be usable after that.

Source: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/mman.h#L155

Ryan McGrath
  • 2,042
  • 14
  • 23