Expand description
Hooks as rewrites of the lifted code.
A Hook names the sites in a block it cares about — the block’s entry,
a guest address, every store to guest memory, every comparison — and, for
each, emits QCode through an Emitter. What it emits is ordinary IR: a
VM_INTERRUPT where the host must act, arithmetic to decide whether it
must, loads and stores that count. The interpreter and the JIT run the
result like any other code, so a hook whose condition is false costs a few
native instructions and never leaves compiled code.
The two ways to stop:
Emitter::interruptplaces an unconditional interrupt before the site.Emitter::interrupt_ifplaces the interrupt on a detour: the block is split before the site, and a conditional branch chooses between a small block holding the interrupt and the rest of the code. Only the condition is evaluated on the fast path.
Both pass values to the host — literals, or anything the block computes, such as the address and datum of a store — which the exit reports as the interrupt’s arguments.
HookInjector adapts a hook to the CodeInjector the machine runs,
and handles idempotence: a site is instrumented once, remembered by its
anchor instruction, which survives absorption and disappears with a
re-lift.
Structs§
- Address
Hook - Stops before the guest instruction at each of a set of addresses, with
vm.interrupt(code, address). - Block
Entry Hook - Stops at the entry of every block whose address lies in a range, with
vm.interrupt(code, address). - Block
View - A read-only look at a block, for choosing sites.
- Compare
Hook - Stops before every integer comparison with
vm.interrupt(code, lhs, rhs): the operands as the guest computed them, which is what a comparison logger for a fuzzer wants. - Emitter
- Emits QCode before a site’s anchor, on the hook’s behalf.
- Hook
Injector - Runs a
Hookas the machine’sCodeInjector, instrumenting each site once. - Write
Watch - Stops before every store to guest memory whose address lies in
begin..=end, withvm.interrupt(code, address, size, value).
Enums§
- Site
- A point in a block a hook may instrument. Every site is anchored to the instruction it precedes, which is where the hook’s code is inserted.
Traits§
- Hook
- A rewrite of lifted code at chosen sites. See the module docs.
Functions§
- is_
interrupt_ op - Whether
insnis aVM_INTERRUPTop.