pub struct JitMemory { /* private fields */ }Expand description
A buffer for JIT code execution.
§Example
use gaia_jit::JitMemory;
let mut jit = JitMemory::new(4096).unwrap();
// Write some machine code...
jit.write(&[0x90, 0xc3]).unwrap(); // nop; ret
jit.make_executable().unwrap();
unsafe {
let f: unsafe extern "C" fn() = jit.as_fn();
f();
}Implementations§
Source§impl JitMemory
impl JitMemory
Sourcepub fn new(capacity: usize) -> Result<Self>
pub fn new(capacity: usize) -> Result<Self>
Allocate a new JIT memory block with the given capacity.
Sourcepub fn write(&mut self, code: &[u8]) -> Result<()>
pub fn write(&mut self, code: &[u8]) -> Result<()>
Write code into the buffer.
This method automatically ensures the memory is writable before writing, and restores the previous protection after if possible.
Sourcepub fn make_executable(&self) -> Result<*const u8>
pub fn make_executable(&self) -> Result<*const u8>
Make the memory executable and return a pointer to the start.
Sourcepub fn make_writable(&self) -> Result<()>
pub fn make_writable(&self) -> Result<()>
Make the memory readable and writable again (e.g. for updates).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for JitMemory
impl RefUnwindSafe for JitMemory
impl Unpin for JitMemory
impl UnsafeUnpin for JitMemory
impl UnwindSafe for JitMemory
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more