Struct juicebox_asm::Runtime

source ·
pub struct Runtime { /* private fields */ }
Expand description

A simple mmaped runtime with executable pages.

Implementations§

source§

impl Runtime

source

pub fn new() -> Runtime

Create a new Runtime.

Panics

Panics if the mmap call fails.

source

pub unsafe fn add_code<F>(&mut self, code: impl AsRef<[u8]>) -> F

Add the block of code to the runtime and a get function pointer of type F.

Panics

Panics if the code does not fit on the mmaped pages or is empty.

Safety

The code added must fulfill the ABI of the specified function F and the returned function pointer is only valid until the Runtime is dropped.

Examples
let mut rt = juicebox_asm::Runtime::new();

let code = [ 0x90 /* nop */, 0xc3 /* ret */ ];
let nop = unsafe { rt.add_code::<extern "C" fn()>(&code) };

nop();
source

pub fn dump(&self)

Dump the code added so far to the runtime into a file called jit.asm in the processes current working directory.

The code can be inspected with a disassembler as for example ndiasm from nasm.us.

ndisasm -b 64 jit.asm
Panics

Panics if writing the file failed.

Trait Implementations§

source§

impl Drop for Runtime

source§

fn drop(&mut self)

Unmaps the code page. This invalidates all the function pointer returned by Runtime::add_code.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.