cpu: lower 32-bit immediate RSP adjustments in cpu_chained_aot #252

Merged
Vonsek merged 2 commits from upstream-pr/255 into main 2026-11-22 03:40:44 +00:00
Vonsek commented 2026-11-21 19:28:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:28:17Z.


Change

  • Lower ADD_RM64_IMM32 and SUB_RM64_IMM32 on RSP in tools/cpu_chained_aot.py using ins.immediate32to64, while preserving the existing 8-byte alignment and [-4096, 0] frame-depth checks.
  • Add a source-built USE_LARGE_FRAME variant (cpu_chained_frame) in tests/cpu/chained.asm and CMakeLists.txt that allocates and frees a 136-byte (0x88) frame (sub rsp, 136 / add rsp, 136) with a stack spill and reload (mov [rsp + 32], rcx / mov rsi, [rsp + 32]) and matching UWOP_ALLOC_LARGE unwind metadata.
  • Extend tests/cpu/chained_check.py to differentially verify cpu_chained_frame against cpu_chained_frame_lifted, assert that the fixture emits SUB_RM64_IMM32 and ADD_RM64_IMM32, and verify that patching the allocation to 4096 bytes (sp = -4112) is rejected with unsupported stack adjustment.

Verification

Tested on Windows 11 (VS 2022 Build Tools 17.14, MSVC 19.44, ML64 14.44, Windows SDK 10.0.26100, Python 3.12):

  • Before the change, building cpu_chained_frame_lifted failed with:
    unsupported operation at 0x1002: sub rsp,88h
    
  • After the change:
    • cmake --build --preset dev --target cpu_chained_frame_lifted succeeded (3 owned ranges, 3 return paths, indirect stops: []).
    • ctest --preset dev --no-tests=error -R "chained|callback|destroy" -V: 3/3 passed (cpu_aot_destroy_contract, cpu_aot_object_callback, cpu_aot_chained_ranges).

Evidence and follow-up

  • tools/cpu_chained_aot.py already enforced -4096 <= sp <= 0, but only decoded imm8 RSP adjustments (ADD_RM64_IMM8 / SUB_RM64_IMM8), which capped frames at 120 bytes.
  • All fixture binaries are source-built via MASM and CMake; no game files or external dumps are included.

Checklist

  • Focused, single-purpose change
  • Source-built test that fails without the change and passes with it
  • Verified locally on Windows
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6533402005 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/255). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:28:17Z. --- ## Change - Lower `ADD_RM64_IMM32` and `SUB_RM64_IMM32` on `RSP` in `tools/cpu_chained_aot.py` using `ins.immediate32to64`, while preserving the existing 8-byte alignment and `[-4096, 0]` frame-depth checks. - Add a source-built `USE_LARGE_FRAME` variant (`cpu_chained_frame`) in `tests/cpu/chained.asm` and `CMakeLists.txt` that allocates and frees a 136-byte (`0x88`) frame (`sub rsp, 136` / `add rsp, 136`) with a stack spill and reload (`mov [rsp + 32], rcx` / `mov rsi, [rsp + 32]`) and matching `UWOP_ALLOC_LARGE` unwind metadata. - Extend `tests/cpu/chained_check.py` to differentially verify `cpu_chained_frame` against `cpu_chained_frame_lifted`, assert that the fixture emits `SUB_RM64_IMM32` and `ADD_RM64_IMM32`, and verify that patching the allocation to 4096 bytes (`sp = -4112`) is rejected with `unsupported stack adjustment`. ## Verification Tested on Windows 11 (VS 2022 Build Tools 17.14, MSVC 19.44, ML64 14.44, Windows SDK 10.0.26100, Python 3.12): - Before the change, building `cpu_chained_frame_lifted` failed with: ```text unsupported operation at 0x1002: sub rsp,88h ``` - After the change: - `cmake --build --preset dev --target cpu_chained_frame_lifted` succeeded (`3 owned ranges, 3 return paths, indirect stops: []`). - `ctest --preset dev --no-tests=error -R "chained|callback|destroy" -V`: 3/3 passed (`cpu_aot_destroy_contract`, `cpu_aot_object_callback`, `cpu_aot_chained_ranges`). ## Evidence and follow-up - `tools/cpu_chained_aot.py` already enforced `-4096 <= sp <= 0`, but only decoded `imm8` RSP adjustments (`ADD_RM64_IMM8` / `SUB_RM64_IMM8`), which capped frames at 120 bytes. - All fixture binaries are source-built via MASM and CMake; no game files or external dumps are included. ## Checklist - [x] Focused, single-purpose change - [x] Source-built test that fails without the change and passes with it - [x] Verified locally on Windows
upstream-sync closed this pull request 2026-11-24 06:42:04 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:42:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:35:04Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d50a8319cb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6007704609 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/255#pullrequestreview-6007704609). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:35:04Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `d50a8319cb` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
chatgpt-codex-connector[bot commented 2026-11-24 06:47:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:30:54Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T19:35:06.558962Z d50a831 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068075557 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/255#issuecomment-7068075557). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:30:54Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"d50a8319cba95fc8e55e9f4c7bd9423d7fd8d7b8","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-21T19:35:06.558962Z">2026-11-21T19:35:06.558962Z</relative-time> | `d50a831` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Vonsek commented 2026-11-24 06:47:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T19:41:24Z.


Added cpu_chained_frame_lifted to the focused build command and updated the variant/control summary in docs/experiments.md.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068205384 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/255#issuecomment-7068205384). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T19:41:24Z. --- Added `cpu_chained_frame_lifted` to the focused build command and updated the variant/control summary in `docs/experiments.md`.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:35:04Z.

Code review location: CMakeLists.txt; line 578

@@ -571,7 +574,8 @@ if(EXISTS "${INTAKE_PYTHON}")
         "$<TARGET_FILE:cpu_chained_lifted>" "$<TARGET_FILE:cpu_register_probe>"
         "$<TARGET_FILE:cpu_chained_jne>" "$<TARGET_FILE:cpu_chained_jne_lifted>"
         "$<TARGET_FILE:cpu_chained_zero>" "$<TARGET_FILE:cpu_chained_zero_lifted>"
-        "$<TARGET_FILE:cpu_chained_imm>" "$<TARGET_FILE:cpu_chained_imm_lifted>")
+        "$<TARGET_FILE:cpu_chained_imm>" "$<TARGET_FILE:cpu_chained_imm_lifted>"
+        "$<TARGET_FILE:cpu_chained_frame>" "$<TARGET_FILE:cpu_chained_frame_lifted>")

