cpu: track string direction across branches and ABI boundaries #593

Merged
Joacoorandom merged 3 commits from upstream-pr/599 into main 2026-11-22 18:49:35 +00:00
Joacoorandom commented 2026-11-22 15:01:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Joacoorandom on 2026-11-22T15:01:47Z.


Change

Allow STD/CLD around repeated memory transfers in the control-flow CPU lifter. Carry a local direction flag along the actual path and use unsigned pointer steps for forward/backward copies and fills.

A separate control-flow proof starts with DF clear and rejects any path that reaches a call, tail jump or return with DF potentially set. Joins retain both possibilities; a branch-selected backwards region must clear DF before its ABI boundary. Instruction effects invalidate stale pointer/count provenance as before.

Depends on #598; #597 is merged. Rebased the remaining two commits on current main: fill 461a4f5 and direction 2b74c4c. The PR still includes #598 until that dependency is merged. Review the direction increment in 2b74c4c; original Windows verification predates this rebase.

Verification

Commit 9014984. Windows 11 26300.9974, MSVC/ML64 19.44.35230, Python 3.12.8.

cmake --build out/native --target cpu_switch_strings_lifted cpu_switch_strings_lifted_o2 cpu_switch_strings_mutants cpu_string_probe cpu_guarded_call cpu_switch_original_lifted cpu_switch_swapped_lifted cpu_register_probe cpu_flag_conditions_lifted cpu_frame_lifted cpu_calls_lifted cpu_call_entries_lifted --parallel 4
ctest --test-dir out/native --no-tests=error -R "^cpu_aot_(switch_strings|jump_tables|flag_conditions|stack_frames|direct_calls|call_entries)$" -V

All six selected tests passed. The cumulative comparison covers nineteen exports and 7,608 native/AOT/reference cases, plus 63 access-violation comparisons, including /O2. New cases cover all repeated copy/fill widths backwards, branch-selected directions and a join with different DF states. The assembly harness checks RSI/RDI restoration and physical DF on normal return.

Nine whole-PE rejection controls and five unsupported forms passed, including a set DF at a call, tail jump or return, and a missing clear on one path. Three compiled semantic mutations must mismatch: ignored backwards direction, memmove overlap and truncated repeat count.

Linux checks all passed:

python -B tests/form_coverage_check.py
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
git diff --check

Evidence and follow-up

Original MIT source-built assembly and independent byte-array reference, extending the existing comparison. No external source was copied. Assumes Windows x64 clear-DF entry; does not model exception resumption, native REP register state at a fault, concurrent observation or throughput equivalence. Non-repeated forms remain rejected. README and experiment notes updated. AI-assisted.

Checklist

  • One reviewable behavior.
  • Exact checks and results included.
  • Negative controls included.
  • README and experiments updated.
  • No game files, distribution links or secrets.

Conflict-resolution update (2026-11-22)

