startup: hold other threads while a hook steps over its byte #1401

Merged
tedin7 merged 14 commits from upstream-pr/1408 into main 2026-11-27 21:59:13 +00:00
tedin7 commented 2026-11-24 10:48:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:48:56Z.


Fixes #1281

What this unblocks: a startup run that traces every call of a hooked function even when two threads enter it at once (files.txt, the offline socket refusal and rewrites built on the hook no longer miss concurrent calls).

Source: Microsoft Win32 debugging API documentation: WaitForDebugEvent / ContinueDebugEvent (https://learn.microsoft.com/windows/win32/api/debugapi/nf-debugapi-waitfordebugevent), SuspendThread and GetThreadContext (https://learn.microsoft.com/windows/win32/api/processthreadsapi/nf-processthreadsapi-suspendthread); the single-step trap flag is the x86 EFLAGS TF bit.

Change

The startup debugger's function hooks are one patched byte per function. To run the original instruction it restores the byte, single-steps the thread that hit it and patches the byte again. A second thread entering the same function in that window ran untraced, so files.txt, the offline socket refusal and any rewrite built on the hook missed calls.

Chosen fix: hold every other thread for the step (SuspendThread plus a GetThreadContext to wait until it has stopped), step the owner alone, patch the byte again, then resume them. Why this and not the alternatives:

  • Hardware breakpoints are per thread but only four, and every new thread has to be armed; the hooks here are more than four.
  • Emulating the original instruction needs a decoder for every hooked prologue.
  • Holding the others for one instruction is bounded: the step is one instruction of an ntdll stub, so a held thread's lock is not needed.

Details:

  • A thread that had already trapped before it was held goes back to the hook address and traps again after the window, so its call is traced once.
  • A thread created during the window is held too; a thread that exited is skipped.
  • Every window has a 2 s deadline. A thread that cannot be held, or a deadline that passes, is counted.
  • Per-thread state of a call in flight (return address and stack pointer) was already keyed by thread id; the docs now say so.
  • Every run ends with hook windows: entries=N windows=W unprotected=U deferred=D timeouts=T protection=on|off in the console, finished.txt and files.txt, also when all are 0.
  • --suspend-others 0 turns the holding off, to measure it or to see the loss.

Bookkeeping is in tools/startup/hook_window.py (no Win32 calls) so it can be checked without Windows.

Verification

Linux, run here:

  • python3 -B tests/startup_hook_check.py: PASS. Five single mutations of hook_window.py (defer never, any thread closes the window, deadline not counted, failed hold not counted, owner held) each make it fail.
  • py_compile of the three Python files, tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check: clean.
  • The probe builds with a cross compiler and, run alone under Wine, opens 64 of 64.

Windows (Win2025, D3D12 WARP node, MSVC 14.44, Windows Server 2025 build 26100), PR head 88e0aa815 (origin/main merged in, merge commit, no force):

python x2w_pipe.py win2025 1408 --host proxmox --regex '^(startup_launch|startup_hook_window|startup_hook_overlap|startup_debug)' --keep-release
  • Debug and release: 7/7 passed each: startup_launch, startup_launch_cli_check, startup_hook_window, startup_hook_overlap, startup_debug, startup_debug_log, startup_debug_hooks.
  • startup_hook_overlap: 64 of 64 opens traced with the window, three times, unprotected=0; the control with --suspend-others 0 lost opens and reported unprotected above 0.
  • Found and fixed while merging with main: the hit-limit release asked the return book returns.get(addr) (the class has no get; ReturnBook.pending() added with a test), and a duplicate file_log assignment overrode main's trace or log_at (startup_debug_log failed before the fix, passes after).
  • Not covered here: the two-thread --map-drive case needs #1251, which is not in main.

Evidence and follow-up

  • Outside the pr preset: startup_hook_window, startup_hook_overlap.
  • Interaction with #1251 (--map-drive): that PR registers startup_map_drive_overlap as WILL_FAIL for this issue. After both are merged, that test passes and WILL_FAIL must be removed. The name pool there already hands each call its own buffer, and its in-flight data is kept per call in returns, so it needs no change for this fix. This PR does not touch those lines; it applies on main without #1251.
  • #1229 also edits debug_launch.py (near set_ctx, the event loop and the stop report); the hunks are separate from mine, but whichever merges second may need a small rebase.
  • Not measured: how often a real startup run enters one hooked function from two threads, and the time cost of holding threads on a run with many threads.

Checklist

  • docs/experiments.md and docs/startup-runtime.md updated
  • Title-neutral, original code, no game files or logs
  • Test fails without the change

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5470703281 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:48:56Z. --- Fixes #1281 What this unblocks: a startup run that traces every call of a hooked function even when two threads enter it at once (files.txt, the offline socket refusal and rewrites built on the hook no longer miss concurrent calls). Source: Microsoft Win32 debugging API documentation: WaitForDebugEvent / ContinueDebugEvent (https://learn.microsoft.com/windows/win32/api/debugapi/nf-debugapi-waitfordebugevent), SuspendThread and GetThreadContext (https://learn.microsoft.com/windows/win32/api/processthreadsapi/nf-processthreadsapi-suspendthread); the single-step trap flag is the x86 EFLAGS TF bit. ## Change The startup debugger's function hooks are one patched byte per function. To run the original instruction it restores the byte, single-steps the thread that hit it and patches the byte again. A second thread entering the same function in that window ran untraced, so files.txt, the offline socket refusal and any rewrite built on the hook missed calls. Chosen fix: hold every other thread for the step (SuspendThread plus a GetThreadContext to wait until it has stopped), step the owner alone, patch the byte again, then resume them. Why this and not the alternatives: - Hardware breakpoints are per thread but only four, and every new thread has to be armed; the hooks here are more than four. - Emulating the original instruction needs a decoder for every hooked prologue. - Holding the others for one instruction is bounded: the step is one instruction of an ntdll stub, so a held thread's lock is not needed. Details: - A thread that had already trapped before it was held goes back to the hook address and traps again after the window, so its call is traced once. - A thread created during the window is held too; a thread that exited is skipped. - Every window has a 2 s deadline. A thread that cannot be held, or a deadline that passes, is counted. - Per-thread state of a call in flight (return address and stack pointer) was already keyed by thread id; the docs now say so. - Every run ends with `hook windows: entries=N windows=W unprotected=U deferred=D timeouts=T protection=on|off` in the console, finished.txt and files.txt, also when all are 0. - `--suspend-others 0` turns the holding off, to measure it or to see the loss. Bookkeeping is in tools/startup/hook_window.py (no Win32 calls) so it can be checked without Windows. ## Verification Linux, run here: - `python3 -B tests/startup_hook_check.py`: PASS. Five single mutations of hook_window.py (defer never, any thread closes the window, deadline not counted, failed hold not counted, owner held) each make it fail. - `py_compile` of the three Python files, `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `git diff --check`: clean. - The probe builds with a cross compiler and, run alone under Wine, opens 64 of 64. Windows (Win2025, D3D12 WARP node, MSVC 14.44, Windows Server 2025 build 26100), PR head 88e0aa815 (origin/main merged in, merge commit, no force): ```powershell python x2w_pipe.py win2025 1408 --host proxmox --regex '^(startup_launch|startup_hook_window|startup_hook_overlap|startup_debug)' --keep-release ``` - Debug and release: **7/7 passed each**: startup_launch, startup_launch_cli_check, startup_hook_window, startup_hook_overlap, startup_debug, startup_debug_log, startup_debug_hooks. - `startup_hook_overlap`: 64 of 64 opens traced with the window, three times, `unprotected=0`; the control with `--suspend-others 0` lost opens and reported `unprotected` above 0. - Found and fixed while merging with main: the hit-limit release asked the return book `returns.get(addr)` (the class has no `get`; `ReturnBook.pending()` added with a test), and a duplicate `file_log` assignment overrode main's `trace or log_at` (startup_debug_log failed before the fix, passes after). - Not covered here: the two-thread `--map-drive` case needs #1251, which is not in main. ## Evidence and follow-up - Outside the `pr` preset: startup_hook_window, startup_hook_overlap. - Interaction with #1251 (--map-drive): that PR registers startup_map_drive_overlap as WILL_FAIL for this issue. After both are merged, that test passes and WILL_FAIL must be removed. The name pool there already hands each call its own buffer, and its in-flight data is kept per call in `returns`, so it needs no change for this fix. This PR does not touch those lines; it applies on main without #1251. - #1229 also edits debug_launch.py (near set_ctx, the event loop and the stop report); the hunks are separate from mine, but whichever merges second may need a small rebase. - Not measured: how often a real startup run enters one hooked function from two threads, and the time cost of holding threads on a run with many threads. ## Checklist - [x] docs/experiments.md and docs/startup-runtime.md updated - [x] Title-neutral, original code, no game files or logs - [x] Test fails without the change AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-24 11:03:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:54:42Z.


AI-assisted. Cause of "88 of 64" in the unprotected control: with --suspend-others 0 another thread can re-patch the hook byte before the stepping thread has run the original instruction, so that thread traps again at the same address. The entry hook registered the same call twice (same thread, same stack slot), and the return wrote one line per registration. Replaying that bookkeeping with 24 re-trapped calls out of 64 gives 88 lines with the old logic and 64 with the fix.

Changes in the new commit: pending returns now live in ReturnBook (tools/startup/hook_window.py), where a call is identified by thread and stack slot and a repeat registration replaces the first. The control counts lost opens as max(0, 64 - traced) and fails if traced exceeds 64. The overlap probe now uses 4 threads x 16 rounds (still 64 opens) with a spin barrier to make the race more likely.

Linux: startup_hook_window logic, py_compile, docs_links_check, bidi_controls_check pass. Windows not run by me. Node command: ctest --preset dev -R 'startup_hook|startup_launch' (Debug and /O2). PR stays Draft.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129407158 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7129407158). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:54:42Z. --- AI-assisted. Cause of "88 of 64" in the unprotected control: with --suspend-others 0 another thread can re-patch the hook byte before the stepping thread has run the original instruction, so that thread traps again at the same address. The entry hook registered the same call twice (same thread, same stack slot), and the return wrote one line per registration. Replaying that bookkeeping with 24 re-trapped calls out of 64 gives 88 lines with the old logic and 64 with the fix. Changes in the new commit: pending returns now live in `ReturnBook` (tools/startup/hook_window.py), where a call is identified by thread and stack slot and a repeat registration replaces the first. The control counts lost opens as max(0, 64 - traced) and fails if traced exceeds 64. The overlap probe now uses 4 threads x 16 rounds (still 64 opens) with a spin barrier to make the race more likely. Linux: startup_hook_window logic, py_compile, docs_links_check, bidi_controls_check pass. Windows not run by me. Node command: ctest --preset dev -R 'startup_hook|startup_launch' (Debug and /O2). PR stays Draft.
tedin7 commented 2026-11-24 11:03:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T10:57:28Z.


