runtime: hold the unmapped window for the reader-without-retry control #1841
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1848"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-24T19:30:27Z.
Problem
xmem_shim_page_runsis flaky in its negative controlreader-without-retry:It failed once in a serial
mainrun (run 45421896173, Debug job 138545800299) and in the--parallel 4run discussed in #1173. The control needs a Python reader thread to read page 20 in the short window betweenUnmapViewOfFile2and the remap of the shared view insideXMemMapPhysicalPagesScatter. When the reader never lands there in 3 s, the child survives and the check fails.Refs #1173, #1306
Change
src/xmem_mapped_pages.cpp, test build only (#ifdef X2W_XMEM_TEST_CONTROLS): withX2W_XMEM_TEST_HOLD_WINDOW=<name>, an unmap that took a run apart sets the event<name>.unmapped, then waits up to 5 s for<name>.releasebefore mapping again. In the deployed shimhold_window()is empty.tests/xmem_page_runs_check.py: thereader-without-retrychild waits for<name>.unmappedwithout the GIL and reads the unmapped page, so the fault happens every time. If the hold never comes, the child says so and the parent fails with "the hold hook did not run" instead of "survived". The deployed-shim control now runs as ahold-ignoredchild with both variables set (still 3 s of toggling) and also checks that no unmap waited in the window.docs/startup-runtime.md: names the new test switch next toX2W_XMEM_NO_FAULT_RETRY.Not changed: the positive reader case (
reader_while_togglingwith the handler) still does not require an observed retry.Verification
Windows 11 Pro 26300.9974, MSVC 19.44.35230 x64, Python 3.12.0. CPU only.
One core:
cmd /c "start /wait /b /affinity 1 ctest --test-dir <build> --no-tests=error -R ^xmem_shim_page_runs$". Unconstrained:ctest --test-dir <build> --no-tests=error -R '^xmem_shim_page_runs$'.68969ed864e57c51dev)dev)/O2(release)/O2(release)Before the change, the one-core run with
--output-on-failureshows the assertion above; the other "before" runs did not capture output, and their failures end after about 5.3 s against about 9.4 s for a pass, as that one does. With thereader-without-retryline skipped, the rest of the check passed 3/3 on one core.A separate check of the same patch by a second reviewer on the earlier base
68969ed8(before the rebase and the docs/3 s change; counts from that reviewer's report, not re-run here): Debug and/O210/10 each on one core and unconstrained; 10/10 with four busy-loop processes; 5/5 on two cores;ctest -R '^xmem_' -E 'warp|hardware'22/22. Negative controls on modified copies:no fault ... reader survived;hold_window()call removed: fails in 12 s withthe hold hook did not run, no hang.Strings
X2W_XMEM_TEST_HOLD_WINDOW/x2w-xmem test hold: 0 inxmem.dll(Debug, Release), 1 each in the test-controls DLL.Device tests at
e6ac2d05, Debug,ctest --no-tests=error -R '^xmem_page_runs_device_(warp|hardware)$' -j1 -V:xmem_page_runs_device_warpPassed (0.13 s);xmem_page_runs_device_hardwarePassed (0.33 s) on NVIDIA GeForce RTX 3070 Ti (10de:2482), driver 32.0.16.2101 (621.01); 2/2, no skip. The log does not report the debug-layer state.The
prpreset does not runxmem_shim_page_runs, so the PR check will not exercise this change.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:38:25Z.
Review: COMMENTED
Review of
e6ac2d05a956b987e1bd16971d3c092580332827(runtime: hold the unmapped window for the reader-without-retry control), checked out at exactly that SHA. Verdict: no P1, no P2 found by reading. I could not run this change: it is Windows-only (named events,UnmapViewOfFile2, a second build of the shim), and this host is Linux.What the change does
In the test build only (
X2W_XMEM_TEST_CONTROLS; the#elsebranch is an empty function),hold_window()is called after the unmapped runs of a batch are recorded as gone and before they are mapped again. IfX2W_XMEM_TEST_HOLD_WINDOW=<name>is set it signals the manual-reset event<name>.unmappedand waits up to 5 s for<name>.release. The reader thread of the control waits for.unmapped, then reads a page of the run that is unmapped at that moment, so the read always lands in the window and, without the fault handler, ends in an access violation. Before, the control relied on the reader hitting the window by chance within three seconds.What I checked by reading
.unmappedis set, so the read cannot precede the unmap; if the shim's 5 s wait ends first, the reader's read could miss the window, but the reader is released only by the read and the wait is long compared with a thread wake-up. The release event is manual-reset and stays signalled after the first read, so later unmaps do not wait again.hold_window()on every path, with null checks (if (unmapped) CloseHandle, same forrelease). Nothing is stored. The Python side creates its two events once per child and exits.GetEnvironmentVariableAreturns a length at least the buffer size when the value is too long; the code refuses both zero and>= sizeof(name) - 16, so.unmapped/.releasealways fit in the 128-byte event name.hold_windowis an empty function withoutX2W_XMEM_TEST_CONTROLS. The new child modehold-ignoredruns the same reader against the deployed shim and assertsWaitForSingleObject(unmapped, 0) != 0, i.e. that nothing signalled;expect_access_violationnow fails if the child printednever held the window, so a missing hook cannot pass as an access violation. The markerchild: reader reads the unmapped pageis printed before the read, so a crash elsewhere before that point is not accepted.Commands run (Linux)
No mutations: the code under change cannot be built or run here, so I did not claim any. A useful pair for the Windows run: delete the
hold_window()call (the control must then fail withnever held the window) and move it before the unmap loop (the reader must then read a mapped page and the child must survive).P3
Local\\prefix would keep them out of other sessions' namespace on a shared machine (the name already contains the parent's pid).Limits
Not built, not run on Windows: please run
ctest -R xmem_shim_page_runs(or the CI Windows job) to confirm; my verdict rests on reading the code and the test.AI-assisted; commands listed were executed locally.