cpu: lower INT3 and UD2 to the host exceptions they raise #1021

Closed
opened 2026-11-26 22:35:41 +00:00 by github-bot · 2 comments
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-23 21:34 UTC · original

Claim and design question: lower INT3 and UD2 to the host exceptions they raise

int3 and ud2 (Integer group of docs/coverage/x64_zen2.tsv) have no passing fixture. The shared lowering rejects both. The only translator that handles INT3 is tools/bink_descriptors_aot.py, which binds it to return 0; for its own stop sites. Compiled startup code uses both:

  • int3 is the failure path of checks and of __debugbreak(). MoonYueya's and Holastor's startup notes in #870 show the main executable stopping at an int3 after a failed check.
  • ud2 marks 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 raises EXCEPTION_BREAKPOINT (0x80000003) to the caller's handlers or debugger, and no later guest instruction runs.
  • UD2 calls __ud2(), which raises STATUS_ILLEGAL_INSTRUCTION (0xC000001D) like the original. It also ends the block.
  • Guest state is not passed through: the exception address is in the translated code, not the guest RIP, and the context holds host registers. The PR would document this as the contract.
  • INT 3 in its two-byte form (CD 03), INT1/ICEBP, UD0/UD1 and INT n stay rejected in this increment. That includes INT 29h/__fastfail, which needs its own decision.

Proposed fixture (source-built MASM, child processes)

Exports:

  • an int3 after a guest store;
  • a ud2 after a guest store;
  • a conditional path that reaches int3 only 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 /O2 and checked for the same results. An optional check confirms that __debugbreak and __ud2 remain in the /O2 code.

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

  1. Is raising the host exception the intended first contract? The other option is a runtime hook that receives the guest RIP, so a later SEH or pe_map path can report guest addresses as #65 does for mapped images. I'd start with the host exception and keep the hook for later.
  2. Shared lowering only, or also cpu_switch_aot in 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).

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-23 21:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/1021) ### Claim and design question: lower `INT3` and `UD2` to the host exceptions they raise `int3` and `ud2` (Integer group of `docs/coverage/x64_zen2.tsv`) have no passing fixture. The shared lowering rejects both. The only translator that handles `INT3` is `tools/bink_descriptors_aot.py`, which binds it to `return 0;` for its own stop sites. Compiled startup code uses both: - `int3` is the failure path of checks and of `__debugbreak()`. MoonYueya's and Holastor's startup notes in #870 show the main executable stopping at an `int3` after a failed check. - `ud2` marks 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 raises `EXCEPTION_BREAKPOINT` (`0x80000003`) to the caller's handlers or debugger, and no later guest instruction runs. - `UD2` calls `__ud2()`, which raises `STATUS_ILLEGAL_INSTRUCTION` (`0xC000001D`) like the original. It also ends the block. - Guest state is not passed through: the exception address is in the translated code, not the guest RIP, and the context holds host registers. The PR would document this as the contract. - `INT 3` in its two-byte form (`CD 03`), `INT1`/`ICEBP`, `UD0`/`UD1` and `INT n` stay rejected in this increment. That includes `INT 29h`/`__fastfail`, which needs its own decision. **Proposed fixture (source-built MASM, child processes)** Exports: - an `int3` after a guest store; - a `ud2` after a guest store; - a conditional path that reaches `int3` only 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 /O2` and checked for the same results. An optional check confirms that `__debugbreak` and `__ud2` remain in the `/O2` code. 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** 1. Is raising the host exception the intended first contract? The other option is a runtime hook that receives the guest RIP, so a later SEH or `pe_map` path can report guest addresses as #65 does for mapped images. I'd start with the host exception and keep the hook for later. 2. Shared lowering only, or also `cpu_switch_aot` in 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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:35:41 +00:00
Author
Owner

@⁠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 21:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/1021#issuecomment-7114831321) 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](https://learn.microsoft.com/en-us/windows/win32/debug/getexceptioncode)
Author
Owner

@⁠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.

**@⁠R0Y00** on GitHub · 2026-11-23 22:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/1021#issuecomment-7116054243) 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.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/R0Y00--Xbox2Windows#1021
No description provided.