Hello! I've made a library for allocating executable memory on multiple platforms safely with all security implications:
https://github.com/playXE/jit-allocator/
It supports regular RWX memory, dual mapping and macOS's W^X memory + allocation does not happen on page granularity but the crate has bitmap allocation and allows freeing arbitrary functions without problems. If I would write PR for cranelift-jit to use it would it get merged?
How can you handle freeing a function which shares a page with a function that is currently being called? Do you ensure all functions get separate pages?
bjorn3 said:
How can you handle freeing a function which shares a page with a function that is currently being called? Do you ensure all functions get separate pages?
It's pretty simple, I do not allocate page per function but instead use bitmap to search holes in large blocks of like 64KB of memory.
<https://github.com/playXE/jit-allocator/blob/main/src/allocator.rs#L878>
<https://github.com/playXE/jit-allocator/blob/main/src/allocator.rs#L1008>
If there is no memory left then new block is allocated, it might be sized up to 32MB, and allocation is done in granularity of 64, 128, 256 bytes
Last updated: Dec 23 2024 at 12:05 UTC