Platform: Mac OS X
Lang: Obj-C/C
Is it possible to somehow make 'malloc' to allocate memory within first 4GB of process address space ?
I'm emulating i386 stack and need to guarantee that address will lie within allowed 32bit range.
Using mmap+MAP_FIXED requires to RESERVE memory before any 'malloc', it's not quite convenient. 'malloc' with constraints would be much more handy.
It is not possible, unless you code your own implementation of malloc
(or dive into the implementation details of some existing malloc
then change it to suit your needs).
Most malloc
-s implementations are using the system mmap
(or sbrk
) syscalls (see e.g. syscalls(2) on Linux, and memory(3) for MacOSX), and these are giving some arbitrary memory addresses (e.g. because of ASLR, which is very useful).
PS. On Linux, you might use mmap(2) with MAP_NORESERVE
or MAP_32BIT
, but MacOSX mmap(2) does not seem to have them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With