Skip to content

startup: map a console package drive letter to a real folder - #1251

Open
triggered02 wants to merge 20 commits into
R0Y00:mainfrom
triggered02:startup/map-drive
Open

triggered02 wants to merge 20 commits into
R0Y00:mainfrom
triggered02:startup/map-drive

Conversation

@triggered02

Copy link
Copy Markdown
Contributor

Implements the option proposed here.

A console executable opens its package at a fixed drive letter. --map-drive LETTER=FOLDER[;...] (or run.ps1 -MapDrive) rewrites the path of an open on a mapped letter to the real folder, in the caller's own path structure, inside the file hooks the launcher already installs for tracing. Nothing needs the letter to be free, and a real volume on that letter is not disturbed.

Two things the shape in the issue did not cover, which this had to handle:

  • The replacement is longer than the caller's buffer. A folder path is longer than a single letter, so an in-place write into the caller's UNICODE_STRING does not fit. When it does not, the launcher allocates the name in the target process and repoints the UNICODE_STRING at it, leaving that allocation to the process (the caller may keep the name while its handle is open).
  • Path form. Opens arrive as NT paths with a \??\ device prefix and optionally a [root ...] prefix; the rewrite keeps both. Separators are normalised, because the build directory arrives with forward slashes and NT paths reject those — that one cost me a debugging round.

Coverage — startup_map_drive, using a source-built consumer that opens <letter>:\map_drive_probe.txt:

case result
mapped letter (not a volume) with the option open succeeds, reads mapped ok, trace shows the MAP rewrite
same open without the option fails (open failed: 3)
open on a letter that is not mapped no MAP line; left alone
mapped letter Z: ok ('read 9 bytes: mapped ok')
negative control without the option: ok ('open failed: 3')
unmapped letter C: ok

Measured on Windows 11 build 26200 with the release preset; docs_links_check.py passes and the option is documented in docs/startup-runtime.md under the run instructions, including both limits.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T05:36:01.293558Z f618453 PR opened
ℹ️ 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.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dual-platform review of f6184535fdac13761aae61358f8f81cab23e2275 (startup: map a console package drive letter to a real folder).

Linux Checks

  • docs_links_check.py: PASS (16 Markdown files, 280 links)
  • bidi_controls_check.py: PASS (1055 tracked files, no bidirectional controls)
  • git diff --check origin/main...HEAD: PASS
  • AGENTS.md / title-neutrality audit: PASS (all 6 changed files are title-neutral)

Windows Server 2025 (MSVC 14.44 + sccache)

Command: run_pr_test.ps1 -Pr 1251 -Targets startup_map_drive_consumer,startup_stub_consumer -Regex startup_map_drive

  • dev (Debug): configure 1.51s, build 27.77s, ctest (startup_map_drive) 1/1 Passed in 0.44s
  • release (/O2): configure 1.52s, build 39.47s, ctest (startup_map_drive) 1/1 Passed in 0.36s

Code Audit & Edge Cases (tools/startup/debug_launch.py)

  1. [root ...] prefix mismatch in map_drive():
    • oa_name() formats root-relative paths without a space: f"[root {root:#x}]" + text (e.g. [root 0x123]\??\G:\foo).
    • map_drive() checks if body.startswith("[root ") and "] " in body: (looking for "] ", with a space), so when OBJECT_ATTRIBUTES.RootDirectory is non-zero, "] " is not matched, body[1] != ":" fails, and the path is never mapped.
    • Furthermore, even if "] " were present, replacement = root + prefix + ... prepends the synthetic [root 0x...] display tag into encoded before writing it back into the target process's UNICODE_STRING buffer, which would corrupt the kernel UNICODE_STRING if root were non-empty. root should only be kept in the log/display string, not written into UNICODE_STRING.
  2. Minor edge cases:
    • drive_map accepts letter.isalpha() (which includes non-ASCII Unicode letters in Python 3) rather than ASCII A–Z.
    • \\?\ (Win32 long-path prefix) is not in ("\\??\\", "\\\\.\\") (Win32 CreateFileW normalizes \\?\ to \??\ before NtCreateFile, so NT hooks see \??\, though direct callers passing \\?\ wouldn't match).
    • .. path traversal in body[2:] is preserved verbatim (expected for a launcher diagnostic rewrite).
    • struct.pack("<HH4xQ", len(encoded), len(encoded), fresh) assumes len(encoded) <= 65535 (USHORT limit of UNICODE_STRING).

triggered02 added a commit to triggered02/Xbox2Windows that referenced this pull request Nov 24, 2026
Review of R0Y00#1251 found that map_drive() looked for a "] " separator, but oa_name() formats a
root-relative name as "[root 0x...]" + text with no space. So a root-relative open was never
rewritten, and had the separator matched, the synthetic "[root 0x...]" display tag would have been
written into the caller's UNICODE_STRING and corrupted the kernel string.

The tag is now drained by finding "]" and dropped: it is only a label for the log, so it never takes
part in the rewrite.

Three smaller points from the same review:

- The "\\\\?\\" Win32 long-path prefix is matched alongside the "\\??\\" and "\\\\.\\" device
  prefixes.
- Mapping letters are ASCII A-Z. isalpha() alone also accepts non-ASCII letters, which no NT path
  has.
- A replacement longer than 0xFFFF bytes is refused, because a UNICODE_STRING length is a USHORT and
  the name could not be expressed at all.

The root-relative case is not covered by startup_map_drive yet: CreateFileW builds the object name
without a RootDirectory, so the fixture never produces the "[root ...]" form. A direct NtCreateFile
consumer would be needed to exercise it; the separator and the tag handling are the code that
changed.
@triggered02

Copy link
Copy Markdown
Contributor Author

Fixed in 78c8796d. The root-relative case was a real bug, and worse than a missed mapping: had the separator matched, the synthetic [root 0x...] tag would have gone into the kernel UNICODE_STRING. The tag is now drained by finding ] and dropped entirely, since it is only a log label and never part of the name.

Also taken from the review: \\\\\\\\?\\\\\\\\ is matched alongside \\\\\\\\??\\\\\\\\ and \\\\\\\\.\\\\\\\\; mapping letters are ASCII A-Z rather than anything isalpha() accepts; and a replacement over 0xFFFF bytes is refused, because a UNICODE_STRING length is a USHORT.

