11 个版本
0.2.8 | 2023年7月6日 |
---|---|
0.2.7 | 2023年7月6日 |
0.2.5 | 2023年6月27日 |
0.1.1 | 2023年6月25日 |
156 在 内存管理 中
每月下载量 32
在 2 个 Crates 中使用(通过 macroassembler)
86KB
2K SLoC
jit-allocator
一个简单的可执行代码内存分配器。使用 JitAllocator
类型来分配/释放内存,并使用 virtual_memory
模块函数来启用对可执行代码的正确访问。因此,如果您想分配新代码以执行,通常如下所示
use jit_allocator::*;
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)?;
}
依赖项
~0.8–9MB
~63K SLoC