I am generating tons of small fragments of executable machine code dynamically, all of them with unpredictable sizes and lifetimes. Currently I am using a naive executable mmap
preallocated region, but this is only provisional due to the eventual memory exhaustion. I did not implemented any memory reclamation mechanism and I do not want to: this is a hard problem (hard to debug bugs, fragmentation, multi-threading, etc.).
What I need is a library that implements the malloc
/free
protocol but with the executable bit enabled.
Is there any malloc
implementation that offers this option (can be a compile-time flag)?
Further details to answer comments:
- My current platform is Linux on x86_64, but Windows and ARM 32/64 support will be welcome (but not a must).
- Memory never will be shared with different processes, but the allocator must be multi-threading aware and, if possible, scalable in this scenario.