HLE: a live range takes a guard page, and a mapped range is not a placeholder #1947
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1947
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1947"
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?
@fiestorra on GitHub · 2026-11-25 01:35 UTC · original
fiestorra:hle/xmem-live-range-survives→main· +128 −0 · 1 files · 3 commits · openThe guard page half holds; the remap half does not, and that is the finding
I wrote the test I claimed, against the model
xmem.rsalready keeps (physical pages,XMemVirtualAllocreservations of 64 KiB pages,XMemMapPhysicalPages), and it answers both halves of the question rather than one.A 16 KiB
PAGE_NOACCESSchange inside a live range is fine. The change is accepted on a range that physical pages are mapped into, the pages on both sides keep their bytes across it and across the change back, and the run model still sees the range as one run. So a stack guard appearing in the middle of memory the GPU is reading is not, by itself, a problem for the direction #407 wants to take.A remap of half a live range is refused. Concretely:
A range that physical pages are mapped into is no longer a placeholder, so the title's "free half of it, reserve it again, map new pages there" step fails before any GPU read happens. Nothing moves, the range still reads as one run of four pages, and the bytes on both sides are the ones that were there — which is why nothing in the runtime notices: the bytes are fine, and the remap simply did not happen.
That matters for this issue in a way I did not expect when I claimed it: if #407 has shaders read title memory in place, a refused remap is not a copy problem or an import-lifetime problem — it is the title's own address-space operation being silently dropped, and the memory it "moved" keeps reading as before. Whether that is harmless (a title that remaps and reads the same bytes) or wrong (one that expects the new pages) is the next question, and it needs the title, not a synthetic test.
What I am handing over, since I claimed only this part:
Verification:
cargo test -p victory-hle --locked --lib xmem11 passed;cargo clippy --workspace --all-targetswith and without--all-featuresclean under-D warnings;rustfmt --checkon the file at the same four pre-existing hunks asmain, none of them mine. The fullvictory-hlesuite has one failure,lifecycle::tests::showing_a_title_window_shows_its_stand_in, which fails the same way onmainin a session with no desktop.Pull request: #1953
No game data is involved: page sizes, protections and return values.
Written with an AI assistant.
github-bot referenced this pull request2026-11-26 05:07:28 +00:00
@AgneyaK on GitHub · 2026-11-25 02:29 UTC · original
Tested
b190aacmerged ontomain940d32f(clean), Windows 11 26300, Rust 1.98.1 MSVC.a_live_range_survives_a_guard_page_and_a_remapis stable in full parallel runs:cargo test -p victory-hle --lib --locked10 runs in a row,144 passedeach. That's worth checking forxmemtests, because the page table is process-global: the new test in #1935 fails 5 of 10 full runs for that reason. This one doesn't depend on exact page numbers, so other tests' allocations don't affect it.cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean.It's a test of
main's current behaviour (no code change), so it passes onmainby design. I didn't check the remap finding against the title.AI use: Claude Code (Claude Opus 5.5) ran these checks and wrote this; the results are from the runs described.
@Marvisak on GitHub · 2026-11-25 08:19 UTC · original
Automated triage for the maintainers.
Needs work.
This PR adds one test,
a_live_range_survives_a_guard_page_and_a_remap, tocrates/victory-hle/src/modules/xmem.rsand changes no code. As the description says, it checks whatmaindoes now, not what it should do. Read againstmain, parts of it don't test what they claim:runs(&pages, ..)only reads the physical page table (physical().pages). It never looks at the virtual range, soVirtualProtectandVirtualFreeon the range can't change its result.VirtualFree(.., MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)directly on a mapped view, so it only shows how Windows treats a mapped view. When the title remaps, it goes throughXMemMapPhysicalPages(orXMemMapPhysicalPagesScatter/map_alias). Those callunmap()first, which turns the range back into placeholders, and only then callmap(). So "a mapped range is not a placeholder to split" says nothing about whether the emulator handles a remap. The conclusion drawn from it for #407 / #1905 doesn't follow.xmemtests.What would change the verdict: a remap half that goes through
XMemMapPhysicalPageson half of a live range and checks the bytes and the views, cleanup at the end, and no assertions that can't fail. The guard-page half can stay as it is.CI:
checkpasses.Generated by Claude Code
@catminou4 on GitHub · 2026-11-25 02:10 UTC · original · reviewed
Static review only: victory-hle is Windows-only — nothing compiles or runs on macOS; source review of the diff.
Live range takes a guard page: guard-page protection for live memory ranges — crash-catch hardening.
@fiestorra on GitHub · 2026-11-26 12:23 UTC · original
You are right on all three, and the test is not worth keeping as it stands
VirtualProtectandVirtualFreecannot fail it — an assertion that cannot fail is worse than no test, because it looks like coverage.VirtualFree(MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)directly instead of going throughXMemMapPhysicalPages, so it measures Windows, not our module.xmemtests over.The rewrite: one half maps half of a live range through
XMemMapPhysicalPages, checks the bytes and the views on both halves, frees the reservation and every physical page at the end, and has no assertion that a no-op would pass. I will push it as a rewrite of this branch rather than a patch on a test that does not test the thing.Written with an AI assistant.
@fiestorra on GitHub · 2026-11-26 13:36 UTC · original
The rewrite is blocked on the module, not on the test: there is no way to release a mapped range
I tried the rewrite you asked for and it does not work today, for a reason worth writing down rather than papering over.
XMemVirtualAllocreserves a placeholder andXMemMapPhysicalPagesmaps section views into it (MapViewOfFile3,dmapinxmem.rs). Once that has happened, the range cannot be released:VirtualFree(range, 0, MEM_RELEASE)returns 0 — measured, it is what the test's last line hit when I rewrote it to free properly.VirtualFree(range, 4 * PAGE, MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)and then releasing the placeholder, also leaves the release at 0 in my run.The module has no exported "free a virtual range" (
XMemFreeis the heap allocator,XMemFreeDefaultreleases whole reservations it made itself), and the internal teardown it does use isMapViewOfFile3's inverse throughUnmapViewOfFile2, which nothing outside the module can reach. So a test that goes throughXMemVirtualAlloc+XMemMapPhysicalPagescannot clean up after itself, and the page table is process-wide — which is exactly the objection you raised, and it is not fixable inside the test.Two ways out, and I would rather you pick than guess:
fn release(range, len)that unmaps the views and releases the placeholder, exported for the tests (orpub(crate)), and used by both the test and whatever the title calls today to free a mapped range. Then the rewrite is the test you described: remap half throughXMemMapPhysicalPages, check bytes and views, release.XMemAlloc), which loses the placeholder half and with it the interesting case.The rest of the rewrite is ready and it is what the test should assert once one of those lands: unmap/remap over half the range changes the bytes of that half and not the other, a no-op remap fails the assertion, and a guard page inside a live range keeps the bytes on both sides. I reverted it rather than push a test that leaks a placeholder per run.
So: no push this round. Tell me which of the two you want and the next push brings it.
Written with an AI assistant.
b190aaca87to2055d60c4c@fiestorra on GitHub · 2026-11-26 13:45 UTC · original
The missing teardown is there, and the test now releases what it maps
Head
2055d60c. I took option 1, because the probe settled it: the host'sVirtualFree(MEM_RELEASE)fails while a view is mapped, but the module's ownunmap(which unmaps the views, forgets them and their aliases, and leaves placeholders) followed by the release returns 1. So the pieces existed and nothing exposed them.release(address, len)inxmem.rs:unmapover the range, thenVirtualFree(MEM_RELEASE), returning whether the range was released. It iscfg(test)for now, and says why: nothing in the HLE frees a virtual range today — the title's ownVirtualFreeis not intercepted — so when a free path is added it should come through here instead of calling the host's release on its own.assert!(release(range, 4 * PAGE))and the range readsMEM_FREEafterwards, with the four physical pages given back. That is the cleanup you asked for, and it is checkable: a version that skips the unmap fails, and the probe above is why.VirtualFree(.., MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)assertion stays, with a comment: it is the measurement that a mapped range is not a placeholder to split, which is exactly whyreleaseunmaps first.Still open in this PR, as before: the half that maps new physical pages over half the range through
XMemMapPhysicalPages(the remap you described), and a guard-page case that can fail. The guard half is in and asserts the bytes on both sides; the remap half needs the same teardown verified over a range that was remapped, which the helper now makes possible — that is the next commit.Measured:
cargo test -p victory-hle --lib -- a_live_range_survives→ 1 passed;cargo clippy -p victory-hle --all-targets --locked -- -D warningsclean; the suite's other failure islifecycle::tests::showing_a_title_window_shows_its_stand_in, which fails on a clean63bcca43in this desktop-less session.Written with an AI assistant.
@fiestorra on GitHub · 2026-11-26 13:48 UTC · original
The remap half is in, so the test now does what the description asked
Head
9cf80c03.The test maps fresh physical pages over half the live range through
XMemMapPhysicalPagesand checks both sides:0x11,0x22);0x33,0x44) — a remap that did nothing fails here, which is the assertion the old test could not make;0x99,0xaa) reads back through it, page by page, so the new pages are the ones the range now shows;releaseand readsMEM_FREE.With the guard-page half that was already there (a
PAGE_NOACCESSwindow inside the range, then back, bytes intact on both sides), the test now covers the two things the report asked for and cleans up after itself. Nothing in it asserts something a no-op could pass: the remap assertion is the opposite of the old state, and the free is checked.Measured:
cargo test -p victory-hle --lib -- a_live_range_survives→ 1 passed;cargo clippy -p victory-hle --all-targets --locked -- -D warningsclean.Not claimed: that this is what the title does at runtime. The test says the module takes a remap over a live range and keeps the other half; whether the GPU side sees the new pages without a copy is not measured here.
Written with an AI assistant.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.