cpu: pass bounded frame-slot pointers to internal callees in cpu_switch_aot #3121

Manually merged
github merged 5 commits from github-bot/gh-3121 into gh-pr/3121/base 2026-11-29 17:51:41 +00:00 AGit
Owner

@⁠Ammmae0x on GitHub · 2026-11-27 16:07 UTC · original
Ammmae0x:cpu/switch-frame-ptr-callees → main · +1905 −11 · 6 files · 5 commits · merged 2026-11-29 17:48 UTC

Change

Extend tools/cpu_switch_aot.py so bounded, non-recursive internal callees that read or write a single fixed-width scalar (1, 2, 4, or 8 bytes) through an argument register (RCX/RDX/R8/R9) without pointer escape can receive a proven frame-slot address via LEA reg, [rsp+disp] or [rbp+disp] (under a proven frame anchor). Refs #317.

  • Pointer-parameter summary (analyze_pointer_param, _step_ptr_instruction, _check_ptr_mem, PointerParam): tracks non-escaping 64-bit scalar pointer flow across copies, nested non-recursive internal callees, and control-flow joins; computes (width, reads_before_write, must_write, may_write) across all normal exits (RET and tail jumps), rejecting escapes (return in RAX, memory/stack stores, pointer arithmetic, displaced/indexed LEA or memory operands, 32-bit [ecx] addressing, register BT*, MOVS/STOS, SIGN_EXTENSIONS, one-operand MUL/DIV, 32-bit/16-bit CMOVcc truncation, COND_WRITE such as BSF/BSR on a live pointer destination, 8/16-bit partial overwrites, recursive/cyclic callees, mixed widths, and unaccessed pointer parameters).
  • Caller frame bounds & initialization proof (Frame, prove_frame): only treats RBP-based LEA as a frame pointer when a frame anchor is proven (preserving non-anchor RBP integer arithmetic); validates pointed bytes stay within [frame.offsets[ip] + HOME_SIZE + 8*len(stack_args), frame.end), never overlap return address or callee home space/stack args, and never alias across multiple pointer arguments; enforces caller initialization before any reads_before_write callee and marks written bytes defined after must_write (or preserves/clears saved-register markers conservatively on may_write). HostImport --stack-output is unchanged.
  • Fixture & verification (tests/cpu/switch_frame_ptr.asm, tests/cpu/switch_frame_ptr.def, tests/cpu/switch_frame_ptr_check.py, tests/cmake/cpu_switch_frame_ptr.cmake, docs/experiments.md): adds 4 differential exports (out_u32_rsp, rmw_u64_rbp, all_widths_and_regs, non_anchor_rbp_arith) across 313 input pairs at both /Od and /O2, 2 compiled C++ mutants, 2 Python guard mutations, and 49 refusal negative controls (44 exercising the new pointer-parameter/aliasing/bounds/saved-slot/incoming-slot rules and 5 caught by main's existing frame/tail/anchor checks).

Guard -> Red Control Table

Guard removed / weakened Failing control
General register-read escape (READS) neg_escape_store_mem (plus _store_stack, neg_ptr_arith)
Callee tail-jump live pointer arg check neg_callee_tail_ptr_live
Nested callee multi-arg pointer check (len(live_args) > 1) neg_nested_multi_live
Nested callee integer-use check (nested is None) neg_nested_int_callee
LEA zero-displacement / zero-index guard neg_lea_disp_callee
LEA 64-bit base guard (RegisterExt.is_gpr64(ins.memory_base)) neg_lea_ecx_callee
Join state-2 (merged[r] = 2) + _check_ptr_mem state-1 requirement neg_join_maybe_ptr_callee
check_mem displacement / index / 64-bit base / BIT_TESTS guards neg_mem_disp_callee, neg_mem_index_callee, neg_mem_ecx_callee, neg_bit_test_reg_callee
CMOVcc memory-form 32-bit truncation (w_reg != 8) neg_cmov32_mem_callee
STRING_TRANSFERS (STOS/MOVS), SIGN_EXTENSIONS, MUL/DIV, <4B partial writes neg_stos_ptr_rax, neg_sign_ext_callee, neg_mul_ptr_callee, neg_bsf_cond_write_escape
may_write clearing saved-register slot markers neg_may_write_saved_reg
Caller min_offset stack-argument size & incoming stack-slot demand propagation neg_callee_stack_arg_overlap, neg_incoming_stack_slot_uninit
Multi-arg pointer aliasing check neg_multi_arg_alias_same, neg_multi_arg_alias_overlap

Verification

Verified on commit 2a685c06 in liaison worktree on Windows x64 (MSVC 19.50.35727.0):

  • ctest --preset dev -N -> 2929 tests including #2497: cpu_switch_frame_ptr.
  • cmake --build --preset dev & release (affected 7 test targets) -> exit 0 (0 errors, 0 warnings).
  • ctest --preset dev --no-tests=error -R "^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$" -E "cpu_native_archive_" --output-on-failure -> 7/7 passed (exit 0).
  • ctest --preset release --no-tests=error -R "^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$" -E "cpu_native_archive_" --output-on-failure -> 7/7 passed (exit 0).
  • out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py, tests/docs_links_check.py (154 md / 676 links), tests/bidi_controls_check.py (2537 files) -> all exit 0.
  • Guard-mutation audit: 18/18 targeted guard removals + 5/5 verifier spot-mutations killed.

Evidence and follow-up

All fixtures (tests/cpu/switch_frame_ptr.asm, .def, _check.py) are source-owned under this repository; no external binaries or game files are used.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

Repair: @⁠pigalot review on 2a685c06 (head c66aa6be)

Merged origin/main 5de0b114 cleanly (merge commit 9af6f85a; git merge-tree --write-tree origin/main HEAD exits 0).

  • Blocking fix: _step_ptr_instruction's LEA copy branch now requires RegisterExt.is_gpr64(ins.memory_base), so lea reg, [ecx] (67 4C 8D 09) is refused instead of tracked as an exact state-1 copy. New control neg_lea_ecx_callee next to neg_mem_ecx_callee.
  • Join/state-1 control: new neg_join_maybe_ptr_callee (test edx, edx / jz / mov rcx, r8, then a store through rcx) dereferences a pointer that is only possibly the parameter (state 2 at the join). Weakening the join to merged[r] = 1 and dropping _check_ptr_mem's state-1 requirement each accept it independently. The store uses edx, the fixture's stored-value register: with eax the callee is refused as undefined register rax instead, since eax is undefined at callee entry.
  • Refusal controls are now 49 (44 + 5); the guard table above gains both rows.
  • Other survivors assessed, not pinned in this push: the live-index sub-checks in the LEA branch and _check_ptr_mem are equivalent (any index refuses the copy/deref anyway — verified on Linux: removing either alone changes nothing). LEA 32-bit destination, the state-1 requirement in the LEA copy, 8/16-bit LEA destination, a pointer live at a host-import/unresolved call or as a jump-table index, the volatile drop after a nested call, memory-form CMOVcc giving state 2, and the 16-bit MUL/DIV RDX, segment-prefix and access-kind checks in _check_ptr_mem still have no dedicated control — follow-up candidates, no behavior change in this push.
  • Linux verification on c66aa6be: lea r9, [ecx] and the join encodings cross-checked with keystone (LLVM MC) and iced-x86 (67 4C 8D 09; join 85 D2 74 03 4C 89 C1 89 11 31 C0 C3); a synthetic-PE translation harness refuses all four controls (neg_lea_ecx_callee, neg_join_maybe_ptr_callee, plus neg_mem_ecx_callee / neg_lea_disp_callee regressions) with escapes or is unsupported and kills spot-mutants A (drop LEA is_gpr64), B (merged[r] = 2 -> 1) and C (drop _check_ptr_mem != 1), each accepting only its own control; form_coverage_check.py, docs_links_check.py (175 md / 713 links), bidi_controls_check.py (2669 files) and git diff --check all exit 0. llvm-ml-19 -m64 assembly of the fixture on Linux is still pending (toolchain install needs approval); Windows ml64 assembly plus the full cpu_switch_frame_ptr differential run are covered by the WIN-VERIFY run below.

Windows Verification

  • Commit: c66aa6be397db9ea7d15f89fb510e5e5b091ce49
  • Preset dev: ctest --preset dev --no-tests=error -R '^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$' --output-on-failure -> 7 passed, 0 failed (4.88s; cpu_switch_frame_ptr 1.30s)
  • Preset release: ctest --preset release --no-tests=error -R '^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$' --output-on-failure -> 7 passed, 0 failed (4.45s; cpu_switch_frame_ptr 1.22s)
  • Repo checks: form_coverage_check.py, docs_links_check.py (175 Markdown files, 713 links), and bidi_controls_check.py (2669 files) passed.
2542: refused neg_mem_ecx_callee: escapes or is unsupported
2542: refused neg_lea_ecx_callee: escapes or is unsupported
2542: refused neg_join_maybe_ptr_callee: escapes or is unsupported
2542: guard mutation (disable prove_frame ptr_calls) confirmed: neg_uninit_callee_read accepted
2542: guard mutation (disable post-call must_write marking) confirmed: out_u32_rsp refused
2542: cpu_switch_frame_ptr: all differential (/Od, /O2), mutant, and 49 refusal checks passed
1/1 Test #2542: cpu_switch_frame_ptr .............   Passed    1.16 sec

AI-assisted.

**@⁠Ammmae0x** on GitHub · 2026-11-27 16:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3121) `Ammmae0x:cpu/switch-frame-ptr-callees` → `main` · +1905 −11 · 6 files · 5 commits · merged 2026-11-29 17:48 UTC ## Change Extend `tools/cpu_switch_aot.py` so bounded, non-recursive internal callees that read or write a single fixed-width scalar (1, 2, 4, or 8 bytes) through an argument register (`RCX`/`RDX`/`R8`/`R9`) without pointer escape can receive a proven frame-slot address via `LEA reg, [rsp+disp]` or `[rbp+disp]` (under a proven frame anchor). Refs #317. - **Pointer-parameter summary (`analyze_pointer_param`, `_step_ptr_instruction`, `_check_ptr_mem`, `PointerParam`)**: tracks non-escaping 64-bit scalar pointer flow across copies, nested non-recursive internal callees, and control-flow joins; computes `(width, reads_before_write, must_write, may_write)` across all normal exits (`RET` and tail jumps), rejecting escapes (return in `RAX`, memory/stack stores, pointer arithmetic, displaced/indexed `LEA` or memory operands, 32-bit `[ecx]` addressing, register `BT*`, `MOVS`/`STOS`, `SIGN_EXTENSIONS`, one-operand `MUL`/`DIV`, 32-bit/16-bit `CMOVcc` truncation, `COND_WRITE` such as `BSF`/`BSR` on a live pointer destination, 8/16-bit partial overwrites, recursive/cyclic callees, mixed widths, and unaccessed pointer parameters). - **Caller frame bounds & initialization proof (`Frame`, `prove_frame`)**: only treats `RBP`-based `LEA` as a frame pointer when a frame anchor is proven (preserving non-anchor `RBP` integer arithmetic); validates pointed bytes stay within `[frame.offsets[ip] + HOME_SIZE + 8*len(stack_args), frame.end)`, never overlap return address or callee home space/stack args, and never alias across multiple pointer arguments; enforces caller initialization before any `reads_before_write` callee and marks written bytes defined after `must_write` (or preserves/clears saved-register markers conservatively on `may_write`). `HostImport --stack-output` is unchanged. - **Fixture & verification (`tests/cpu/switch_frame_ptr.asm`, `tests/cpu/switch_frame_ptr.def`, `tests/cpu/switch_frame_ptr_check.py`, `tests/cmake/cpu_switch_frame_ptr.cmake`, `docs/experiments.md`)**: adds 4 differential exports (`out_u32_rsp`, `rmw_u64_rbp`, `all_widths_and_regs`, `non_anchor_rbp_arith`) across 313 input pairs at both `/Od` and `/O2`, 2 compiled C++ mutants, 2 Python guard mutations, and 49 refusal negative controls (44 exercising the new pointer-parameter/aliasing/bounds/saved-slot/incoming-slot rules and 5 caught by main's existing frame/tail/anchor checks). ### Guard -> Red Control Table | Guard removed / weakened | Failing control | |---|---| | General register-read escape (`READS`) | `neg_escape_store_mem` (plus `_store_stack`, `neg_ptr_arith`) | | Callee tail-jump live pointer arg check | `neg_callee_tail_ptr_live` | | Nested callee multi-arg pointer check (`len(live_args) > 1`) | `neg_nested_multi_live` | | Nested callee integer-use check (`nested is None`) | `neg_nested_int_callee` | | `LEA` zero-displacement / zero-index guard | `neg_lea_disp_callee` | | `LEA` 64-bit base guard (`RegisterExt.is_gpr64(ins.memory_base)`) | `neg_lea_ecx_callee` | | Join state-2 (`merged[r] = 2`) + `_check_ptr_mem` state-1 requirement | `neg_join_maybe_ptr_callee` | | `check_mem` displacement / index / 64-bit base / `BIT_TESTS` guards | `neg_mem_disp_callee`, `neg_mem_index_callee`, `neg_mem_ecx_callee`, `neg_bit_test_reg_callee` | | `CMOVcc` memory-form 32-bit truncation (`w_reg != 8`) | `neg_cmov32_mem_callee` | | `STRING_TRANSFERS` (`STOS`/`MOVS`), `SIGN_EXTENSIONS`, `MUL`/`DIV`, `<4B` partial writes | `neg_stos_ptr_rax`, `neg_sign_ext_callee`, `neg_mul_ptr_callee`, `neg_bsf_cond_write_escape` | | `may_write` clearing saved-register slot markers | `neg_may_write_saved_reg` | | Caller `min_offset` stack-argument size & incoming stack-slot demand propagation | `neg_callee_stack_arg_overlap`, `neg_incoming_stack_slot_uninit` | | Multi-arg pointer aliasing check | `neg_multi_arg_alias_same`, `neg_multi_arg_alias_overlap` | ## Verification Verified on commit `2a685c06` in `liaison` worktree on Windows x64 (MSVC 19.50.35727.0): - `ctest --preset dev -N` -> 2929 tests including `#2497: cpu_switch_frame_ptr`. - `cmake --build --preset dev` & `release` (affected 7 test targets) -> exit 0 (0 errors, 0 warnings). - `ctest --preset dev --no-tests=error -R "^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$" -E "cpu_native_archive_" --output-on-failure` -> 7/7 passed (exit 0). - `ctest --preset release --no-tests=error -R "^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$" -E "cpu_native_archive_" --output-on-failure` -> 7/7 passed (exit 0). - `out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`, `tests/docs_links_check.py` (154 md / 676 links), `tests/bidi_controls_check.py` (2537 files) -> all exit 0. - Guard-mutation audit: 18/18 targeted guard removals + 5/5 verifier spot-mutations killed. ## Evidence and follow-up All fixtures (`tests/cpu/switch_frame_ptr.asm`, `.def`, `_check.py`) are source-owned under this repository; no external binaries or game files are used. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted. ### Repair: @⁠pigalot review on `2a685c06` (head `c66aa6be`) Merged `origin/main` `5de0b114` cleanly (merge commit `9af6f85a`; `git merge-tree --write-tree origin/main HEAD` exits 0). - **Blocking fix:** `_step_ptr_instruction`'s `LEA` copy branch now requires `RegisterExt.is_gpr64(ins.memory_base)`, so `lea reg, [ecx]` (`67 4C 8D 09`) is refused instead of tracked as an exact state-1 copy. New control `neg_lea_ecx_callee` next to `neg_mem_ecx_callee`. - **Join/state-1 control:** new `neg_join_maybe_ptr_callee` (`test edx, edx` / `jz` / `mov rcx, r8`, then a store through `rcx`) dereferences a pointer that is only possibly the parameter (state 2 at the join). Weakening the join to `merged[r] = 1` and dropping `_check_ptr_mem`'s state-1 requirement each accept it independently. The store uses `edx`, the fixture's stored-value register: with `eax` the callee is refused as `undefined register rax` instead, since `eax` is undefined at callee entry. - Refusal controls are now 49 (44 + 5); the guard table above gains both rows. - **Other survivors assessed, not pinned in this push:** the live-index sub-checks in the `LEA` branch and `_check_ptr_mem` are equivalent (any index refuses the copy/deref anyway — verified on Linux: removing either alone changes nothing). `LEA` 32-bit destination, the state-1 requirement in the `LEA` copy, 8/16-bit `LEA` destination, a pointer live at a host-import/unresolved call or as a jump-table index, the volatile drop after a nested call, memory-form `CMOVcc` giving state 2, and the 16-bit `MUL`/`DIV` RDX, segment-prefix and access-kind checks in `_check_ptr_mem` still have no dedicated control — follow-up candidates, no behavior change in this push. - **Linux verification on `c66aa6be`:** `lea r9, [ecx]` and the join encodings cross-checked with keystone (LLVM MC) and iced-x86 (`67 4C 8D 09`; join `85 D2 74 03 4C 89 C1 89 11 31 C0 C3`); a synthetic-PE translation harness refuses all four controls (`neg_lea_ecx_callee`, `neg_join_maybe_ptr_callee`, plus `neg_mem_ecx_callee` / `neg_lea_disp_callee` regressions) with `escapes or is unsupported` and kills spot-mutants A (drop LEA `is_gpr64`), B (`merged[r] = 2` -> `1`) and C (drop `_check_ptr_mem` `!= 1`), each accepting only its own control; `form_coverage_check.py`, `docs_links_check.py` (175 md / 713 links), `bidi_controls_check.py` (2669 files) and `git diff --check` all exit 0. `llvm-ml-19 -m64` assembly of the fixture on Linux is still pending (toolchain install needs approval); Windows `ml64` assembly plus the full `cpu_switch_frame_ptr` differential run are covered by the `WIN-VERIFY` run below. ## Windows Verification - Commit: `c66aa6be397db9ea7d15f89fb510e5e5b091ce49` - Preset `dev`: `ctest --preset dev --no-tests=error -R '^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$' --output-on-failure` -> `7 passed, 0 failed` (`4.88s`; `cpu_switch_frame_ptr` `1.30s`) - Preset `release`: `ctest --preset release --no-tests=error -R '^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$' --output-on-failure` -> `7 passed, 0 failed` (`4.45s`; `cpu_switch_frame_ptr` `1.22s`) - Repo checks: `form_coverage_check.py`, `docs_links_check.py` (175 Markdown files, 713 links), and `bidi_controls_check.py` (2669 files) passed. ```text 2542: refused neg_mem_ecx_callee: escapes or is unsupported 2542: refused neg_lea_ecx_callee: escapes or is unsupported 2542: refused neg_join_maybe_ptr_callee: escapes or is unsupported 2542: guard mutation (disable prove_frame ptr_calls) confirmed: neg_uninit_callee_read accepted 2542: guard mutation (disable post-call must_write marking) confirmed: out_u32_rsp refused 2542: cpu_switch_frame_ptr: all differential (/Od, /O2), mutant, and 49 refusal checks passed 1/1 Test #2542: cpu_switch_frame_ptr ............. Passed 1.16 sec ``` AI-assisted. <!-- WIN-VERIFY: passed | sha=c66aa6be397db9ea7d15f89fb510e5e5b091ce49 -->
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 16:07:47 +00:00
Author
Owner

