Expand description
Rewriting lifted code before it runs: the mechanism every hook is built on.
An injector is handed each block once it has been lifted and cleaned, and
again whenever the block grows, and may edit it through the ordinary
builder: insert a VM_INTERRUPT where the host wants control, add loads
and stores that count or log, rewrite an operation. The interpreter and
the JIT both run whatever the block then contains, so instrumentation is
compiled along with the code it instruments and costs nothing where none
was injected.
§Idempotence
A block is offered to an injector more than once: at discovery, after
absorption has folded more guest instructions into it, and after a new
injector is registered. The injector must therefore recognise its own
earlier edits and not repeat them. is_interrupt is what the built-in
injectors use for that.
Most hooks are better written against crate::hook, which chooses
sites, hides the builder and handles idempotence; this is the layer
underneath it.
Traits§
- Code
Injector - Edits a block before it runs. See the module documentation.
Functions§
- insert_
interrupt - Inserts
vm.interrupt(code, args...)intoblock, beforebeforeor at the block’s start whenbeforeisNone. The op declares no result and is stamped with guest addressaddress, which is what the interrupt then reports as itspc.argsare any values visible at that point. - instruction_
at_ address - The first instruction of
blocklifted from guest addressaddr, if the block covers it. - is_
interrupt - Whether
insnis aVM_INTERRUPTwhose first operand is the literalcodeand, whenargis given, whose second is the literalarg.