AI-assisted. Pushed 3cfa1726 for the Windows Server 2025 failure of startup_hook_overlap (windows=132 unprotected=1 timeouts=0).

Cause: a thread that has called ExitThread stays in the debugger's thread list until its exit event is read. OpenThread still succeeds on it, but SuspendThread/GetThreadContext fail with access denied, and hold_thread returned FAILED, so the window counted it as unprotected although it runs no code. The hold is now classified after the failure by a pure function (hook_window.classify_hold): GONE when GetExitCodeThread != STILL_ACTIVE (or the handle is already signaled, for a thread that is terminating and has no exit code yet), FAILED when the thread is alive and could not be suspended. A live unsuspendable thread still counts as unprotected, and the test still requires unprotected == 0.

Ruled out by reading: a thread created after the list is read (CREATE_THREAD held at its event), an already suspended thread (nested count is not an error, only 0xFFFFFFFF is), a reused or closed handle (a fresh handle per hold, threads dropped from the list on exit), the owner itself (excluded from the others).

Linux checks: py_compile, startup_hook_window (new GONE/FAILED cases; the old module has no classifier), docs_links_check, bidi_controls_check, preflight. The Win32 debugger race cannot be run on Linux, so it is not verified here. Windows: ctest --preset dev -R 'startup_hook|startup_launch' (Debug and /O2).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129465775 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7129465775). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:57:28Z. --- AI-assisted. Pushed 3cfa1726 for the Windows Server 2025 failure of startup_hook_overlap (windows=132 unprotected=1 timeouts=0). Cause: a thread that has called ExitThread stays in the debugger's thread list until its exit event is read. OpenThread still succeeds on it, but SuspendThread/GetThreadContext fail with access denied, and hold_thread returned FAILED, so the window counted it as unprotected although it runs no code. The hold is now classified after the failure by a pure function (hook_window.classify_hold): GONE when GetExitCodeThread != STILL_ACTIVE (or the handle is already signaled, for a thread that is terminating and has no exit code yet), FAILED when the thread is alive and could not be suspended. A live unsuspendable thread still counts as unprotected, and the test still requires unprotected == 0. Ruled out by reading: a thread created after the list is read (CREATE_THREAD held at its event), an already suspended thread (nested count is not an error, only 0xFFFFFFFF is), a reused or closed handle (a fresh handle per hold, threads dropped from the list on exit), the owner itself (excluded from the others). Linux checks: py_compile, startup_hook_window (new GONE/FAILED cases; the old module has no classifier), docs_links_check, bidi_controls_check, preflight. The Win32 debugger race cannot be run on Linux, so it is not verified here. Windows: ctest --preset dev -R 'startup_hook|startup_launch' (Debug and /O2).
tedin7 commented 2026-11-24 11:03:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:02:07Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit 3cfa1726:

  • Debug (--preset dev): ctest --preset dev -R '^(startup_launch|startup_hook_window|startup_hook_overlap)$' --no-tests=error --output-on-failure — 3/3 passed (startup_hook_window 0.07s, startup_hook_overlap 0.78s, startup_launch 1.77s)
  • Release /O2 (--preset release): ctest --preset release -R '^(startup_launch|startup_hook_window|startup_hook_overlap)$' --no-tests=error --output-on-failure — 3/3 passed (startup_hook_window 0.07s, startup_hook_overlap 0.75s, startup_launch 1.76s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129568413 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7129568413). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:02:07Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit `3cfa1726`: - **Debug (`--preset dev`)**: `ctest --preset dev -R '^(startup_launch|startup_hook_window|startup_hook_overlap)$' --no-tests=error --output-on-failure` — **3/3 passed** (`startup_hook_window` 0.07s, `startup_hook_overlap` 0.78s, `startup_launch` 1.77s) - **Release `/O2` (`--preset release`)**: `ctest --preset release -R '^(startup_launch|startup_hook_window|startup_hook_overlap)$' --no-tests=error --output-on-failure` — **3/3 passed** (`startup_hook_window` 0.07s, `startup_hook_overlap` 0.75s, `startup_launch` 1.76s)
chatgpt-codex-connector[bot commented 2026-11-24 11:03:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:02:14Z.


Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T10:46:36.092276Z
We couldn’t complete this review. Comment @codex review to try again.
88e0aa8 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:7129571111 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7129571111). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T11:02:14Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"88e0aa81516f8feb47eb137a9a76b0559ad4f1cf","has_any_findings":true,"has_unresolved_findings":true,"status":"failed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ❌ Failed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ❌ **Failed** <relative-time datetime="2026-11-26T10:46:36.092276Z">2026-11-26T10:46:36.092276Z</relative-time><br/>We couldn’t complete this review. Comment `@codex review` to try again. | `88e0aa8` | 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>
chatgpt-codex-connector[bot] commented 2026-11-24 11:10:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:10:58Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3cfa1726b4

ℹ️ 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:6038147530 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#pullrequestreview-6038147530). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-11-24T11:10:58Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `3cfa1726b4` <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>
tedin7 commented 2026-11-24 12:02:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:17:44Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6038249305 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#pullrequestreview-6038249305). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:17:44Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 12:02:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:17:47Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6038249736 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#pullrequestreview-6038249736). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:17:47Z. **Review:** COMMENTED --- _No description provided._
SimSalabimse commented 2026-11-24 12:03:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-24T11:21:14Z.


Tested on Windows 11 26200, MSVC 19.42, RTX 4070 Ti (driver 621.35) at 3cfa172: startup_launch, startup_hook_window and startup_hook_overlap all passed. Overlap traced 64/64 opens, while the control lost 12.

AI-Assisted

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129986920 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7129986920). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-24T11:21:14Z. --- Tested on Windows 11 26200, MSVC 19.42, RTX 4070 Ti (driver 621.35) at 3cfa172: `startup_launch`, `startup_hook_window` and `startup_hook_overlap` all **passed**. Overlap traced 64/64 opens, while the control lost 12. AI-Assisted
tedin7 commented 2026-11-24 12:03:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:33:59Z.


Thanks @SimSalabimse for verifying on Windows 11 26200 / MSVC 19.42! Rebased onto current main at 6df8cf0a after addressing the Codex P2 notes (3/3 pass on Win2025 Debug & Release).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130260824 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7130260824). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:33:59Z. --- Thanks @SimSalabimse for verifying on Windows 11 26200 / MSVC 19.42! Rebased onto current `main` at `6df8cf0a` after addressing the Codex P2 notes (`3/3` pass on Win2025 Debug & Release).
tedin7 commented 2026-11-24 12:03:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:35:37Z.


Thanks @SimSalabimse: that is the hardware pass (RTX 4070 Ti, 64/64 opens traced against 12 lost by the control) on top of our Windows Server 2025 run. No change to the head is needed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130296314 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7130296314). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:35:37Z. --- Thanks @SimSalabimse: that is the hardware pass (RTX 4070 Ti, 64/64 opens traced against 12 lost by the control) on top of our Windows Server 2025 run. No change to the head is needed.
RenzoWit35 commented 2026-11-24 12:03:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RenzoWit35 on 2026-11-24T11:38:54Z.


Ran this branch on a Windows 11 client (build 26300, MSVC 14.51, Python 3.14), commit 86d81f9e (same hook code as the rebased head 6df8cf0a).

