Stream: cranelift

Topic: Change cranelift-jit allocator


view this post on Zulip Adel Prokurov (Jul 21 2023 at 12:02):

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?

Executable memory allocator with support for dual mapping and W^X protection - GitHub - playXE/jit-allocator: Executable memory allocator with support for dual mapping and W^X protection

view this post on Zulip bjorn3 (Jul 21 2023 at 13:41):

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?

view this post on Zulip Adel Prokurov (Jul 21 2023 at 14:09):

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: Nov 22 2024 at 16:03 UTC