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

Manually merged
github merged 14 commits from github-bot/gh-1408 into gh-pr/1408/base 2026-11-27 22:03:29 +00:00 AGit
Owner

@⁠tedin7 on GitHub · 2026-11-24 10:48 UTC · original
tedin7:x2w-frontier-1281-hooks → main · +580 −12 · 8 files · 14 commits · merged 2026-11-27 21:59 UTC

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.

**@⁠tedin7** on GitHub · 2026-11-24 10:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408) `tedin7:x2w-frontier-1281-hooks` → `main` · +580 −12 · 8 files · 14 commits · merged 2026-11-27 21:59 UTC 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.
Two threads entering the same hooked function could run through the step-over window untraced. The debugger now holds every other thread for the step, defers a hit that trapped before the hold, bounds each window with a deadline and always reports how many windows were unprotected.
A thread that was not held no longer raises when it steps at another hook: the open window stays with its owner and is reported as exposed. Only a held thread is deferred.
With the step window off, another thread can re-patch the hook byte before the stepping thread runs the original instruction, so the thread traps again at the same address and stack slot. The call was registered twice and its return wrote two lines (88 traces for 64 opens). Pending returns are now keyed by thread and slot, and the control counts lost opens as max(0, 64 - traced). The overlap probe uses four threads with a spin barrier.
A thread that has called ExitThread stays in the debugger's thread list until its exit event is read. OpenThread still works on it but SuspendThread and GetThreadContext fail with access denied, and the window counted that as an unprotected window although the thread runs no code. A hold that fails is now classified after the failure: GONE when GetExitCodeThread is not STILL_ACTIVE (or the handle is already signaled), FAILED when the thread is alive. The decision is a pure function in hook_window.py checked by startup_hook_window.

Refs #1281
Thanks @RenzoWit35 for the Win11 26300 finding.
The hook window replaced the returns dict with ReturnBook; the hit-limit release still called returns.get(addr), which the class does not have.
The merge left a second file_log assignment that opened files.txt only when tracing, overriding the main definition that also opens it for X2W_LOG_AT. startup_debug_log then failed with a None log.
A hooked call may change its arguments for the call only (a mapped drive name). The book now keeps an optional restore per call and runs it once on the return, so the caller's state is back before anything else runs; a re-trap of the same call keeps the first restore.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:04:53 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 10:54 UTC · original

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** on GitHub · 2026-11-24 10:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7129407158) 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.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 10:57 UTC · original

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** on GitHub · 2026-11-24 10:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7129465775) 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).
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 11:02 UTC · original

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)
**@⁠tedin7** on GitHub · 2026-11-24 11:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7129568413) 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)
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 11:02 UTC · original · edited 2026-11-26 10:46 UTC

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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 11:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7129571111) · edited 2026-11-26 10:46 UTC <!-- 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>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 11:10 UTC · original

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 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 11:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#discussion_r4679118021) **<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 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 11:10 UTC · original

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 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 11:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#discussion_r4679118030) **<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 -->
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 11:17 UTC · original

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** on GitHub · 2026-11-24 11:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#discussion_r4679201933) 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.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 11:17 UTC · original

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.

**@⁠tedin7** on GitHub · 2026-11-24 11:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#discussion_r4679202349) 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.
Author
Owner

@⁠SimSalabimse on GitHub · 2026-11-24 11:21 UTC · original

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

**@⁠SimSalabimse** on GitHub · 2026-11-24 11:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7129986920) 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
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 11:33 UTC · original

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** on GitHub · 2026-11-24 11:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7130260824) 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).
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 11:35 UTC · original

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.

**@⁠tedin7** on GitHub · 2026-11-24 11:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7130296314) 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.
Author
Owner

@⁠RenzoWit35 on GitHub · 2026-11-24 11:38 UTC · original

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.

**@⁠RenzoWit35** on GitHub · 2026-11-24 11:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7130367428) 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.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 11:45 UTC · original

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.

**@⁠tedin7** on GitHub · 2026-11-24 11:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7130505852) 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.
Author
Owner

@⁠SimSalabimse on GitHub · 2026-11-24 13:57 UTC · original

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

**@⁠SimSalabimse** on GitHub · 2026-11-24 13:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7133605628) 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
Author
Owner

@⁠SuperCraft3M on GitHub · 2026-11-24 14:07 UTC · original

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).

**@⁠SuperCraft3M** on GitHub · 2026-11-24 14:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7133877247) 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).
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 14:11 UTC · original

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** on GitHub · 2026-11-24 14:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7133968536) 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)
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 21:01 UTC · original

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** on GitHub · 2026-11-24 21:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7144364545) 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.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 01:02 UTC · original

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.

**@⁠tedin7** on GitHub · 2026-11-25 01:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7149152337) 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.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 13:51 UTC · original

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.

**@⁠tedin7** on GitHub · 2026-11-25 13:51 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7164386509) 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.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 10:44 UTC · original

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.

**@⁠tedin7** on GitHub · 2026-11-26 10:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7189768020) 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.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 10:46 UTC · original · edited 2026-11-26 10:51 UTC

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** on GitHub · 2026-11-26 10:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7189818786) · edited 2026-11-26 10:51 UTC 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.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-26 10:46 UTC · original

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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-26 10:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7189823025) 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).
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 10:51 UTC · original

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** on GitHub · 2026-11-26 10:51 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7189935774) 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.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 11:09 UTC · original

@⁠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!

**@⁠tedin7** on GitHub · 2026-11-26 11:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7190354444) @⁠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!
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 11:10 UTC · original · reviewed

💡 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".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 11:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#pullrequestreview-6038147530) · **reviewed** <!-- 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>
Author
Owner

@⁠pigalot on GitHub · 2026-11-27 17:58 UTC · original · requested changes

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.

**@⁠pigalot** on GitHub · 2026-11-27 17:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#pullrequestreview-6091816059) · **requested changes** 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.
fix: open the hook step window only when a single-step follows
Author
Owner

@⁠tedin7 on GitHub · 2026-11-27 21:28 UTC · original

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** on GitHub · 2026-11-27 21:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7228471962) 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.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-27 21:47 UTC · original

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.

**@⁠tedin7** on GitHub · 2026-11-27 21:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#issuecomment-7228755842) 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.
github-bot changed target branch from main to gh-pr/1408/base 2026-11-27 22:03:28 +00:00
github manually merged commit ac0f5e2161 into gh-pr/1408/base 2026-11-27 22:03:29 +00:00
Author
Owner

@⁠pigalot on GitHub · 2026-11-27 21:58 UTC · original · approved these changes

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.

**@⁠pigalot** on GitHub · 2026-11-27 21:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1408#pullrequestreview-6093739664) · **approved these changes** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.