Rebased onto current upstream main after #597 was merged, preserving each increment in stack order. Local checks passed: form_coverage_check.py, docs_links_check.py, bidi_controls_check.py, cpu/lower_prefixes_check.py, plus git diff --check. Previous native-Windows results describe the original commits; the official Windows CI on the new head provides independent revalidation. No workflow or unrelated files were edited.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6543904444 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/599). Originally posted by [Joacoorandom](https://github.com/Joacoorandom) on 2026-11-22T15:01:47Z. --- ## Change Allow STD/CLD around repeated memory transfers in the control-flow CPU lifter. Carry a local direction flag along the actual path and use unsigned pointer steps for forward/backward copies and fills. A separate control-flow proof starts with DF clear and rejects any path that reaches a call, tail jump or return with DF potentially set. Joins retain both possibilities; a branch-selected backwards region must clear DF before its ABI boundary. Instruction effects invalidate stale pointer/count provenance as before. **Depends on #598; #597 is merged.** Rebased the remaining two commits on current `main`: fill `461a4f5` and direction `2b74c4c`. The PR still includes #598 until that dependency is merged. Review the direction increment in `2b74c4c`; original Windows verification predates this rebase. ## Verification Commit `9014984`. Windows 11 26300.9974, MSVC/ML64 19.44.35230, Python 3.12.8. ```powershell cmake --build out/native --target cpu_switch_strings_lifted cpu_switch_strings_lifted_o2 cpu_switch_strings_mutants cpu_string_probe cpu_guarded_call cpu_switch_original_lifted cpu_switch_swapped_lifted cpu_register_probe cpu_flag_conditions_lifted cpu_frame_lifted cpu_calls_lifted cpu_call_entries_lifted --parallel 4 ctest --test-dir out/native --no-tests=error -R "^cpu_aot_(switch_strings|jump_tables|flag_conditions|stack_frames|direct_calls|call_entries)$" -V ``` All six selected tests passed. The cumulative comparison covers nineteen exports and 7,608 native/AOT/reference cases, plus 63 access-violation comparisons, including /O2. New cases cover all repeated copy/fill widths backwards, branch-selected directions and a join with different DF states. The assembly harness checks RSI/RDI restoration and physical DF on normal return. Nine whole-PE rejection controls and five unsupported forms passed, including a set DF at a call, tail jump or return, and a missing clear on one path. Three compiled semantic mutations must mismatch: ignored backwards direction, memmove overlap and truncated repeat count. Linux checks all passed: ```sh python -B tests/form_coverage_check.py python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py git diff --check ``` ## Evidence and follow-up Original MIT source-built assembly and independent byte-array reference, extending the existing comparison. No external source was copied. Assumes Windows x64 clear-DF entry; does not model exception resumption, native REP register state at a fault, concurrent observation or throughput equivalence. Non-repeated forms remain rejected. README and experiment notes updated. AI-assisted. ## Checklist - [x] One reviewable behavior. - [x] Exact checks and results included. - [x] Negative controls included. - [x] README and experiments updated. - [x] No game files, distribution links or secrets. ### Conflict-resolution update (2026-11-22) Rebased onto current upstream `main` after #597 was merged, preserving each increment in stack order. Local checks passed: `form_coverage_check.py`, `docs_links_check.py`, `bidi_controls_check.py`, `cpu/lower_prefixes_check.py`, plus `git diff --check`. Previous native-Windows results describe the original commits; the official Windows CI on the new head provides independent revalidation. No workflow or unrelated files were edited.
upstream-sync closed this pull request 2026-11-24 06:43:52 +00:00
legacy-code-archaeologist commented 2026-11-24 06:48:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-22T17:34:42Z.


Verification of 9014984 on an Intel Core i7-6820HQ (Skylake), Windows 11 26100.9168, MSVC/ML64 19.52.37029, dev preset. I tested this head separately from the rest of the series, see #598:

ctest --preset dev --no-tests=error -R "^cpu_" -j 4
100% tests passed, 0 tests failed out of 114
cpu_aot_switch_strings:
9 whole-PE rejection controls and 5 unsupported forms rejected
7608 native/AOT/reference cases passed: bytes, guards, remaining count, pointers, CF, RSI/RDI and DF
63 nonzero-count access violations preserved, including /O2
3 compiled /O2 semantic mutations detected: ignored DF, memmove overlap, truncated REP count

Like #598, this head no longer merges cleanly with main now that #597 has landed.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7082944654 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/599#issuecomment-7082944654). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-22T17:34:42Z. --- Verification of `9014984` on an Intel Core i7-6820HQ (Skylake), Windows 11 26100.9168, MSVC/ML64 19.52.37029, `dev` preset. I tested this head separately from the rest of the series, see #598: ```text ctest --preset dev --no-tests=error -R "^cpu_" -j 4 100% tests passed, 0 tests failed out of 114 cpu_aot_switch_strings: 9 whole-PE rejection controls and 5 unsupported forms rejected 7608 native/AOT/reference cases passed: bytes, guards, remaining count, pointers, CF, RSI/RDI and DF 63 nonzero-count access violations preserved, including /O2 3 compiled /O2 semantic mutations detected: ignored DF, memmove overlap, truncated REP count ``` Like #598, this head no longer merges cleanly with `main` now that #597 has landed. AI-assisted (Claude Code).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!593
No description provided.