HLE: validate XMemMapPhysicalPages inputs before unmapping and roll back partial runs #2742
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!2742
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2742"
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?
@fuzeofficlal on GitHub · 2026-11-25 19:26 UTC · original
fuzeofficlal:fix/hle-xmem-validate-before-unmap→main· +55 −2 · 1 files · 1 commits · openSummary
Fix partial-mapping and destructive-failure behavior in
crates/victory-hle/src/modules/xmem.rs::XMemMapPhysicalPages:XMemMapPhysicalPagescalledunmap(&mut physical, base, n * PAGE)before resolvingpages[0..n]inphysical.pages, and returnednull_mut()without cleaning up earlier runs if a later run hit an unknown page or a failedmap()call.pagesis non-null, all contiguous(offset_pages, run_pages, Slice)runs are resolved before callingunmap, so an unknown page leaves existing mappings at[base, base + n * PAGE)intact.map()fails on a subsequent run (offset_pages > 0), the already-mapped prefix[base, base + offset_pages * PAGE)is unmapped before returningnull_mut(), preventing half-mapped views from remaining in OS address space andphysical.views/physical.shown.XMemMapPhysicalPages(map_aliasis untouched to stay orthogonal to #2199).Tests
Added
unknown_page_leaves_existing_mappings_intactandfailed_second_run_rolls_back_first_runincrates/victory-hle/src/modules/xmem.rs.Verification
cargo clippy --locked -p victory-hle --all-targets -- -D warningsand--all-features: 0 warnings.cargo test --locked -p victory-hle --lib modules::xmem(3 consecutive runs): all passed.cargo test --locked -p victory-hle --lib: 148 passed, 0 failed.cargo xtask policy: 184 files ok.@kotekompotek on GitHub · 2026-11-25 20:06 UTC · original
Correct ordering: collecting (run, first) before unmapping means an unknown page now fails the call with existing mappings intact (previously unmap had already destroyed them). The rollback unmaps only offset_pages > 0 of completed runs - a failed first run leaves nothing to undo. Tests exercise both the intact-mapping and partial-rollback paths.
@oni-swr on GitHub · 2026-11-25 20:15 UTC · original
Independent WARP/CPU verification for head 24ecb89dc9868cfe051d64c11aa3276fdd50476e against origin/main
13f91caee2. State check at start and again before posting: open, non-draft, mergeable, head unchanged; no prior oni-swr comment.Environment: Windows 11 x64, Rust 1.98.1 (48a229cea 2026-09-01), cargo 1.98.1, Windows SDK dxil.dll 10.0.26100.0 (file version 1.8.2502.11).
VICTORY_WARP=1andVICTORY_D3D12_WARP=1set (WARP only, no physical GPU); no game files.CARGO_TARGET_DIR=D:\victory-warp-2741-target. Tested commit: the PR head itself, which is exactly one commit on top oforigin/main(merge-base =origin/main, so no temporary merge was needed).Commands/results:
cargo test --locked -p victory-hle— lib 146 passed, 0 failed; other binaries pass.cargo clippy --locked -p victory-hle --all-targets -- -D warnings— pass.cargo test --locked -p victory-hle --lib unknown_page_leavesandfailed_second_run— 1/1 each passed.cargo test --locked -p victory-hle— lib 148 passed (+2), 0 failed, 0 ignored; other binaries pass.cargo clippy --locked -p victory-hle --all-targets -- -D warnings— pass.unknown_page_leaves_existing_mappings_intactFAILED, 12 passed / 1 failed inmodules::xmem::tests::; (b) partial-run rollback removed ->failed_second_run_rolls_back_first_runFAILED, 12 passed / 1 failed.Review: no blocker found. Validation of every page now runs before anything is unmapped, so an unknown page leaves the previous mapping untouched, and a host failure while mapping run k unmaps the runs already mapped. One scope note (not a defect): the rollback only removes the new partial runs; the previous mapping is unmapped before mapping begins and is not restored if the host fails, so the doc comment's "or the host fails" is not covered by the same guarantee as the unknown-page case. The second test builds its host failure with a released placeholder page at a high address, which worked here and passed in the full run.
Not tested: physical GPU, retail title/game behavior, release build (debug profile only).
AI disclosure: Claude Code (Claude Sonnet 5.5).
@Marvisak on GitHub · 2026-11-25 23:24 UTC · original · edited 2026-11-26 02:16 UTC
Automated triage for the maintainers.
Merge candidate (recommending a look, not an approval). Thanks for scoping it down.
XMemMapPhysicalPagesincrates/victory-hle/src/modules/xmem.rsnow keepsmain's order (unmap the range first) and only adds the rollback: when a later run fails, on an unknown page or a hostmapfailure, the runs mapped earlier in the same call are unmapped again, sophysical.views/shownmatch the address space and the documented outcome (range unmapped, null returned) holds in both failure cases. The doc comment now says that, andfailed_second_run_rolls_back_first_runcovers the host-failure path. No change to what the title sees on success. It merges cleanly and CIcheckis passing.Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-25 23:33 UTC · original
Rebased onto
origin/main(842b0cb) and scoped down in284f50f2per triage feedback:unmap(&mut physical, base, n * PAGE)up front, matchingmain) and droppedunknown_page_leaves_existing_mappings_intact.unmap(&mut physical, base, i * PAGE)if a later run fails on either an unknown page or a hostmapfailure) withfailed_second_run_rolls_back_first_run.XMemMapPhysicalPagesdoc comment to state explicitly that failure leaves the range unmapped after rolling back any runs mapped during the call.Verified on Windows 11:
cargo test --locked -p victory-hle(153/153 unit +fidelityfx1/1 +no_dll_planting1/1),cargo clippy --locked -p victory-hle --all-targets -- -D warnings, andcargo xtask policy(191 files ok).@Dukestar69 on GitHub · 2026-11-26 04:52 UTC · original · approved these changes
Tested merged onto
origin/main(63bcca4) on Windows 11 x64:cargo test -p victory-hle --lib modules::xmem::: 15 passed, 0 failed (including newfailed_second_run_rolls_back_first_run).cargo clippy -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@futurepro62 on GitHub · 2026-11-26 13:17 UTC · original
NVIDIA full-suite run, to go with the reports above by Dukestar69, oni-swr, since none of them names a GPU run. Tested exact head
284f50f(on its base842b0cb).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.failed_second_run_rolls_back_first_run.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
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.