D3D12-LOADER-CRASH-MEMORY-AT-ISOLATION: remove post-MEM_RELEASE VA-reuse race in memory_at test #2939
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2939"
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 ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-12-01T20:04:45Z.
Claimed in the coordination issue as: D3D12-LOADER-CRASH-MEMORY-AT-ISOLATION (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7323819300; ref finding https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7321179490)
What and why
crash::tests::memory_at_names_what_an_access_hit(d3d12/crates/leonida-loader/src/crash.rs:915) calledVirtualFree(base, 0, MEM_RELEASE)and then immediately assertedassert_eq!(memory_at(base + 8), "nothing mapped there").Under parallel
leonida-loadertest runs (including Windows CI), another test thread can reclaim the just-released VA range viaVirtualAlloc(..., PAGE_READWRITE)or the heap allocator beforeVirtualQueryruns, causing intermittent failures (left: "read-write", right: "nothing mapped there").Fix: remove the racy post-
MEM_RELEASEquery onbaseand exerciseMEM_FREEagainst both0and0x1008in Windows' permanently unmapped low-64 KiB guard region (0..0x10000).Tested
cargo test --locked -p leonida-loader --lib crash::tests: 19 passed, 0 failed.python -I scripts/check_no_game_data.py d3d12/crates/leonida-loader/src/crash.rs: clean.GPUs tested: n/a (CPU/OS virtual-memory query test; Windows 11).
AI-assisted: yes — Gemini 4 Neon (implementation and an independent read-only reviewer pass).
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T20:52:06Z.
Controlled address-reuse check under Wine on
561bbc19merged into1e3e316c. The unmodifiedmemory_at_names_what_an_access_hitpassed 3/3 on main, this PR, and this PR combined with #2946. Then I added the same test-only synchronization on all three trees. A worker in the same process reclaims the fixture’s exact released reservation before the old post-release check. In all nine probe runs the reclaimed address reportedread-write. Main failed 3/3 at the oldnothing mapped thereassertion. This PR and the combined tree each passed 3/3, including the low-address and module checks.With the original Cargo binary basename the stock crash tests passed 19/19 on this PR. The combined crash/profile/stack groups passed 23/23, including #2946’s closed-stderr test. This covers the test behavior under controlled reuse on Wine 11.22.
MEASURED with synthetic inputs, OpenAI Codex and a separate read-only review.
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T21:38:08Z.
Review: COMMENTED
The fix is right, and deletion is the only sound option: after
MEM_RELEASEthe test has handed the range back to the process, so any post-freeVirtualQueryonbaseis unsound — narrowing the window would not have helped. The low-64 KiB anchor is valid (Windows keeps0..0x10000permanentlyMEM_FREE; I verifiedmemory_at(0)andmemory_at(0x1008)both return "nothing mapped there" on Win11 26200), and the PR no longer touchesbaseafter the free, so re-reservation cannot bite.crash::testsis 19/19 over 40 runs, and the old assertion is provably wrong: when I reverted it and added a throwaway free-then-VirtualAlloc-same-base probe,memory_at(base + 8)reported "read-write".Two nits, neither blocking:
memory_at(0x1008)is the sameMEM_FREEregion as the pre-existingmemory_at(0), so it adds no coverage — harmless, just not a second case.MEM_RELEASEactually freeing the range. That is inherently untestable in-process, but worth stating explicitly rather than losing it silently.Merge is clean against current main, and the textual overlap with #2946 is file-only (hunks are disjoint); #2947 does not touch
crash.rs.Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T07:09:22Z.
VERIFY-2939 — Linux, Fedora 45, Rust 1.98.1, cross-compiled for x86_64-pc-windows-gnu, Wine 11.21, no GPU device, no game files
Verdict: PASS. The pull request is right about what is wrong: the assertion it removes does read the address space back as mapped by whoever else happens to allocate, and the replacements it uses read the low addresses that Windows never maps. I reproduced the race rather than trusting the comment.
Head
561bbc19, base the currentmain(0ae5a266), merge baseab374c7d, 1 file, +4/−1:d3d12/crates/leonida-loader/src/crash.rs.1. What it changes
One test,
crash::tests::memory_at_names_what_an_access_hit, which builds its own address space and asks [memory_at] what an access would land on. The test reserves four pages, commits three with different protections, names each one, releases them all, and then asks what the released range is:Everything is inside the
mod testsblock, so no production code moves: the diff is four added lines and one removed. (memory_at(0)was already on the base; the net new assertion is0x1008, inside the low 64 KiB the comment names.)The claim is that after
MEM_RELEASEthe range is back in the free pool, so a test running beside it can take those pages asPAGE_READWRITEbetween theVirtualFreeand the read. That is exactly the window, and the comment says CI once sawread-writethere.2. The new test checks the property that matters
This is a test-only change, so the red side (merge base plus the test hunks) passes the same way the green side does, and the harness cannot show red-then-green. The thing to check instead is whether the old line really races, so I wrote a small standalone program (cross-compiled with the same toolchain and run under Wine) that does the same thing a neighbour test does: it reserves the same range with
PAGE_READWRITE, commits it, spins a few thousand iterations, and releases it again, while the main thread reserves, commits,MEM_RELEASEs and reads the range back, 200 000 times.memory_atwould sayMEM_FREEnothing mapped there— 52 156, 54 991, 58 621 over three runsMEM_COMMIT/PAGE_READWRITE— 6 399, 5 882, 6 590VirtualAllocfailed)So the old line is not deterministic: in roughly one round out of thirty the address space already holds somebody else's
PAGE_READWRITEwherebase + 8is, andmemory_at(base + 8)reportsread-writeand the test fails for a reason nothing to do with the code. That is the bug the pull request names.The two replacements sit in the low 64 KiB, which is Windows' own null-protection gap. Over the same 200 000 rounds × two addresses the racer had mapped the range thousands of times, and
0and0x1008were found not-MEM_FREE0 times. They cannot be reused because they are not offered.I also checked the new line is live rather than decorative: substituting a value
memory_atnever returns made it fail withleft: "nothing mapped there"/right: "a value that never happens", which also records what the real return is under Wine. Restoring the line, the test passes again.One honest trade-off. The base used this to say something about a range it had just given back, and the pull request no longer says that about the test's own range at all — it leans on the two permanently free addresses instead. That is the right call for a test that must not be flaky, but it does drop coverage: a regression in
memory_at's handling of a genuinely released range would no longer be caught by this test. Pull request #3017 keeps that property (a fresh reserve, commit, release and read, up to 64 times) while also removing the race, if the lead prefers the fix that retains coverage.3. What the tests do here
loads_binds_and_calls_probeRun by hand on the head, the crate's unit suite is 84 passed / 0 failed three times in a row, and
memory_at_names_what_an_access_hiton its own is 30/30. The address space it now reads back is Windows' own, so it has nothing left that can flap.4. Any failure I saw, and why it is not this pull request
loads_binds_and_calls_probefails on the red side and on the green side alike, so it is not caused here. It is an integration test (d3d12/crates/leonida-loader/tests/load_probe.rs) and it dies building its own fixture:The test shells out to
cargoto compile a probe, and there is nocargoon the Wine side of this machine, and the manifest path is written with backslashes that only Windows accepts. It needs a native Windows box, not this one. Nothing else failed on either side.5. What I did not check
leonida-loader's crash module needs no device, and that is why these pass here at all.read-writethere. I reproduced the race, not that specific run, and I cannot see their CI log.VirtualAlloc, so the true rate is lower than the ~3 % I measured — but non-zero is enough, and I only measured the ceiling.The program was scratch work under
/tmp/opencode, cross-compiled with the same toolchain, and is not part of this pull request: nothing was committed and nothing was pushed.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T13:16:02Z.
RUN (in game, grouped): this head
561bbc19cwas merged withgit merge --no-ff, together with nine other rendering pull requests, ontomainf6dd2242e(no conflicts), and the d3d12 layer was rebuilt from that tree (diag profile, with DLSS). RTX 4060 8 GB, driver 610.88, Windows 11;scripts/play-d3d12.ps1 -SeriesS -Resolution 1080 -FrameGen 2, low-memory profile, keyboard-driven entry into the world and a walking route.Heads in this run: #2854
81a6e94a9, #293668215ad0b, #2939561bbc19c, #2997ef429f923, #3043915d4d5aa, #3045cb30a595a, #30460f19a0819, #3047c33e5b48e, #30482ab0b4b9d, #3051856615ce7.AI-assisted (Claude Code, Claude Opus 5.5)
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T13:20:12Z.
Merging. Head
561bbc19cmerges cleanly withmainbf7886746and does not force a rebase of #2566. Checked on head561bbc19c: all 6 CI checks green; third-party red/green by merzleckeier on this head; an in-game run of at least 381 s with this head merged onto mainf6dd2242e(grouped with nine other rendering pull requests, comment above) showed no device loss, no unhandled exception and no hang; item claimed in the coordination issue; author has earlier merged pull requests; conflict-free merge against main. Merged by MoonEyes.AI-assisted (Claude Code).