tooling: keep VALLOC callers when the stack read crosses an uncommitted page #2194

Merged
Jess-Doit merged 2 commits from upstream-pr/2202 into main 2026-11-25 04:54:25 +00:00
Jess-Doit commented 2026-11-25 04:23:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-25T04:23:40Z.


startup_debug fails intermittently on a Windows 10 host because the allocation-caller check finds an empty caller list:

tests/startup_debug_check.py:150
AssertionError: ['  0.017 VALLOC NtAllocateVirtualMemory requested=0x0 size=0x10000000 type=0x2000 protect=0x1 callers: ']

Cause: the X2W_VALLOC_MIN hook reads 200 qwords (1,600 bytes) from the hooked thread's rsp. When rsp is within 1,600 bytes of the end of the last committed stack page, ReadProcessMemory crosses into an uncommitted page and returns nothing. The caller chain then comes out empty. Whether it happens depends on where the stack sits at the hooked call, so it comes and goes.

Change: when the full read returns nothing, read again up to the end of rsp's page. The return addresses closest to rsp are the ones the hook needs. This is one hunk in tools/startup/debug_launch.py and changes nothing when the full read succeeds.

Measured on Windows 10 build 19045, MSVC 19.44, dev preset:

ctest --preset dev --no-tests=error -R '^startup_debug$' --output-on-failure   # repeated
Head Runs Failures (all at line 150, empty callers:)
main c118f569 8 3
this PR (main fd457299 + 4eafbd8c) 10 0

CI's Windows host passes main, so this only shows up on some hosts. This came up during review of #2190 and was split out to keep that PR to one behavior.

AI-assisted.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6597165363 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2202). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-25T04:23:40Z. --- `startup_debug` fails intermittently on a Windows 10 host because the allocation-caller check finds an empty caller list: ```text tests/startup_debug_check.py:150 AssertionError: [' 0.017 VALLOC NtAllocateVirtualMemory requested=0x0 size=0x10000000 type=0x2000 protect=0x1 callers: '] ``` **Cause:** the `X2W_VALLOC_MIN` hook reads 200 qwords (1,600 bytes) from the hooked thread's `rsp`. When `rsp` is within 1,600 bytes of the end of the last committed stack page, `ReadProcessMemory` crosses into an uncommitted page and returns nothing. The caller chain then comes out empty. Whether it happens depends on where the stack sits at the hooked call, so it comes and goes. **Change:** when the full read returns nothing, read again up to the end of `rsp`'s page. The return addresses closest to `rsp` are the ones the hook needs. This is one hunk in `tools/startup/debug_launch.py` and changes nothing when the full read succeeds. **Measured** on Windows 10 build 19045, MSVC 19.44, `dev` preset: ```powershell ctest --preset dev --no-tests=error -R '^startup_debug$' --output-on-failure # repeated ``` | Head | Runs | Failures (all at line 150, empty `callers:`) | |---|---:|---:| | `main` `c118f569` | 8 | 3 | | this PR (`main` `fd457299` + 4eafbd8c) | 10 | 0 | CI's Windows host passes `main`, so this only shows up on some hosts. This came up during review of #2190 and was split out to keep that PR to one behavior. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-25 05:04:52 +00:00
tedin7 commented 2026-11-25 05:04:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T04:28:10Z.

Review: COMMENTED


Review of head 4eafbd8cf910a8caacb47798dcee9ecda439574a (one hunk, tools/startup/debug_launch.py:378-386).

Result: no P1, no P2. Two nits.

What I checked

  • git diff --stat origin/main...HEAD: 1 file, +6/-1.
  • CI on this head: Linux Python checks pass, Windows build+test pass, gfx1013 fixtures pass. PR is mergeable and the title is neutral.
  • python3 -I tests/docs_links_check.py: self-test passed, 405 links OK.
  • python3 -I tests/bidi_controls_check.py: self-test passed, no bidi controls in 1481 files.
  • git diff --check origin/main...HEAD: clean. python3 -I -m py_compile tools/startup/debug_launch.py: OK.

Logic

  • read() (line 136) returns b"" on failure, never None, so stack.ljust(...) at line 386 is safe even if the retry also fails (caller list is then empty, same as before).
  • The retry size min(1600, 0x1000 - (rsp & 0xfff)) stays inside rsp's page, which is committed (rsp points into it). When rsp is page-aligned the size is 0x1000, which the min caps at 1600. Correct.
  • A short result is zero-padded to 1600 bytes, so unpack_from("<200Q") keeps working. Zero words never fall in a module range, so no false callers.
  • Behavior is unchanged when the first read succeeds.