startup_hook_window, startup_launch, startup_debug and startup_host_cpu_debug pass. The
tracing itself looks right: in every protected run 64 of 64 opens were traced. A second probe of
mine, two threads opening their own file 64 times each without a barrier, gave exact per-thread
counts in 20 of 20 runs, where current main is wrong in 16 of 20.

startup_hook_overlap is intermittent here: 17 of 40 runs failed with (262, 1, 0) or
(262, 2, 0), so unprotected was 1 or 2 with all 64 opens traced. Single runs do pass, which fits the passes reported above. I logged the failed holds
in 15 more runs (5 failed). All 8 failed holds looked the same: SuspendThread failed,
GetExitCodeThread returned 259, the handle was still not signaled after the 20 ms wait, and
NtSuspendThread on the same handle returned 0xC000004B (STATUS_THREAD_IS_TERMINATING). My
guess is that the thread is inside its exit and waits for the debugger to take its EXIT_THREAD
event, so it cannot become signaled while the window is open. Treating 0xC000004B from
NtSuspendThread as GONE (the thread runs no more user code) covered it in a similar change
here. The failures appeared when the test was started from PowerShell, directly or through ctest;
15 runs started from Git Bash all passed, and I don't know why the shell matters.

Cost: 2 x 2000 serial opens took 7.1 to 8.0 s on main and 12.5 to 13.3 s at 2fabc905 (three runs
each; similar at 86d81f9e on a busier machine). In a similar change most of that was OpenThread
per held thread per step, about 80 µs each here. The hThread from the CREATE_THREAD and
CREATE_PROCESS events already has suspend/resume and get-context access, and the system closes it
after the exit event.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130367428 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7130367428). Originally posted by [RenzoWit35](https://github.com/RenzoWit35) on 2026-11-24T11:38:54Z. --- Ran this branch on a Windows 11 client (build 26300, MSVC 14.51, Python 3.14), commit 86d81f9e (same hook code as the rebased head 6df8cf0a). `startup_hook_window`, `startup_launch`, `startup_debug` and `startup_host_cpu_debug` pass. The tracing itself looks right: in every protected run 64 of 64 opens were traced. A second probe of mine, two threads opening their own file 64 times each without a barrier, gave exact per-thread counts in 20 of 20 runs, where current main is wrong in 16 of 20. **`startup_hook_overlap` is intermittent here: 17 of 40 runs failed** with `(262, 1, 0)` or `(262, 2, 0)`, so `unprotected` was 1 or 2 with all 64 opens traced. Single runs do pass, which fits the passes reported above. I logged the failed holds in 15 more runs (5 failed). All 8 failed holds looked the same: `SuspendThread` failed, `GetExitCodeThread` returned 259, the handle was still not signaled after the 20 ms wait, and `NtSuspendThread` on the same handle returned `0xC000004B` (`STATUS_THREAD_IS_TERMINATING`). My guess is that the thread is inside its exit and waits for the debugger to take its EXIT_THREAD event, so it cannot become signaled while the window is open. Treating `0xC000004B` from `NtSuspendThread` as `GONE` (the thread runs no more user code) covered it in a similar change here. The failures appeared when the test was started from PowerShell, directly or through ctest; 15 runs started from Git Bash all passed, and I don't know why the shell matters. Cost: 2 x 2000 serial opens took 7.1 to 8.0 s on main and 12.5 to 13.3 s at 2fabc905 (three runs each; similar at 86d81f9e on a busier machine). In a similar change most of that was `OpenThread` per held thread per step, about 80 µs each here. The `hThread` from the CREATE_THREAD and CREATE_PROCESS events already has suspend/resume and get-context access, and the system closes it after the exit event. AI-assisted.
tedin7 commented 2026-11-24 12:03:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:45:23Z.


Thanks @RenzoWit35, great catch on the Win11 26300 STATUS_THREAD_IS_TERMINATING case. hold_thread now suspends with NtSuspendThread and treats 0xC000004B and 0xC0000008 as GONE (a unit test covers it, and it does not count as unprotected). It also reuses the hThread from the CREATE_PROCESS and CREATE_THREAD debug events, and only falls back to OpenThread when that handle is missing. It never closes the OS-provided handle.

Verified on Windows Server 2025 at 4b05247a: startup_launch, startup_hook_window and startup_hook_overlap pass 3/3 in both Debug and Release /O2. I haven't re-run it on Win11 26300.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130505852 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7130505852). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:45:23Z. --- Thanks @RenzoWit35, great catch on the Win11 26300 `STATUS_THREAD_IS_TERMINATING` case. `hold_thread` now suspends with `NtSuspendThread` and treats `0xC000004B` and `0xC0000008` as GONE (a unit test covers it, and it does not count as unprotected). It also reuses the `hThread` from the CREATE_PROCESS and CREATE_THREAD debug events, and only falls back to `OpenThread` when that handle is missing. It never closes the OS-provided handle. Verified on Windows Server 2025 at `4b05247a`: `startup_launch`, `startup_hook_window` and `startup_hook_overlap` pass 3/3 in both Debug and Release `/O2`. I haven't re-run it on Win11 26300.
chatgpt-codex-connector[bot commented 2026-11-24 12:03:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:10:58Z.

Code review location: tools/startup/hook_window.py; line 49

@@ -0,0 +1,135 @@
+"""Step-over window of the startup debugger's one-byte hooks (docs/startup-runtime.md).
+
+A hook is one patched byte per function. To run the original instruction the debugger restores the
+byte, single-steps the thread that hit it and patches the byte again. A second thread that enters
+the function inside that window would run the original instruction untraced, so the window holds
+every other thread for the step: the owner steps alone and the others resume when it is done.
+
+This module is the bookkeeping only (no Win32 calls); debug_launch.py passes the suspend and resume
+functions. Every window has a deadline, a thread that cannot be held is counted, and the counters
+are always reported so a run says how many calls it may have missed.
+"""
+
+HELD, GONE, FAILED = "held", "gone", "failed"
+ERROR_INVALID_PARAMETER = 87  # OpenThread: no thread has this id
+STILL_ACTIVE = 259  # GetExitCodeThread of a thread that has not exited
+
+
+def classify_hold(exit_code, error=0, signaled=False):
+    """Outcome of a hold that did not take: GONE when the thread has exited, FAILED when it is alive.
+
+    A thread that called ExitThread stays in the debugger's thread list until its EXIT_THREAD event is
+    read, and by then OpenThread still works but SuspendThread and GetThreadContext fail (access
+    denied). That thread runs no more code, so nothing can race with it: GONE. A live thread that
+    cannot be suspended is a real hole in the window and stays FAILED. `exit_code` is
+    GetExitCodeThread (None when it could not be read), `signaled` whether the thread handle is
+    already signaled, `error` the GetLastError of an OpenThread that returned no handle."""
+    if error == ERROR_INVALID_PARAMETER:
+        return GONE
+    if signaled or (exit_code is not None and exit_code != STILL_ACTIVE):
+        return GONE
+    return FAILED
+
+
+class ReturnBook:
+    """Pending hooked calls, keyed by return address; each is traced once, when its call returns.
+
+    A call is identified by its thread and the stack slot of its return address. The entry hook can
+    trap twice for one call when protection is off: another thread re-patches the byte before this
+    one has run the original instruction, so the thread traps again at the same address and slot.
+    That is the same call, so it replaces the first registration; two entries made the return write
+    two lines and a run counted 88 opens for 64 made."""
+
+    def __init__(self):
+        self._pending = {}  # return address -> list of (tid, stack slot, description)
+
+    def add(self, address, tid, slot, description):
+        kept = [item for item in self._pending.get(address, []) if (item[0], item[1]) != (tid, slot)]
+        kept.append((tid, slot, description))
+        self._pending[address] = kept

P2 Badge Preserve distinct hooked calls that share a return slot

When a hooked function tail-calls another hooked function, both entries have the same return address, thread and return-stack slot. Filtering solely on (tid, slot) therefore deletes the outer function's pending description rather than just deduplicating a repeated breakpoint. A synthetic tail-call sequence through the actual breakpoint handler produces two return records before this change but only the inner record afterward, even with protection enabled. Restrict replacement to confirmed re-traps of an unexecuted hook entry so legitimate tail-called functions remain visible in files.txt.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679118021 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#discussion_r4679118021). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T11:10:58Z. **Code review location:** `tools/startup/hook_window.py`; line 49 ~~~~diff @@ -0,0 +1,135 @@ +"""Step-over window of the startup debugger's one-byte hooks (docs/startup-runtime.md). + +A hook is one patched byte per function. To run the original instruction the debugger restores the +byte, single-steps the thread that hit it and patches the byte again. A second thread that enters +the function inside that window would run the original instruction untraced, so the window holds +every other thread for the step: the owner steps alone and the others resume when it is done. + +This module is the bookkeeping only (no Win32 calls); debug_launch.py passes the suspend and resume +functions. Every window has a deadline, a thread that cannot be held is counted, and the counters +are always reported so a run says how many calls it may have missed. +""" + +HELD, GONE, FAILED = "held", "gone", "failed" +ERROR_INVALID_PARAMETER = 87 # OpenThread: no thread has this id +STILL_ACTIVE = 259 # GetExitCodeThread of a thread that has not exited + + +def classify_hold(exit_code, error=0, signaled=False): + """Outcome of a hold that did not take: GONE when the thread has exited, FAILED when it is alive. + + A thread that called ExitThread stays in the debugger's thread list until its EXIT_THREAD event is + read, and by then OpenThread still works but SuspendThread and GetThreadContext fail (access + denied). That thread runs no more code, so nothing can race with it: GONE. A live thread that + cannot be suspended is a real hole in the window and stays FAILED. `exit_code` is + GetExitCodeThread (None when it could not be read), `signaled` whether the thread handle is + already signaled, `error` the GetLastError of an OpenThread that returned no handle.""" + if error == ERROR_INVALID_PARAMETER: + return GONE + if signaled or (exit_code is not None and exit_code != STILL_ACTIVE): + return GONE + return FAILED + + +class ReturnBook: + """Pending hooked calls, keyed by return address; each is traced once, when its call returns. + + A call is identified by its thread and the stack slot of its return address. The entry hook can + trap twice for one call when protection is off: another thread re-patches the byte before this + one has run the original instruction, so the thread traps again at the same address and slot. + That is the same call, so it replaces the first registration; two entries made the return write + two lines and a run counted 88 opens for 64 made.""" + + def __init__(self): + self._pending = {} # return address -> list of (tid, stack slot, description) + + def add(self, address, tid, slot, description): + kept = [item for item in self._pending.get(address, []) if (item[0], item[1]) != (tid, slot)] + kept.append((tid, slot, description)) + self._pending[address] = kept ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve distinct hooked calls that share a return slot** When a hooked function tail-calls another hooked function, both entries have the same return address, thread and return-stack slot. Filtering solely on `(tid, slot)` therefore deletes the outer function's pending description rather than just deduplicating a repeated breakpoint. A synthetic tail-call sequence through the actual breakpoint handler produces two return records before this change but only the inner record afterward, even with protection enabled. Restrict replacement to confirmed re-traps of an unexecuted hook entry so legitimate tail-called functions remain visible in `files.txt`. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 12:03:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:10:59Z.

Code review location: docs/startup-runtime.md; line 178

@@ -161,6 +161,32 @@ and no game files are needed, and the `pr` preset builds the probe and runs the
 ctest --preset release --no-tests=error -R '^startup_launch$' -V
 ```
 
+## Concurrent calls through a hooked function
+
+The debugger's file, socket and allocation hooks are one patched byte per function. To run the original
+instruction it restores the byte, single-steps the thread that hit it and patches the byte again. A second thread that
+entered the function inside that window ran untraced, so `files.txt` could miss opens and the
+offline mode could miss a refused socket. Now every other thread is held for the step and resumes when the stepping
+thread is done (`tools/startup/hook_window.py`). A thread that had already trapped when it was held goes back to the
+hook address and traps again afterwards, so its call is traced once, not twice. Each window has a 2 s deadline, so a
+thread is never held forever. Per-thread state of a call in flight (the return address and stack pointer it will come back to) is
+keyed by thread id, not shared.
+
+Every run ends with `hook windows: entries=N windows=W unprotected=U deferred=D timeouts=T protection=on|off` in the
+console output, `finished.txt` and `files.txt`, also when everything is 0. `unprotected` counts the windows in which another thread could
+not be held (a thread that has already exited is not counted: it runs no code), or the deadline passed, or protection was off with other threads alive: an upper bound on the calls a run may have
+missed. `--suspend-others 0` turns the holding off, to measure what it costs or to see the loss.

P2 Badge Remove the unsupported upper bound on missed calls

When holding fails, a deadline expires, or protection is disabled, one exposed window can let several other threads—or repeated calls from one thread—cross the restored hook byte before it is rearmed. The bookkeeping increments unprotected once for that window, so U=1 can correspond to several missed calls and is not an upper bound on tracing loss. Describe this value only as a count of exposed windows; the current wording can understate missing file operations and offline-hook coverage.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679118030 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#discussion_r4679118030). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T11:10:59Z. **Code review location:** `docs/startup-runtime.md`; line 178 ~~~~diff @@ -161,6 +161,32 @@ and no game files are needed, and the `pr` preset builds the probe and runs the ctest --preset release --no-tests=error -R '^startup_launch$' -V ``` +## Concurrent calls through a hooked function + +The debugger's file, socket and allocation hooks are one patched byte per function. To run the original +instruction it restores the byte, single-steps the thread that hit it and patches the byte again. A second thread that +entered the function inside that window ran untraced, so `files.txt` could miss opens and the +offline mode could miss a refused socket. Now every other thread is held for the step and resumes when the stepping +thread is done (`tools/startup/hook_window.py`). A thread that had already trapped when it was held goes back to the +hook address and traps again afterwards, so its call is traced once, not twice. Each window has a 2 s deadline, so a +thread is never held forever. Per-thread state of a call in flight (the return address and stack pointer it will come back to) is +keyed by thread id, not shared. + +Every run ends with `hook windows: entries=N windows=W unprotected=U deferred=D timeouts=T protection=on|off` in the +console output, `finished.txt` and `files.txt`, also when everything is 0. `unprotected` counts the windows in which another thread could +not be held (a thread that has already exited is not counted: it runs no code), or the deadline passed, or protection was off with other threads alive: an upper bound on the calls a run may have +missed. `--suspend-others 0` turns the holding off, to measure what it costs or to see the loss. ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Remove the unsupported upper bound on missed calls** When holding fails, a deadline expires, or protection is disabled, one exposed window can let several other threads—or repeated calls from one thread—cross the restored hook byte before it is rearmed. The bookkeeping increments `unprotected` once for that window, so `U=1` can correspond to several missed calls and is not an upper bound on tracing loss. Describe this value only as a count of exposed windows; the current wording can understate missing file operations and offline-hook coverage. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-24 12:03:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:17:44Z.

Code review location: tools/startup/hook_window.py; line 49

@@ -0,0 +1,135 @@
+"""Step-over window of the startup debugger's one-byte hooks (docs/startup-runtime.md).
+
+A hook is one patched byte per function. To run the original instruction the debugger restores the
+byte, single-steps the thread that hit it and patches the byte again. A second thread that enters
+the function inside that window would run the original instruction untraced, so the window holds
+every other thread for the step: the owner steps alone and the others resume when it is done.
+
+This module is the bookkeeping only (no Win32 calls); debug_launch.py passes the suspend and resume
+functions. Every window has a deadline, a thread that cannot be held is counted, and the counters
+are always reported so a run says how many calls it may have missed.
+"""
+
+HELD, GONE, FAILED = "held", "gone", "failed"
+ERROR_INVALID_PARAMETER = 87  # OpenThread: no thread has this id
+STILL_ACTIVE = 259  # GetExitCodeThread of a thread that has not exited
+
+
+def classify_hold(exit_code, error=0, signaled=False):
+    """Outcome of a hold that did not take: GONE when the thread has exited, FAILED when it is alive.
+
+    A thread that called ExitThread stays in the debugger's thread list until its EXIT_THREAD event is
+    read, and by then OpenThread still works but SuspendThread and GetThreadContext fail (access
+    denied). That thread runs no more code, so nothing can race with it: GONE. A live thread that
+    cannot be suspended is a real hole in the window and stays FAILED. `exit_code` is
+    GetExitCodeThread (None when it could not be read), `signaled` whether the thread handle is
+    already signaled, `error` the GetLastError of an OpenThread that returned no handle."""
+    if error == ERROR_INVALID_PARAMETER:
+        return GONE
+    if signaled or (exit_code is not None and exit_code != STILL_ACTIVE):
+        return GONE
+    return FAILED
+
+
+class ReturnBook:
+    """Pending hooked calls, keyed by return address; each is traced once, when its call returns.
+
+    A call is identified by its thread and the stack slot of its return address. The entry hook can
+    trap twice for one call when protection is off: another thread re-patches the byte before this
+    one has run the original instruction, so the thread traps again at the same address and slot.
+    That is the same call, so it replaces the first registration; two entries made the return write
+    two lines and a run counted 88 opens for 64 made."""
+
+    def __init__(self):
+        self._pending = {}  # return address -> list of (tid, stack slot, description)
+
+    def add(self, address, tid, slot, description):
+        kept = [item for item in self._pending.get(address, []) if (item[0], item[1]) != (tid, slot)]
+        kept.append((tid, slot, description))
+        self._pending[address] = kept

Fixed in 86d81f9e: ReturnBook.add() now tracks the hooked entry address alongside (tid, slot) so tail-called hooked functions keep both pending return records while re-traps of the same entry still deduplicate; added unit test coverage in tests/startup_hook_check.py.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679201933 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#discussion_r4679201933). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:17:44Z. **Code review location:** `tools/startup/hook_window.py`; line 49 ~~~~diff @@ -0,0 +1,135 @@ +"""Step-over window of the startup debugger's one-byte hooks (docs/startup-runtime.md). + +A hook is one patched byte per function. To run the original instruction the debugger restores the +byte, single-steps the thread that hit it and patches the byte again. A second thread that enters +the function inside that window would run the original instruction untraced, so the window holds +every other thread for the step: the owner steps alone and the others resume when it is done. + +This module is the bookkeeping only (no Win32 calls); debug_launch.py passes the suspend and resume +functions. Every window has a deadline, a thread that cannot be held is counted, and the counters +are always reported so a run says how many calls it may have missed. +""" + +HELD, GONE, FAILED = "held", "gone", "failed" +ERROR_INVALID_PARAMETER = 87 # OpenThread: no thread has this id +STILL_ACTIVE = 259 # GetExitCodeThread of a thread that has not exited + + +def classify_hold(exit_code, error=0, signaled=False): + """Outcome of a hold that did not take: GONE when the thread has exited, FAILED when it is alive. + + A thread that called ExitThread stays in the debugger's thread list until its EXIT_THREAD event is + read, and by then OpenThread still works but SuspendThread and GetThreadContext fail (access + denied). That thread runs no more code, so nothing can race with it: GONE. A live thread that + cannot be suspended is a real hole in the window and stays FAILED. `exit_code` is + GetExitCodeThread (None when it could not be read), `signaled` whether the thread handle is + already signaled, `error` the GetLastError of an OpenThread that returned no handle.""" + if error == ERROR_INVALID_PARAMETER: + return GONE + if signaled or (exit_code is not None and exit_code != STILL_ACTIVE): + return GONE + return FAILED + + +class ReturnBook: + """Pending hooked calls, keyed by return address; each is traced once, when its call returns. + + A call is identified by its thread and the stack slot of its return address. The entry hook can + trap twice for one call when protection is off: another thread re-patches the byte before this + one has run the original instruction, so the thread traps again at the same address and slot. + That is the same call, so it replaces the first registration; two entries made the return write + two lines and a run counted 88 opens for 64 made.""" + + def __init__(self): + self._pending = {} # return address -> list of (tid, stack slot, description) + + def add(self, address, tid, slot, description): + kept = [item for item in self._pending.get(address, []) if (item[0], item[1]) != (tid, slot)] + kept.append((tid, slot, description)) + self._pending[address] = kept ~~~~ --- Fixed in 86d81f9e: ReturnBook.add() now tracks the hooked entry address alongside (tid, slot) so tail-called hooked functions keep both pending return records while re-traps of the same entry still deduplicate; added unit test coverage in tests/startup_hook_check.py.
tedin7 commented 2026-11-24 12:03:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:17:46Z.

Code review location: docs/startup-runtime.md; line 178

@@ -161,6 +161,32 @@ and no game files are needed, and the `pr` preset builds the probe and runs the
 ctest --preset release --no-tests=error -R '^startup_launch$' -V
 ```
 
+## Concurrent calls through a hooked function
+
+The debugger's file, socket and allocation hooks are one patched byte per function. To run the original
+instruction it restores the byte, single-steps the thread that hit it and patches the byte again. A second thread that
+entered the function inside that window ran untraced, so `files.txt` could miss opens and the
+offline mode could miss a refused socket. Now every other thread is held for the step and resumes when the stepping
+thread is done (`tools/startup/hook_window.py`). A thread that had already trapped when it was held goes back to the
+hook address and traps again afterwards, so its call is traced once, not twice. Each window has a 2 s deadline, so a
+thread is never held forever. Per-thread state of a call in flight (the return address and stack pointer it will come back to) is
+keyed by thread id, not shared.
+
+Every run ends with `hook windows: entries=N windows=W unprotected=U deferred=D timeouts=T protection=on|off` in the
+console output, `finished.txt` and `files.txt`, also when everything is 0. `unprotected` counts the windows in which another thread could
+not be held (a thread that has already exited is not counted: it runs no code), or the deadline passed, or protection was off with other threads alive: an upper bound on the calls a run may have
+missed. `--suspend-others 0` turns the holding off, to measure what it costs or to see the loss.

Fixed in 86d81f9e: docs/startup-runtime.md now describes unprotected (U) strictly as the count of exposed step windows, noting that one exposed window can miss multiple calls.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679202349 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#discussion_r4679202349). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:17:46Z. **Code review location:** `docs/startup-runtime.md`; line 178 ~~~~diff @@ -161,6 +161,32 @@ and no game files are needed, and the `pr` preset builds the probe and runs the ctest --preset release --no-tests=error -R '^startup_launch$' -V ``` +## Concurrent calls through a hooked function + +The debugger's file, socket and allocation hooks are one patched byte per function. To run the original +instruction it restores the byte, single-steps the thread that hit it and patches the byte again. A second thread that +entered the function inside that window ran untraced, so `files.txt` could miss opens and the +offline mode could miss a refused socket. Now every other thread is held for the step and resumes when the stepping +thread is done (`tools/startup/hook_window.py`). A thread that had already trapped when it was held goes back to the +hook address and traps again afterwards, so its call is traced once, not twice. Each window has a 2 s deadline, so a +thread is never held forever. Per-thread state of a call in flight (the return address and stack pointer it will come back to) is +keyed by thread id, not shared. + +Every run ends with `hook windows: entries=N windows=W unprotected=U deferred=D timeouts=T protection=on|off` in the +console output, `finished.txt` and `files.txt`, also when everything is 0. `unprotected` counts the windows in which another thread could +not be held (a thread that has already exited is not counted: it runs no code), or the deadline passed, or protection was off with other threads alive: an upper bound on the calls a run may have +missed. `--suspend-others 0` turns the holding off, to measure what it costs or to see the loss. ~~~~ --- Fixed in 86d81f9e: docs/startup-runtime.md now describes unprotected (U) strictly as the count of exposed step windows, noting that one exposed window can miss multiple calls.
SimSalabimse commented 2026-11-24 14:03:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-24T13:57:43Z.


Retested at ecbbf3e2 on Windows 11 26200, MSVC 19.42, RTX 4070 Ti (driver 621.35): startup_launch, startup_hook_window and startup_hook_overlap pass in both presets (ctest exit 0 for dev and release).

startup_hook_overlap traced 64/64 opens with the window on both presets; the unprotected control lost 21 opens on dev and 30 on release. So the NtSuspendThread path holds on Win11 as well.

AI-Assisted

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7133605628 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7133605628). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-24T13:57:43Z. --- Retested at ecbbf3e2 on Windows 11 26200, MSVC 19.42, RTX 4070 Ti (driver 621.35): startup_launch, startup_hook_window and startup_hook_overlap pass in both presets (ctest exit 0 for dev and release). startup_hook_overlap traced 64/64 opens with the window on both presets; the unprotected control lost 21 opens on dev and 30 on release. So the NtSuspendThread path holds on Win11 as well. AI-Assisted
SuperCraft3M commented 2026-11-24 15:02:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SuperCraft3M on 2026-11-24T14:07:29Z.


Independent integration check on Windows 11 build 26300.9711, Python 3.13 / MSVC 19.44 Debug: combined main 8f438025, #1251 at ad94c950, and #1408 at ecbbf3e2 (plus the independent UTF-8 storage change #1551).

The merge needs one semantic resolution in debug_launch.py: store (description, restore) as the ReturnBook payload, then invoke the restore callback when taking the matching return. Keeping only the description loses the mapped caller-name restoration. No change to ReturnBook's bookkeeping API is needed.

The combined source-built map overlap control reports 64 opens / 64 traces / 64 rewrites, two pooled name allocations, and both caller names intact. Its former WILL_FAIL registration can therefore become a normal pass when both PRs are present.

ctest --test-dir C:/Xbox2Windows-build --no-tests=error -R '^startup_(map_drive|map_drive_overlap|hook_window|hook_overlap)$' --output-on-failure: 4/4 passed, no skips. Integration and gate changes are on SuperCraft3M/Xbox2Windows branch runtime/startup-null-diagnosis, commit 30988289. This is an integration check of the existing PRs, not a replacement implementation. No binary inputs or raw runtime traces attached.

AI-assisted (Codex).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7133877247 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7133877247). Originally posted by [SuperCraft3M](https://github.com/SuperCraft3M) on 2026-11-24T14:07:29Z. --- Independent integration check on Windows 11 build 26300.9711, Python 3.13 / MSVC 19.44 Debug: combined main 8f438025, #1251 at ad94c950, and #1408 at ecbbf3e2 (plus the independent UTF-8 storage change #1551). The merge needs one semantic resolution in `debug_launch.py`: store `(description, restore)` as the ReturnBook payload, then invoke the restore callback when taking the matching return. Keeping only the description loses the mapped caller-name restoration. No change to ReturnBook's bookkeeping API is needed. The combined source-built map overlap control reports **64 opens / 64 traces / 64 rewrites**, two pooled name allocations, and both caller names intact. Its former WILL_FAIL registration can therefore become a normal pass when both PRs are present. `ctest --test-dir C:/Xbox2Windows-build --no-tests=error -R '^startup_(map_drive|map_drive_overlap|hook_window|hook_overlap)$' --output-on-failure`: 4/4 passed, no skips. Integration and gate changes are on SuperCraft3M/Xbox2Windows branch `runtime/startup-null-diagnosis`, commit 30988289. This is an integration check of the existing PRs, not a replacement implementation. No binary inputs or raw runtime traces attached. AI-assisted (Codex).
tedin7 commented 2026-11-24 15:02:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T14:11:00Z.


Thanks @SuperCraft3M for the independent integration check with #1251 (and noting the (description, restore) ReturnBook payload resolution for debug_launch.py when both PRs are combined).

Rebased #1408 onto origin/main at 19d57310 (resolving the docs/experiments.md conflict) and re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207):

  • Debug (--preset dev): ctest --preset dev -R '^(startup_launch|startup_hook_window|startup_hook_overlap)$' --parallel 4 --no-tests=error --output-on-failure — 3/3 passed (startup_hook_window 0.07s, startup_hook_overlap 0.80s, startup_launch 2.01s)
  • Release /O2 (--preset release): ctest --preset release -R '^(startup_launch|startup_hook_window|startup_hook_overlap)$' --parallel 4 --no-tests=error --output-on-failure — 3/3 passed (startup_hook_window 0.07s, startup_hook_overlap 0.83s, startup_launch 1.98s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7133968536 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7133968536). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T14:11:00Z. --- Thanks @SuperCraft3M for the independent integration check with `#1251` (and noting the `(description, restore)` `ReturnBook` payload resolution for `debug_launch.py` when both PRs are combined). Rebased `#1408` onto `origin/main` at `19d57310` (resolving the `docs/experiments.md` conflict) and re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207): - **Debug (`--preset dev`)**: `ctest --preset dev -R '^(startup_launch|startup_hook_window|startup_hook_overlap)$' --parallel 4 --no-tests=error --output-on-failure` — **3/3 passed** (`startup_hook_window` 0.07s, `startup_hook_overlap` 0.80s, `startup_launch` 2.01s) - **Release `/O2` (`--preset release`)**: `ctest --preset release -R '^(startup_launch|startup_hook_window|startup_hook_overlap)$' --parallel 4 --no-tests=error --output-on-failure` — **3/3 passed** (`startup_hook_window` 0.07s, `startup_hook_overlap` 0.83s, `startup_launch` 1.98s)