@⁠JohnConnorNPC on GitHub · 2026-11-27 18:11 UTC · original

Hi @⁠Ammmae0x, thanks for this. The frame-slot pointer analysis is careful, and the parts I could reproduce held up.

On a Linux cross build (llvm-ml + lld-link for the fixture, clang-cl for the lifted C++, run under Wine):

  • your check's Python half passes (26 refusals, both guard mutations);
  • native, lifted /Od and lifted /O2 agree on all 4 × 313 pairs;
  • both C++ mutants are caught;
  • every export of the other 167 fixture DLLs I could assemble translates exactly as before.

I also tried a dozen hand-written probe exports against the analysis, and it refused every one that should be refused.

A few things before this is ready:

  1. Pin the new guards. I deleted each guard in analyze_pointer_param / resolve_pointer_calls / prove_frame one at a time. 34 of 51 deletions leave cpu_switch_frame_ptr fully green: same refusals, same guard-mutation results, and byte-identical positive C++. That includes the central "any register read of the pointer escapes" check.
    • The reason: store_mem_callee, store_stack_callee and ptr_arith_callee never dereference the pointer, so the no-access fallback refuses them anyway.
    • Could each escape control also access the pointer once, the way ret_rax_callee does? That way the guard it names is the only reason it is refused.
    • Please also add controls for the guards that currently have none:
      • the callee-side tail jump with the pointer still in an argument register;
      • a nested callee that uses the register as an integer;
      • LEA with an index or displacement, and [ptr+disp] / [idx] / [ecx] operands;
      • MOVS/STOS, sign extensions, MUL/DIV, and 8/16-bit partial writes;
      • may_write over a saved-register slot, and a read of a saved-register slot;
      • a pointer into the call's own stack-argument slot, and a pointer into the caller's incoming stack-argument slot.
    • For several of these (for example a callee doing mov [rcx], edx; mov [r8], rcx) I measured native ≠ lifted once the guard is removed, so each matters.
    • A small table in the PR body ("guard removed → which control goes red") would make this easy to review.
  2. Make each control fail for its own reason. Today:
    • neg_multi_arg_alias_same / _overlap leave R8/R9 unset, so without the alias check they are still refused, as callee argument r9 is undefined.
    • Five controls (neg_tail_jump, neg_tail_rbp, neg_var_index_lea, neg_multi_arg_copy_alias, neg_unproven_rbp) are refused by main's translator with the same message. They are fine as "still refused" checks, but they don't exercise the new code, so the body's "26 refusal negative controls" overstates the new coverage.
  3. docs/experiments.md. The paragraph on direct calls still says that "a frame address passed to a callee (LEA RCX, [RSP+20h]) … stay rejected", and that LEA RAX, [RSP+8] is rejected because the frame address would escape. Both are no longer true for bounded internal callees. Please:
    • update that paragraph;
    • add an entry for cpu_switch_frame_ptr with the reproduction command and the measured result (AGENTS.md › Pull requests asks for this).
  4. CI evidence. The pr preset doesn't build or run cpu_switch_frame_ptr (or the other cpu_aot_* regression tests besides cpu_aot_fuzz_smoke), and the /O2 job is skipped on pull requests. So the green checks don't cover this test. Could you paste the full ctest --preset dev --no-tests=error -R "^cpu_switch_frame_ptr$" -V output from your Windows run, including the test's own printed lines? Whether to add it to the pr preset is the maintainers' call.
  5. Comments.
    • In prove_frame, the call-step comment says the rest of the frame "is kept", but the new loop just below now changes the pointed-to bytes.
    • The Frame docstring describes accesses as bytes each instruction accesses, but pointer LEAs are now recorded there without accessing anything.
    • The call-site comment in lift_function only describes stack arguments passed by value.
    • Please bring these in line with the new code.
  6. Small things.
    • if not accesses: return None is already covered by len(widths) != 1, and the frame_ptr_params = {} reset in Program.callee is already implied by function.recursive. Keep them with a comment saying they are deliberate redundancy, or drop them.
    • In the PR body, analyze_pointer_param reads as ^Gnalyze_pointer_param, and four tests/... paths lost their \t to a tab character.