Mutation check (Linux model of the read/retry logic, not the Windows hook itself)

  • I modelled a stack whose committed region ends at 0x7000 and ran rsp = 0x6000, 0x6a00, 0x6fe0, 0x6ff8.
  • With the PR logic: 1600, 1536, 32, 8 bytes recovered.
  • With the retry removed (mutation): 1600, 0, 0, 0. So the retry is what restores the callers.
  • This is a model only. The real hook needs Windows, and I did not run win2025 (the change is Python tooling for the debug launcher, not gfx2hlsl or C++, and CI Windows already passes). The PR's own 10/10 vs 5/8 measurement on a Windows 10 host is the evidence for the real fix.

Nits

  1. No regression test: the failure depends on stack position on a live process, so a deterministic test is hard. A small helper (read_stack(read, rsp)) would allow a unit test with a fake read, but this is optional.
  2. The PR body footer carries a tool-attribution line. Neutral wording is preferred in this repo's PR text.

Cause statement in the PR body matches what the code does. Fine to merge from my side once the maintainers are happy.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6051862210 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2202#pullrequestreview-6051862210). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T04:28:10Z. **Review:** COMMENTED --- Review of head `4eafbd8cf910a8caacb47798dcee9ecda439574a` (one hunk, `tools/startup/debug_launch.py:378-386`). **Result: no P1, no P2. Two nits.** What I checked - `git diff --stat origin/main...HEAD`: 1 file, +6/-1. - CI on this head: Linux Python checks pass, Windows build+test pass, gfx1013 fixtures pass. PR is mergeable and the title is neutral. - `python3 -I tests/docs_links_check.py`: self-test passed, 405 links OK. - `python3 -I tests/bidi_controls_check.py`: self-test passed, no bidi controls in 1481 files. - `git diff --check origin/main...HEAD`: clean. `python3 -I -m py_compile tools/startup/debug_launch.py`: OK. Logic - `read()` (line 136) returns `b""` on failure, never `None`, so `stack.ljust(...)` at line 386 is safe even if the retry also fails (caller list is then empty, same as before). - The retry size `min(1600, 0x1000 - (rsp & 0xfff))` stays inside rsp's page, which is committed (rsp points into it). When `rsp` is page-aligned the size is `0x1000`, which the `min` caps at 1600. Correct. - A short result is zero-padded to 1600 bytes, so `unpack_from("<200Q")` keeps working. Zero words never fall in a module range, so no false callers. - Behavior is unchanged when the first read succeeds. Mutation check (Linux model of the read/retry logic, not the Windows hook itself) - I modelled a stack whose committed region ends at 0x7000 and ran rsp = 0x6000, 0x6a00, 0x6fe0, 0x6ff8. - With the PR logic: 1600, 1536, 32, 8 bytes recovered. - With the retry removed (mutation): 1600, 0, 0, 0. So the retry is what restores the callers. - This is a model only. The real hook needs Windows, and I did not run `win2025` (the change is Python tooling for the debug launcher, not gfx2hlsl or C++, and CI Windows already passes). The PR's own 10/10 vs 5/8 measurement on a Windows 10 host is the evidence for the real fix. Nits 1. No regression test: the failure depends on stack position on a live process, so a deterministic test is hard. A small helper (`read_stack(read, rsp)`) would allow a unit test with a fake `read`, but this is optional. 2. The PR body footer carries a tool-attribution line. Neutral wording is preferred in this repo's PR text. Cause statement in the PR body matches what the code does. Fine to merge from my side once the maintainers are happy. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 05:04:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T04:42:21Z.

Review: COMMENTED


Re-review of head 6948da674ff471983e8ef4a81e94c39a84d1ed1e (previous review covered 4eafbd8c).

Scope: tools/startup/debug_launch.py (+10/-1) and tests/startup_debug_check.py (+10/-1). The stack read moves into a small read_stack(read, rsp, words) helper: try the full read, else read to the end of RSP's page, else zero-fill; always pad to 8*words.

Commands executed locally (Linux)

  • git diff --check origin/main...HEAD -> clean
  • python3 tests/docs_links_check.py -> self-test passed, 18 files / 405 links OK
  • python3 tests/bidi_controls_check.py -> self-test passed, 1481 files, no bidi controls
  • debug_launch.py imports ctypes.WinDLL, so it cannot be imported on Linux. I extracted read_stack verbatim and ran the exact new assertions from startup_debug_check.py (RSP 0x6000/0x6a00/0x6fe0/0x6ff8 plus the all-fail case): PASS.
  • Mutations of read_stack, each reverted with git checkout -- .:
    1. read length 0x1000 - (rsp & 0xfff) -> 0x1000: killed (AssertionError at rsp 0x6a00)
    2. remove the within-page retry: killed (same assertion)
    3. remove the ljust zero padding: killed (same assertion)
  • CI on this head: Linux Python checks pass, Windows build+test pass, gfx1013 fixtures pass; the /O2 job and the chart publish job are skipped. Mergeable, title neutral, no model or codename mentions.
  • Win2025 WARP run not needed: Python tooling only, no shader or C++ change.