startup_map_drive still passes (mapped letter reads its content, negative control fails, unmapped letter untouched). The root-relative path is not covered by that fixture, because CreateFileW builds the object name without a RootDirectory — a direct NtCreateFile consumer would be needed to exercise it. Say if you want that added before merge.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the mapped name temporary to the hooked NT call. The current path overwrites the caller's original name even in the short case. In the long case, every fresh name does a VirtualAllocEx and no path releases it, including a failed write after allocation. The test's single open cannot detect either problem.

Use the existing entry/return tracing boundary so the caller's name is restored, and release or reuse the temporary backing after the call. Please add a source-built case that reuses one caller-owned UNICODE_STRING across multiple opens and checks its length, buffer pointer, and contents after each return. Repeated opens on the mapped letter should still succeed and the number of live name allocations should not grow with the number of opens. The current disabled and unmapped controls still apply.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dual-platform retest of 78c8796d104a46e6c030392b1b82e428ecf6fa33 (delta from f6184535: 78c8796d startup: fix the drive rewrite for root-relative opens).

Delta Since f6184535 (tools/startup/debug_launch.py)

  • Restricts drive_map keys to ASCII A–Z (letter.isascii()).
  • Drops the synthetic [root 0x...] log tag from body instead of prepending it into replacement.
  • Adds \\?\ alongside \??\ and \\.\ prefix matching.
  • Guards len(encoded) against 0 < len(encoded) <= 0xFFFF before writing UNICODE_STRING.Length.

Linux Checks

  • git diff --check origin/main...HEAD: PASS
  • docs_links_check.py: PASS (16 Markdown files, 280 links)
  • bidi_controls_check.py: PASS (1055 tracked files, no bidirectional controls)

Windows Server 2025 (Build 26100, MSVC 14.44)

Command: C:\OEM\run_pr_test.ps1 -Pr 1251 -Targets 'startup_map_drive_consumer,startup_stub_consumer' -Regex '^startup_map_drive$' -Jobs 6 -Parallel 4

  • dev (Debug): ctest (startup_map_drive) 1/1 Passed (0.39s)
  • release (/O2): ctest (startup_map_drive) 1/1 Passed (0.37s)

