startup-tools: the launcher drops concurrent hits on a hooked function #1274

Closed
opened 2026-11-24 06:38:36 +00:00 by triggered02 · 3 comments
triggered02 commented 2026-11-24 06:38:36 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T06:38:36Z.


Problem

The startup launcher's function-entry hooks are one patched byte per function. When two threads enter
the same hooked function at the same time, one of them runs through the window where the original
byte is restored for a single-step, so that call is never traced. Any behaviour that depends on the
hook — file tracing, the offline socket deny, and the -MapDrive rewrite — silently misses those
calls.

Measured

Source-built consumer with two threads calling NtCreateFile 32 times each through a mapped letter
(so every call must be rewritten to succeed), run under tools/startup/debug_launch.py, Windows 11
build 26200:

case result
two threads, no mapping, real file through its own letter 64/64 opens succeed
two threads, --map-drive Z=<folder> 40/64 opens traced and rewritten; the rest keep the unmapped name and fail
repeat of the mapped case 46/64, and one caller's name was replaced while its call was still in flight

The first row matters: without any rewrite the same two-thread pattern is 64/64, so the loss is not in
the consumer, the file system, or general tracing — it is the entry hook dropping concurrent hits on
the same function. The second row is a direct count of NtCreateFile entry traces versus the 64 calls
the consumer made.

Why it matters beyond -MapDrive

  • Offline mode denies sockets by hooking the same way; a concurrent call that slips through is a socket
    the run was supposed to refuse.
  • files.txt under-reports opens during multi-threaded loading.

I have not measured how often the title enters the same hooked function concurrently, so the practical
rate for a startup run is unknown.

Possible directions

  • Use per-thread hardware breakpoints (debug registers) for the entry hooks instead of an int3 byte,
    so concurrent entries are each trapped.
  • Or keep the byte but, when a hit is being stepped over, keep other threads from entering: suspend
    them for the step or single-step the faulting thread with the byte still in place and emulate the
    original instruction.
  • At minimum, count and report dropped hits so a run can say how much it silently missed.

Done when

Two threads calling the same hooked function get the same treatment as one (the overlap control in
startup_map_drive_overlap becomes a normal pass), or the launcher reports that it dropped hits so
runs can be interpreted.

Context: docs/startup-runtime.md (#1135). Do not attach game files, dumps or logs that contain
addresses or names from an executable; describe results in terms of the component tested.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6576177809 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1281). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T06:38:36Z. --- ## Problem The startup launcher's function-entry hooks are one patched byte per function. When two threads enter the same hooked function at the same time, one of them runs through the window where the original byte is restored for a single-step, so that call is never traced. Any behaviour that depends on the hook — file tracing, the offline socket deny, and the `-MapDrive` rewrite — silently misses those calls. ## Measured Source-built consumer with two threads calling `NtCreateFile` 32 times each through a mapped letter (so every call must be rewritten to succeed), run under `tools/startup/debug_launch.py`, Windows 11 build 26200: | case | result | |---|---| | two threads, no mapping, real file through its own letter | **64/64 opens succeed** | | two threads, `--map-drive Z=<folder>` | **40/64** opens traced and rewritten; the rest keep the unmapped name and fail | | repeat of the mapped case | 46/64, and one caller's name was replaced while its call was still in flight | The first row matters: without any rewrite the same two-thread pattern is 64/64, so the loss is not in the consumer, the file system, or general tracing — it is the entry hook dropping concurrent hits on the same function. The second row is a direct count of `NtCreateFile` entry traces versus the 64 calls the consumer made. ## Why it matters beyond `-MapDrive` - Offline mode denies sockets by hooking the same way; a concurrent call that slips through is a socket the run was supposed to refuse. - `files.txt` under-reports opens during multi-threaded loading. I have not measured how often the title enters the same hooked function concurrently, so the practical rate for a startup run is unknown. ## Possible directions - Use per-thread hardware breakpoints (debug registers) for the entry hooks instead of an `int3` byte, so concurrent entries are each trapped. - Or keep the byte but, when a hit is being stepped over, keep other threads from entering: suspend them for the step or single-step the faulting thread with the byte still in place and emulate the original instruction. - At minimum, count and report dropped hits so a run can say how much it silently missed. ## Done when Two threads calling the same hooked function get the same treatment as one (the overlap control in `startup_map_drive_overlap` becomes a normal pass), or the launcher reports that it dropped hits so runs can be interpreted. Context: `docs/startup-runtime.md` (#1135). Do not attach game files, dumps or logs that contain addresses or names from an executable; describe results in terms of the component tested. AI-assisted (Claude Code).
tedin7 commented 2026-11-24 11:03:01 +00:00 (Migrated from github.com)
Author
Contributor

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


Working on this (AI-assisted). Plan: hold every other thread while one steps over a hook byte, defer a hit that trapped before the hold, give each window a deadline and always report how many windows were unprotected. Python parts are checked on Linux; the two-thread run needs Windows.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129093657 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1281#issuecomment-7129093657). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:40:27Z. --- Working on this (AI-assisted). Plan: hold every other thread while one steps over a hook byte, defer a hit that trapped before the hold, give each window a deadline and always report how many windows were unprotected. Python parts are checked on Linux; the two-thread run needs Windows.
SimSalabimse commented 2026-11-24 11:03:01 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-24T10:45:24Z.


@tedin7 Happy to run the two-thread test on Windows once there's a PR. I have Windows 11 (26200) with MSVC 19.42 and an RTX 4070 Ti. Ping me and I'll post the results.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129202896 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1281#issuecomment-7129202896). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-24T10:45:24Z. --- @tedin7 Happy to run the two-thread test on Windows once there's a PR. I have Windows 11 (26200) with MSVC 19.42 and an RTX 4070 Ti. Ping me and I'll post the results.
tedin7 commented 2026-11-24 11:03:03 +00:00 (Migrated from github.com)
Author
Contributor

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


@SimSalabimse #1408 is ready for review at 3cfa1726 — passes 3/3 Debug & Release on our Windows Server 2025 box (ctest --preset release -R '^(startup_launch|startup_hook_window|startup_hook_overlap)$' -V). Would appreciate a sanity-check on Windows 11 26200 / MSVC 19.42 whenever you have a moment!

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129573095 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1281#issuecomment-7129573095). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:02:20Z. --- @SimSalabimse #1408 is ready for review at `3cfa1726` — passes 3/3 Debug & Release on our Windows Server 2025 box (`ctest --preset release -R '^(startup_launch|startup_hook_window|startup_hook_overlap)$' -V`). Would appreciate a sanity-check on Windows 11 26200 / MSVC 19.42 whenever you have a moment!
Sign in to join this conversation.
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#1274
No description provided.