Thanks again; with the controls tightened, this will be much easier to trust and keep.

This comment was AI-assisted.

**@⁠JohnConnorNPC** on GitHub · 2026-11-27 18:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3121#issuecomment-7225220947) Hi @⁠Ammmae0x, thanks for this. The frame-slot pointer analysis is careful, and the parts I could reproduce held up. On a Linux cross build (llvm-ml + lld-link for the fixture, clang-cl for the lifted C++, run under Wine): - your check's Python half passes (26 refusals, both guard mutations); - native, lifted /Od and lifted /O2 agree on all 4 × 313 pairs; - both C++ mutants are caught; - every export of the other 167 fixture DLLs I could assemble translates exactly as before. I also tried a dozen hand-written probe exports against the analysis, and it refused every one that should be refused. A few things before this is ready: 1. **Pin the new guards.** I deleted each guard in `analyze_pointer_param` / `resolve_pointer_calls` / `prove_frame` one at a time. 34 of 51 deletions leave `cpu_switch_frame_ptr` fully green: same refusals, same guard-mutation results, and byte-identical positive C++. That includes the central "any register read of the pointer escapes" check. - The reason: `store_mem_callee`, `store_stack_callee` and `ptr_arith_callee` never dereference the pointer, so the no-access fallback refuses them anyway. - Could each escape control also access the pointer once, the way `ret_rax_callee` does? That way the guard it names is the only reason it is refused. - Please also add controls for the guards that currently have none: - the callee-side tail jump with the pointer still in an argument register; - a nested callee that uses the register as an integer; - LEA with an index or displacement, and `[ptr+disp]` / `[idx]` / `[ecx]` operands; - `MOVS`/`STOS`, sign extensions, `MUL`/`DIV`, and 8/16-bit partial writes; - `may_write` over a saved-register slot, and a read of a saved-register slot; - a pointer into the call's own stack-argument slot, and a pointer into the caller's incoming stack-argument slot. - For several of these (for example a callee doing `mov [rcx], edx; mov [r8], rcx`) I measured native ≠ lifted once the guard is removed, so each matters. - A small table in the PR body ("guard removed → which control goes red") would make this easy to review. 2. **Make each control fail for its own reason.** Today: - `neg_multi_arg_alias_same` / `_overlap` leave R8/R9 unset, so without the alias check they are still refused, as `callee argument r9 is undefined`. - Five controls (`neg_tail_jump`, `neg_tail_rbp`, `neg_var_index_lea`, `neg_multi_arg_copy_alias`, `neg_unproven_rbp`) are refused by main's translator with the same message. They are fine as "still refused" checks, but they don't exercise the new code, so the body's "26 refusal negative controls" overstates the new coverage. 3. **docs/experiments.md.** The paragraph on direct calls still says that "a frame address passed to a callee (`LEA RCX, [RSP+20h]`) … stay rejected", and that `LEA RAX, [RSP+8]` is rejected because the frame address would escape. Both are no longer true for bounded internal callees. Please: - update that paragraph; - add an entry for `cpu_switch_frame_ptr` with the reproduction command and the measured result (AGENTS.md › Pull requests asks for this). 4. **CI evidence.** The `pr` preset doesn't build or run `cpu_switch_frame_ptr` (or the other `cpu_aot_*` regression tests besides `cpu_aot_fuzz_smoke`), and the /O2 job is skipped on pull requests. So the green checks don't cover this test. Could you paste the full `ctest --preset dev --no-tests=error -R "^cpu_switch_frame_ptr$" -V` output from your Windows run, including the test's own printed lines? Whether to add it to the `pr` preset is the maintainers' call. 5. **Comments.** - In `prove_frame`, the call-step comment says the rest of the frame "is kept", but the new loop just below now changes the pointed-to bytes. - The `Frame` docstring describes `accesses` as bytes each instruction accesses, but pointer LEAs are now recorded there without accessing anything. - The call-site comment in `lift_function` only describes stack arguments passed by value. - Please bring these in line with the new code. 6. **Small things.** - `if not accesses: return None` is already covered by `len(widths) != 1`, and the `frame_ptr_params = {}` reset in `Program.callee` is already implied by `function.recursive`. Keep them with a comment saying they are deliberate redundancy, or drop them. - In the PR body, `analyze_pointer_param` reads as `^Gnalyze_pointer_param`, and four `tests/...` paths lost their `\t` to a tab character. Thanks again; with the controls tightened, this will be much easier to trust and keep. This comment was AI-assisted.
Author
Owner

@⁠KelboLive on GitHub · 2026-11-27 18:51 UTC · original · approved these changes

Significant and well-executed extension of cpu_switch_aot.py for bounded frame-slot pointer passing. The PointerParam analysis correctly tracks width, read-before-write ordering, write certainty, and escape detection across all control-flow exits. Frame bounds validation ensures pointed bytes stay within the caller's stack frame without overlapping return addresses or callee home space. Multi-argument aliasing guards, recursive/cycle rejection, and initialization proofs are all correct. The differential fixture with 313 input pairs at /Od and /O2, plus 26 refusal negative controls and mutation audit, provides thorough verification. Approved.

**@⁠KelboLive** on GitHub · 2026-11-27 18:51 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3121#pullrequestreview-6092273826) · **approved these changes** Significant and well-executed extension of `cpu_switch_aot.py` for bounded frame-slot pointer passing. The `PointerParam` analysis correctly tracks width, read-before-write ordering, write certainty, and escape detection across all control-flow exits. Frame bounds validation ensures pointed bytes stay within the caller's stack frame without overlapping return addresses or callee home space. Multi-argument aliasing guards, recursive/cycle rejection, and initialization proofs are all correct. The differential fixture with 313 input pairs at /Od and /O2, plus 26 refusal negative controls and mutation audit, provides thorough verification. Approved.
Author
Owner

@⁠KelboLive on GitHub · 2026-11-28 00:04 UTC · original

This is a significant extension to cpu_switch_aot.py. JohnConnorNPC's 6-point review covers the most important issues (guard pinning, control reasons, docs update, CI evidence, comments, small things). I'll add a few additional observations:

1. analyze_pointer_param complexity (~250 lines). The function is dense and handles many instruction types inline. Consider extracting step_ptr into its own helper with a docstring explaining the state machine (the 3 states: 0=dead, 1=proven pointer, 2=possibly-pointer). This would make future maintenance much easier.

2. Hardcoded instruction sets. The function references BIT_TESTS, CMOVCC, STRING_TRANSFERS, SIGN_EXTENSIONS — these are defined elsewhere in the file but not imported or documented at the call site. Please add a comment listing what each set covers, or verify they're already well-documented nearby.

3. PR body accuracy. The body claims "26 refusal negative controls" but JohnConnorNPC notes that 5 of those (neg_tail_jump, neg_tail_rbp, neg_var_index_lea, neg_multi_arg_copy_alias, neg_unproven_rbp) are refused by main's translator before the new code runs. The actual new-code coverage is 21 controls, not 26. Please correct this in the body.

4. may_write over saved-register slots. JohnConnorNPC flags this as a missing guard. Looking at the code: when param.may_write is true and the slot holds saved nonvolatile bytes (not all ones), the current code clears it to zero on post-call marking. But there's no pre-call check that prevents a pointer into a saved-register slot from being passed — the reads_before_write guard only catches reads, not writes. A callee could write through such a pointer without triggering any refusal. This seems like a real gap worth flagging explicitly in the controls.

5. Tail-jump handling. In step_ptr, tail jumps check if argument registers are live and return "escape". But the fixture neg_tail_jump uses jmp write_u32_out (not through the normal call path), so it's caught by main's translator before reaching the new code. A proper test would be a tail jump to an internal callee where the pointer is in RCX — that should exercise the new escape check directly.

6. Redundancy guards. JohnConnorNPC notes if not accesses: return None is covered by len(widths) != 1, and function.frame_ptr_params = {} reset is implied by function.recursive. These are harmless but add noise. If kept, add a comment like "# deliberate redundancy for clarity" as suggested.

**@⁠KelboLive** on GitHub · 2026-11-28 00:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3121#issuecomment-7230626933) This is a significant extension to cpu_switch_aot.py. JohnConnorNPC's 6-point review covers the most important issues (guard pinning, control reasons, docs update, CI evidence, comments, small things). I'll add a few additional observations: **1. `analyze_pointer_param` complexity (~250 lines).** The function is dense and handles many instruction types inline. Consider extracting `step_ptr` into its own helper with a docstring explaining the state machine (the 3 states: 0=dead, 1=proven pointer, 2=possibly-pointer). This would make future maintenance much easier. **2. Hardcoded instruction sets.** The function references `BIT_TESTS`, `CMOVCC`, `STRING_TRANSFERS`, `SIGN_EXTENSIONS` — these are defined elsewhere in the file but not imported or documented at the call site. Please add a comment listing what each set covers, or verify they're already well-documented nearby. **3. PR body accuracy.** The body claims "26 refusal negative controls" but JohnConnorNPC notes that 5 of those (`neg_tail_jump`, `neg_tail_rbp`, `neg_var_index_lea`, `neg_multi_arg_copy_alias`, `neg_unproven_rbp`) are refused by main's translator before the new code runs. The actual new-code coverage is 21 controls, not 26. Please correct this in the body. **4. `may_write` over saved-register slots.** JohnConnorNPC flags this as a missing guard. Looking at the code: when `param.may_write` is true and the slot holds saved nonvolatile bytes (not all ones), the current code clears it to zero on post-call marking. But there's no pre-call check that prevents a pointer into a saved-register slot from being passed — the `reads_before_write` guard only catches reads, not writes. A callee could write through such a pointer without triggering any refusal. This seems like a real gap worth flagging explicitly in the controls. **5. Tail-jump handling.** In `step_ptr`, tail jumps check if argument registers are live and return "escape". But the fixture `neg_tail_jump` uses `jmp write_u32_out` (not through the normal call path), so it's caught by main's translator before reaching the new code. A proper test would be a tail jump to an internal callee where the pointer is in RCX — that should exercise the new escape check directly. **6. Redundancy guards.** JohnConnorNPC notes `if not accesses: return None` is covered by `len(widths) != 1`, and `function.frame_ptr_params = {}` reset is implied by `function.recursive`. These are harmless but add noise. If kept, add a comment like "# deliberate redundancy for clarity" as suggested.
Author
Owner

@⁠JohnConnorNPC on GitHub · 2026-11-28 08:18 UTC · original

