My main problem is that I need to enable several OS processes to exchange data through a large heap of shared memory, which maps to the same address ranges in all processes. (To make sure the pointer values ββare really significant.)
Now I am having problems with the fact that part of the program / library uses standard malloc / free, and it seems to me that the base implementation does not take into account the mappings that I create using mmap. Or, another option is that I create mappings in regions that malloc has already planned to use.
Unfortunately, I cannot guarantee 100% identical malloc / free behavior in all processes before setting up mmap mappings.
This leads me to have the MAP_FIXED flag in mmap. The first process uses 0x0 as the base address to ensure that the display range is at least somehow reasonable, but doesn't seem to be shared with other processes. (The binary is also associated with -Wl, -no_pie.)
I tried to find out if I could query the system to find out which pages it plans to use for malloc by reading malloc_default_zone , but this API does not seem to offer what I need.
Is there a way to ensure that malloc does not use specific memory pages / address ranges?
(It should work on OSX. Linux tips that guide me in the right direction are also appreciated.)
smarr source share