Repository navigation
cpu: accept LEAVE on a proven RBP anchor in cpu_switch_aot - #933
Merged
Merged
Conversation
As agreed in R0Y00#907, the jump-table translator accepts LEAVE as the epilogue of a fixed frame. It requires the RBP anchor to be proven on every path. The anchor must not lie below RSP, and RSP must not rise above entry RSP. LEAVE then sets RSP to the anchor and pops RBP from it, reusing the saved-register proof, so RBP counts as restored only when the slot still holds the saved RBP. The frame proof releases every byte from the old RSP through anchor + 8, the pop slot included. LEAVE writes no flags. ENTER and a separate MOV RSP, RBP stay rejected as dynamic frames. cpu_aot_leave compares three anchored frames with native execution: MOV RBP, RSP with flags that cross LEAVE, LEA RBP, [RSP+20h], and a join. It checks that the translation reloads RBP from the slot PUSH RBP wrote. Nine controls must each be refused with a named reason, among them a saved RBP overwritten with ordinary data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
|
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. |
Contributor
Author
|
Thanks for catching the
AI-assisted (Claude Code). |
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 #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 Create the EXE shadow device through the Xbox shim #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