cpu: accept version-2 chained unwind headers in function_ranges #141

Merged
Vonsek merged 3 commits from upstream-pr/142 into main 2026-11-21 17:44:48 +00:00
Vonsek commented 2026-11-21 17:03:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T17:03:44Z.


Change

Accept x64 UNWIND_INFO version 2 on chained unwind records (UNW_FLAG_CHAININFO, flags == 4) in tools/cpu_ranges.py (function_ranges).

Version 2 UNWIND_INFO (used by MSVC for UWOP_EPILOG) keeps the same 4-byte header, even-padded UNWIND_CODE array (((CountOfCodes + 1) & ~1) * 2), and 12-byte chained RUNTIME_FUNCTION trailer as version 1. Because function_ranges walks every .pdata entry in the image, rejecting version 2 on chained records caused the whole image to fail whenever any chained entry used version 2.

function_ranges now allows version in (1, 2) when flags == 4, while continuing to reject other versions (0, 3, etc.) and combined flags (flags != 4).

tests/cpu/chained_check.py adds:

  • a positive test patching a chained UNWIND_INFO header in the source-built cpu_chained.dll from version 1 (0x21) to version 2 (0x22) and checking that translate() produces the identical output and owned ranges;
  • three negative controls rejecting version 0 (0x20), version 3 (0x23), and combined UNW_FLAG_CHAININFO | UNW_FLAG_EHANDLER (0x2a).

Verification

Tested on Windows 11 x64, VS 2022 Build Tools 17.14 (MSVC 19.44.35230.0, ML64 14.44.35230.0), Windows SDK 10.0.26100, Python 3.12.10 (pefile==2024.8.26, iced-x86==1.21.0), at commit 10d404e:

  • Before the fix in tools/cpu_ranges.py, the new test fails as expected:
    ctest --preset dev --no-tests=error -R '^cpu_aot_chained_ranges$' -V
    ValueError: unsupported chained unwind header at 0x21a0
    1/1 Test #56: cpu_aot_chained_ranges ...........***Failed    0.32 sec
    
  • After the fix:
    ctest --preset dev --no-tests=error -R '^cpu_aot_chained_ranges$' -V
    two null paths, two non-null inputs, RBX/RSI, guarded writes, version-2 chained unwind and seven rejection controls passed
    1/1 Test #56: cpu_aot_chained_ranges ...........   Passed    0.19 sec
    
  • Full CPU suite:
    ctest --preset dev --no-tests=error -R '^cpu_' -V
    100% tests passed, 0 tests failed out of 15
    

Evidence and follow-up

All tests run on the existing source-built MASM fixture tests/cpu/chained.asm (cpu_chained.dll) patched in a temporary directory.

This change covers only chained UNWIND_INFO trailer lookup (version in (1, 2) with UNW_FLAG_CHAININFO); non-chained unwind code decoding and indirect RUNTIME_FUNCTION pointers (bit 0 set on UnwindData) remain unchanged.

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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6531827930 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/142). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T17:03:44Z. --- ## Change Accept x64 `UNWIND_INFO` version 2 on chained unwind records (`UNW_FLAG_CHAININFO`, `flags == 4`) in `tools/cpu_ranges.py` (`function_ranges`). Version 2 `UNWIND_INFO` (used by MSVC for `UWOP_EPILOG`) keeps the same 4-byte header, even-padded `UNWIND_CODE` array (`((CountOfCodes + 1) & ~1) * 2`), and 12-byte chained `RUNTIME_FUNCTION` trailer as version 1. Because `function_ranges` walks every `.pdata` entry in the image, rejecting version 2 on chained records caused the whole image to fail whenever any chained entry used version 2. `function_ranges` now allows `version in (1, 2)` when `flags == 4`, while continuing to reject other versions (`0`, `3`, etc.) and combined flags (`flags != 4`). `tests/cpu/chained_check.py` adds: - a positive test patching a chained `UNWIND_INFO` header in the source-built `cpu_chained.dll` from version 1 (`0x21`) to version 2 (`0x22`) and checking that `translate()` produces the identical output and owned ranges; - three negative controls rejecting version 0 (`0x20`), version 3 (`0x23`), and combined `UNW_FLAG_CHAININFO | UNW_FLAG_EHANDLER` (`0x2a`). ## Verification Tested on Windows 11 x64, VS 2022 Build Tools 17.14 (MSVC 19.44.35230.0, ML64 14.44.35230.0), Windows SDK 10.0.26100, Python 3.12.10 (`pefile==2024.8.26`, `iced-x86==1.21.0`), at commit `10d404e`: - Before the fix in `tools/cpu_ranges.py`, the new test fails as expected: ```text ctest --preset dev --no-tests=error -R '^cpu_aot_chained_ranges$' -V ValueError: unsupported chained unwind header at 0x21a0 1/1 Test #56: cpu_aot_chained_ranges ...........***Failed 0.32 sec ``` - After the fix: ```text ctest --preset dev --no-tests=error -R '^cpu_aot_chained_ranges$' -V two null paths, two non-null inputs, RBX/RSI, guarded writes, version-2 chained unwind and seven rejection controls passed 1/1 Test #56: cpu_aot_chained_ranges ........... Passed 0.19 sec ``` - Full CPU suite: ```text ctest --preset dev --no-tests=error -R '^cpu_' -V 100% tests passed, 0 tests failed out of 15 ``` ## Evidence and follow-up All tests run on the existing source-built MASM fixture `tests/cpu/chained.asm` (`cpu_chained.dll`) patched in a temporary directory. This change covers only chained `UNWIND_INFO` trailer lookup (`version in (1, 2)` with `UNW_FLAG_CHAININFO`); non-chained unwind code decoding and indirect `RUNTIME_FUNCTION` pointers (bit 0 set on `UnwindData`) remain unchanged. ## 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.
upstream-sync closed this pull request 2026-11-24 06:41:31 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:41:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T17:08:43Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 10d404ebc2

