d3d12: a guard page fails a copy and stays a guard page (D3D12-GPU-SAFECOPY-GUARD-PAGE-REARM) #2709
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2709"
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 Kal0s-design on 2026-11-30T10:28:59Z.
Claimed in the coordination issue as: D3D12-GPU-SAFECOPY-GUARD-PAGE-REARM (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7275542541)
What and why
Title memory has guard pages: stack guards, and guards the title sets up itself. When a copy, put or merge of title memory (
safecopy, running under the write-catch handler inwatch.rs) touches one, it takesSTATUS_GUARD_PAGE_VIOLATION, and Windows clears the page's guard flag as it raises that. The handler sent every fault inside a copy to the copy's failing exit, whatever the code, and nothing set the flag again. The page stayed an ordinary page, so the title's own next touch of it no longer raised the guard fault the title set it up for: a stack that can't grow, or a guard the title waits on that never fires.The change:
rearm_guardchecks that the page is still committed and thatVirtualProtectsucceeds. If it can't re-arm, or the fault carried no address, it counts the case inNOT_REARMEDand logs the first one.This is a port of zocram4cc's fix and tests from the sibling VIctory tree (TaynanGT/Vice-Tay
fa11650andc277533, GPL-3.0), credited as co-author. In their traced runs, a lost guard was linked to silent exits a few minutes into the world under Proton. That link is their reading of a trace, not something reproduced here.Tested
safecopy::tests: a guard page in the source of a copy, and in the destination of a copy, a put and a merge. Each checks that the call fails and the page is still a guard page. Onmain(454df8e95) all four fail on native Windows ("the guard flag was consumed" / "...cleared the guard flag"); with the change they pass.watch::rearm_tests::a_page_that_cannot_be_guarded_again_is_counted: a committed page is guarded again, a decommitted one is not, and both that case and a fault with no address are counted.cargo test -p leonida-gpu --lib: 564 passed, 0 failed, 50 ignored.cargo clippy -p leonida-gpu --all-targets(with and without--all-features): no warning in the changed lines. The warningswatch.rsalready has are untouched.GPUs tested: n/a (CPU unit tests)
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T10:35:42Z.
Independent Wine verification. I merged
42b1f4ae4onto012b79a67(treefa6cddb25) and cross-built the stockleonida-gpulibrary tests forx86_64-pc-windows-msvcwith Rust 1.98.1 and xwin. Tested on CachyOS with Wine 11.22, both with and without thediagnosticsfeature.safecopy::tests::passed 11 tests in each build, including all four new guard-page cases. The existingcopy_costsbenchmark was ignored.watch::rearm_tests::passed in each build. The committed page was re-armed, and the two failure cases were counted.watch::tests::family, the diagnostics build had 33 passes and one failure on bothmainand the PR. The PR build without diagnostics had 30 passes and the same failure.what_is_left_alone_is_no_known_holefails at(0..3).all(known) == holes. I reproduced it in isolation on both trees, and the isolated case passed on both withLEONIDA_KNOWN_HOLES=0as a control.CPU tests using synthetic allocations. AI-assisted with OpenAI Codex.
Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-11-30T12:14:04Z.
Merged
main(d367675c7, all CI green there) into the branch, as MoonEyes asked on #2710 for the same two red checks: new head6a206d82c(merge commit, no rebase or force-push).cargo test -p leonida-gpu --libon the new head: 568 passed, 52 ignored, 0 failed. merzleckeier's Wine results are on the previous head42b1f4ae4; the PR's own change is unchanged.AI-assisted: yes
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T15:24:47Z.
Independent check on Windows (not the author), at
6a206d82c.cargo test --locked --jobs 8 -p leonida-gpu --lib -- --test-threads=8: 568 passed, 0 failed, 52 ignored in 15.6 s (build included separately).cargo build --locked --profile diag -p leonida --features diagnostics,mimalloc— succeeded in 2m 09s.The PR's diff adds no unit test (source-only in
safecopy.rs/watch.rs), so this is compile + regression coverage; the guard-page rearm behaviour itself needs a game run, which I did not do.Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, NVIDIA RTX 4070 Ti SUPER (driver 621.01), Rust 1.98.1 pinned.
AI-assisted: yes (opencode).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T03:16:28Z.
Verified on Windows, for a merge (not the author). AI-assisted (Claude Code agent
oreofr-agent). RTX 4070 Laptop 8 GB, NVIDIA 621.40, Core Ultra 7 155H, Windows 11 Pro, Rust 1.98.1 pinned,cargo test --locked.Head
6a206d82cmerged into currentmain90c514437(clean), tested in one batch with #2589, #2766, #2709 and #2802 (main + all four, merged in that order, clean).if falsein place of theSTATUS_GUARD_PAGE_VIOLATIONtest), the foursafecopyguard-page tests fail. Read in code:not_rearmedlogs from the vectored handler only on the first failure, and the faulting thread is inside a safe copy, not inside a log call, so it cannot hold the logger's lock there. The doc line "Whetheratis committed read-write memory now." now sits aboverearm_guardinstead ofwritable(watch.rs~4569), cosmetic. The mutation was reverted after the run.leonida-gpumain 589 passed / 0 failed, main + the four 598 / 0;leonida-hle242 / 0 on both.diagnostics,mimalloc, no DLSS), fresh copy of our gate data,-SeriesS -NoDlss -NoFrameGen, BAR 0, texture budget 1024, walking (keys file, 115 key changes): 330 s in the world, 0 device loss, 0 ERROR lines, no crash, clean close. Early stalls while ~169 pipelines were first made (as on main), then steady 21-23 fps (median of the last 30 fps lines 21.6), 24 GB private at the end.One run of several pull requests together covers each at its head (
docs/maintaining.md, #2797); if a merge of one of them breaksmain, the others are split out and re-run.Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-12-01T05:22:22Z.
Merging (after #2589, #2766). Head
6a206d82cmerges cleanly with main10bed9ff2(merge commit1fc92830b).Claim: in the description, a comment in #2570 by the author (checked).
Red/green: by oreofr-agent (not the author), RTX 4070 Laptop, Windows 11: red by mutation on this head (comment above). I ran on main
86c30fcea+ #2589, #2766, #2709, #2802 (this order):cargo test --locked -p leonida-gpu599 passed, 0 failed (main alone 590/0);-p leonida-hle242/0. An independent second check (separate agent) found no blocker.In-game run: RTX 4070 Laptop 8 GB, NVIDIA 621.40, the four together at their heads on
90c514437: 330 s in the world walking, 0 device loss, 0 ERROR lines; same-scene picture against main: no visible change. Since thenmainonly gained the two CI fixes (#2825, #2827: a test-module declaration and a tool's__main__), nothing that runs in the game. Default change with no switch: a guard page that stops a safe copy is guarded again (a revert undoes it). Note: GitHub's file list shows 13 files because of a stale base; the real diff is safecopy.rs and watch.rs.CI: green on the head (5/5) and on main (CI, No Game Data on
86c30fcea; Runtime last green oncd9fe51a9).AI-assisted: yes, Claude Code agent
oreofr-agent, merged on OreoFR's (maintainer) written instruction.