Skip to main content

JitHook

Trait JitHook 

Source
pub trait JitHook: Send {
    // Required method
    fn try_call(
        &mut self,
        fn_id: u32,
        args: &[Value],
        step_counter_ptr: *mut u64,
        step_limit: u64,
    ) -> Result<Option<Value>, VmError>;
}
Expand description

Hook into the VM dispatch loop for Op::Call.

See the module docs for the contract.

Required Methods§

Source

fn try_call( &mut self, fn_id: u32, args: &[Value], step_counter_ptr: *mut u64, step_limit: u64, ) -> Result<Option<Value>, VmError>

The dispatch loop has just verified refinements and missed the memo cache for fn_id. The arguments are at the top of the value stack — args is a borrowed view; do not mutate.

step_counter_ptr points at the VM’s steps: u64 field; step_limit is the current cap. JITed code is expected to atomically *step_counter_ptr += 1 at every backward jump (loop iteration) and abort if the new value would meet or exceed step_limit, surfacing VmError::Panic("step limit exceeded") so the dispatcher can propagate the same shape it would have on the interpreter path.

Return:

  • Ok(Some(v)) — hook handled the call; the dispatcher will pop args.len() values from the stack, push v, emit the synthetic exit_ok trace event, and continue.
  • Ok(None) — hook declines; the dispatcher proceeds with normal frame setup as if the hook weren’t installed.
  • Err(e) — JITed code raised an error (typically VmError::Panic("step limit exceeded")). The dispatcher surfaces it as the call’s error.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§