Skip to main content

CodeSource

Trait CodeSource 

Source
pub trait CodeSource {
    // Required method
    fn lift(
        &mut self,
        ctx: &mut Context<'static>,
        memory: &VmMemory,
        index: &mut AddressIndex,
        addr: u64,
        stats: &mut Stats,
    ) -> Result<(), CodeError>;
}
Expand description

Supplies code the machine has not seen yet.

Kept as a trait so the VM does not depend on SLEIGH: a decoder is a policy choice (which specification, which variant), and a test wants to hand over blocks without compiling one. An implementation reads instruction bytes from the Mmu — via read_code, so that executing a non-executable page faults at the fetch — and lowers them into ctx.

Required Methods§

Source

fn lift( &mut self, ctx: &mut Context<'static>, memory: &VmMemory, index: &mut AddressIndex, addr: u64, stats: &mut Stats, ) -> Result<(), CodeError>

Lifts the code at addr into ctx.

Returning Ok(()) asserts that a block starting at addr now exists; the VM re-resolves the address itself rather than trusting a returned id, so a source is free to lift a whole run of instructions at once.

index is the machine’s live address lookup, and the implementation must keep it current as it adds blocks — every lifting entry point takes one for exactly this reason. Rebuilding it per instruction instead is quadratic in the size of the module discovered so far.

stats is the machine’s own counters: an implementation records the time it spends fetching and decoding there, so a benchmark can separate translation cost from interpretation cost.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§