tedin7 commented 2026-11-24 21:01:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:01:06Z.


Updated the branch for the conflict with main.

  • New base: origin/main at e263314d (merged, no force push)
  • New head: c100ac3737
  • Conflict resolved: docs/startup-runtime.md. Main's "Trap-by-default header check" and this PR's "Concurrent calls through a hooked function" sections are both kept.
  • Run locally: git diff --check origin/main...HEAD, tests/startup_hook_check.py (startup_hook_window PASS), tests/docs_links_check.py (378 links), tests/bidi_controls_check.py, py_compile of the touched tools: all passed.
  • Windows Server 2025 (x2w_pipe.py win2025 1408) at c100ac37: Debug 6/6 and Release 6/6 passed.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7144364545 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7144364545). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T21:01:06Z. --- Updated the branch for the conflict with main. - New base: origin/main at e263314d (merged, no force push) - New head: c100ac37374a43e7191c793e7ccd9776bd88b034 - Conflict resolved: docs/startup-runtime.md. Main's "Trap-by-default header check" and this PR's "Concurrent calls through a hooked function" sections are both kept. - Run locally: `git diff --check origin/main...HEAD`, `tests/startup_hook_check.py` (startup_hook_window PASS), `tests/docs_links_check.py` (378 links), `tests/bidi_controls_check.py`, py_compile of the touched tools: all passed. - Windows Server 2025 (`x2w_pipe.py win2025 1408`) at c100ac37: Debug 6/6 and Release 6/6 passed. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 02:02:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:02:56Z.