Status Note

  • The CHANGES_REQUESTED items from @R0Y00 (restoring the caller's UNICODE_STRING after the hooked NT call, releasing/reusing VirtualAllocEx backing, and adding a multi-open reuse test) remain open as of 78c8796d.

triggered02 added a commit to triggered02/Xbox2Windows that referenced this pull request Nov 24, 2026
Review of R0Y00#1251 found that map_drive() looked for a "] " separator, but oa_name() formats a
root-relative name as "[root 0x...]" + text with no space. So a root-relative open was never
rewritten, and had the separator matched, the synthetic "[root 0x...]" display tag would have been
written into the caller's UNICODE_STRING and corrupted the kernel string.

The tag is now drained by finding "]" and dropped: it is only a label for the log, so it never takes
part in the rewrite.

Three smaller points from the same review:

- The "\\\\?\\" Win32 long-path prefix is matched alongside the "\\??\\" and "\\\\.\\" device
  prefixes.
- Mapping letters are ASCII A-Z. isalpha() alone also accepts non-ASCII letters, which no NT path
  has.
- A replacement longer than 0xFFFF bytes is refused, because a UNICODE_STRING length is a USHORT and
  the name could not be expressed at all.

The root-relative case is not covered by startup_map_drive yet: CreateFileW builds the object name
without a RootDirectory, so the fixture never produces the "[root ...]" form. A direct NtCreateFile
consumer would be needed to exercise it; the separator and the tag handling are the code that
changed.
triggered02 added a commit to triggered02/Xbox2Windows that referenced this pull request Nov 24, 2026
Addresses the review of R0Y00#1251. The rewrite changed the caller's name permanently: in the short case
it overwrote the caller's own buffer, and in the long case it repointed the caller's UNICODE_STRING at
a fresh VirtualAllocEx that nothing released, including after a failed write. A caller that opens with
the same UNICODE_STRING twice, or that reads it after the call, saw the rewritten name.

The name is now temporary to the call. The entry trace records what the caller's UNICODE_STRING held,
and the existing return boundary restores it — length, buffer pointer and contents — before anything
else runs, so a failure or a retry sees the name it built. The offline deny path also runs before the
rewrite, so a refused call never borrows the name at all.

The long case writes into one backing allocation that is grown on demand and reused, so the number of
name allocations does not follow the number of opens, and a failed write after growth leaves the
caller's string untouched.

Covered by a new fixture mode: the source-built consumer builds one UNICODE_STRING whose buffer is
exactly the caller's size, calls NtCreateFile through the mapped letter 32 times, and checks its
length, buffer pointer and contents after every return, while the trace must show a single name
allocation.

Measured, Windows 11 build 26200, release preset:

  mapped letter Z: ok ('read 9 bytes: mapped ok')
  negative control without the option: ok ('open failed: 3')
  unmapped letter C: ok
  reused caller name over 32 opens: ok (name allocations=1, rewrites=32)

Mutation control: with the restore removed the same case fails at the first open with
"caller name changed after open 0: length=136 maximum=136 buffer_moved=1", so the check does detect a
name that is not given back.
@triggered02

Copy link
Copy Markdown
Contributor Author

All three points are addressed in db912372.

The name is now temporary to the hooked call. The entry trace records what the caller's UNICODE_STRING held, and the existing return boundary restores it — length, buffer pointer and contents — before anything else runs. Both cases you called out are covered: the short case restores the caller's own buffer contents as well as the header, and the long case restores the pointed-to name. I also moved the offline deny check ahead of the rewrite, so a refused call never borrows the name at all.

The backing is one reusable allocation, not one per open. It is grown on demand and the previous block released; a failed write after growth leaves the caller's string untouched (the previous code leaked in that path too).

New fixture mode (X2W_PROBE_MODE=reuse), as asked: the source-built consumer builds one caller-owned UNICODE_STRING whose buffer is exactly its own size, calls NtCreateFile through the mapped letter 32 times, and after every return checks Length, MaximumLength, Buffer identity and contents. The check also requires the trace to show one name allocation for those 32 opens, so allocation growth fails it.

mapped letter Z: ok ('read 9 bytes: mapped ok')
negative control without the option: ok ('open failed: 3')
unmapped letter C: ok
reused caller name over 32 opens: ok (name allocations=1, rewrites=32)

Mutation control, so the new case is known to bite: with the restore removed it fails at the first open with caller name changed after open 0: length=136 maximum=136 buffer_moved=1, and with per-open allocation it fails on the allocation count.

The disabled and unmapped controls still apply and still pass. docs_links_check.py passes and docs/startup-runtime.md now describes the temporary-name and reuse behaviour instead of the old "allocation left to the process" limit.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 32-open fixture now checks restoration on the serial long-name path. Two cases still fail by inspection in db912372.

  • The one process-wide scratch allocation can still be in use when a second thread enters a hooked call. The second rewrite can overwrite it, or free it when growing the buffer, before the first call has consumed its name. Please keep the backing valid per in-flight call and add a deterministic overlap control, or use separate temporary allocations tied to each return.
  • restore is assigned only in the file-name branch, but the common if desc: also handles the other trace kinds. Initialise it before the dispatch so those traces cannot see an unbound or earlier callback.

The serial restoration check should stay. A two-call overlap test should verify both observed names and both restored caller strings.

triggered02 added a commit to triggered02/Xbox2Windows that referenced this pull request Nov 24, 2026
Addresses the second review of R0Y00#1251.

The backing buffer is no longer one process-wide allocation. Each hooked call borrows a buffer for the
duration of that call and returns it to a pool when the caller's name is restored, so two calls that
overlap on different threads cannot overwrite or free each other's name, while a serial run still
reuses one buffer (the 32-open case stays at one name allocation).

`restore` is now initialised before the trace-kind dispatch. It was assigned inside the file-name
branch only, and the common "if desc:" below serves every kind, so a count, runtime or bink trace could
see an unbound name or, worse, carry over the previous call's callback and restore a different call's
string.

The two-thread overlap control the review asked for is added, and it found a separate, larger problem
that is not in this change: the launcher's entry hooks are one patched byte per function, so a thread
that enters the same hooked function while another is being stepped over runs untraced. Measured with
the source-built consumer, 32 opens per thread:

  two threads, no mapping, real file through its own letter: 64/64 opens succeed
  two threads, --map-drive:                                 40/64 opens traced and rewritten (46/64 on a repeat)

Without mapping the same pattern is 64/64, so the loss is the hook dropping concurrent hits, not the
consumer or the file system. It affects file tracing and the offline socket deny as well as this
rewrite, so it is filed as R0Y00#1281 rather than worked around here. `startup_map_drive_overlap` holds the
control as an expected failure (CTest WILL_FAIL) so it is visible and documented, and will start
failing the suite once the hook stops dropping calls — which is the signal to make it a normal gate.

Measured, Windows 11 build 26200, release preset:

  mapped letter Z: ok ('read 9 bytes: mapped ok')
  negative control without the option: ok ('open failed: 3')
  unmapped letter C: ok
  reused caller name over 32 opens: ok (name allocations=1, rewrites=32)
  startup_map_drive: Passed
  startup_map_drive_overlap: Passed (expected failure: traced 46 of 64)

Mutation controls: with the buffer forced back to a single shared one the overlap case reports one
name allocation instead of two, and with the restore removed the serial case fails at the first open
with "caller name changed after open 0".
@triggered02

Copy link
Copy Markdown
Contributor Author

Both points are fixed in a6c20e2b, and the overlap control you asked for is added — it also found a separate problem worth its own issue.

Per-call backing. The single scratch allocation is gone. Each hooked call borrows a buffer for the duration of that call and returns it to a pool when its name is restored, so overlapping calls cannot overwrite or free each other's name, while a serial run still reuses one buffer — the 32-open case still reports one name allocation.

restore initialisation. It is now set before the trace-kind dispatch. You were right that the common if desc: serves every kind: a count, runtime or bink trace would either see an unbound name or, worse, carry over the previous call's callback and restore another call's string.

The overlap control, and what it exposed. Two threads, 32 opens each, source-built consumer:

case result
two threads, no mapping, real file through its own letter 64/64 opens succeed
two threads, --map-drive 40/64 opens traced and rewritten (46/64 on a repeat)

Without mapping the same two-thread pattern is 64/64, so this is not the consumer, the file system or general tracing — it is the launcher's entry hook: one patched byte per function, so a thread entering while another is being stepped over runs untraced and keeps its unmapped name. That misses file-tracing lines and, worse, can let an offline-denied socket through, so I filed it as #1281 instead of papering over it here.

startup_map_drive_overlap holds your control in the tree as an expected failure (WILL_FAIL), so it runs on every CI job, is documented, and will start failing the suite once the hook stops dropping concurrent calls — that failure is the signal to promote it to a normal gate. If you would rather it were a hard gate now, the fix belongs in the hook (per-thread hardware breakpoints or suspending during the step) and I can take that as #1281.

Verification at a6c20e2b (Windows 11 build 26200, release preset):

mapped letter Z: ok ('read 9 bytes: mapped ok')
negative control without the option: ok ('open failed: 3')
unmapped letter C: ok
reused caller name over 32 opens: ok (name allocations=1, rewrites=32)
startup_map_drive .......... Passed
startup_map_drive_overlap .. Passed (expected failure: traced 46 of 64)

Mutation controls: forcing the buffer back to one shared allocation makes the overlap case report one name allocation instead of two; removing the restore makes the serial case fail at the first open with "caller name changed after open 0". The serial restoration check stays, as you asked.

triggered02 added a commit to triggered02/Xbox2Windows that referenced this pull request Nov 24, 2026
Review of R0Y00#1251 found that map_drive() looked for a "] " separator, but oa_name() formats a
root-relative name as "[root 0x...]" + text with no space. So a root-relative open was never
rewritten, and had the separator matched, the synthetic "[root 0x...]" display tag would have been
written into the caller's UNICODE_STRING and corrupted the kernel string.

The tag is now drained by finding "]" and dropped: it is only a label for the log, so it never takes
part in the rewrite.

Three smaller points from the same review:

- The "\\\\?\\" Win32 long-path prefix is matched alongside the "\\??\\" and "\\\\.\\" device
  prefixes.
- Mapping letters are ASCII A-Z. isalpha() alone also accepts non-ASCII letters, which no NT path
  has.
- A replacement longer than 0xFFFF bytes is refused, because a UNICODE_STRING length is a USHORT and
  the name could not be expressed at all.

The root-relative case is not covered by startup_map_drive yet: CreateFileW builds the object name
without a RootDirectory, so the fixture never produces the "[root ...]" form. A direct NtCreateFile
consumer would be needed to exercise it; the separator and the tag handling are the code that
changed.
triggered02 added a commit to triggered02/Xbox2Windows that referenced this pull request Nov 24, 2026
Addresses the review of R0Y00#1251. The rewrite changed the caller's name permanently: in the short case
it overwrote the caller's own buffer, and in the long case it repointed the caller's UNICODE_STRING at
a fresh VirtualAllocEx that nothing released, including after a failed write. A caller that opens with
the same UNICODE_STRING twice, or that reads it after the call, saw the rewritten name.

The name is now temporary to the call. The entry trace records what the caller's UNICODE_STRING held,
and the existing return boundary restores it — length, buffer pointer and contents — before anything
else runs, so a failure or a retry sees the name it built. The offline deny path also runs before the
rewrite, so a refused call never borrows the name at all.

The long case writes into one backing allocation that is grown on demand and reused, so the number of
name allocations does not follow the number of opens, and a failed write after growth leaves the
caller's string untouched.

Covered by a new fixture mode: the source-built consumer builds one UNICODE_STRING whose buffer is
exactly the caller's size, calls NtCreateFile through the mapped letter 32 times, and checks its
length, buffer pointer and contents after every return, while the trace must show a single name
allocation.

Measured, Windows 11 build 26200, release preset:

  mapped letter Z: ok ('read 9 bytes: mapped ok')
  negative control without the option: ok ('open failed: 3')
  unmapped letter C: ok
  reused caller name over 32 opens: ok (name allocations=1, rewrites=32)

Mutation control: with the restore removed the same case fails at the first open with
"caller name changed after open 0: length=136 maximum=136 buffer_moved=1", so the check does detect a
name that is not given back.
triggered02 added a commit to triggered02/Xbox2Windows that referenced this pull request Nov 24, 2026
Addresses the second review of R0Y00#1251.

The backing buffer is no longer one process-wide allocation. Each hooked call borrows a buffer for the
duration of that call and returns it to a pool when the caller's name is restored, so two calls that
overlap on different threads cannot overwrite or free each other's name, while a serial run still
reuses one buffer (the 32-open case stays at one name allocation).

`restore` is now initialised before the trace-kind dispatch. It was assigned inside the file-name
branch only, and the common "if desc:" below serves every kind, so a count, runtime or bink trace could
see an unbound name or, worse, carry over the previous call's callback and restore a different call's
string.

The two-thread overlap control the review asked for is added, and it found a separate, larger problem
that is not in this change: the launcher's entry hooks are one patched byte per function, so a thread
that enters the same hooked function while another is being stepped over runs untraced. Measured with
the source-built consumer, 32 opens per thread:

  two threads, no mapping, real file through its own letter: 64/64 opens succeed
  two threads, --map-drive:                                 40/64 opens traced and rewritten (46/64 on a repeat)

Without mapping the same pattern is 64/64, so the loss is the hook dropping concurrent hits, not the
consumer or the file system. It affects file tracing and the offline socket deny as well as this
rewrite, so it is filed as R0Y00#1281 rather than worked around here. `startup_map_drive_overlap` holds the
control as an expected failure (CTest WILL_FAIL) so it is visible and documented, and will start
failing the suite once the hook stops dropping calls — which is the signal to make it a normal gate.

Measured, Windows 11 build 26200, release preset:

  mapped letter Z: ok ('read 9 bytes: mapped ok')
  negative control without the option: ok ('open failed: 3')
  unmapped letter C: ok
  reused caller name over 32 opens: ok (name allocations=1, rewrites=32)
  startup_map_drive: Passed
  startup_map_drive_overlap: Passed (expected failure: traced 46 of 64)

Mutation controls: with the buffer forced back to a single shared one the overlap case reports one
name allocation instead of two, and with the restore removed the serial case fails at the first open
with "caller name changed after open 0".
@triggered02

Copy link
Copy Markdown
Contributor Author

Conflict fixed. The branch is rebased onto current main (a8946ec0) and force-pushed as ad94c950; it is 0 commits behind.

The conflict was in tools/startup/debug_launch.py, in the frame-hook dispatch, and it was a real one — both sides edited the same block for different reasons:

  • main added the valloc trace branch (NtAllocateVirtualMemory/Ex requested base, size, type, protect and the caller chain);
  • this branch added restore = None initialisation so every trace kind starts with a clean restore callback, plus a return-address read that tolerates a short read.

I kept both: the valloc branch is preserved verbatim, restore = None is initialised before the dispatch so a non-name trace cannot see an unbound name or carry over the previous call's callback, and the return-address read uses the short-read-tolerant form. Nothing from either side was dropped.

Verified after the rebase:

  • startup_map_drive and startup_map_drive_overlap pass (2/2);
  • debug_launch.py parses, and a live 75 s launcher run with -MapDrive worked: 374 mapped-name log lines, no trace-related errors.

startup_map_drive_overlap is still registered WILL_FAIL on purpose — it documents the launcher dropping concurrent hits (#1281) rather than asserting correct behaviour.

The earlier CHANGES_REQUESTED from 06:32 predates the previous head, so it may not reflect this state; happy to address anything that still applies.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rebase keeps the valloc trace and initializes the restore callback before dispatch. The serial 32-open control is useful. The overlap case still permits a mapped open to miss the rewrite, and WILL_FAIL can accept unrelated failures. Please keep this waiting on #1281, then make the overlap case pass only when both opens see the mapped names and both caller strings are restored. Keep the serial reuse and disabled controls.

@lambirou

Copy link
Copy Markdown
Contributor

I tested this branch against the failure in #1158 with a local package stored on another volume, with no G: volume present.

-MapDrive G=F:\... does rewrite the NT opens. files.txt shows MAP \??\G:\appdata0.rpf -> \??\F:\...\appdata0.rpf for both NtQueryAttributesFile and NtCreateFile, and common.rpf follows the same path. Those opens succeed.

The run still stops at 0.36 s in vcruntime140.dll+0x1989 (access violation, write to null, size 0x7ffffe0f0). stderr.txt shows:

x2w-dstorage Factory::OpenFile path="G:\appdata0.rpf" ... -> ok (err 0)

The DirectStorage stand-in's own Factory::OpenFile path is not rewritten by the file hook, so the package data is still not read from the real folder. With subst G: F:\... (a real drive mapping), the same run passes this point, reaches D3D12 and reaches about 29 fps in a 240 s run; a 25 s run rewrites CLZERO and presents frames.

So the NT path rewrite works, but it does not cover the DirectStorage stand-in. If that is outside this PR's scope, the documented limit should state that a title using DirectStorage still needs the drive letter mounted. Otherwise the stand-in's OpenFile needs to resolve the mapped letter too.

Measured on Windows 11 26H2 build 26300 with a Radeon RX 9060 XT (driver 32.0.32029.2010).

@SuperCraft3M

Copy link
Copy Markdown
Contributor

Independent local integration result: main 8f43802 + #1251 ad94c95 + #1408 ecbbf3e + UTF-8 storage #1551, integration branch SuperCraft3M/Xbox2Windows runtime/startup-null-diagnosis at 3098828.

On Windows 11 build 26300.9711 / RTX 4070 driver 32.0.16.2114, Debug stand-ins, offline debugger, the same isolated local executable stopped on an early null write without the package-drive mapping. Mapping its expected package letter to the actual package directory passed that point. With #1251 alone one repeat still stopped early. With #1408's protected step windows integrated, the final mapped run reached its 150-second timeout and displayed a profile-selection prompt. The debugger reported 12,330 hook entries, 24,651 step windows, 0 unprotected windows, 143 deferred hits and 0 timeouts; 4 network opens were refused. Six translated pipelines were available, none missing at the last render summary.

This used the documented diagnostic runtime with --continue-asserts 1000, a 14 GiB job cap and a local shader cache. It is not evidence of gameplay or original-executable startup without diagnostic assertion continuation. No executable bytes were patched on disk; raw logs and screenshots stay local.

The combined source-built checks (startup_map_drive, startup_map_drive_overlap, startup_hook_window, startup_hook_overlap) passed 4/4, no skips. The overlap fixture now reports 64/64 opens, traces and rewrites with both caller-owned names intact. Merge-resolution details are on #1408: #1408 (comment) .

AI-assisted (Codex).

@lambirou

Copy link
Copy Markdown
Contributor

Correction to my comment above: the 0.36 s failure came from testing the PR head before current main was merged, not from a DirectStorage gap.

I merged current main into the branch locally (the conflicts were in CMakeLists.txt and run.ps1; both were mechanical), rebuilt the stand-ins, and reran the same 30 s startup with no G: volume. It now reaches the 30 s timeout with:

host-cpu sites rewritten: clzero x5, monitorx x1, mwaitx x1

Factory::OpenFile returns ok for G:\appdata0.rpf, common.rpf, movies.rpf, shaders.rpf, anim.rpf, data.rpf, levels.rpf, navmeshes.rpf, packs.rpf, textures.rpf, audio.rpf and script.rpf, and files.txt shows the corresponding MAP lines. So the option does cover the DirectStorage opens; no stand-in change is needed.

The PR just needs a rebase onto current main. Sorry for the noise in the previous comment.

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.
…others

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 R0Y00#1281
…one; reuse the debug event's thread handle

Thanks @RenzoWit35 for the Win11 26300 finding.
@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

@triggered02 could you rebase this branch onto current main and force-push?

GitHub reports head ad94c950 as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (cf97bee1):

  • CMakeLists.txt
  • docs/startup-runtime.md
  • tools/startup/run.ps1

Commands run locally:

git fetch origin main pull/1251/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1251 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

triggered02 added a commit to triggered02/Xbox2Windows that referenced this pull request Nov 25, 2026
Review of R0Y00#1251 found that map_drive() looked for a "] " separator, but oa_name() formats a
root-relative name as "[root 0x...]" + text with no space. So a root-relative open was never
rewritten, and had the separator matched, the synthetic "[root 0x...]" display tag would have been
written into the caller's UNICODE_STRING and corrupted the kernel string.

The tag is now drained by finding "]" and dropped: it is only a label for the log, so it never takes
part in the rewrite.

Three smaller points from the same review:

- The "\\\\?\\" Win32 long-path prefix is matched alongside the "\\??\\" and "\\\\.\\" device
  prefixes.
- Mapping letters are ASCII A-Z. isalpha() alone also accepts non-ASCII letters, which no NT path
  has.
- A replacement longer than 0xFFFF bytes is refused, because a UNICODE_STRING length is a USHORT and
  the name could not be expressed at all.

The root-relative case is not covered by startup_map_drive yet: CreateFileW builds the object name
without a RootDirectory, so the fixture never produces the "[root ...]" form. A direct NtCreateFile
consumer would be needed to exercise it; the separator and the tag handling are the code that
changed.
triggered02 added a commit to triggered02/Xbox2Windows that referenced this pull request Nov 25, 2026
Addresses the review of R0Y00#1251. The rewrite changed the caller's name permanently: in the short case
it overwrote the caller's own buffer, and in the long case it repointed the caller's UNICODE_STRING at
a fresh VirtualAllocEx that nothing released, including after a failed write. A caller that opens with
the same UNICODE_STRING twice, or that reads it after the call, saw the rewritten name.

The name is now temporary to the call. The entry trace records what the caller's UNICODE_STRING held,
and the existing return boundary restores it — length, buffer pointer and contents — before anything
else runs, so a failure or a retry sees the name it built. The offline deny path also runs before the
rewrite, so a refused call never borrows the name at all.

The long case writes into one backing allocation that is grown on demand and reused, so the number of
name allocations does not follow the number of opens, and a failed write after growth leaves the
caller's string untouched.

Covered by a new fixture mode: the source-built consumer builds one UNICODE_STRING whose buffer is
exactly the caller's size, calls NtCreateFile through the mapped letter 32 times, and checks its
length, buffer pointer and contents after every return, while the trace must show a single name
allocation.

Measured, Windows 11 build 26200, release preset:

  mapped letter Z: ok ('read 9 bytes: mapped ok')
  negative control without the option: ok ('open failed: 3')
  unmapped letter C: ok
  reused caller name over 32 opens: ok (name allocations=1, rewrites=32)

Mutation control: with the restore removed the same case fails at the first open with
"caller name changed after open 0: length=136 maximum=136 buffer_moved=1", so the check does detect a
name that is not given back.
triggered02 added a commit to triggered02/Xbox2Windows that referenced this pull request Nov 25, 2026
Addresses the second review of R0Y00#1251.

The backing buffer is no longer one process-wide allocation. Each hooked call borrows a buffer for the
duration of that call and returns it to a pool when the caller's name is restored, so two calls that
overlap on different threads cannot overwrite or free each other's name, while a serial run still
reuses one buffer (the 32-open case stays at one name allocation).

`restore` is now initialised before the trace-kind dispatch. It was assigned inside the file-name
branch only, and the common "if desc:" below serves every kind, so a count, runtime or bink trace could
see an unbound name or, worse, carry over the previous call's callback and restore a different call's
string.

The two-thread overlap control the review asked for is added, and it found a separate, larger problem
that is not in this change: the launcher's entry hooks are one patched byte per function, so a thread
that enters the same hooked function while another is being stepped over runs untraced. Measured with
the source-built consumer, 32 opens per thread:

  two threads, no mapping, real file through its own letter: 64/64 opens succeed
  two threads, --map-drive:                                 40/64 opens traced and rewritten (46/64 on a repeat)

Without mapping the same pattern is 64/64, so the loss is the hook dropping concurrent hits, not the
consumer or the file system. It affects file tracing and the offline socket deny as well as this
rewrite, so it is filed as R0Y00#1281 rather than worked around here. `startup_map_drive_overlap` holds the
control as an expected failure (CTest WILL_FAIL) so it is visible and documented, and will start
failing the suite once the hook stops dropping calls — which is the signal to make it a normal gate.

Measured, Windows 11 build 26200, release preset:

  mapped letter Z: ok ('read 9 bytes: mapped ok')
  negative control without the option: ok ('open failed: 3')
  unmapped letter C: ok
  reused caller name over 32 opens: ok (name allocations=1, rewrites=32)
  startup_map_drive: Passed
  startup_map_drive_overlap: Passed (expected failure: traced 46 of 64)

Mutation controls: with the buffer forced back to a single shared one the overlap case reports one
name allocation instead of two, and with the restore removed the serial case fails at the first open
with "caller name changed after open 0".
@triggered02

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and force-pushed: head is now 83a7023d on startup/map-drive (was ad94c950, based on cf97bee1).

83a7023d startup: keep the mapped name per call and report a dropped-hook limit
86fcb9d4 startup: borrow the mapped name only for the hooked call
73d617f5 startup: fix the drive rewrite for root-relative opens
7a7473a1 startup: map a console package drive letter to a real folder

All four commits replayed; none became empty and the messages are unchanged. git diff --stat origin/main..HEAD is the PR's six files and nothing else: CMakeLists.txt +19, docs/startup-runtime.md +30, tests/startup_map_drive_check.py +112, tests/startup_map_drive_consumer.cpp +202, tools/startup/debug_launch.py +128, tools/startup/run.ps1 +5.

Conflict resolutions (all three files, keeping main's newer text and re-applying only the PR's own lines):

  • CMakeLists.txt — main has moved and grown the launcher/debugger block. The startup_map_drive_consumer executable and its cxx_std_17 are now defined with the other debugger inputs after startup_debug_probe/startup_debug_calls (:1114-1117), and startup_map_drive (:3460) plus startup_map_drive_overlap (:3468, WILL_FAIL) are registered right after startup_debug inside the if(EXISTS "${INTAKE_PYTHON}") guard. main's storage/inflate/refusal tests are verbatim.
  • docs/startup-runtime.md — the ### Package on another volume section sits after the "It writes:" log-file table (:692) and before ### Translating shaders during a run; main's expanded run.ps1 paragraph and new log-table prose are kept.
  • tools/startup/run.ps1 — -MapDrive is added before $StoragePath (:23) with main's trailing-backslash note intact, $mapArgs at :76-77, fed as @mapArgs @traceArgs into main's $python/try-finally invocation (:80).

Verification on 83a7023d (from F:\x2w-wt-1251, out/pe-env Python 3.12.10):

command exit result
git diff --check (and origin/main..HEAD) 0 clean
tools/startup/debug_launch.py argv harness with -MapDrive 0 forwarded as --map-drive G=D:\package, no problems
tests/docs_links_check.py 0 19 Markdown files, 466 links
tests/bidi_controls_check.py 0 1728 tracked files
tests/startup_tools_lint_check.py tools/startup 0 9 files parse, control rejected
tests/startup_run_ps1_check.py 0 0 failed (Windows PowerShell 5.1)
tests/startup_run_sh_check.py 77 skip: POSIX launcher, as intended on Windows
tests/startup_translator_check.py 0 0 failed

Not verified locally, CI must: the new startup_map_drive_consumer C++ target, startup_map_drive and startup_map_drive_overlap (Windows-only; they launch the consumer through debug_launch.py). I did not configure a build tree in this worktree. Selection is ctest --preset dev --no-tests=error -R '^startup_map_drive' -V.

The mergeable flag was stale UNKNOWN right after the push; it should settle to MERGEABLE on GitHub's next check. If CI goes red on the consumer, I will fix it here rather than drop the target.

One pre-existing thing I left alone because it is in the PR head and not a conflict: tools/startup/debug_launch.py has the offline-deny block twice (:606 and :623), and the second repeat is unreachable because it tests the same target condition. Say the word if you want it removed in this PR rather than a follow-up.

A console executable opens its package at a fixed drive letter, so a package on another volume never
mounts: the first open returns "not found", nothing is mounted, and the run stops within a second on
a table sized from data that was never loaded. subst does not help when the letter is already a real
volume.

tools/startup/debug_launch.py --map-drive LETTER=FOLDER[;...], exposed as run.ps1 -MapDrive, rewrites
the path of an open on a mapped letter to the real folder, in the caller's own path structure and
inside the file hooks the launcher already installs for tracing. The rewrite keeps the device prefix,
and because the replacement is usually longer than the buffer the caller allocated (a folder path
against a single letter), the new name is allocated in the process and the UNICODE_STRING is
repointed at it. Each rewrite is logged as a MAP line and appears in files.txt.

Covered by startup_map_drive (tests/startup_map_drive_check.py with a source-built consumer): the
rewrite makes an open on a letter that is not a volume succeed and read its content, the same open
fails without the option, and an open on a letter that is not mapped is left alone. Measured on
Windows 11 build 26200, where the mapped letter does not exist as a volume.

Documented in docs/startup-runtime.md under the run instructions, including the two limits (only
opens through the installed file hooks are rewritten, and the replacement allocation is left to the
process).
Review of R0Y00#1251 found that map_drive() looked for a "] " separator, but oa_name() formats a
root-relative name as "[root 0x...]" + text with no space. So a root-relative open was never
rewritten, and had the separator matched, the synthetic "[root 0x...]" display tag would have been
written into the caller's UNICODE_STRING and corrupted the kernel string.

The tag is now drained by finding "]" and dropped: it is only a label for the log, so it never takes
part in the rewrite.

Three smaller points from the same review:

- The "\\\\?\\" Win32 long-path prefix is matched alongside the "\\??\\" and "\\\\.\\" device
  prefixes.
- Mapping letters are ASCII A-Z. isalpha() alone also accepts non-ASCII letters, which no NT path
  has.
- A replacement longer than 0xFFFF bytes is refused, because a UNICODE_STRING length is a USHORT and
  the name could not be expressed at all.

The root-relative case is not covered by startup_map_drive yet: CreateFileW builds the object name
without a RootDirectory, so the fixture never produces the "[root ...]" form. A direct NtCreateFile
consumer would be needed to exercise it; the separator and the tag handling are the code that
changed.
Addresses the review of R0Y00#1251. The rewrite changed the caller's name permanently: in the short case
it overwrote the caller's own buffer, and in the long case it repointed the caller's UNICODE_STRING at
a fresh VirtualAllocEx that nothing released, including after a failed write. A caller that opens with
the same UNICODE_STRING twice, or that reads it after the call, saw the rewritten name.

The name is now temporary to the call. The entry trace records what the caller's UNICODE_STRING held,
and the existing return boundary restores it — length, buffer pointer and contents — before anything
else runs, so a failure or a retry sees the name it built. The offline deny path also runs before the
rewrite, so a refused call never borrows the name at all.

The long case writes into one backing allocation that is grown on demand and reused, so the number of
name allocations does not follow the number of opens, and a failed write after growth leaves the
caller's string untouched.

Covered by a new fixture mode: the source-built consumer builds one UNICODE_STRING whose buffer is
exactly the caller's size, calls NtCreateFile through the mapped letter 32 times, and checks its
length, buffer pointer and contents after every return, while the trace must show a single name
allocation.

Measured, Windows 11 build 26200, release preset:

  mapped letter Z: ok ('read 9 bytes: mapped ok')
  negative control without the option: ok ('open failed: 3')
  unmapped letter C: ok
  reused caller name over 32 opens: ok (name allocations=1, rewrites=32)

Mutation control: with the restore removed the same case fails at the first open with
"caller name changed after open 0: length=136 maximum=136 buffer_moved=1", so the check does detect a
name that is not given back.
Addresses the second review of R0Y00#1251.

The backing buffer is no longer one process-wide allocation. Each hooked call borrows a buffer for the
duration of that call and returns it to a pool when the caller's name is restored, so two calls that
overlap on different threads cannot overwrite or free each other's name, while a serial run still
reuses one buffer (the 32-open case stays at one name allocation).

`restore` is now initialised before the trace-kind dispatch. It was assigned inside the file-name
branch only, and the common "if desc:" below serves every kind, so a count, runtime or bink trace could
see an unbound name or, worse, carry over the previous call's callback and restore a different call's
string.

The two-thread overlap control the review asked for is added, and it found a separate, larger problem
that is not in this change: the launcher's entry hooks are one patched byte per function, so a thread
that enters the same hooked function while another is being stepped over runs untraced. Measured with
the source-built consumer, 32 opens per thread:

  two threads, no mapping, real file through its own letter: 64/64 opens succeed
  two threads, --map-drive:                                 40/64 opens traced and rewritten (46/64 on a repeat)

Without mapping the same pattern is 64/64, so the loss is the hook dropping concurrent hits, not the
consumer or the file system. It affects file tracing and the offline socket deny as well as this
rewrite, so it is filed as R0Y00#1281 rather than worked around here. `startup_map_drive_overlap` holds the
control as an expected failure (CTest WILL_FAIL) so it is visible and documented, and will start
failing the suite once the hook stops dropping calls — which is the signal to make it a normal gate.

Measured, Windows 11 build 26200, release preset:

  mapped letter Z: ok ('read 9 bytes: mapped ok')
  negative control without the option: ok ('open failed: 3')
  unmapped letter C: ok
  reused caller name over 32 opens: ok (name allocations=1, rewrites=32)
  startup_map_drive: Passed
  startup_map_drive_overlap: Passed (expected failure: traced 46 of 64)

Mutation controls: with the buffer forced back to a single shared one the overlap case reports one
name allocation instead of two, and with the restore removed the serial case fails at the first open
with "caller name changed after open 0".
@triggered02

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (e46d336); head is now 14a7a18 (was 83a7023). Replay clean, no conflict markers.

Verified on 14a7a18: startup_translator_check 0 failed; startup_run_ps1_check exit 0; docs_links_check 523 links; �idi_controls_check 1974 files; startup_tools_lint_check 11 files; git diff --check clean. New files ests/startup_map_drive_check.py / startup_map_drive_consumer.cpp, both CTests (incl. the WILL_FAIL overlap test), the ### Package on another volume docs section, and -MapDrive/$mapArgs/--map-drive all survived; main's added lines in the overlapping files are intact.

c1 added 6 commits November 26, 2026 11:34
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.
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

@triggered02 @R0Y00 I pushed a fast-forward to startup/map-drive (14a7a18 -> 0ffbbde, no force push, maintainer edit). What it does and why:

What changed

  • Merged current main (clean) and the step window from startup: hold other threads while a hook steps over its byte #1408 (the debugger holds every other thread while it steps one over a hooked byte), so a thread that enters the same hooked function is no longer dropped.
  • ReturnBook (from startup: hold other threads while a hook steps over its byte #1408) now carries an optional restore callback per call and runs it once when that call returns. The mapped-name restore uses it, so the caller's UNICODE_STRING is back before anything else runs and the borrowed name buffer is tied to the call that is in flight (each overlapping call gets its own buffer from the pool, as in your pool change).
  • startup_map_drive_overlap is no longer WILL_FAIL. It passes only when all 64 opens (two threads, 32 each, caller-owned names) are traced as mapped and succeed, all 64 MAP lines are present, the consumer reports both caller strings intact, and the debugger reports unprotected=0; three times. Its control runs the same case with --suspend-others 0 (other threads not held, the broken behaviour): it must lose at least one open in 8 runs and report unprotected above 0, otherwise the control fails because the overlap was not exercised.
  • The serial 32-open reuse check and the disabled/unmapped controls are unchanged.
  • The two CTests now own separate package and log folders. While preparing this I saw startup_map_drive_overlap fail with 0 of 64 and 0xc000003a even though the rewritten path was correct: the two tests shared one map_drive_pkg folder and each removed it at its end, so under ctest --parallel one deleted the folder under the other. With --parallel 1 it passed, with separate folders it passes in parallel.
  • docs/startup-runtime.md: the "two limits" paragraph now describes the remaining limit only (memory-mapped reads) and the overlap test.

Verification (Windows Server 2025 build 26100, MSVC 14.44, head 0ffbbde, default parallel):

python x2w_pipe.py win2025 1251 --regex '^(startup_map_drive|startup_hook_window|startup_hook_overlap|startup_launch|startup_debug)' --keep-release

Debug 9/9 and release 9/9 passed: startup_map_drive, startup_map_drive_overlap, startup_hook_window, startup_hook_overlap, startup_launch, startup_launch_cli_check, startup_debug, startup_debug_log, startup_debug_hooks. Linux: python3 -B tests/startup_hook_check.py PASS, tests/docs_links_check.py clean.

Note: the branch now contains the #1408 commits. Once #1408 merges, this PR's diff shrinks to the map-drive files.

AI-assisted; commands listed were executed locally.

@tedin7 tedin7 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review of head f953501 (comment only, not an approval). Supersedes my review of 0ffbbde; only the overlap test changed since.

Code (tools/startup/debug_launch.py, map_drive()), unchanged and sound: a name that does not fit the caller's buffer is written into a buffer popped from name_pool["free"] for that call only and pushed back by that call's restore() at its return, so a second thread's rewrite cannot overwrite or free the first call's name. restore = None is set before the dispatch; a re-trap keeps the first restore (#1408 at 08f0f4e); the offline deny runs before map_drive().

Tests: startup_map_drive_overlap has no WILL_FAIL. The two threads now open different files of different lengths (map_drive_probe.txt, map_drive_probe_second_longer_name.txt), each checks with GetFinalPathNameByHandleW that it opened its own, both caller strings are verified after every return, and the launcher script requires 32 mapped successful opens per file, 64 rewrites and unprotected=0, three times. The serial 32-open reuse, disabled and unmapped controls are kept.

The P2 of my previous review is closed. Control I ran: replacing the pool with one process-wide scratch buffer (grown, never freed, shared by calls in flight; a change to a local copy of debug_launch.py, same CTests) makes startup_map_drive_overlap fail (33, 32 and 35 of 64 opens succeeded in the three runs; startup_map_drive still passes). A pool that only partitions by size does not fail it, which is expected since those calls never share a buffer.

Verification (Win2025, proxmox only), head f953501, x2w_pipe.py win2025 1251 --host proxmox --force --keep-release --regex '^(startup_map_drive|startup_hook|startup_launch|startup_debug)': dev 9/9 and release 9/9 passed. Linux: tests/startup_hook_check.py, py_compile, git diff --check origin/main...HEAD clean.

AI-assisted; commands listed were executed locally.

…t lengths

A name buffer shared between calls in flight now hands one thread the other's name or a cut-off one, so the case fails for it: each thread checks the file it actually opened (GetFinalPathNameByHandleW) and the check counts 32 mapped opens per file.
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Follow-up push on startup/map-drive: f953501 (fast-forward, no force). The overlap case could not tell per-call name buffers from one shared scratch buffer, because both threads opened the same file. Now the two threads open different mapped files of different lengths (map_drive_probe.txt and map_drive_probe_second_longer_name.txt). The consumer checks which file each open really reached (GetFinalPathNameByHandleW), and the check requires 32 mapped opens per file plus the 64 MAP lines, the intact caller strings and unprotected=0.

Win2025 (build 26100) on f953501: startup_map_drive, startup_map_drive_overlap, startup_hook_overlap pass in debug and release (3/3 each).

Control for the buffer: with the pool replaced by one process-wide scratch buffer that is never taken out while a call is in flight (the shared-scratch behaviour from the review), startup_map_drive_overlap fails in all three held attempts (33 and 34 of 64 opens succeed, the other thread's opens do not see their own mapped name) while the serial startup_map_drive still passes. The mutant was applied as a patch on the Windows node only and is not part of the branch.

AI-assisted; commands listed were executed locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants