cpu: accept LEAVE on a proven RBP anchor in cpu_switch_aot #926
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/933"
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-23T17:47:42Z.
Change
As agreed in #907,
tools/cpu_switch_aot.pyacceptsLEAVEas the epilogue of a fixed frame with a proven RBP anchor (the anchor proof from #889).Frame proof (
Frame.step).LEAVEis accepted only when:anchor + 8is at or below entry RSP.It then sets RSP to the anchor and pops RBP from it, an 8-byte read at the anchor. The existing
releasedbookkeeping frees every byte from the old RSP throughanchor + 8, the pop slot included.prove_framereads the slot before it zeroes the interval.Restore proof.
slot_register(LEAVE)is RBP, so the existing saved-register proof applies. RBP counts as restored only when the slot still holds the saved RBP bytes; eight ordinary defined bytes are not enough.Flags.
LEAVEis inFLAG_NEUTRAL, since it writes no flags. A consumer after it uses the producer before it.Lowering. RBP is reloaded from the anchor slot. RSP stays a constant offset, as for
ADD RSP.Still rejected.
ENTERand a separateMOV RSP, RBPstay rejected as dynamic frames. The module docstring, theFrameandprove_framedocstrings, anddocs/experiments.mdsay so.Tests
cpu_aot_leave(leave.asm) compares three translated exports with native execution overdirect_check.input_pairs(), on return value, guarded trace, RBX and RSI:leave_frame:MOV RBP, RSP, withCMPbeforeLEAVEandSETBafter it;leave_lea:LEA RBP, [RSP+20h]afterSUB RSP, 20h;leave_join: both paths keep the anchor and write the same local.It also checks in the generated C++ that
LEAVEreloads RBP from exactly the slotPUSH RBPwrote. The register probe samples only RBX and RSI, and the translated RBP is a local of the generated function, so the restore is shown by the frame proof and this slot check, not by execution.Nine controls must each be refused with a named reason:
MOV RBP, RSPpatched to a NOPLEAVE without a proven frame anchorleave_split: anchors differ at a joinframe pointer differs at joinleave_unsaved: anchor slot never writtenundefined stack byte at entry RSP-0x8leave_overwritten: saved RBP overwritten with ordinary data (mov [rbp], rcx)nonvolatile register rbp is not restoredleave_released: a local read afterLEAVEreleased itundefined stack byte at entry RSP-0x10leave_lowers: anchor below RSPLEAVE with the frame anchor below RSPleave_above: anchor in the caller's home spaceLEAVE would raise RSP above entry RSPmov_rsp_frame: a separateMOV RSP, RBPdynamic frameenter_frame:ENTERdynamic frameVerification
At
8e3d647(onmainaf8fcba) 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_leave$' -V: passes. 747 calls per side match. All nine controls are rejected with their reasons.ctest --preset dev --no-tests=error -R '^cpu_' -j 4: 173 of 174 pass. The capability skips arecpu_aot_fences_hints_clwb,cpu_aot_crypto_shaandcpu_shim_chain_hardware.cpu_aot_stack_output,cpu_aot_stack_frames,cpu_aot_direct_calls) pass.cpu_shim_shadow_hardwarein its native run (D3D12XboxCreateDevice failed (HRESULT 0x887a0004)), independent of this change and reported in #799.tools/form_coverage.pyon a JUnit run of the^cpu_suite no longer listsleave.tests/docs_links_check.py,tests/bidi_controls_check.pyandtests/form_coverage_check.pypass.Refs #907
AI-assisted: written with Claude Code; design and diff reviewed by fresh agents; checked and submitted by the account owner.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T18:02:56Z.
I found that the decoder also classifies 66 c9 as LEAVE, with a 16-bit operand. The frame proof implements an eight-byte pop, so I restricted it to the qword encoding and added a static-only rejection control. The native/lifted LEAVE, stack frame and direct call suites passed 3/3 in Windows x64 Release. Fresh CI is running.
Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-23T18:13:42Z.
Thanks for catching the
66 c9form. With82a1eedon the Skylake host (Windows 11 26100, MSVC 19.52,devpreset),ctest --preset dev --no-tests=error -R "^cpu_aot_(leave|stack_frames|direct_calls|stack_output)$"passes 4/4:cpu_aot_leave: 747 calls per side match, and the ten rejection controls pass, includingleave_word(unsupported LEAVE operand size).cpu_aot_stack_frames: 2241 calls per side and 36 rejection controls pass.cpu_aot_direct_callsandcpu_aot_stack_outputalso pass.AI-assisted (Claude Code).