Updated the branch for the new conflict with main (merge, no force push).

  • New base: origin/main at 84ce2942. New head: 36bb4ada.
  • Conflicts: CMakeLists.txt (kept both the hook tests and startup_launch_cli_check) and docs/experiments.md (kept both sections).
  • The two earlier review threads (tail-called hook returns, wording of the unprotected count) were already fixed in 22294074 and answered; nothing new to change.
  • Run locally: tests/startup_hook_check.py (startup_hook_window PASS), tests/docs_links_check.py (397 links), tests/bidi_controls_check.py, py_compile of tools/startup, git diff --check origin/main...HEAD: all passed.
  • Windows Server 2025 (x2w_pipe.py win2025 1408): Debug 7/7 and Release 7/7 passed on the previous head c100ac37; the merge only touches test registration and docs, so a re-run on 36bb4ada is left to CI.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7149152337 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7149152337). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T01:02:56Z. --- Updated the branch for the new conflict with main (merge, no force push). - New base: origin/main at 84ce2942. New head: 36bb4ada. - Conflicts: `CMakeLists.txt` (kept both the hook tests and `startup_launch_cli_check`) and `docs/experiments.md` (kept both sections). - The two earlier review threads (tail-called hook returns, wording of the unprotected count) were already fixed in 22294074 and answered; nothing new to change. - Run locally: `tests/startup_hook_check.py` (startup_hook_window PASS), `tests/docs_links_check.py` (397 links), `tests/bidi_controls_check.py`, py_compile of `tools/startup`, `git diff --check origin/main...HEAD`: all passed. - Windows Server 2025 (`x2w_pipe.py win2025 1408`): Debug 7/7 and Release 7/7 passed on the previous head c100ac37; the merge only touches test registration and docs, so a re-run on 36bb4ada is left to CI. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 14:04:13 +00:00
