cpu: pass stack arguments to internal callees in cpu_switch_aot #2200
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2208"
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 dicnunz on 2026-11-25T05:12:35Z.
Change
tools/cpu_switch_aot.pyrefused any callee that read a fifth or later argument (unsupported stack argument), and so were its callers. An internal callee may now take stack arguments, the fifth to the twelfth: the 8-byte slots from its entry RSP + 0x28, which the Windows x64 calling convention places above the caller's home space. Each access must lie inside one slot. The caller must have written the bytes the callee reads, at RSP + 0x20 + 8 * slot and below the caller's return address. A slot the callee only writes is passed as 0. After the call those slots are undefined, like the callee's home space. A tail jump to a callee with stack arguments stays refused, and so do stack arguments of exported functions.This branch contains the commits of the recursion PR (
cpu/switch-recursion). Please review and merge that PR first, then this one. A rebase will be needed after the first lands.Refs #317.
Verification
Tested commit:
172c07f(tip ofdicnunz:cpu/switch-stack-arguments), rebased onto166d866(upstream #2176, 10:12 PM ET on 24 Nov 2026), including a docs commit that counts all eight stack-argument exports. The three-dot compare against currentR0Y00/Xbox2Windowsmain is 7 commits ahead and 26 behind (main tipab9a020at 11:54 PM ET on 24 Nov 2026). The compare is 12 files, +1530 / -52, limited to the translator,tools/fuzz_cpu.py(the plantedstale_rspfault now passes the newFrameargument), the recursion fixture, the new stack-argument fixture, existing call-test controls, CMake test wiring anddocs/experiments.md.docs/experiments.mdnow says the fixture "translates eight exports" and "all eight exports were refused" before the change.Full Windows results are from a temporary fork branch
ci/stack-full(b38a69f) that differed from the previous tip39e43fconly by raising the Windows job timeouts from 20 minutes to 150 in.github/workflows/windows.yml. That timeout change is not in this PR branch. Those jobs have not been re-run on this tip; there are no GitHub Actions runs on172c07fyet. ForkWindows checksworkflow,workflow_dispatch,windows-2025runners, 6:16 to 6:49 PM ET: https://github.com/dicnunz/Xbox2Windows/actions/runs/45508514322Verified from the job logs:
call_evidence_check)call_evidence_check)In both Windows jobs
cpu_aot_recursionandcpu_aot_stack_argumentspassed. The 18 skips are the same capability or host skips listed in the recursion PR.The one failure is
tests/call_evidence_check.py,test_main_writes_expected_json_for_three_imagesat line 312:AssertionErrorcomparingC:/Users/runneradmin/AppData/Local/Temp/...with the 8.3 short pathC:/Users/RUNNER~1/AppData/Local/Temp/.... This branch does not touchtests/call_evidence_check.pyortools/call_evidence.py. The same assertion failed on upstream main in Windows checks run 45533450301 (push of #2141, 9:30 PM ET), so it is pre-existing and unrelated.Failure-before, verified from the logs of fork run https://github.com/dicnunz/Xbox2Windows/actions/runs/45508518358 (
ci/before-maine14f2a8, workflow conclusion success, Debug and /O2). On main, building the lifted DLLs exited 1, andctestof the two new tests exited nonzero. The native originals matched the Python reference. All 8 stack-argument exports were refused (unsupported stack argument, exceptcall_rec, which main refuses first asself-recursion).check_structureandcheck_refusalsfailed. No unexpected pass. The same run also shows the 4 recursion exports refused, as described in the recursion PR.Claude also reported a local Linux run (
llvm-ml18,lld-link,clang++at-O0and-O2) where the translation matched the original on 7,184 calls, and that generated C++ was unchanged for the othercpu_switch_aotfixtures (includingrecursion.asm) and for the fuzz areasllvm-mlcan assemble. I did not re-run those checks. From the fixture source, 8 exports over 449 input pairs is 3,592 translation-vs-original comparisons plus 3,592 original-vs-Python checks, which is the 7,184 figure.Evidence and follow-up
tests/cpu/stack_args.asmis original source written for this test (MIT), marked in the file as a source-owned differential fixture, withtests/cpu/stack_args.defandtests/cpu/stack_args_check.py. I found no game files, dumps or other proprietary material in the compare.Open this after the recursion PR, or rebase this branch onto that PR once it lands. This branch was rebased onto
166d866, which already includestools/cpu_switch_aot.py(47fa55b, register-indexed memory bit tests, 6:26 PM ET on 24 Nov 2026). The BIT_TESTS lowering on this tip is identical to that commit and to current main. Current main (ab9a020) is 26 commits ahead of the rebase base. Those commits do not touchtools/cpu_switch_aot.py. They do editCMakeLists.txtanddocs/experiments.md, which auto-merge cleanly onto current main (local merge-tree, no conflicts). A further rebase is optional.Not verified here: upstream PR CI has not been run. The
prCTest preset is a small smoke set and does not includecpu_aot_stack_arguments,cpu_aot_recursionorcall_evidence_check. A full-suite baseline on main (ci/main-full, run 45515371589) was still queued with no jobs as of 10:11 PM ET and has produced no results. Floating-point arguments, frame addresses passed to callees and indirect calls stay refused. Recursion depth depends on the host stack. Nothing here shows that a game starts.Checklist
This change was written by Claude (Anthropic's Claude Code, Opus 5.5) and submitted by dicnunz after review.
🤖 Generated with Claude Code
Depends on #2207, which should merge first; the first three commits here are that PR's.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T05:17:15Z.
Review: COMMENTED
Review of head
172c07fae2e22e4806b8b2724a78d12db79875c8(external PR, comment only).Summary: no P1, no P2 found. The stack-argument handling in
tools/cpu_switch_aot.pyis consistent end to end: slot-aligned access check inFrame, per-slot demand width, entry state of the byte proof (caller-written bytes), kill of the callee-writable slots after a call, and rejection of tail jumps and of calls whose slots would reach the return address.Commands executed locally (Linux), all clean:
git diff --stat origin/main...HEAD: 12 files, +1530/-52 (also carries the 3 recursion commits, as the body says; that PR must land first, then a rebase).python3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 406 links.python3 tests/bidi_controls_check.py: no bidirectional controls in 1471 files.git diff --check origin/main...HEAD: clean.Windows (Server 2025, MSVC, dev preset), same head:
ctest --preset dev -R 'cpu_aot_(stack_arguments|recursion|direct_calls)'after buildingcpu_stack_args(_lifted),cpu_recursion(_lifted),cpu_calls(_lifted),cpu_register_probe: 3/3 passed.prove_frame, the check that every stack argument byte a callee reads was written by the caller was disabled (if passed != b"\1" * needed:replaced byif False:).cpu_aot_stack_argumentsfailed withunset_slot accepted: stack argument 6 of the call ... is undefined, so the refusal tests do kill it. The mutation was reverted.Notes (nit, not blocking):
lift_functionthat rejects stack arguments reaching the return address (frame.offsets[ip] + HOME_SIZE + 8 * len(stack) > 0) is exercised only throughhigh_slots; fine, but a comment with the arithmetic would help the next reader.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T08:45:36Z.
Review: COMMENTED
Re-review of head
ba24d5fda8aff96a553a5548fa00daa26551fc46(external PR, comment only). Previous review was on172c07fa.Summary: no P1, no P2. The previous review had no P2 either, so there was nothing to resolve. Its two nits are still open and are not blocking. The new head is a merge of main. The recursion PR (#2207) has landed, so the diff is now 8 files, +775/-30, and only the stack-argument increment remains.
Commands executed locally (Linux), all clean:
git diff --stat origin/main...HEAD: 8 files (CMakeLists.txt, docs/experiments.md, tests/cpu/calls_check.py, stack_args.asm/.def/_check.py, tools/cpu_switch_aot.py, tools/fuzz_cpu.py).git diff --check origin/main...HEAD: clean.python3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 430 links.python3 tests/bidi_controls_check.py: no bidirectional controls in 1546 files.python3 -I -m py_compile tools/cpu_switch_aot.py tests/cpu/stack_args_check.py: ok.Windows (Server 2025, MSVC, dev preset), same head:
python3 x2w_pipe.py win2025 2208 --skip-release --targets cpu_stack_args,cpu_stack_args_lifted,cpu_recursion,cpu_recursion_lifted,cpu_calls,cpu_calls_lifted,cpu_register_probe --regex 'cpu_aot_(stack_arguments|recursion|direct_calls)'ctest --preset dev -R 'cpu_aot_(stack_arguments|recursion|direct_calls)': 3/3 passed (cpu_aot_recursion,cpu_aot_direct_calls,cpu_aot_stack_arguments).Mutation: not repeated on this head. The merge only brought in main's recursion changes. The stack-argument logic is unchanged since the earlier review, where disabling the caller-written-bytes check in
prove_framemadecpu_aot_stack_argumentsfail.Notes (nit, not blocking), carried over:
lift_functionthat rejects stack arguments reaching the return address is exercised only throughhigh_slots. A comment with the arithmetic would help the next reader.AI-assisted; commands listed were executed locally.