P1 Badge Include the frame fixture in the documented focused build

On a freshly configured Windows build, the reproduction sequence in docs/experiments.md:69-70 now fails because its build command omits cpu_chained_frame_lifted. CMake's build help defines --target as “Build instead of default targets,” and none of the documented targets depends on the new frame pair. This added CTest argument nevertheless makes chained_check.py load both frame DLLs, producing a missing-DLL error. Add cpu_chained_frame_lifted to the documented build command; it also builds the native fixture and satisfies the reproduction-command update requirement in AGENTS.md.

AGENTS.md reference: AGENTS.md:L145-L146

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4654605350 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/255#discussion_r4654605350). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:35:04Z. **Code review location:** `CMakeLists.txt`; line 578 ~~~~diff @@ -571,7 +574,8 @@ if(EXISTS "${INTAKE_PYTHON}") "$<TARGET_FILE:cpu_chained_lifted>" "$<TARGET_FILE:cpu_register_probe>" "$<TARGET_FILE:cpu_chained_jne>" "$<TARGET_FILE:cpu_chained_jne_lifted>" "$<TARGET_FILE:cpu_chained_zero>" "$<TARGET_FILE:cpu_chained_zero_lifted>" - "$<TARGET_FILE:cpu_chained_imm>" "$<TARGET_FILE:cpu_chained_imm_lifted>") + "$<TARGET_FILE:cpu_chained_imm>" "$<TARGET_FILE:cpu_chained_imm_lifted>" + "$<TARGET_FILE:cpu_chained_frame>" "$<TARGET_FILE:cpu_chained_frame_lifted>") ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Include the frame fixture in the documented focused build** On a freshly configured Windows build, the reproduction sequence in `docs/experiments.md:69-70` now fails because its build command omits `cpu_chained_frame_lifted`. CMake's build help defines `--target` as “Build <tgt> instead of default targets,” and none of the documented targets depends on the new frame pair. This added CTest argument nevertheless makes `chained_check.py` load both frame DLLs, producing a missing-DLL error. Add `cpu_chained_frame_lifted` to the documented build command; it also builds the native fixture and satisfies the reproduction-command update requirement in `AGENTS.md`. AGENTS.md reference: [AGENTS.md:L145-L146](https://github.com/R0Y00/Xbox2Windows/blob/d50a8319cba95fc8e55e9f4c7bd9423d7fd8d7b8/AGENTS.md#L145-L146) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
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!252
No description provided.