Repository navigation
startup: map a console package drive letter to a real folder - #1251
triggered02 wants to merge 20 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
tedin7
left a comment
There was a problem hiding this comment.
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: PASSAGENTS.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.44srelease(/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)
[root ...]prefix mismatch inmap_drive():oa_name()formats root-relative paths without a space:f"[root {root:#x}]" + text(e.g.[root 0x123]\??\G:\foo).map_drive()checksif body.startswith("[root ") and "] " in body:(looking for"] ", with a space), so whenOBJECT_ATTRIBUTES.RootDirectoryis 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 intoencodedbefore writing it back into the target process'sUNICODE_STRINGbuffer, which would corrupt the kernelUNICODE_STRINGifrootwere non-empty.rootshould only be kept in the log/display string, not written intoUNICODE_STRING.
- Minor edge cases:
drive_mapacceptsletter.isalpha()(which includes non-ASCII Unicode letters in Python 3) rather than ASCIIA–Z.\\?\(Win32 long-path prefix) is not in("\\??\\", "\\\\.\\")(Win32CreateFileWnormalizes\\?\to\??\beforeNtCreateFile, so NT hooks see\??\, though direct callers passing\\?\wouldn't match)...path traversal inbody[2:]is preserved verbatim (expected for a launcher diagnostic rewrite).struct.pack("<HH4xQ", len(encoded), len(encoded), fresh)assumeslen(encoded) <= 65535(USHORTlimit ofUNICODE_STRING).
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.
|
Fixed in Also taken from the review:
|
R0Y00
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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_mapkeys to ASCIIA–Z(letter.isascii()). - Drops the synthetic
[root 0x...]log tag frombodyinstead of prepending it intoreplacement. - Adds
\\?\alongside\??\and\\.\prefix matching. - Guards
len(encoded)against0 < len(encoded) <= 0xFFFFbefore writingUNICODE_STRING.Length.
Linux Checks
git diff --check origin/main...HEAD: PASSdocs_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_REQUESTEDitems from@R0Y00(restoring the caller'sUNICODE_STRINGafter the hooked NT call, releasing/reusingVirtualAllocExbacking, and adding a multi-open reuse test) remain open as of78c8796d.
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.
78c8796 to
4f07ff3
Compare
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.
|
All three points are addressed in The name is now temporary to the hooked call. The entry trace records what the caller's 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 ( Mutation control, so the new case is known to bite: with the restore removed it fails at the first open with The disabled and unmapped controls still apply and still pass. |
R0Y00
left a comment
There was a problem hiding this comment.
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.
restoreis assigned only in the file-name branch, but the commonif 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.
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".
|
Both points are fixed in 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.
The overlap control, and what it exposed. Two threads, 32 opens each, source-built consumer:
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.
Verification at 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. |
a6c20e2 to
ad94c95
Compare
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".
|
Conflict fixed. The branch is rebased onto current The conflict was in
I kept both: the Verified after the rebase:
The earlier |
R0Y00
left a comment
There was a problem hiding this comment.
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.
|
I tested this branch against the failure in #1158 with a local package stored on another volume, with no
The run still stops at 0.36 s in The DirectStorage stand-in's own 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 Measured on Windows 11 26H2 build 26300 with a Radeon RX 9060 XT (driver |
|
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). |
|
Correction to my comment above: the 0.36 s failure came from testing the PR head before current I merged current
The PR just needs a rebase onto current |
…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.
|
@triggered02 could you rebase this branch onto current GitHub reports head Files that conflict with current
Commands run locally: Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally. |
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".
ad94c95 to
83a7023
Compare
|
Rebased onto current All four commits replayed; none became empty and the messages are unchanged. Conflict resolutions (all three files, keeping
Verification on
Not verified locally, CI must: the new The One pre-existing thing I left alone because it is in the PR head and not a conflict: |
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".
83a7023 to
14a7a18
Compare
|
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. |
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.
|
@triggered02 @R0Y00 I pushed a fast-forward to What changed
Verification (Windows Server 2025 build 26100, MSVC 14.44, head 0ffbbde, default parallel): 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: 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. |
There was a problem hiding this comment.
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.
|
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. |
|
Independent retest of This replaces the
.\tools\startup\run.ps1 -Exe <run folder>\<title>.exe -DataDir <package root> -MapDrive "G=<package root>" `
-StoragePath <existing writable folder> -BuildDir <main release build> -ShaderCache <warm cache> `
-LogDir <log> -Seconds 180 -MemoryGiB 20 -Render -FakeUser -GpuMirror -ContinueAsserts 1000 -InputScript 4@70
The The Prepared with AI assistance (Claude Code). |
Implements the option proposed here.
A console executable opens its package at a fixed drive letter.
--map-drive LETTER=FOLDER[;...](orrun.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:
UNICODE_STRINGdoes not fit. When it does not, the launcher allocates the name in the target process and repoints theUNICODE_STRINGat it, leaving that allocation to the process (the caller may keep the name while its handle is open).\??\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:mapped ok, trace shows theMAPrewriteopen failed: 3)MAPline; left aloneMeasured on Windows 11 build 26200 with the
releasepreset;docs_links_check.pypasses and the option is documented indocs/startup-runtime.mdunder the run instructions, including both limits.