tedin7 commented 2026-11-25 14:05:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:51:16Z.


Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is.

We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7164386509 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7164386509). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T13:51:16Z. --- Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is. We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here. AI-assisted; commands listed were executed locally.
upstream-sync reopened this pull request 2026-11-26 11:02:38 +00:00
tedin7 commented 2026-11-26 11:03:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T10:44:19Z.


Win2025 receipt for head 88e0aa815 (origin/main merged in, no force push):

  • startup_launch|startup_hook_window|startup_hook_overlap|startup_debug on Windows Server 2025 build 26100: dev 7/7 and release 7/7 passed (startup_launch, startup_launch_cli_check, startup_hook_window, startup_hook_overlap, startup_debug, startup_debug_log, startup_debug_hooks).
  • startup_hook_overlap: 64 of 64 opens traced, three times, unprotected=0; the control with --suspend-others 0 lost opens.
  • Two defects from the merge with main were fixed in this head: ReturnBook had no get() for the hit-limit release (pending() added, with a test), and a duplicate file_log assignment broke startup_debug_log.
  • The two-thread --map-drive case depends on #1251, which is not in main, so it is not part of this run.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7189768020 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7189768020). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T10:44:19Z. --- Win2025 receipt for head 88e0aa815 (origin/main merged in, no force push): - `startup_launch|startup_hook_window|startup_hook_overlap|startup_debug` on Windows Server 2025 build 26100: dev 7/7 and release 7/7 passed (startup_launch, startup_launch_cli_check, startup_hook_window, startup_hook_overlap, startup_debug, startup_debug_log, startup_debug_hooks). - `startup_hook_overlap`: 64 of 64 opens traced, three times, unprotected=0; the control with --suspend-others 0 lost opens. - Two defects from the merge with main were fixed in this head: ReturnBook had no get() for the hit-limit release (pending() added, with a test), and a duplicate file_log assignment broke startup_debug_log. - The two-thread --map-drive case depends on #1251, which is not in main, so it is not part of this run. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 11:03:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T10:46:43Z.


You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7189823025 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7189823025). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T10:46:43Z. --- You have reached your Codex usage limits for code reviews. You can see your limits in the [Codex usage dashboard](https://chatgpt.com/codex/cloud/settings/usage). To continue using code reviews, add credits to your account and enable them for code reviews in your [settings](https://chatgpt.com/settings/code-review).
tedin7 commented 2026-11-26 11:03:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T10:51:44Z.


Head moved to 08f0f4e9f: ReturnBook gets an optional per-call restore callback (run once when the call returns; a re-trap of the same call keeps the first restore), so #1251 can restore a rewritten name through the same return book. Covered in startup_hook_check.

Win2025 (build 26100) on 08f0f4e9f: startup_launch|startup_hook_window|startup_hook_overlap|startup_debug dev 7/7 and release 7/7 passed (hook_overlap 64 of 64 with the window, control loses opens).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7189935774 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7189935774). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T10:51:44Z. --- Head moved to 08f0f4e9f: ReturnBook gets an optional per-call restore callback (run once when the call returns; a re-trap of the same call keeps the first restore), so #1251 can restore a rewritten name through the same return book. Covered in startup_hook_check. Win2025 (build 26100) on 08f0f4e9f: startup_launch|startup_hook_window|startup_hook_overlap|startup_debug dev 7/7 and release 7/7 passed (hook_overlap 64 of 64 with the window, control loses opens). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 11:03:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T10:46:31Z.


Independent Stage-2 gate of head 08f0f4e9f: PASS (supersedes my receipt for 88e0aa815).