Findings

  • P1: none.
  • P2: none.
  • nit: the test's stack_read models only a committed-end boundary. A case with RSP exactly page-aligned at the end (rsp=0x7000, expect all zeros) would pin the "no committed bytes" edge. It is covered in effect by the all-fail case, so optional.

The refactor makes the new read path unit-testable. Behavior matches the intent: the words nearest RSP are recovered and the rest is zero-padded. LGTM from a review standpoint (comment only, no approval).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6051963516 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2202#pullrequestreview-6051963516). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T04:42:21Z. **Review:** COMMENTED --- Re-review of head `6948da674ff471983e8ef4a81e94c39a84d1ed1e` (previous review covered `4eafbd8c`). **Scope:** `tools/startup/debug_launch.py` (+10/-1) and `tests/startup_debug_check.py` (+10/-1). The stack read moves into a small `read_stack(read, rsp, words)` helper: try the full read, else read to the end of RSP's page, else zero-fill; always pad to `8*words`. **Commands executed locally (Linux)** - `git diff --check origin/main...HEAD` -> clean - `python3 tests/docs_links_check.py` -> self-test passed, 18 files / 405 links OK - `python3 tests/bidi_controls_check.py` -> self-test passed, 1481 files, no bidi controls - `debug_launch.py` imports `ctypes.WinDLL`, so it cannot be imported on Linux. I extracted `read_stack` verbatim and ran the exact new assertions from `startup_debug_check.py` (RSP 0x6000/0x6a00/0x6fe0/0x6ff8 plus the all-fail case): PASS. - Mutations of `read_stack`, each reverted with `git checkout -- .`: 1. read length `0x1000 - (rsp & 0xfff)` -> `0x1000`: killed (AssertionError at rsp 0x6a00) 2. remove the within-page retry: killed (same assertion) 3. remove the `ljust` zero padding: killed (same assertion) - CI on this head: Linux Python checks pass, Windows build+test pass, gfx1013 fixtures pass; the /O2 job and the chart publish job are skipped. Mergeable, title neutral, no model or codename mentions. - Win2025 WARP run not needed: Python tooling only, no shader or C++ change. **Findings** - P1: none. - P2: none. - nit: the test's `stack_read` models only a committed-end boundary. A case with RSP exactly page-aligned at the end (`rsp=0x7000`, expect all zeros) would pin the "no committed bytes" edge. It is covered in effect by the all-fail case, so optional. The refactor makes the new read path unit-testable. Behavior matches the intent: the words nearest RSP are recovered and the rest is zero-padded. LGTM from a review standpoint (comment only, no approval). AI-assisted; commands listed were executed locally.
Jess-Doit commented 2026-11-25 05:04:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-25T04:37:38Z.


Thanks for the review and the read/retry model.

  1. Regression test: done in 6948da67. The read and retry moved into read_stack(read, rsp, words), and the hook calls it. tests/startup_debug_check.py checks it with a fake read whose committed region ends at 0x7000, using your four RSP values. It must recover 1,600, 1,536, 32 and 8 bytes of the right content, zero-pad the rest to 1,600, and return all zeros when both reads fail. With the retry removed, the helper recovers 1,600, 0, 0 and 0 bytes, so those assertions fail. This runs in the Python part of startup_debug before the probe starts, so it doesn't depend on stack position.
  2. Footer line: noted. I'll leave that one for R0Y00 to call.

ctest --preset dev --no-tests=error -R '^startup_debug$' at 6948da67: 5 of 5 passed on the Windows 10 host. The bidi check and git diff --check are clean.

Status: ready to merge from our side.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7153016594 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2202#issuecomment-7153016594). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-25T04:37:38Z. --- Thanks for the review and the read/retry model. 1. **Regression test:** done in 6948da67. The read and retry moved into `read_stack(read, rsp, words)`, and the hook calls it. `tests/startup_debug_check.py` checks it with a fake `read` whose committed region ends at `0x7000`, using your four RSP values. It must recover 1,600, 1,536, 32 and 8 bytes of the right content, zero-pad the rest to 1,600, and return all zeros when both reads fail. With the retry removed, the helper recovers 1,600, 0, 0 and 0 bytes, so those assertions fail. This runs in the Python part of `startup_debug` before the probe starts, so it doesn't depend on stack position. 2. **Footer line:** noted. I'll leave that one for R0Y00 to call. `ctest --preset dev --no-tests=error -R '^startup_debug$'` at 6948da67: 5 of 5 passed on the Windows 10 host. The bidi check and `git diff --check` are clean. **Status:** ready to merge from our side.
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!2194
No description provided.