pub struct JitPage { /* private fields */ }Expand description
A page-aligned block of executable memory holding JIT-compiled machine code.
Implementations§
Source§impl JitPage
impl JitPage
Sourcepub fn new(code: &[u8]) -> Result<JitPage, JitError>
pub fn new(code: &[u8]) -> Result<JitPage, JitError>
Allocate an executable page, copy code into it, and make it runnable.
Sourcepub fn patch_word(&self, offset: usize, value: u64) -> Result<(), JitError>
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.
Sourcepub fn with_layout(
len: usize,
fill: impl FnOnce(u64) -> Vec<u8>,
) -> Result<JitPage, JitError>
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.
Sourcepub unsafe fn as_fn_i64_i64(&self) -> extern "C" fn(i64, i64) -> i64
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.
Sourcepub fn as_ptr(&self) -> *const u8
pub fn as_ptr(&self) -> *const u8
Raw pointer to the executable code (for patching / inspection).
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Length of the machine code in bytes (the mapping itself is
JitPage::alloc_len bytes).