Checked:

  • tools/startup/hook_window.py / debug_launch.py: the owner steps alone while every other live thread is held (NtSuspendThread plus a GetThreadContext to wait until it has stopped); a thread that trapped before it was held goes back to the hook address and is traced after the window; a thread created in the window is held; a thread that is already exiting counts as gone; every window has a 2 s deadline and the counters are always reported.
  • Three further single mutations of hook_window.py (defer for any thread, _expose not counted, any thread closes the window) are killed by tests/startup_hook_check.py, on top of the author's five.
  • startup_hook_overlap asserts the real-thread result itself: 4 threads x 16 rounds through one hooked CreateFileW (the probe from this PR), every one of the 64 opens traced with its result and unprotected=0 / timeouts=0 / protection=on in three runs; the control --suspend-others 0 must lose opens and report unprotected above 0, else the test fails.

Verification (Win2025, proxmox only):

  • python3 -B tests/startup_hook_check.py, tests/docs_links_check.py, py_compile of the Python files: pass on Linux.
  • x2w_pipe.py win2025 1408 --host proxmox --force --keep-release --regex '^(startup_launch|startup_hook_window|startup_hook_overlap|startup_debug)': dev 7/7 and release 7/7 passed (startup_hook_overlap 0.8 s dev, 0.9 s release).

Not covered, as the PR says: the two-thread --map-drive case needs #1251.

Update, head 08f0f4e9f (ReturnBook restore callback): the callback runs once, when its call returns, and only for that call; a re-trap of the same call keeps the first restore (the caller's original state). Three single mutations (restore order swapped, callback never run, callbacks of other calls run too) are killed by tests/startup_hook_check.py. x2w_pipe.py win2025 1408 --host proxmox --force --keep-release --regex '^(startup_launch|startup_hook_window|startup_hook_overlap|startup_debug)': dev 7/7 and release 7/7 passed.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7189818786 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7189818786). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T10:46:31Z. --- Independent Stage-2 gate of head 08f0f4e9f: PASS (supersedes my receipt for 88e0aa815). Checked: - `tools/startup/hook_window.py` / `debug_launch.py`: the owner steps alone while every other live thread is held (NtSuspendThread plus a GetThreadContext to wait until it has stopped); a thread that trapped before it was held goes back to the hook address and is traced after the window; a thread created in the window is held; a thread that is already exiting counts as gone; every window has a 2 s deadline and the counters are always reported. - Three further single mutations of `hook_window.py` (defer for any thread, `_expose` not counted, any thread closes the window) are killed by `tests/startup_hook_check.py`, on top of the author's five. - `startup_hook_overlap` asserts the real-thread result itself: 4 threads x 16 rounds through one hooked `CreateFileW` (the probe from this PR), every one of the 64 opens traced with its result and `unprotected=0` / `timeouts=0` / `protection=on` in three runs; the control `--suspend-others 0` must lose opens and report `unprotected` above 0, else the test fails. Verification (Win2025, proxmox only): - `python3 -B tests/startup_hook_check.py`, `tests/docs_links_check.py`, `py_compile` of the Python files: pass on Linux. - `x2w_pipe.py win2025 1408 --host proxmox --force --keep-release --regex '^(startup_launch|startup_hook_window|startup_hook_overlap|startup_debug)'`: dev 7/7 and release 7/7 passed (`startup_hook_overlap` 0.8 s dev, 0.9 s release). Not covered, as the PR says: the two-thread `--map-drive` case needs #1251. Update, head 08f0f4e9f (`ReturnBook` restore callback): the callback runs once, when its call returns, and only for that call; a re-trap of the same call keeps the first restore (the caller's original state). Three single mutations (restore order swapped, callback never run, callbacks of other calls run too) are killed by `tests/startup_hook_check.py`. `x2w_pipe.py win2025 1408 --host proxmox --force --keep-release --regex '^(startup_launch|startup_hook_window|startup_hook_overlap|startup_debug)'`: dev 7/7 and release 7/7 passed. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 12:04:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T11:09:42Z.


@MasterDomino these are tested and Ready. Could you merge them in this order when you have a moment?

  1. #1408 (hold other threads while a launcher hook steps over its byte)
  2. #1251 (map a package drive letter to a folder): builds on #1408. The change request on it is addressed: per-call buffers, and the overlap test now fails on a shared-buffer copy. Win2025 dev 9/9 + release 9/9.
  3. #1939 (decode the C++ exception record)
  4. #2782
  5. #2794
  6. #2766

Each PR has its Win2025 dev + release receipt in its comments. Thanks!

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7190354444 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7190354444). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T11:09:42Z. --- @MasterDomino these are tested and Ready. Could you merge them in this order when you have a moment? 1. #1408 (hold other threads while a launcher hook steps over its byte) 2. #1251 (map a package drive letter to a folder): builds on #1408. The change request on it is addressed: per-call buffers, and the overlap test now fails on a shared-buffer copy. Win2025 dev 9/9 + release 9/9. 3. #1939 (decode the C++ exception record) 4. #2782 5. #2794 6. #2766 Each PR has its Win2025 dev + release receipt in its comments. Thanks!
pigalot commented 2026-11-27 17:58:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T17:58:40Z.

Review: CHANGES_REQUESTED


Independently reviewed 08f0f4e9 integrated over main 5ebdc581 (tree ad6137f4, clean merge).

I traced the step window through the breakpoint handler in debug_launch.py and through hook_window.py. StepWindow.open() holds every other thread. Only finish() releases them early, from the owner's single-step or its EXIT_THREAD; otherwise they stay held until the 2 s deadline. One path opens a window with no step behind it; see the finding below.

Built startup_launch_probe, startup_debug_probe and startup_debug_calls in dev and release, then ran
ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(startup_launch|startup_launch_cli_check|startup_hook_window|startup_hook_overlap|startup_debug|startup_debug_log|startup_debug_hooks)$':
7/7 passed in Debug and in Release /O2, no skips.

ctest ... --repeat until-fail:20 -R '^startup_hook_overlap$', started from PowerShell, passed 20 of 20 in each preset.

On main 5ebdc581, startup_hook_window and startup_hook_overlap are not registered. A mutant whose hold_thread reports HELD without calling NtSuspendThread fails startup_hook_overlap with 16 of 64 opens traced. git diff --check is clean.

Finding: a LOG_AT breakpoint retired at its hit limit leaves its step window open until the deadline.

In the breakpoint handler, window.open(tid, ...) runs before the hit-limit branch. That branch:

  • restores the original byte for good;
  • calls set_ctx;
  • returns without setting TF.

So no single-step event follows, and finish(tid) is never called for that window. The other threads stay held until the 2 s deadline. Then expire() counts the window as both a timeout and unprotected, although nothing could be missed: the byte is no longer patched.

To reproduce, use the source-built startup_debug_probe. It calls its log site 19 times, then waits 3 s.

python -B tools/startup/debug_launch.py <probe> <work> <logdir> --timeout 30 --console 0 --continue-asserts 10 --offline 0

Set X2W_LOG_AT=<site>:rdx with a hit limit, taking <site> from the probe's debug-probe log site line:

  • @2 (retire path): hook windows: entries=0 windows=2 unprotected=1 deferred=0 timeouts=1 protection=on. The run took 5.1 s.
  • @100 (control, no retire): windows=19 unprotected=0 timeouts=0. The run took 3.1 s.

Two runs each gave the same result.

Suggested direction (tried locally, not pushed): move window.open(...) below the retire branch, directly before TF is set. With that change, @2 reports windows=1 unprotected=0 timeouts=0 in 3.1 s, and the 7 tests above still pass in Debug.

The existing log-at case in tests/startup_debug_check.py already takes the retire path (@2 of 19 calls) but doesn't read the counters. An assert on timeouts=0 unprotected=0 there would catch this.

