pub trait JitAlloc {
// Required methods
fn alloc(&self, size: usize) -> Result<(*const u8, *mut u8), JitAllocError>;
unsafe fn release(&self, rx_ptr: *const u8) -> Result<(), JitAllocError>;
unsafe fn protect_jit_memory(
ptr: *const u8,
size: usize,
access: ProtectJitAccess,
);
unsafe fn flush_instruction_cache(rx_ptr: *const u8, size: usize);
}Expand description
Generic allocator providing virtual memory suitable for emitting code at runtime.
The API is meant to be a thin abstraction over the jit-allocator crate’s API, to allow it
to be swapped with other allocators.
Required Methods§
Sourcefn alloc(&self, size: usize) -> Result<(*const u8, *mut u8), JitAllocError>
fn alloc(&self, size: usize) -> Result<(*const u8, *mut u8), JitAllocError>
Allocates size bytes in the executable memory region.
Returns two pointers. One points to Read-Execute mapping and another to Read-Write mapping.
All code writes must go to the Read-Write mapping.
Sourceunsafe fn release(&self, rx_ptr: *const u8) -> Result<(), JitAllocError>
unsafe fn release(&self, rx_ptr: *const u8) -> Result<(), JitAllocError>
Releases the memory allocated by alloc.
§Safety
rx_ptrmust have been returned fromallocrx_ptrmust have been allocated from this allocatorrx_ptrmust not have been passed toreleasebeforerx_ptrmust point to read-execute part of memory returned fromalloc.
Sourceunsafe fn protect_jit_memory(
ptr: *const u8,
size: usize,
access: ProtectJitAccess,
)
unsafe fn protect_jit_memory( ptr: *const u8, size: usize, access: ProtectJitAccess, )
On hardened architectures with MAP_JIT-like memory flags, set the access for the current
thread.
This is expected to be a no-op on most platforms, but should be called before writing or executing JIT memory.
§Safety
ptrmust point at leastsizebytes of readable memory.
Sourceunsafe fn flush_instruction_cache(rx_ptr: *const u8, size: usize)
unsafe fn flush_instruction_cache(rx_ptr: *const u8, size: usize)
Flushes the instruction cache for (at least) the given slice of executable memory. Should be called after the JIT memory is ready to be executed.
On architectures with shared data/instruction caches, like x86_64, this is a no-op.
§Safety
rx_ptrmust point at leastsizebytes of Read-Execute memory.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl JitAlloc for RefCell<JitAllocator>
Available on crate feature bundled_jit_alloc only.
impl JitAlloc for RefCell<JitAllocator>
bundled_jit_alloc only.fn alloc(&self, size: usize) -> Result<(*const u8, *mut u8), JitAllocError>
unsafe fn release(&self, rx_ptr: *const u8) -> Result<(), JitAllocError>
unsafe fn flush_instruction_cache(rx_ptr: *const u8, size: usize)
unsafe fn protect_jit_memory( _ptr: *const u8, _size: usize, access: ProtectJitAccess, )
Source§impl JitAlloc for Mutex<JitAllocator>
Available on crate feature bundled_jit_alloc and non-crate feature no_std only.
impl JitAlloc for Mutex<JitAllocator>
bundled_jit_alloc and non-crate feature no_std only.fn alloc(&self, size: usize) -> Result<(*const u8, *mut u8), JitAllocError>
unsafe fn release(&self, rx_ptr: *const u8) -> Result<(), JitAllocError>
unsafe fn flush_instruction_cache(rx_ptr: *const u8, size: usize)
unsafe fn protect_jit_memory( _ptr: *const u8, _size: usize, access: ProtectJitAccess, )
Source§impl JitAlloc for RwLock<JitAllocator>
Available on crate feature bundled_jit_alloc and non-crate feature no_std only.
impl JitAlloc for RwLock<JitAllocator>
bundled_jit_alloc and non-crate feature no_std only.fn alloc(&self, size: usize) -> Result<(*const u8, *mut u8), JitAllocError>
unsafe fn release(&self, rx_ptr: *const u8) -> Result<(), JitAllocError>
unsafe fn flush_instruction_cache(rx_ptr: *const u8, size: usize)
unsafe fn protect_jit_memory( _ptr: *const u8, _size: usize, access: ProtectJitAccess, )
Source§impl<J: JitAlloc> JitAlloc for &J
impl<J: JitAlloc> JitAlloc for &J
fn alloc(&self, size: usize) -> Result<(*const u8, *mut u8), JitAllocError>
unsafe fn release(&self, rx_ptr: *const u8) -> Result<(), JitAllocError>
unsafe fn flush_instruction_cache(rx_ptr: *const u8, size: usize)
unsafe fn protect_jit_memory( ptr: *const u8, size: usize, access: ProtectJitAccess, )
Implementors§
impl JitAlloc for GlobalJitAlloc
bundled_jit_alloc only.impl JitAlloc for ThreadJitAlloc
no_std and crate feature bundled_jit_alloc only.