Skip to main content

JitPage

Struct JitPage 

Source
pub struct JitPage { /* private fields */ }
Expand description

A page-aligned block of executable memory holding JIT-compiled machine code.

Implementations§

Source§

impl JitPage

Source

pub fn new(code: &[u8]) -> Result<JitPage, JitError>

Allocate an executable page, copy code into it, and make it runnable.

Source

pub fn patch_word(&self, offset: usize, value: u64) -> Result<(), JitError>

Patch one 8-byte LITERAL-POOL word after sealing (the self-call entry: a chain’s own base address becomes known only after layout). Data-only — the word lives in the pool, never decoded as code — so no instruction-cache concerns; the brief RW window happens on the compiling thread before the chain ever runs.

Source

pub fn with_layout( len: usize, fill: impl FnOnce(u64) -> Vec<u8>, ) -> Result<JitPage, JitError>

Two-phase construction for PATCHED code: maps first (so the final base address is known), lets fill produce the bytes against that base, then writes and seals. fill must return exactly len bytes.

Source

pub unsafe fn as_fn_i64_i64(&self) -> extern "C" fn(i64, i64) -> i64

Reinterpret the page as an extern "C" fn(i64, i64) -> i64.

§Safety

The caller must guarantee the page actually contains valid machine code implementing this exact signature, and must not call the pointer after the JitPage is dropped.

Source

pub fn as_ptr(&self) -> *const u8

Raw pointer to the executable code (for patching / inspection).

Source

pub fn len(&self) -> usize

Length of the machine code in bytes (the mapping itself is JitPage::alloc_len bytes).

Source

pub fn alloc_len(&self) -> usize

Bytes actually mapped (page-size multiple).

Source

pub fn is_empty(&self) -> bool

Whether the page is empty (always false; new rejects empty code).

Trait Implementations§

Source§

impl Debug for JitPage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for JitPage

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for JitPage

Source§

impl Sync for JitPage

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.