Class JitPassage.ExitPcodeOp

java.lang.Object
ghidra.program.model.pcode.PcodeOp
ghidra.pcode.emu.jit.JitPassage.ExitPcodeOp
Enclosing class:
JitPassage

public static class JitPassage.ExitPcodeOp extends PcodeOp
A synthetic p-code op that represents a return from the JitCompiledPassage.run(int) method.

When execution encounters this op (and the corresponding JitPassage.ExtBranch), the emulator's program counter and context values are set to the branch target, and the appropriate entry point is returned.

This is used in a few ways: The simplest, though perhaps not obvious, way is when the decoder encounters an existing entry point. We avoid re-translating the same instructions by forcing the stride to end. However, the last instruction in that stride would have fall through, causing dangling control flow. To mitigate that, we append a synthetic exit op to return the existing entry point. The emulator can then resume execution accordingly.

The next is even less obvious. When the emulation client (or user) injects Sleigh, a common mistake is to forget control flow. The decoder detects this when "falling through" does not actually advance the program counter. In this case, we append this synthetic op to exit the translated passage. While it still results in an endless loop (just like the interpretation-based emulator), it's easier to interrupt and diagnose when we exit the translation between each "iteration."

The last is a small hack: The decoder needs to know whether each instruction (possibly instrumented by an inject) falls through. To do this, it appends an exit op to the very end of the instruction's (and inject's) ops and performs rudimentary control flow analysis (see JitControlFlowModel.BlockSplitter). It then seeks a path from start to exit. If one is found, it has fall through. This "probe" op is not included in the decoded stride.

  • Constructor Details