Thanks for this. This follows up the earlier review comment. I re-checked on head 129fcc38, which is still the only commit, so none of the items from either review comment are in yet. Two things still block it:

  1. Most new guards are still unpinned. I deleted one guard at a time in a copy of tools/cpu_switch_aot.py. For each copy I ran the check's Python half (check_refusals_and_guard_mutations plus translate of the four exports) against the fixture DLL built from this head.
    • With step_ptr's register-read escape turned into pass, all 26 controls are still refused, both guard mutations still behave as expected, and the generated C++ is byte-identical.
    • Three more deletions stay green the same way: keeping saved-register markers after may_write (replacement = existing), allowing [ptr+disp] in check_mem (dropping ins.memory_displacement != 0), and the memory-form 32-bit CMOVcc escape (if w_reg != 8 → if False).
    • Dropping offset < min_offset, the must-write meet (and → or) or the pre-call read check goes red, as it should.
    • An escape control that also dereferences the pointer once, plus one control per remaining guard, would pin these.
  2. docs/experiments.md still says "A frame address passed to a callee (LEA RCX, [RSP+20h]) … stay rejected". It also has no cpu_switch_frame_ptr entry (see AGENTS.md › Pull requests).

Smaller points:
3. With the alias check deleted, neg_multi_arg_alias_same goes red only because of the message match: expected 'aliased frame-slot pointers', got callee argument r9 is undefined. Setting R8/R9 in those controls would make them fail for their own reason.
4. On item 4 of the 00:04 UTC comment: by my reading of prove_frame, a write through the pointer into a saved-register slot that is later restored from is already refused. The post-call rule replaces the saved markers (b"\1" or bytes(param.width)), so the POP doesn't count as a restore and the RET check rejects it. That rule is unpinned, though: the replacement = existing mutant above stays green.
5. CI still doesn't run the new test. The Windows job reports 100% tests passed out of 41, and its log has no cpu_switch_frame_ptr line.

The PR still merges cleanly into current main 1f07b2c1 (git merge-tree --write-tree rc 0). On the merged tree the check's Python half passes, with 26 refusals and the same generated C++.

This comment was AI-assisted.

**@⁠JohnConnorNPC** on GitHub · 2026-11-28 08:18 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3121#issuecomment-7236495715) Thanks for this. This follows up the earlier review comment. I re-checked on head 129fcc38, which is still the only commit, so none of the items from either review comment are in yet. Two things still block it: 1. **Most new guards are still unpinned.** I deleted one guard at a time in a copy of `tools/cpu_switch_aot.py`. For each copy I ran the check's Python half (`check_refusals_and_guard_mutations` plus `translate` of the four exports) against the fixture DLL built from this head. - With `step_ptr`'s register-read escape turned into `pass`, all 26 controls are still refused, both guard mutations still behave as expected, and the generated C++ is byte-identical. - Three more deletions stay green the same way: keeping saved-register markers after `may_write` (`replacement = existing`), allowing `[ptr+disp]` in `check_mem` (dropping `ins.memory_displacement != 0`), and the memory-form 32-bit `CMOVcc` escape (`if w_reg != 8` → `if False`). - Dropping `offset < min_offset`, the must-write meet (`and` → `or`) or the pre-call read check goes red, as it should. - An escape control that also dereferences the pointer once, plus one control per remaining guard, would pin these. 2. **docs/experiments.md** still says "A frame address passed to a callee (`LEA RCX, [RSP+20h]`) … stay rejected". It also has no `cpu_switch_frame_ptr` entry (see AGENTS.md › Pull requests). Smaller points: 3. With the alias check deleted, `neg_multi_arg_alias_same` goes red only because of the message match: `expected 'aliased frame-slot pointers', got callee argument r9 is undefined`. Setting R8/R9 in those controls would make them fail for their own reason. 4. On item 4 of the 00:04 UTC comment: by my reading of `prove_frame`, a write through the pointer into a saved-register slot that is later restored from is already refused. The post-call rule replaces the saved markers (`b"\1"` or `bytes(param.width)`), so the `POP` doesn't count as a restore and the RET check rejects it. That rule is unpinned, though: the `replacement = existing` mutant above stays green. 5. CI still doesn't run the new test. The Windows job reports `100% tests passed out of 41`, and its log has no `cpu_switch_frame_ptr` line. The PR still merges cleanly into current main 1f07b2c1 (`git merge-tree --write-tree` rc 0). On the merged tree the check's Python half passes, with 26 refusals and the same generated C++. This comment was AI-assisted.
Author
Owner

@⁠Ammmae0x on GitHub · 2026-11-28 11:07 UTC · original

Addressed all items from JohnConnorNPC and KelboLive in 2a685c06 (merged with upstream/main ec71c290):

  1. Pinned guards & isolated failure reasons:
    • Updated store_mem_callee, store_stack_callee, and ptr_arith_callee to dereference [rcx] before escaping so removing the general register-read escape accepts them directly instead of hitting the no-access fallback.
    • Defined r8/r9 in neg_multi_arg_alias_same and neg_multi_arg_alias_overlap so the aliasing check is the sole refusal reason.
    • Added 21 new refusal controls (neg_callee_tail_ptr_live, neg_nested_int_callee, neg_nested_multi_live, neg_nested_cmov_ptr, neg_lea_disp_callee, neg_lea_index_callee, neg_mem_disp_callee, neg_mem_index_callee, neg_mem_ecx_callee, neg_stos_ptr_rax, neg_movs_ptr_rsi, neg_sign_ext_callee, neg_mul_ptr_callee, neg_partial_write_callee, neg_xor8_partial_callee, neg_bit_test_reg_callee, neg_cmov32_mem_callee, neg_may_write_saved_reg, neg_read_saved_reg, neg_callee_stack_arg_overlap, neg_incoming_stack_slot_uninit) — 47 total (42 new-code controls + 5 existing main-translator controls). Verified 18/18 guard-removal mutations killed.
  2. Code readability & comments (tools/cpu_switch_aot.py):
    • Extracted _check_ptr_mem and _step_ptr_instruction with a docstring documenting the 3-state lattice (0=dead, 1=proven, 2=possibly-pointer) and the BIT_TESTS/CMOVCC/STRING_TRANSFERS/SIGN_EXTENSIONS sets.
    • Updated Frame docstring, prove_frame call-step comment, and lift_function call-site comment; documented deliberate redundancy on if not accesses: and member.frame_ptr_params = {}.
  3. Docs & PR body:
    • Updated docs/experiments.md (direct-call/frame paragraphs + new cpu_switch_frame_ptr section with reproduction command and results) and fixed the analyze_pointer_param / tests/... typos and guard-to-control table in the PR body.
  4. Full Windows ctest --preset dev --no-tests=error -R "^cpu_switch_frame_ptr$" -V output:
2497: Test command: C:\Users\Ammar\.gemini\antigravity\scratch\Xbox2Windows\out\pe-env\Scripts\python.exe "-B" "C:/Users/Ammar/.gemini/antigravity/scratch/Xbox2Windows-wt/liaison/tests/cpu/switch_frame_ptr_check.py" "C:/Users/Ammar/.gemini/antigravity/scratch/Xbox2Windows-wt/liaison/out/build/dev/cpu_register_probe.dll" "C:/Users/Ammar/.gemini/antigravity/scratch/Xbox2Windows-wt/liaison/out/build/dev/cpu_switch_frame_ptr.dll" "C:/Users/Ammar/.gemini/antigravity/scratch/Xbox2Windows-wt/liaison/out/build/dev/cpu_switch_frame_ptr_lifted.dll" "C:/Users/Ammar/.gemini/antigravity/scratch/Xbox2Windows-wt/liaison/out/build/dev/cpu_switch_frame_ptr_lifted.cpp" "C:/Program Files (x86)/Microsoft Visual Studio/18/BuildTools/VC/Tools/MSVC/14.50.35717/bin/Hostx64/x64/cl.exe"
2497: Working Directory: C:/Users/Ammar/.gemini/antigravity/scratch/Xbox2Windows-wt/liaison/out/build/dev
2497: Test timeout computed to be: 10000000
2497: verified 4 exports x 313 inputs (/Od)
2497: verified 4 exports x 313 inputs (/O2)
2497: cpp mutant shift_frame_ptr caught: shift_frame_ptr.dll lifted_out_u32_rsp(0x0, 0x0) = (53, (6510797682304636536, 0, 53, 18446744073709551615, 11935946389686928161), (81985529216486895, 18364758544493064720)), expected (0xa55a1269, (6510797682304636536, 2774143540, 53, 18446744073709551615, 11935946389686928161), (81985529216486895, 18364758544493064720))
2497: cpp mutant drop_callee_store caught: drop_callee_store.dll lifted_out_u32_rsp(0x0, 0x0) = (53, (6510797682304636536, 0, 53, 18446744073709551615, 11935946389686928161), (81985529216486895, 18364758544493064720)), expected (0xa55a1269, (6510797682304636536, 2774143540, 53, 18446744073709551615, 11935946389686928161), (81985529216486895, 18364758544493064720))
2497: refused neg_escape_ret_rax: escapes or is unsupported
2497: refused neg_escape_store_mem: escapes or is unsupported
2497: refused neg_escape_store_stack: escapes or is unsupported
2497: refused neg_recursive_cycle: recursive callee
2497: refused neg_mutual_cycle: recursive callee
2497: refused neg_tail_jump: frame address escapes
2497: refused neg_tail_rbp: unsupported stack operand
2497: refused neg_var_index_lea: frame address escapes
2497: refused neg_multi_arg_alias_same: aliased frame-slot pointers
2497: refused neg_multi_arg_alias_overlap: aliased frame-slot pointers
2497: refused neg_multi_arg_copy_alias: frame address escapes
2497: refused neg_home_space_overlap: overlaps callee home space
2497: refused neg_ret_addr_overlap: return address slot accessed
2497: refused neg_past_home_end: unsupported stack argument
2497: refused neg_uninit_callee_read: undefined stack byte
2497: refused neg_uninit_caller_wider_read: undefined stack byte
2497: refused neg_cond_write_uninit_read: undefined stack byte
2497: refused neg_mixed_widths: escapes or is unsupported
2497: refused neg_unaccessed_ptr: escapes or is unsupported
2497: refused neg_ptr_arith: escapes or is unsupported
2497: refused neg_unproven_rbp: nonvolatile register rbp may hold the caller's value
2497: refused neg_split_anchor_rbp: frame pointer differs at join
2497: refused neg_tail_exit_partial_write: undefined stack byte
2497: refused neg_cmov32_ptr_trunc: escapes or is unsupported
2497: refused neg_bsf_cond_write_escape: escapes or is unsupported
2497: refused neg_bsr_cond_write_escape: escapes or is unsupported
2497: refused neg_callee_tail_ptr_live: escapes or is unsupported
2497: refused neg_nested_int_callee: escapes or is unsupported
2497: refused neg_nested_multi_live: escapes or is unsupported
2497: refused neg_nested_cmov_ptr: escapes or is unsupported
2497: refused neg_lea_disp_callee: escapes or is unsupported
2497: refused neg_lea_index_callee: escapes or is unsupported
2497: refused neg_mem_disp_callee: escapes or is unsupported
2497: refused neg_mem_index_callee: escapes or is unsupported
2497: refused neg_mem_ecx_callee: escapes or is unsupported
2497: refused neg_stos_ptr_rax: escapes or is unsupported
2497: refused neg_movs_ptr_rsi: escapes or is unsupported
2497: refused neg_sign_ext_callee: escapes or is unsupported
2497: refused neg_mul_ptr_callee: escapes or is unsupported
2497: refused neg_partial_write_callee: escapes or is unsupported
2497: refused neg_xor8_partial_callee: escapes or is unsupported
2497: refused neg_bit_test_reg_callee: escapes or is unsupported
2497: refused neg_cmov32_mem_callee: escapes or is unsupported
2497: refused neg_may_write_saved_reg: undefined stack byte
2497: refused neg_read_saved_reg: hold the saved rbx, read as data
2497: refused neg_callee_stack_arg_overlap: overlaps callee home space or stack arguments
2497: refused neg_incoming_stack_slot_uninit: stack argument 5 of the call
2497: guard mutation (disable prove_frame ptr_calls) confirmed: neg_uninit_callee_read accepted
2497: guard mutation (disable post-call must_write marking) confirmed: out_u32_rsp refused
2497: cpu_switch_frame_ptr: all differential (/Od, /O2), mutant, and 47 refusal checks passed
1/1 Test #2497: cpu_switch_frame_ptr .............   Passed    1.84 sec

