HLE: Preserve xmem bookkeeping when unmapping fails #3526
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!3526
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3526"
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?
@GaussianGuaicai on GitHub · 2026-11-27 14:20 UTC · original
GaussianGuaicai:fix/xmem-unmap-bookkeeping→main· +85 −23 · 1 files · 2 commits · openSummary
Keep the tracked view, alias records, and GPU mapping state intact when
UnmapViewOfFile2fails. Only update those records after the OS releases the view, and return failure fromXMemMapPhysicalPagesormap_aliasrather than proceeding. Also return failure if a view outside the requested range cannot be restored. Earlier successful changes in a multi-view request are not rolled back.This addresses the OS unmap failure path, separate from the input validation and mapping rollback in #2742. It is not a verified fix for any VM bugcheck.
Tests
cargo test -p victory-hle --lib --profile diag --locked --offline modules::xmem::passed: 15 passed, 0 failed, 0 ignored.AI-assisted with GitHub Copilot.
@oni-swr on GitHub · 2026-11-27 14:47 UTC · original
Independent CPU-only verification (no physical GPU, no game, no game data). AI use: Claude Code (Claude Sonnet 5.5).
Environment: AMD Ryzen 7 5700X3D 8C/16T, Windows 11 25H2 build 10.0.26200, rustc 1.98.1 (48a229cea 2026-09-01),
-j 4, one shared target dir.SHAs: head
240291893ce9c07777dc8d7db7f5478c6471068f(unchanged when I started and when I posted), merge base63bcca43c6a00a758510398fa43096ce7e4f7df0(current main tip).victory-hle --lib --lockedmodules::xmem::failed_unmap_preserves_view_and_alias_bookkeepingok)No regressions. The PR has no other comments, so nothing to duplicate.
Diff read (no blocking issue found):
unmap_withcalls the OS unmap first (xmem.rs:995) and only then removes the view fromviews/shownand callstitle_memory_remapped, so a failedUnmapViewOfFile2leaves the records untouched.XMemMapPhysicalPages(:709) andmap_alias(:778) now return failure instead of proceeding.title_memory_remapped(at, size)(:1009) now runs after the OS unmap instead of before it. Looks harmless, but it is a small ordering change on the default path.:1010-1017): if the re-map of a part outside the requested range fails, the view is already unmapped and already removed from the records, so records and OS state still agree (that range is left as a placeholder). The right-hand restore is still attempted when the left one fails. But the loop then stops, so later views in the range stay mapped and the call returns failure with the range part-unmapped. The doc comment says so ("does not undo earlier changes"). Callers get null and may treat the old mapping as intact.unmap_with. The realUnmapViewOfFile2wrapper'sErrpath and the "outside the requested range restore fails" return are not exercised.Verified on CPU only; not a statement about VM bugchecks.
@cloph-dsp on GitHub · 2026-11-27 15:13 UTC · original
Independent CPU-only verification on Windows / Rust 1.100.0 / MSVC.
240291893ce9c07777dc8d7db7f5478c6471068f, merge base63bcca43c6a00a758510398fa43096ce7e4f7df0.cargo test --locked -p victory-hle --lib -- modules::xmem::tests::failed_unmap_preserves_view_and_alias_bookkeeping --exact --test-threads=1 --quiettest result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 152 filtered out, exit 0.git grep -F -c failed_unmap_preserves_view_and_alias_bookkeeping 63bcca43 -- .→ exit 1 / 0 hits (test genuinely new); present on PR head.git diff --check 63bcca43 HEAD→ exit 0.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.