cpu: lower INT3 and UD2 to the host exceptions they raise #1021
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#1021
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@legacy-code-archaeologist on GitHub · 2026-11-23 21:34 UTC · original
Claim and design question: lower
INT3andUD2to the host exceptions they raiseint3andud2(Integer group ofdocs/coverage/x64_zen2.tsv) have no passing fixture. The shared lowering rejects both. The only translator that handlesINT3istools/bink_descriptors_aot.py, which binds it toreturn 0;for its own stop sites. Compiled startup code uses both:int3is the failure path of checks and of__debugbreak(). MoonYueya's and Holastor's startup notes in #870 show the main executable stopping at anint3after a failed check.ud2marks unreachable code after calls that do not return.I found no open issue or PR about lowering them and would like to take a first, small increment.
Proposed behavior (shared lowering)
INT3(CC) calls__debugbreak(). Like the original, it raisesEXCEPTION_BREAKPOINT(0x80000003) to the caller's handlers or debugger, and no later guest instruction runs.UD2calls__ud2(), which raisesSTATUS_ILLEGAL_INSTRUCTION(0xC000001D) like the original. It also ends the block.INT 3in its two-byte form (CD 03),INT1/ICEBP,UD0/UD1andINT nstay rejected in this increment. That includesINT 29h/__fastfail, which needs its own decision.Proposed fixture (source-built MASM, child processes)
Exports:
int3after a guest store;ud2after a guest store;int3only for one input.A child process calls each native and translated export. It must report the same exception code, and a marker written after the instruction must stay unwritten. The branch case must return normally for the other input. The translation is also built with
cl /O2and checked for the same results. An optional check confirms that__debugbreakand__ud2remain in the/O2code.A control that drops the instruction must let the marker through, and a control that swaps the two instructions must report the wrong code.
Questions
pe_mappath can report guest addresses as #65 does for mapped images. I'd start with the host exception and keep the hook for later.cpu_switch_aotin the same PR? I'd keep it to the shared lowering first.Test host: Intel Skylake (i7-6820HQ) on Windows 11 26100.
AI-assisted (Claude Code).
@R0Y00 on GitHub · 2026-11-23 21:43 UTC · original
Please take the shared Windows x64 lowerer first, for the exact CC and 0F 0B encodings. The observable contract is the host exception class and the effects before a trap when the caller unwinds. Exception addresses and registers belong to the host. Resuming through a debugger or a handler, mapping the guest RIP and expanding the switch lowerer remain separate work.
Use a child with an SEH boundary and a volatile or otherwise observable marker. Check the exact exception code, that the earlier store is visible and that later guest work does not run on the unwind path. The untaken branch must still return and produce its expected result. Run the same source-built controls in both Windows presets and verify that the required opcodes survive the optimized build. Keep the other interrupt, undefined-instruction and fast-fail encodings refused. Windows exception codes
@R0Y00 on GitHub · 2026-11-23 22:40 UTC · original
Implemented in #1033. Windows Release reproduced both native exception codes, preserved the earlier writes, left later writes untouched, and returned normally on the untaken branch. The three mutation controls failed as intended. This closes the shared-lowering slice; guest context and resume semantics remain separate.