Also verified dev & release builds/tests across all 7 affected cpu_aot_* / cpu_switch_frame_ptr targets (7/7 passed in both presets).

AI-assisted.

**@⁠Ammmae0x** on GitHub · 2026-11-28 11:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3121#issuecomment-7238341823) Addressed all items from JohnConnorNPC and KelboLive in `2a685c06` (merged with `upstream/main` `ec71c290`): 1. **Pinned guards & isolated failure reasons**: - Updated `store_mem_callee`, `store_stack_callee`, and `ptr_arith_callee` to dereference `[rcx]` before escaping so removing the general register-read escape accepts them directly instead of hitting the no-access fallback. - Defined `r8`/`r9` in `neg_multi_arg_alias_same` and `neg_multi_arg_alias_overlap` so the aliasing check is the sole refusal reason. - Added 21 new refusal controls (`neg_callee_tail_ptr_live`, `neg_nested_int_callee`, `neg_nested_multi_live`, `neg_nested_cmov_ptr`, `neg_lea_disp_callee`, `neg_lea_index_callee`, `neg_mem_disp_callee`, `neg_mem_index_callee`, `neg_mem_ecx_callee`, `neg_stos_ptr_rax`, `neg_movs_ptr_rsi`, `neg_sign_ext_callee`, `neg_mul_ptr_callee`, `neg_partial_write_callee`, `neg_xor8_partial_callee`, `neg_bit_test_reg_callee`, `neg_cmov32_mem_callee`, `neg_may_write_saved_reg`, `neg_read_saved_reg`, `neg_callee_stack_arg_overlap`, `neg_incoming_stack_slot_uninit`) — 47 total (42 new-code controls + 5 existing main-translator controls). Verified 18/18 guard-removal mutations killed. 2. **Code readability & comments (`tools/cpu_switch_aot.py`)**: - Extracted `_check_ptr_mem` and `_step_ptr_instruction` with a docstring documenting the 3-state lattice (`0=dead`, `1=proven`, `2=possibly-pointer`) and the `BIT_TESTS`/`CMOVCC`/`STRING_TRANSFERS`/`SIGN_EXTENSIONS` sets. - Updated `Frame` docstring, `prove_frame` call-step comment, and `lift_function` call-site comment; documented deliberate redundancy on `if not accesses:` and `member.frame_ptr_params = {}`. 3. **Docs & PR body**: - Updated `docs/experiments.md` (direct-call/frame paragraphs + new `cpu_switch_frame_ptr` section with reproduction command and results) and fixed the `analyze_pointer_param` / `tests/...` typos and guard-to-control table in the PR body. 4. **Full Windows `ctest --preset dev --no-tests=error -R "^cpu_switch_frame_ptr$" -V` output**: ```text 2497: Test command: C:\Users\Ammar\.gemini\antigravity\scratch\Xbox2Windows\out\pe-env\Scripts\python.exe "-B" "C:/Users/Ammar/.gemini/antigravity/scratch/Xbox2Windows-wt/liaison/tests/cpu/switch_frame_ptr_check.py" "C:/Users/Ammar/.gemini/antigravity/scratch/Xbox2Windows-wt/liaison/out/build/dev/cpu_register_probe.dll" "C:/Users/Ammar/.gemini/antigravity/scratch/Xbox2Windows-wt/liaison/out/build/dev/cpu_switch_frame_ptr.dll" "C:/Users/Ammar/.gemini/antigravity/scratch/Xbox2Windows-wt/liaison/out/build/dev/cpu_switch_frame_ptr_lifted.dll" "C:/Users/Ammar/.gemini/antigravity/scratch/Xbox2Windows-wt/liaison/out/build/dev/cpu_switch_frame_ptr_lifted.cpp" "C:/Program Files (x86)/Microsoft Visual Studio/18/BuildTools/VC/Tools/MSVC/14.50.35717/bin/Hostx64/x64/cl.exe" 2497: Working Directory: C:/Users/Ammar/.gemini/antigravity/scratch/Xbox2Windows-wt/liaison/out/build/dev 2497: Test timeout computed to be: 10000000 2497: verified 4 exports x 313 inputs (/Od) 2497: verified 4 exports x 313 inputs (/O2) 2497: cpp mutant shift_frame_ptr caught: shift_frame_ptr.dll lifted_out_u32_rsp(0x0, 0x0) = (53, (6510797682304636536, 0, 53, 18446744073709551615, 11935946389686928161), (81985529216486895, 18364758544493064720)), expected (0xa55a1269, (6510797682304636536, 2774143540, 53, 18446744073709551615, 11935946389686928161), (81985529216486895, 18364758544493064720)) 2497: cpp mutant drop_callee_store caught: drop_callee_store.dll lifted_out_u32_rsp(0x0, 0x0) = (53, (6510797682304636536, 0, 53, 18446744073709551615, 11935946389686928161), (81985529216486895, 18364758544493064720)), expected (0xa55a1269, (6510797682304636536, 2774143540, 53, 18446744073709551615, 11935946389686928161), (81985529216486895, 18364758544493064720)) 2497: refused neg_escape_ret_rax: escapes or is unsupported 2497: refused neg_escape_store_mem: escapes or is unsupported 2497: refused neg_escape_store_stack: escapes or is unsupported 2497: refused neg_recursive_cycle: recursive callee 2497: refused neg_mutual_cycle: recursive callee 2497: refused neg_tail_jump: frame address escapes 2497: refused neg_tail_rbp: unsupported stack operand 2497: refused neg_var_index_lea: frame address escapes 2497: refused neg_multi_arg_alias_same: aliased frame-slot pointers 2497: refused neg_multi_arg_alias_overlap: aliased frame-slot pointers 2497: refused neg_multi_arg_copy_alias: frame address escapes 2497: refused neg_home_space_overlap: overlaps callee home space 2497: refused neg_ret_addr_overlap: return address slot accessed 2497: refused neg_past_home_end: unsupported stack argument 2497: refused neg_uninit_callee_read: undefined stack byte 2497: refused neg_uninit_caller_wider_read: undefined stack byte 2497: refused neg_cond_write_uninit_read: undefined stack byte 2497: refused neg_mixed_widths: escapes or is unsupported 2497: refused neg_unaccessed_ptr: escapes or is unsupported 2497: refused neg_ptr_arith: escapes or is unsupported 2497: refused neg_unproven_rbp: nonvolatile register rbp may hold the caller's value 2497: refused neg_split_anchor_rbp: frame pointer differs at join 2497: refused neg_tail_exit_partial_write: undefined stack byte 2497: refused neg_cmov32_ptr_trunc: escapes or is unsupported 2497: refused neg_bsf_cond_write_escape: escapes or is unsupported 2497: refused neg_bsr_cond_write_escape: escapes or is unsupported 2497: refused neg_callee_tail_ptr_live: escapes or is unsupported 2497: refused neg_nested_int_callee: escapes or is unsupported 2497: refused neg_nested_multi_live: escapes or is unsupported 2497: refused neg_nested_cmov_ptr: escapes or is unsupported 2497: refused neg_lea_disp_callee: escapes or is unsupported 2497: refused neg_lea_index_callee: escapes or is unsupported 2497: refused neg_mem_disp_callee: escapes or is unsupported 2497: refused neg_mem_index_callee: escapes or is unsupported 2497: refused neg_mem_ecx_callee: escapes or is unsupported 2497: refused neg_stos_ptr_rax: escapes or is unsupported 2497: refused neg_movs_ptr_rsi: escapes or is unsupported 2497: refused neg_sign_ext_callee: escapes or is unsupported 2497: refused neg_mul_ptr_callee: escapes or is unsupported 2497: refused neg_partial_write_callee: escapes or is unsupported 2497: refused neg_xor8_partial_callee: escapes or is unsupported 2497: refused neg_bit_test_reg_callee: escapes or is unsupported 2497: refused neg_cmov32_mem_callee: escapes or is unsupported 2497: refused neg_may_write_saved_reg: undefined stack byte 2497: refused neg_read_saved_reg: hold the saved rbx, read as data 2497: refused neg_callee_stack_arg_overlap: overlaps callee home space or stack arguments 2497: refused neg_incoming_stack_slot_uninit: stack argument 5 of the call 2497: guard mutation (disable prove_frame ptr_calls) confirmed: neg_uninit_callee_read accepted 2497: guard mutation (disable post-call must_write marking) confirmed: out_u32_rsp refused 2497: cpu_switch_frame_ptr: all differential (/Od, /O2), mutant, and 47 refusal checks passed 1/1 Test #2497: cpu_switch_frame_ptr ............. Passed 1.84 sec ``` Also verified `dev` & `release` builds/tests across all 7 affected `cpu_aot_*` / `cpu_switch_frame_ptr` targets (`7/7` passed in both presets). AI-assisted.
Author
Owner

@⁠pigalot on GitHub · 2026-11-29 06:46 UTC · original · requested changes

Independently reviewed 2a685c06 integrated over main 212d4b5f (tree 3eebf76f). The trial merge is clean and git diff --check is clean.

I read _check_ptr_mem, _step_ptr_instruction, analyze_pointer_param, Frame.resolve_pointer_calls and the prove_frame changes against the rules the PR body states, and checked JohnConnorNPC's items from 27 and 28 November at this head. One input the body says is refused is accepted, so I'm requesting changes for that; the rest is coverage.

1. lea reg, [ecx] is accepted as an exact copy of the pointer (blocking).

_check_ptr_mem refuses a 32-bit base (neg_mem_ecx_callee), but the LEA copy branch in _step_ptr_instruction only checks the destination width, the index and the displacement. With an address-size prefix the copy is the low 32 bits of the pointer, and it is still tracked as state 1.

  • Input: a copy of cpu_switch_frame_ptr.dll with lea r9, [rcx+4] in lea_disp_callee (4C 8D 49 04, one occurrence) replaced by lea r9, [ecx] (67 4C 8D 09), then translate(copy, ["neg_lea_disp_callee"]).
  • Observed: accepted. The callee is emitted as
    r9 = ...static_cast<std::uint32_t>(rcx)...; store<std::uint32_t>((r9), ...);
    and the caller passes reinterpret_cast<word>(frame + 32). So the translation stores through a truncated host address, and prove_frame marks the slot as written by the callee.
  • Expected: refused, like mov [ecx], edx. The unpatched export is refused (frame-slot pointer in rcx escapes or is unsupported by callee at RVA 0x1585).
  • Direction (tried locally): adding and RegisterExt.is_gpr64(ins.memory_base) to the condition that sets cur[dst] = 1 refuses the patched copy, and the test's Python half stays green. Please add a control for it next to neg_mem_ecx_callee.

