Repository navigation
cpu: lower INT3 and UD2 to the host exceptions they raise - #1033
Merged
Merged
Conversation
As agreed in R0Y00#1021, the shared lowering lowers the exact CC (INT3) and 0F 0B (UD2) encodings to __debugbreak() and __ud2(). Like the original instructions they raise EXCEPTION_BREAKPOINT and STATUS_ILLEGAL_INSTRUCTION to the caller's handlers. Earlier guest stores stay done, and no later guest instruction runs on the unwind path. The exception address and registers are the host's. INT imm8 (including CD 03 and the CD 29 fast-fail), INT1, INTO, UD0 and UD1 stay refused. cpu_aot_trap calls each native and translated export in a child process behind a native SEH boundary. It checks the exact code, the visible earlier store, the skipped later store and the untaken branch's result. Three mutated controls (drop, swap, nostore) must fail, and the /O2 build keeps both opcodes. signed_conds.py used UD2 as its example of a refused instruction; it now uses UD0, which stays refused. form_coverage.py counts MASM's int 3 (also 3h and 03h), which ML64 encodes as CC, as the int3 form instead of int. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 cpu: lower signed condition codes, Jcc, CMOVcc, SETcc, NEG and CWD #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 Create the EXE shadow device through the Xbox shim #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