cpu: lower INT3 and UD2 to the host exceptions they raise #1026
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1033"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-23T22:16:20Z.
Change
As agreed in #1021, the shared lowering in
tools/ffx_version_query.pylowers the exactCC(INT3) and0F 0B(UD2) encodings to__debugbreak()and__ud2().EXCEPTION_BREAKPOINT(0x80000003) andSTATUS_ILLEGAL_INSTRUCTION(0xC000001D) to the caller's handlers.INT imm8(includingCD 03and theCD 29fast fail),INT1,INTO,UD0andUD1.Tests
cpu_aot_trap(trap.asm) calls each native and translated export in a child process. The call goes through a native SEH boundary (trap_harness.cpp:__try/__except,GetExceptionCode()), and the child reports the exception code, the result and two state words.trap_int3must raise0x80000003andtrap_ud20xC000001D. In both, the store before the trap must be visible and the store after it must not happen.trap_branch(1)must trap liketrap_int3.trap_branch(0)skips the INT3 and must return 7 with both stores.CD 03,CD 29,F1,CE,0F FF C0,0F B9 C0), decoded alone, must still reach the lowering'sunsupported query operation.Controls (mutations of the generated C++, each must break a rule):
dropremoves the trap.swapexchanges the two intrinsics.nostoreremoves the earlier store./O2: the translation is also built withcl /O2. A walk that follows every branch must still find INT3 intrap_int3andtrap_branchand UD2 intrap_ud2, and every rule must hold.Two changes outside the new fixture
tests/cpu/signed_conds.py(from #805) used UD2 as its example of a refused instruction, so it failed once UD2 is lowered. The example is now UD0 (0f ff c0), which stays refused with the sameunsupported query operationdiagnostic. The control keeps its purpose; please check that this replacement is what you want.tools/form_coverage.pynow counts MASM'sint 3, which ML64 encodes asCC, as the reference'sint3form instead ofint. ML64 has noint3mnemonic. I measured thatint 3,int 3handint 03hall assemble toCC, whileint 29hstaysCD 29.tests/form_coverage_check.pycovers these spellings.intreturns to the gap list. Before this change it was credited by theint 3inbink_descriptors.asm, which ML64 assembles asCCtoo.int 3throughhost_opsas a host stop (return 0), so it now creditsint3without executing a trap. If you'd rather creditint3only throughtrap.asm, I can follow up with an exclusion for that fixture.Verification
At
838baf7(onmain64ecc87) on Windows 11 Pro (build 26100), Intel Core i7-6820HQ, MSVC 19.52, Python 3.12:ctest --preset dev --no-tests=error -R '^cpu_aot_trap$' -V: passes. The output includes:refused, as before: int 3 (imm8), int 29h (fast fail), int1, into, ud0, ud1;dropcontrol:trap_int3(0): (code, result, before, after) (0, 7, 1, 2);/O2walk keeps INT3 and UD2 in every export.ctest --preset release --no-tests=error -R '^cpu_aot_trap$': passes. Only this fixture's targets were built inrelease.ctest --preset dev --no-tests=error -R '^cpu_' -j 4: 197 of 198 pass, includingcpu_aot_signed_conds, with three capability skips.cpu_shim_shadow_hardwarein its native run, independent of this change and reported in #799.tools/form_coverage.pyon a JUnit run of that suite no longer listsint3orud2.tests/docs_links_check.py,tests/bidi_controls_check.pyandtests/form_coverage_check.pypass.Not tested: behaviour under an attached debugger. A debugger stops at the first
EXCEPTION_BREAKPOINT, as it does for the original.Refs #1021
AI-assisted: written with Claude Code; design and diff reviewed by fresh agents; checked and submitted by the account owner.
🤖 Generated with Claude Code