2. Earlier review items. All of JohnConnorNPC's named items are addressed at this head:

  • The three escape controls now dereference the pointer; with the register-read escape removed, neg_escape_store_mem is accepted and the test fails.
  • neg_multi_arg_alias_same / _overlap now fail for their own reason (accepted when the alias check is removed).
  • Each guard he listed has a control that goes red when I remove it (list below).
  • docs/experiments.md has the corrected paragraphs and the cpu_switch_frame_ptr entry; the body states 42 + 5 controls; the comments and the two deliberate redundancies are documented.
  • The Windows -V output is in the author's comment. CI still does not run this test, which stays the maintainers' call.

3. Mutation results. I removed or weakened one guard at a time in a copy of tools/cpu_switch_aot.py (66 mutants) and ran the check's Python half against the built fixture: translate of the four exports compared with the built cpu_switch_frame_ptr_lifted.cpp, check_structure, and check_refusals_and_guard_mutations. A survivor produces byte-identical C++, so the compiled half cannot tell it apart either.

Killed, 45:

  • callee analysis: register-read escape, live pointer at a callee tail jump, nested multi-live, nested state/recursive check, nested integer use, RET with the pointer in RAX, LEA displacement, LEA own index, both CMOVcc width checks, CMOVcc register form giving state 2, string-instruction registers, 8-bit XOR r, r, sign extensions, MUL/DIV RAX, COND_WRITE, 8/16-bit partial write;
  • _check_ptr_mem: 64-bit base, own index, displacement, register BT*;
  • summary: mixed widths, must-write meet (and → or), reads_before_write (two variants), must_write (all → any), may_write;
  • caller: min_offset (two variants), alias check (two variants), bounds via Frame.access (two variants), the candidate walk's register-use stop, the candidate index check, the incoming-slot read demand, post-call must_write marking, replacement = existing, the pre-call read check, reads.pop, the anchor gate, lifter.slot → lifter.reg;
  • recursion: the resolve_pointer_calls raise and member.recursive. These two, and the candidate walk, are killed by the message match only: with every recursion guard removed, neg_recursive_cycle is still refused as escapes or is unsupported.

Surviving, 15 (the test stays fully green):

  • join of differing states giving state 2 (merged[r] = 2 → 1), and the state-1 requirement for a dereference in _check_ptr_mem. No control dereferences a pointer that is only possibly the parameter, for example test edx, edx / jz L / mov rcx, r8 / L: mov [rcx], eax. These two decide whether must_write can be trusted, so I'd like one control for them in the same push as item 1;
  • the tracked pointer used as an index: in LEA (lea rax, [rdx+rcx]) and in a memory operand (mov eax, [rdx+rcx]);
  • LEA copy with a 32-bit destination (w_reg == 8), the state-1 requirement in the LEA copy, and the 8/16-bit LEA destination check;
  • the pointer live at a host import call, at an unresolved call (callee is None), and as a jump-table index;
  • dropping the volatile registers after a nested call (mov rax, rcx / call g / mov [rax], edx would then count as a write through the pointer);
  • memory-form CMOVcc giving state 2, the 16-bit MUL/DIV RDX check, the segment-prefix check and the access-kind check in _check_ptr_mem.

Equivalent, 6: if not accesses, the recursive gate at the top of analyze_pointer_param, function.recursive in lift_function, the internal and not function.recursive gate, and the frame_ptr_params = {} reset alone or with member.recursive. Each is covered by one of the others, as the comments say.

One more mutant (the dispatch-sequence load check) did not apply because my pattern was wrong, so I have no result for it.

4. What I ran.

Built everything in dev and release, then
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$':
7 passed in Debug and 7 in Release /O2, no skips. cpu_switch_frame_ptr printed verified 4 exports x 313 inputs for /Od and /O2, both C++ mutants caught, both guard mutations confirmed and 47 refusals.

ctest --test-dir out/build/dev --no-tests=error -j 4 -R '^cpu_' -E 'cpu_native_archive_': 315 selected, 314 passed, 0 failed, 1 skipped (cpu_aot_sysdesc), reported separately from the passes.

The 281 *_lifted.cpp files that main already generates are byte-identical after the change, in both presets (SHA-1 before and after the rebuild).
On main 212d4b5f the test is not registered (tests/cmake/cpu_switch_frame_ptr.cmake does not exist there).
tests/form_coverage_check.py, tests/docs_links_check.py and tests/bidi_controls_check.py exit 0.
No title run: the change is confined to the offline CPU translator and its fixture.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10. The ^cpu_ selection includes cpu_shim_shadow_hardware; it ran without the debug layer, so I don't report it as a GPU result.
CI: Build and test on Windows passed on 2a685c06; it does not run cpu_switch_frame_ptr.

This reply was AI-assisted.

**@⁠pigalot** on GitHub · 2026-11-29 06:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3121#pullrequestreview-6101797764) · **requested changes** Independently reviewed `2a685c06` integrated over `main` `212d4b5f` (tree `3eebf76f`). The trial merge is clean and `git diff --check` is clean. I read `_check_ptr_mem`, `_step_ptr_instruction`, `analyze_pointer_param`, `Frame.resolve_pointer_calls` and the `prove_frame` changes against the rules the PR body states, and checked JohnConnorNPC's items from 27 and 28 November at this head. One input the body says is refused is accepted, so I'm requesting changes for that; the rest is coverage. **1. `lea reg, [ecx]` is accepted as an exact copy of the pointer (blocking).** `_check_ptr_mem` refuses a 32-bit base (`neg_mem_ecx_callee`), but the `LEA` copy branch in `_step_ptr_instruction` only checks the destination width, the index and the displacement. With an address-size prefix the copy is the low 32 bits of the pointer, and it is still tracked as state 1. - Input: a copy of `cpu_switch_frame_ptr.dll` with `lea r9, [rcx+4]` in `lea_disp_callee` (`4C 8D 49 04`, one occurrence) replaced by `lea r9, [ecx]` (`67 4C 8D 09`), then `translate(copy, ["neg_lea_disp_callee"])`. - Observed: accepted. The callee is emitted as `r9 = ...static_cast<std::uint32_t>(rcx)...; store<std::uint32_t>((r9), ...);` and the caller passes `reinterpret_cast<word>(frame + 32)`. So the translation stores through a truncated host address, and `prove_frame` marks the slot as written by the callee. - Expected: refused, like `mov [ecx], edx`. The unpatched export is refused (`frame-slot pointer in rcx escapes or is unsupported by callee at RVA 0x1585`). - Direction (tried locally): adding `and RegisterExt.is_gpr64(ins.memory_base)` to the condition that sets `cur[dst] = 1` refuses the patched copy, and the test's Python half stays green. Please add a control for it next to `neg_mem_ecx_callee`. **2. Earlier review items.** All of JohnConnorNPC's named items are addressed at this head: - The three escape controls now dereference the pointer; with the register-read escape removed, `neg_escape_store_mem` is accepted and the test fails. - `neg_multi_arg_alias_same` / `_overlap` now fail for their own reason (accepted when the alias check is removed). - Each guard he listed has a control that goes red when I remove it (list below). - `docs/experiments.md` has the corrected paragraphs and the `cpu_switch_frame_ptr` entry; the body states 42 + 5 controls; the comments and the two deliberate redundancies are documented. - The Windows `-V` output is in the author's comment. CI still does not run this test, which stays the maintainers' call. **3. Mutation results.** I removed or weakened one guard at a time in a copy of `tools/cpu_switch_aot.py` (66 mutants) and ran the check's Python half against the built fixture: `translate` of the four exports compared with the built `cpu_switch_frame_ptr_lifted.cpp`, `check_structure`, and `check_refusals_and_guard_mutations`. A survivor produces byte-identical C++, so the compiled half cannot tell it apart either. Killed, 45: - callee analysis: register-read escape, live pointer at a callee tail jump, nested multi-live, nested state/recursive check, nested integer use, `RET` with the pointer in RAX, `LEA` displacement, `LEA` own index, both `CMOVcc` width checks, `CMOVcc` register form giving state 2, string-instruction registers, 8-bit `XOR r, r`, sign extensions, `MUL`/`DIV` RAX, `COND_WRITE`, 8/16-bit partial write; - `_check_ptr_mem`: 64-bit base, own index, displacement, register `BT*`; - summary: mixed widths, must-write meet (`and` → `or`), `reads_before_write` (two variants), `must_write` (`all` → `any`), `may_write`; - caller: `min_offset` (two variants), alias check (two variants), bounds via `Frame.access` (two variants), the candidate walk's register-use stop, the candidate index check, the incoming-slot read demand, post-call `must_write` marking, `replacement = existing`, the pre-call read check, `reads.pop`, the anchor gate, `lifter.slot` → `lifter.reg`; - recursion: the `resolve_pointer_calls` raise and `member.recursive`. These two, and the candidate walk, are killed by the message match only: with every recursion guard removed, `neg_recursive_cycle` is still refused as `escapes or is unsupported`. Surviving, 15 (the test stays fully green): - join of differing states giving state 2 (`merged[r] = 2` → `1`), and the state-1 requirement for a dereference in `_check_ptr_mem`. No control dereferences a pointer that is only possibly the parameter, for example `test edx, edx / jz L / mov rcx, r8 / L: mov [rcx], eax`. These two decide whether `must_write` can be trusted, so I'd like one control for them in the same push as item 1; - the tracked pointer used as an index: in `LEA` (`lea rax, [rdx+rcx]`) and in a memory operand (`mov eax, [rdx+rcx]`); - `LEA` copy with a 32-bit destination (`w_reg == 8`), the state-1 requirement in the `LEA` copy, and the 8/16-bit `LEA` destination check; - the pointer live at a host import call, at an unresolved call (`callee is None`), and as a jump-table index; - dropping the volatile registers after a nested call (`mov rax, rcx / call g / mov [rax], edx` would then count as a write through the pointer); - memory-form `CMOVcc` giving state 2, the 16-bit `MUL`/`DIV` RDX check, the segment-prefix check and the access-kind check in `_check_ptr_mem`. Equivalent, 6: `if not accesses`, the `recursive` gate at the top of `analyze_pointer_param`, `function.recursive` in `lift_function`, the `internal and not function.recursive` gate, and the `frame_ptr_params = {}` reset alone or with `member.recursive`. Each is covered by one of the others, as the comments say. One more mutant (the dispatch-sequence load check) did not apply because my pattern was wrong, so I have no result for it. **4. What I ran.** Built everything in `dev` and `release`, then `ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$'`: 7 passed in Debug and 7 in Release `/O2`, no skips. `cpu_switch_frame_ptr` printed `verified 4 exports x 313 inputs` for `/Od` and `/O2`, both C++ mutants caught, both guard mutations confirmed and 47 refusals. `ctest --test-dir out/build/dev --no-tests=error -j 4 -R '^cpu_' -E 'cpu_native_archive_'`: 315 selected, 314 passed, 0 failed, 1 skipped (`cpu_aot_sysdesc`), reported separately from the passes. The 281 `*_lifted.cpp` files that `main` already generates are byte-identical after the change, in both presets (SHA-1 before and after the rebuild). On `main` `212d4b5f` the test is not registered (`tests/cmake/cpu_switch_frame_ptr.cmake` does not exist there). `tests/form_coverage_check.py`, `tests/docs_links_check.py` and `tests/bidi_controls_check.py` exit 0. No title run: the change is confined to the offline CPU translator and its fixture. Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10. The `^cpu_` selection includes `cpu_shim_shadow_hardware`; it ran without the debug layer, so I don't report it as a GPU result. CI: `Build and test on Windows` passed on `2a685c06`; it does not run `cpu_switch_frame_ptr`. This reply was AI-assisted.
Author
Owner