Environment: Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10. No GPU is involved in these tests.
CI: Build and test on Windows passes on 08f0f4e9.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6091816059 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#pullrequestreview-6091816059). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-27T17:58:40Z. **Review:** CHANGES_REQUESTED --- Independently reviewed `08f0f4e9` integrated over `main` `5ebdc581` (tree `ad6137f4`, clean merge). I traced the step window through the breakpoint handler in `debug_launch.py` and through `hook_window.py`. `StepWindow.open()` holds every other thread. Only `finish()` releases them early, from the owner's single-step or its EXIT_THREAD; otherwise they stay held until the 2 s deadline. One path opens a window with no step behind it; see the finding below. Built `startup_launch_probe`, `startup_debug_probe` and `startup_debug_calls` in `dev` and `release`, then ran `ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^(startup_launch|startup_launch_cli_check|startup_hook_window|startup_hook_overlap|startup_debug|startup_debug_log|startup_debug_hooks)$'`: 7/7 passed in Debug and in Release `/O2`, no skips. `ctest ... --repeat until-fail:20 -R '^startup_hook_overlap$'`, started from PowerShell, passed 20 of 20 in each preset. On `main` `5ebdc581`, `startup_hook_window` and `startup_hook_overlap` are not registered. A mutant whose `hold_thread` reports HELD without calling `NtSuspendThread` fails `startup_hook_overlap` with `16 of 64 opens traced`. `git diff --check` is clean. **Finding: a LOG_AT breakpoint retired at its hit limit leaves its step window open until the deadline.** In the breakpoint handler, `window.open(tid, ...)` runs before the hit-limit branch. That branch: - restores the original byte for good; - calls `set_ctx`; - returns without setting TF. So no single-step event follows, and `finish(tid)` is never called for that window. The other threads stay held until the 2 s deadline. Then `expire()` counts the window as both a timeout and unprotected, although nothing could be missed: the byte is no longer patched. To reproduce, use the source-built `startup_debug_probe`. It calls its log site 19 times, then waits 3 s. ``` python -B tools/startup/debug_launch.py <probe> <work> <logdir> --timeout 30 --console 0 --continue-asserts 10 --offline 0 ``` Set `X2W_LOG_AT=<site>:rdx` with a hit limit, taking `<site>` from the probe's `debug-probe log site` line: - `@2` (retire path): `hook windows: entries=0 windows=2 unprotected=1 deferred=0 timeouts=1 protection=on`. The run took 5.1 s. - `@100` (control, no retire): `windows=19 unprotected=0 timeouts=0`. The run took 3.1 s. Two runs each gave the same result. Suggested direction (tried locally, not pushed): move `window.open(...)` below the retire branch, directly before TF is set. With that change, `@2` reports `windows=1 unprotected=0 timeouts=0` in 3.1 s, and the 7 tests above still pass in Debug. The existing `log-at` case in `tests/startup_debug_check.py` already takes the retire path (`@2` of 19 calls) but doesn't read the counters. An assert on `timeouts=0 unprotected=0` there would catch this. Environment: Windows 11 25H2 build 26200.9974, MSVC 19.52.37029, Python 3.12.10. No GPU is involved in these tests. CI: `Build and test on Windows` passes on `08f0f4e9`. This reply was AI-assisted.
tedin7 commented 2026-11-27 21:28:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T21:28:12Z.


Thanks for the trace. Pushed ac0f5e216, which merges current main and fixes the finding: window.open(...) now runs after the hit-limit retire branch, directly before TF is set, so a retired LOG_AT breakpoint no longer leaves a window open until the deadline. The log-at case in tests/startup_debug_check.py now also asserts unprotected=0 and timeouts=0.

Not yet run on Windows: startup_debug with the new assertion.

Commands run locally: python3 -m py_compile tools/startup/debug_launch.py tests/startup_debug_check.py, cmake -S . -B <tmp> -DDXC_EXECUTABLE=/bin/true, public_guard.py.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7228471962 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7228471962). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T21:28:12Z. --- Thanks for the trace. Pushed `ac0f5e216`, which merges current `main` and fixes the finding: `window.open(...)` now runs after the hit-limit retire branch, directly before TF is set, so a retired LOG_AT breakpoint no longer leaves a window open until the deadline. The `log-at` case in `tests/startup_debug_check.py` now also asserts `unprotected=0` and `timeouts=0`. Not yet run on Windows: `startup_debug` with the new assertion. Commands run locally: `python3 -m py_compile tools/startup/debug_launch.py tests/startup_debug_check.py`, `cmake -S . -B <tmp> -DDXC_EXECUTABLE=/bin/true`, `public_guard.py`. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-27 21:47:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T21:47:23Z.


Verification: head ac0f5e216 after the main merge and the latest fixes.

Environment: Windows Server 2025 (build 26100), MSVC 14.44, D3D12 WARP and the hardware adapter, dev and release legs in parallel.

Commands (the same selection in both legs):

x2w_pipe.py win2025 1408 --force --regex '^(startup_debug.*|startup_hook_window|startup_hook_overlap)$'
  dev:     cmake --build --preset dev --target auto
           ctest --preset dev -R '^(startup_debug.*|startup_hook_window|startup_hook_overlap)$' --no-tests=error --output-on-failure
  release: cmake --build --preset release --target auto
           ctest --preset release -R '^(startup_debug.*|startup_hook_window|startup_hook_overlap)$' --no-tests=error --output-on-failure

Result: 6/7 passed, 1 skipped by capability (startup_debug_window), no failures, in both legs.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7228755842 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7228755842). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T21:47:23Z. --- Verification: head `ac0f5e216` after the main merge and the latest fixes. Environment: Windows Server 2025 (build 26100), MSVC 14.44, D3D12 WARP and the hardware adapter, dev and release legs in parallel. Commands (the same selection in both legs): ``` x2w_pipe.py win2025 1408 --force --regex '^(startup_debug.*|startup_hook_window|startup_hook_overlap)$' dev: cmake --build --preset dev --target auto ctest --preset dev -R '^(startup_debug.*|startup_hook_window|startup_hook_overlap)$' --no-tests=error --output-on-failure release: cmake --build --preset release --target auto ctest --preset release -R '^(startup_debug.*|startup_hook_window|startup_hook_overlap)$' --no-tests=error --output-on-failure ``` Result: 6/7 passed, 1 skipped by capability (`startup_debug_window`), no failures, in both legs. AI-assisted; commands listed were executed locally.
pigalot commented 2026-11-27 21:58:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-27T21:58:55Z.

Review: APPROVED


Re-reviewed ac0f5e21 merged over current main 28e4a025. The merge is clean and git diff --cached --check is clean.

The finding from my review of 08f0f4e9 is fixed. window.open(...) now sits after the hit-limit retire branch, directly before TF is set. A LOG_AT breakpoint that retires at its limit therefore returns without opening a window. The log-at case in tests/startup_debug_check.py now asserts unprotected=0 and timeouts=0 on the hook windows: line.

What I ran. I built startup_launch_probe startup_debug_probe startup_debug_calls in dev and release, then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_launch|startup_launch_cli_check|startup_hook_window|startup_hook_overlap|startup_debug.*)$'

9/9 pass in both presets, with no skips. The set is startup_debug, _log, _hooks, _window, startup_debug_launch_args, startup_launch, startup_launch_cli_check, startup_hook_window and startup_hook_overlap. startup_debug_window passes on this host; tedin7's Server 2025 run reports it as a capability skip.

Negative control. I moved window.open(...) back above the retire branch, which is the 08f0f4e9 order. startup_debug_log, the group that holds the log-at case, then fails on the new assertion with

process exited with 0x00000000 after 5.01 s
  hook windows: entries=0 windows=2 unprotected=1 deferred=0 timeouts=1 protection=on

Those are the same counters and the same 5 s run time I reported before. With the PR's order the line reads unprotected=0 ... timeouts=0, and the run takes about 3 s. I restored the file afterwards, and git diff --quiet is clean.

Note for anyone re-running this: the case is in startup_debug_log. The anchored -R '^startup_debug$' runs only the core group, which doesn't reach it.

Verdict: approve on ac0f5e21.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10. No GPU is involved in these tests.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on ac0f5e21.

This reply was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6093739664 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1408#pullrequestreview-6093739664). Originally posted by [pigalot](https://github.com/pigalot) on 2026-11-27T21:58:55Z. **Review:** APPROVED --- Re-reviewed `ac0f5e21` merged over current `main` `28e4a025`. The merge is clean and `git diff --cached --check` is clean. **The finding from my review of `08f0f4e9` is fixed.** `window.open(...)` now sits after the hit-limit retire branch, directly before TF is set. A LOG_AT breakpoint that retires at its limit therefore returns without opening a window. The `log-at` case in `tests/startup_debug_check.py` now asserts `unprotected=0` and `timeouts=0` on the `hook windows:` line. **What I ran.** I built `startup_launch_probe startup_debug_probe startup_debug_calls` in `dev` and `release`, then ran ```powershell ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^(startup_launch|startup_launch_cli_check|startup_hook_window|startup_hook_overlap|startup_debug.*)$' ``` 9/9 pass in both presets, with no skips. The set is `startup_debug`, `_log`, `_hooks`, `_window`, `startup_debug_launch_args`, `startup_launch`, `startup_launch_cli_check`, `startup_hook_window` and `startup_hook_overlap`. `startup_debug_window` passes on this host; tedin7's Server 2025 run reports it as a capability skip. **Negative control.** I moved `window.open(...)` back above the retire branch, which is the `08f0f4e9` order. `startup_debug_log`, the group that holds the `log-at` case, then fails on the new assertion with ``` process exited with 0x00000000 after 5.01 s hook windows: entries=0 windows=2 unprotected=1 deferred=0 timeouts=1 protection=on ``` Those are the same counters and the same 5 s run time I reported before. With the PR's order the line reads `unprotected=0 ... timeouts=0`, and the run takes about 3 s. I restored the file afterwards, and `git diff --quiet` is clean. Note for anyone re-running this: the case is in `startup_debug_log`. The anchored `-R '^startup_debug$'` runs only the core group, which doesn't reach it. **Verdict:** approve on `ac0f5e21`. Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; Python 3.12.10. No GPU is involved in these tests. CI: `Build and test on Windows`, `Assemble and translate gfx1013 fixtures` and `Run platform-independent Python checks on Linux` pass on `ac0f5e21`. This reply was AI-assisted.
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!1401
No description provided.