| Crates.io | jit-allocator2 |
| lib.rs | jit-allocator2 |
| version | 0.2.9 |
| created_at | 2025-05-30 01:04:08.419065+00 |
| updated_at | 2025-05-30 01:04:08.419065+00 |
| description | An executable code allocator. Fork for jit-allocator |
| homepage | |
| repository | https://github.com/tremwil/jit-allocator2 |
| max_upload_size | |
| id | 1694582 |
| size | 95,763 |
Maintained fork of jit-allocator. If development ends up continuing on the original repository, this will become a mirror.
A simple memory allocator for executable code. Use JitAllocator type to allocate/release memory and virtual_memory module functions to enable proper access for executable code. So if you want to allocate a new code to execute it is usually done like this:
use jit_allocator2::*;
let compiled_code = ...;
let compiled_code_size = ...;
let mut jit_allocator = JitAllocator::new(Default::default());
let (rx, rw) = jit_allocator.alloc(size)?;
protect_jit_memory(ProtectJitAccess::ReadWrite); // allows to write to RWX code in current thread,
// it is no-op on all platforms except macOS AArch64
unsafe { copy_nonoverlapping(compiled_code, rw, compiled_code_size); }
protect_jit_memory(ProtectJitAccess::ReadExecute); // disables writes to RWX code in current thread,
// it is no-op on all platforms except macOS AArch64
flush_instruction_cache(rx, compiled_code_size); // flush icache, not required on x86-64
// but required on other platforms due
// to lack of coherent dcache/icache.
// When you're done with your machine code you can release it:
unsafe {
jit_allocator.release(rx)?;
}