@⁠JohnConnorNPC on GitHub · 2026-11-29 13:24 UTC · original

Re-review of head 2a685c06, trial-merged onto main c04e0dd6 (git merge-tree --write-tree exits 0, git diff --check clean). I built the fixture on Linux (llvm-ml-19 -m64 + lld-link-19 /DLL /NOENTRY /NODEFAULTLIB /DEF:) and ran the check's Python half: translate of the four exports, check_structure, then the refusals and guard mutations. I did no MSVC build and no native/lifted run.

Since my comments on 129fcc38:

  • 218b68a1 is a clean merge of main (git show --remerge-diff prints nothing).
  • The Python half on the merged tree gives RESULT GREEN-PY refused=47 guards=2, which matches the 42 + 5 controls in the description.
  • Unpinned guards (my first blocking point): addressed. I re-anchored my eight guard deletions to the refactored _step_ptr_instruction/_check_ptr_mem and ran each on a fresh copy. All eight now fail, each on its own control. The four that used to survive:
    • register-read escape: neg_escape_store_mem: unexpectedly accepted
    • may_write keeps saved markers: neg_may_write_saved_reg: unexpectedly accepted
    • [ptr+disp] allowed: neg_mem_disp_callee: unexpectedly accepted
    • 32-bit memory CMOVcc: neg_cmov32_mem_callee: unexpectedly accepted
      The alias deletion now fails as neg_multi_arg_alias_same: unexpectedly accepted, instead of failing on an undefined r9.
  • Stale docs (my second blocking point): addressed. The direct-call and frame paragraphs no longer say a frame address passed to a callee is rejected, and the cpu_switch_frame_ptr entry is added.
  • Semantics, by reading: 32-bit MOV, XCHG, PUSH, TEST/CMP and arithmetic on the tracked register all take the register-read escape. Lifted internal callees take only the four argument registers (static word fn_1000(word rcx, word rdx, word r8, word r9)), so a nested callee can't see a pointer that its caller keeps in a nonvolatile register. The argument-register check at a nested call is enough there.

MUST: none new from me. The blocking lea reg, [ecx] case in the current changes request reproduces here. The fixture copy with 4c8d4904 → 674c8d09 (one occurrence) is accepted for neg_lea_disp_callee, and the emitted source contains static_cast<std::uint32_t>(rcx). The unpatched DLL is refused at RVA 0x1585. I won't repeat the fix or the survivor list.

SHOULD / NIT: none beyond the current review.

Held until a new head addresses the changes request on 2a685c06.

AI-assisted.

**@⁠JohnConnorNPC** on GitHub · 2026-11-29 13:24 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3121#issuecomment-7256515984) Re-review of head `2a685c06`, trial-merged onto `main` `c04e0dd6` (`git merge-tree --write-tree` exits 0, `git diff --check` clean). I built the fixture on Linux (`llvm-ml-19 -m64` + `lld-link-19 /DLL /NOENTRY /NODEFAULTLIB /DEF:`) and ran the check's Python half: translate of the four exports, `check_structure`, then the refusals and guard mutations. I did no MSVC build and no native/lifted run. Since my comments on `129fcc38`: - `218b68a1` is a clean merge of `main` (`git show --remerge-diff` prints nothing). - The Python half on the merged tree gives `RESULT GREEN-PY refused=47 guards=2`, which matches the 42 + 5 controls in the description. - **Unpinned guards (my first blocking point): addressed.** I re-anchored my eight guard deletions to the refactored `_step_ptr_instruction`/`_check_ptr_mem` and ran each on a fresh copy. All eight now fail, each on its own control. The four that used to survive: - register-read escape: `neg_escape_store_mem: unexpectedly accepted` - `may_write` keeps saved markers: `neg_may_write_saved_reg: unexpectedly accepted` - `[ptr+disp]` allowed: `neg_mem_disp_callee: unexpectedly accepted` - 32-bit memory `CMOVcc`: `neg_cmov32_mem_callee: unexpectedly accepted` The alias deletion now fails as `neg_multi_arg_alias_same: unexpectedly accepted`, instead of failing on an undefined `r9`. - **Stale docs (my second blocking point): addressed.** The direct-call and frame paragraphs no longer say a frame address passed to a callee is rejected, and the `cpu_switch_frame_ptr` entry is added. - Semantics, by reading: 32-bit `MOV`, `XCHG`, `PUSH`, `TEST`/`CMP` and arithmetic on the tracked register all take the register-read escape. Lifted internal callees take only the four argument registers (`static word fn_1000(word rcx, word rdx, word r8, word r9)`), so a nested callee can't see a pointer that its caller keeps in a nonvolatile register. The argument-register check at a nested call is enough there. MUST: none new from me. The blocking `lea reg, [ecx]` case in the current changes request reproduces here. The fixture copy with `4c8d4904` → `674c8d09` (one occurrence) is accepted for `neg_lea_disp_callee`, and the emitted source contains `static_cast<std::uint32_t>(rcx)`. The unpatched DLL is refused at RVA 0x1585. I won't repeat the fix or the survivor list. SHOULD / NIT: none beyond the current review. Held until a new head addresses the changes request on `2a685c06`. AI-assisted.
_step_ptr_instruction's LEA copy branch tracked 'lea reg, [ecx]' as an
exact (state 1) copy of the pointer, although the address-size prefix
leaves only its low 32 bits. Require RegisterExt.is_gpr64(memory_base)
for the state-1 copy, matching _check_ptr_mem's 64-bit-base rule.

New refusal controls, next to neg_mem_ecx_callee (49 total, 44 + 5):
- neg_lea_ecx_callee: lea r9, [ecx] then a store through r9; removing
  the new guard accepts it.
- neg_join_maybe_ptr_callee: test edx,edx / jz / mov rcx,r8 joins a
  state-1 path with a dead path, so rcx is state 2 at the store; both
  weakening the join to merged[r] = 1 and dropping _check_ptr_mem's
  state-1 requirement accept it independently. The store uses edx, the
  fixture's stored-value register: eax is undefined at callee entry
  and would refuse as 'undefined register rax' instead.

Linux: encodings cross-checked with keystone (LLVM MC) and iced-x86;
a synthetic-PE harness refuses all four controls cleanly and kills
mutants A (LEA is_gpr64), B (merged 2 -> 1) and C (drop != 1), each
accepting only its own control. The live-index sub-checks in the LEA
branch and _check_ptr_mem are equivalent (any index refuses anyway).

Refs #3121
Author
Owner

@⁠Ammmae0x on GitHub · 2026-11-29 15:10 UTC · original

Addressed @pigalot's CHANGES_REQUESTED review on 2a685c06 in c66aa6be:

  • Blocking (lea reg, [ecx]): Added RegisterExt.is_gpr64(ins.memory_base) to _step_ptr_instruction's LEA copy branch in tools/cpu_switch_aot.py, plus neg_lea_ecx_callee next to neg_mem_ecx_callee.
  • Join/state-1 control: Added neg_join_maybe_ptr_callee (test edx, edx / jz / mov rcx, r8, then mov dword ptr [rcx], edx) so weakening merged[r] = 2 -> 1 and dropping cur.get(base, 0) != 1 in _check_ptr_mem each fail on their own.
  • Windows verification (c66aa6be): ml64 assembled both new controls and cpu_switch_frame_ptr passed differential (/Od, /O2), C++/guard mutants, and all 49 refusal checks in both dev (7/7, 4.88s) and release (7/7, 4.45s), plus repo Python checks (175 docs / 2669 files).

AI-assisted.

**@⁠Ammmae0x** on GitHub · 2026-11-29 15:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3121#issuecomment-7257882873) Addressed `@pigalot`'s `CHANGES_REQUESTED` review on `2a685c06` in `c66aa6be`: - **Blocking (`lea reg, [ecx]`):** Added `RegisterExt.is_gpr64(ins.memory_base)` to `_step_ptr_instruction`'s `LEA` copy branch in `tools/cpu_switch_aot.py`, plus `neg_lea_ecx_callee` next to `neg_mem_ecx_callee`. - **Join/state-1 control:** Added `neg_join_maybe_ptr_callee` (`test edx, edx / jz / mov rcx, r8`, then `mov dword ptr [rcx], edx`) so weakening `merged[r] = 2 -> 1` and dropping `cur.get(base, 0) != 1` in `_check_ptr_mem` each fail on their own. - **Windows verification (`c66aa6be`):** `ml64` assembled both new controls and `cpu_switch_frame_ptr` passed differential (`/Od`, `/O2`), C++/guard mutants, and all 49 refusal checks in both `dev` (`7/7`, `4.88s`) and `release` (`7/7`, `4.45s`), plus repo Python checks (`175` docs / `2669` files). AI-assisted.
Author
Owner

@⁠JohnConnorNPC on GitHub · 2026-11-29 15:36 UTC · original

Re-review at c66aa6be, covering the delta since 2a685c06: the merge 9af6f85a and c66aa6be. I trial-merged onto main cf0c30af (git merge-tree --write-tree exits 0). I built the fixture from this head on Linux with llvm-ml-19 -m64 and lld-link-19 /DLL /NOENTRY /NODEFAULTLIB /DEF:, then ran the check's Python half: translate of the four exports, check_structure, the refusals and the guard mutations. I did no MSVC build and no native/lifted run.

Python half: RESULT GREEN-PY refused=49 guards=2 on the head and on the merged tree, and the merged tree's four-export source matches the head's. 49 agrees with the updated docs/experiments.md count (44 + 5).

The change request's blocking item (lea reg, [ecx]) is fixed. I applied the same patch to the new DLL: lea r9, [rcx+4] (4C 8D 49 04, 1 occurrence) became lea r9, [ecx] (67 4C 8D 09), and I translated neg_lea_disp_callee.

  • At c66aa6be: REFUSED frame-slot pointer in rcx escapes or is unsupported by callee at RVA 0x1585.
  • With the new RegisterExt.is_gpr64(ins.memory_base) term removed: the patched copy is ACCEPTED, with static_cast<std::uint32_t>(rcx) in the source. So the refusal comes from that term.

The new controls are pinned. I removed one guard per copy of tools/cpu_switch_aot.py and ran the Python half each time. The pristine file was unchanged afterwards (sha256 18a7bce51b4d…).

  • M1, the is_gpr64 term dropped from the LEA copy branch: RED neg_lea_ecx_callee: unexpectedly accepted.
  • M2, merged[r] = 2 changed to 1 at a join of differing states: RED neg_join_maybe_ptr_callee: unexpectedly accepted.
  • M3, cur.get(base, 0) != 1 dropped from _check_ptr_mem: RED neg_join_maybe_ptr_callee: unexpectedly accepted.

The join control is a valid input. rdx and r8 are the export's own incoming arguments, so neither control is refused for an unrelated reason.

From us: 0 MUST. Not blocking: this push adds two controls. The other survivors listed in the change request (the pointer used as an index, the 32-bit LEA destination, the pointer live at an import, unresolved or jump-table transfer, dropping volatiles after a nested call, memory CMOVcc, the 16-bit MUL/DIV RDX check, the segment prefix and the access kind) are still uncovered, judging by the diff. CI still does not run cpu_switch_frame_ptr.