ℹ️ 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:6006830395 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/142#pullrequestreview-6006830395). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T17:08:43Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `10d404ebc2` <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:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T17:05:51Z.


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-21T17:08:46.077690Z 10d404e 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:7066207718 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/142#issuecomment-7066207718). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T17:05:51Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"10d404ebc2b8d91cf4e54cc886887dc227a5afc9","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-21T17:08:46.077690Z">2026-11-21T17:08:46.077690Z</relative-time> | `10d404e` | 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:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T17:10:30Z.


Updated \docs/experiments.md\ under Chained function ranges and early returns to record version-2 chained \UNWIND_INFO\ support for trailer lookup (clarifying that general version-2 unwind code decoding is unchanged) and the new fixture controls.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7066268174 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/142#issuecomment-7066268174). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T17:10:30Z. --- Updated \docs/experiments.md\ under **Chained function ranges and early returns** to record version-2 chained \UNWIND_INFO\ support for trailer lookup (clarifying that general version-2 unwind code decoding is unchanged) and the new fixture controls.
chatgpt-codex-connector[bot commented 2026-11-24 06:50:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T17:08:43Z.

Code review location: tools/cpu_ranges.py; line 34

@@ -27,10 +27,11 @@ def function_ranges(pe, entry):
             raise ValueError(f"invalid runtime-function interval at {begin:#x}")
         previous = end
         header = image_bytes(pe, info, 4)
+        version = header[0] & 7
         flags = header[0] >> 3
         parent = None
         if flags & 4:
-            if flags != 4 or header[0] & 7 != 1:
+            if flags != 4 or version not in (1, 2):

P1 Badge Document version-2 chained-unwind support

Accepting version-2 chained headers expands the PE inputs supported by the public CPU translators, but this commit updates neither the CPU experiment entry in README.md nor the chained-range notes in docs/experiments.md. AGENTS.md requires documenting public capability changes. Update the relevant experiment documentation to record the newly accepted version and clarify that this covers chained-trailer lookup, not general version-2 unwind decoding.

AGENTS.md reference: AGENTS.md:L144-L145

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4653891974 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/142#discussion_r4653891974). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T17:08:43Z. **Code review location:** `tools/cpu_ranges.py`; line 34 ~~~~diff @@ -27,10 +27,11 @@ def function_ranges(pe, entry): raise ValueError(f"invalid runtime-function interval at {begin:#x}") previous = end header = image_bytes(pe, info, 4) + version = header[0] & 7 flags = header[0] >> 3 parent = None if flags & 4: - if flags != 4 or header[0] & 7 != 1: + if flags != 4 or version not in (1, 2): ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document version-2 chained-unwind support** Accepting version-2 chained headers expands the PE inputs supported by the public CPU translators, but this commit updates neither the CPU experiment entry in `README.md` nor the chained-range notes in `docs/experiments.md`. `AGENTS.md` requires documenting public capability changes. Update the relevant experiment documentation to record the newly accepted version and clarify that this covers chained-trailer lookup, not general version-2 unwind decoding. AGENTS.md reference: [AGENTS.md:L144-L145](https://github.com/R0Y00/Xbox2Windows/blob/10d404ebc2b8d91cf4e54cc886887dc227a5afc9/AGENTS.md#L144-L145) 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!141
No description provided.