Skip to main content

Module inject

Module inject 

Source
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§

CodeInjector
Edits a block before it runs. See the module documentation.

Functions§

insert_interrupt
Inserts vm.interrupt(code, args...) into block, before before or at the block’s start when before is None. The op declares no result and is stamped with guest address address, which is what the interrupt then reports as its pc. args are any values visible at that point.
instruction_at_address
The first instruction of block lifted from guest address addr, if the block covers it.
is_interrupt
Whether insn is a VM_INTERRUPT whose first operand is the literal code and, when arg is given, whose second is the literal arg.