Not merged: the change request on 2a685c06 is still standing. Its reviewer needs to re-check and lift it.

AI-assisted review.

**@⁠JohnConnorNPC** on GitHub · 2026-11-29 15:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3121#issuecomment-7258228112) Re-review at `c66aa6be`, covering the delta since `2a685c06`: the merge `9af6f85a` and `c66aa6be`. I trial-merged onto `main` `cf0c30af` (`git merge-tree --write-tree` exits 0). I built the fixture from this head on Linux with `llvm-ml-19 -m64` and `lld-link-19 /DLL /NOENTRY /NODEFAULTLIB /DEF:`, then ran the check's Python half: translate of the four exports, `check_structure`, the refusals and the guard mutations. I did no MSVC build and no native/lifted run. **Python half:** `RESULT GREEN-PY refused=49 guards=2` on the head and on the merged tree, and the merged tree's four-export source matches the head's. 49 agrees with the updated `docs/experiments.md` count (44 + 5). **The change request's blocking item (`lea reg, [ecx]`) is fixed.** I applied the same patch to the new DLL: `lea r9, [rcx+4]` (`4C 8D 49 04`, 1 occurrence) became `lea r9, [ecx]` (`67 4C 8D 09`), and I translated `neg_lea_disp_callee`. - At `c66aa6be`: `REFUSED frame-slot pointer in rcx escapes or is unsupported by callee at RVA 0x1585`. - With the new `RegisterExt.is_gpr64(ins.memory_base)` term removed: the patched copy is `ACCEPTED`, with `static_cast<std::uint32_t>(rcx)` in the source. So the refusal comes from that term. **The new controls are pinned.** I removed one guard per copy of `tools/cpu_switch_aot.py` and ran the Python half each time. The pristine file was unchanged afterwards (sha256 `18a7bce51b4d…`). - M1, the `is_gpr64` term dropped from the `LEA` copy branch: `RED neg_lea_ecx_callee: unexpectedly accepted`. - M2, `merged[r] = 2` changed to `1` at a join of differing states: `RED neg_join_maybe_ptr_callee: unexpectedly accepted`. - M3, `cur.get(base, 0) != 1` dropped from `_check_ptr_mem`: `RED neg_join_maybe_ptr_callee: unexpectedly accepted`. The join control is a valid input. `rdx` and `r8` are the export's own incoming arguments, so neither control is refused for an unrelated reason. From us: 0 MUST. Not blocking: this push adds two controls. The other survivors listed in the change request (the pointer used as an index, the 32-bit `LEA` destination, the pointer live at an import, unresolved or jump-table transfer, dropping volatiles after a nested call, memory `CMOVcc`, the 16-bit `MUL`/`DIV` RDX check, the segment prefix and the access kind) are still uncovered, judging by the diff. CI still does not run `cpu_switch_frame_ptr`. Not merged: the change request on `2a685c06` is still standing. Its reviewer needs to re-check and lift it. AI-assisted review.
github-bot changed target branch from main to gh-pr/3121/base 2026-11-29 17:51:39 +00:00
github manually merged commit c66aa6be39 into gh-pr/3121/base 2026-11-29 17:51:41 +00:00
Author
Owner

@⁠pigalot on GitHub · 2026-11-29 17:48 UTC · original · approved these changes

Retested c66aa6be integrated over main 26df1826 (tree e39f568e). The trial merge is clean and git diff --check is clean. This supersedes my changes-requested review on 2a685c06.

The delta since 2a685c06 is the merge 9af6f85a (git show --remerge-diff prints nothing) and c66aa6be: one added term in the LEA copy branch of _step_ptr_instruction, two controls, and the count in docs/experiments.md.

1. lea reg, [ecx] accepted as an exact copy (was blocking): addressed.

  • The LEA copy branch now also requires RegisterExt.is_gpr64(ins.memory_base), the same test _check_ptr_mem uses for a dereference.
  • I repeated my earlier input on the fixture built from this head: lea r9, [rcx+4] (4C 8D 49 04, one occurrence) replaced by lea r9, [ecx] (67 4C 8D 09), then translate(copy, ["neg_lea_disp_callee"]). It is now refused in both presets: frame-slot pointer in rcx escapes or is unsupported by callee at RVA 0x1585.
  • The new control neg_lea_ecx_callee is refused for this reason and no other: with the new term removed, the test fails with neg_lea_ecx_callee: unexpectedly accepted.

2. Control for a pointer that is only possibly the parameter (requested with item 1): addressed.

neg_join_maybe_ptr_callee stores through rcx after a join where one path replaced it with r8. It fails the test when the join gives state 1 instead of 2, and again when _check_ptr_mem no longer requires state 1, so both guards are pinned separately.

3. Mutation results at this head. One change at a time in tools/cpu_switch_aot.py, then ctest -R '^cpu_switch_frame_ptr$' on the dev build; the file was restored afterwards (git diff --quiet exit 0).

Killed, 4:

  • the is_gpr64 term removed from the LEA copy branch: neg_lea_ecx_callee: unexpectedly accepted;
  • the is_gpr64 test moved to the destination register (ins.op0_register): neg_lea_ecx_callee: unexpectedly accepted;
  • merged[r] = 2 changed to 1 at a join: neg_join_maybe_ptr_callee: unexpectedly accepted;
  • the state-1 requirement removed from _check_ptr_mem: neg_join_maybe_ptr_callee: unexpectedly accepted.

Surviving, 2 (the test stays fully green; both were in my earlier list and are not blocking):

  • the 64-bit destination requirement in the LEA copy (w_reg == 8);
  • the state-1 requirement in the LEA copy.

Equivalent: none in this set.

I did not rerun the other survivors from my review of 2a685c06 (the pointer live at an import, unresolved call or jump-table index, the volatile drop after a nested call, memory-form CMOVcc giving state 2, the 16-bit MUL/DIV RDX check, the segment-prefix and access-kind checks). The code they cover is unchanged in this push and the description lists them as follow-up candidates. Each guard is present in the code; what is missing is a control, so a later edit could remove one without the test noticing. A follow-up that pins them would be welcome.

4. What I ran.

Built everything in dev and release, then
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$':
7 passed in Debug and 7 in Release /O2, no skips. cpu_switch_frame_ptr printed verified 4 exports x 313 inputs for /Od and /O2, both C++ mutants caught, both guard mutations confirmed and 49 refusal checks passed.

ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^cpu_' -E '(cpu_native_archive_|_hardware$)': 302 selected in each preset, 301 passed, 0 failed, 1 skipped (cpu_aot_sysdesc), reported separately from the passes. Every fixture that main translates still translates and passes, so the added term refuses none of them.

On main 26df1826 the test is not registered (tests/cmake/cpu_switch_frame_ptr.cmake does not exist there).
tests/form_coverage_check.py, tests/docs_links_check.py and tests/bidi_controls_check.py exit 0.
No title run: the change is confined to the offline CPU translator and its fixture. No GPU tests ran.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10.
CI: Build and test on Windows passed on c66aa6be; it does not run cpu_switch_frame_ptr.

This reply was AI-assisted.

**@⁠pigalot** on GitHub · 2026-11-29 17:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3121#pullrequestreview-6104048857) · **approved these changes** Retested `c66aa6be` integrated over `main` `26df1826` (tree `e39f568e`). The trial merge is clean and `git diff --check` is clean. This supersedes my changes-requested review on `2a685c06`. The delta since `2a685c06` is the merge `9af6f85a` (`git show --remerge-diff` prints nothing) and `c66aa6be`: one added term in the `LEA` copy branch of `_step_ptr_instruction`, two controls, and the count in `docs/experiments.md`. **1. `lea reg, [ecx]` accepted as an exact copy (was blocking): addressed.** - The `LEA` copy branch now also requires `RegisterExt.is_gpr64(ins.memory_base)`, the same test `_check_ptr_mem` uses for a dereference. - I repeated my earlier input on the fixture built from this head: `lea r9, [rcx+4]` (`4C 8D 49 04`, one occurrence) replaced by `lea r9, [ecx]` (`67 4C 8D 09`), then `translate(copy, ["neg_lea_disp_callee"])`. It is now refused in both presets: `frame-slot pointer in rcx escapes or is unsupported by callee at RVA 0x1585`. - The new control `neg_lea_ecx_callee` is refused for this reason and no other: with the new term removed, the test fails with `neg_lea_ecx_callee: unexpectedly accepted`. **2. Control for a pointer that is only possibly the parameter (requested with item 1): addressed.** `neg_join_maybe_ptr_callee` stores through `rcx` after a join where one path replaced it with `r8`. It fails the test when the join gives state 1 instead of 2, and again when `_check_ptr_mem` no longer requires state 1, so both guards are pinned separately. **3. Mutation results at this head.** One change at a time in `tools/cpu_switch_aot.py`, then `ctest -R '^cpu_switch_frame_ptr$'` on the dev build; the file was restored afterwards (`git diff --quiet` exit 0). Killed, 4: - the `is_gpr64` term removed from the `LEA` copy branch: `neg_lea_ecx_callee: unexpectedly accepted`; - the `is_gpr64` test moved to the destination register (`ins.op0_register`): `neg_lea_ecx_callee: unexpectedly accepted`; - `merged[r] = 2` changed to `1` at a join: `neg_join_maybe_ptr_callee: unexpectedly accepted`; - the state-1 requirement removed from `_check_ptr_mem`: `neg_join_maybe_ptr_callee: unexpectedly accepted`. Surviving, 2 (the test stays fully green; both were in my earlier list and are not blocking): - the 64-bit destination requirement in the `LEA` copy (`w_reg == 8`); - the state-1 requirement in the `LEA` copy. Equivalent: none in this set. I did not rerun the other survivors from my review of `2a685c06` (the pointer live at an import, unresolved call or jump-table index, the volatile drop after a nested call, memory-form `CMOVcc` giving state 2, the 16-bit `MUL`/`DIV` RDX check, the segment-prefix and access-kind checks). The code they cover is unchanged in this push and the description lists them as follow-up candidates. Each guard is present in the code; what is missing is a control, so a later edit could remove one without the test noticing. A follow-up that pins them would be welcome. **4. What I ran.** Built everything in `dev` and `release`, then `ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(cpu_switch_frame_ptr|cpu_aot_stack_frames|cpu_aot_leave|cpu_aot_direct_calls|cpu_aot_recursion|cpu_aot_stack_arguments|cpu_aot_stack_output)$'`: 7 passed in Debug and 7 in Release `/O2`, no skips. `cpu_switch_frame_ptr` printed `verified 4 exports x 313 inputs` for `/Od` and `/O2`, both C++ mutants caught, both guard mutations confirmed and `49 refusal checks passed`. `ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^cpu_' -E '(cpu_native_archive_|_hardware$)'`: 302 selected in each preset, 301 passed, 0 failed, 1 skipped (`cpu_aot_sysdesc`), reported separately from the passes. Every fixture that `main` translates still translates and passes, so the added term refuses none of them. On `main` `26df1826` the test is not registered (`tests/cmake/cpu_switch_frame_ptr.cmake` does not exist there). `tests/form_coverage_check.py`, `tests/docs_links_check.py` and `tests/bidi_controls_check.py` exit 0. No title run: the change is confined to the offline CPU translator and its fixture. No GPU tests ran. Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10. CI: `Build and test on Windows` passed on `c66aa6be`; it does not run `cpu_switch_frame_ptr`. This reply was AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.