HLE: validate XMemMapPhysicalPages inputs before unmapping and roll back partial runs #2742

Open
github-bot wants to merge 1 commit from github-bot/gh-2742 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 19:26 UTC · original
fuzeofficlal:fix/hle-xmem-validate-before-unmap → main · +55 −2 · 1 files · 1 commits · open

Summary

Fix partial-mapping and destructive-failure behavior in crates/victory-hle/src/modules/xmem.rs::XMemMapPhysicalPages:

  • Previously, XMemMapPhysicalPages called unmap(&mut physical, base, n * PAGE) before resolving pages[0..n] in physical.pages, and returned null_mut() without cleaning up earlier runs if a later run hit an unknown page or a failed map() call.
  • Now, when pages is non-null, all contiguous (offset_pages, run_pages, Slice) runs are resolved before calling unmap, so an unknown page leaves existing mappings at [base, base + n * PAGE) intact.
  • If map() fails on a subsequent run (offset_pages > 0), the already-mapped prefix [base, base + offset_pages * PAGE) is unmapped before returning null_mut(), preventing half-mapped views from remaining in OS address space and physical.views/physical.shown.
  • Scoped strictly to XMemMapPhysicalPages (map_alias is untouched to stay orthogonal to #2199).

Tests

Added unknown_page_leaves_existing_mappings_intact and failed_second_run_rolls_back_first_run in crates/victory-hle/src/modules/xmem.rs.

Verification

  • cargo clippy --locked -p victory-hle --all-targets -- -D warnings and --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.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 19:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2742) `fuzeofficlal:fix/hle-xmem-validate-before-unmap` → `main` · +55 −2 · 1 files · 1 commits · open ## Summary Fix partial-mapping and destructive-failure behavior in `crates/victory-hle/src/modules/xmem.rs::XMemMapPhysicalPages`: - Previously, `XMemMapPhysicalPages` called `unmap(&mut physical, base, n * PAGE)` before resolving `pages[0..n]` in `physical.pages`, and returned `null_mut()` without cleaning up earlier runs if a later run hit an unknown page or a failed `map()` call. - Now, when `pages` is non-null, all contiguous `(offset_pages, run_pages, Slice)` runs are resolved before calling `unmap`, so an unknown page leaves existing mappings at `[base, base + n * PAGE)` intact. - If `map()` fails on a subsequent run (`offset_pages > 0`), the already-mapped prefix `[base, base + offset_pages * PAGE)` is unmapped before returning `null_mut()`, preventing half-mapped views from remaining in OS address space and `physical.views`/`physical.shown`. - Scoped strictly to `XMemMapPhysicalPages` (`map_alias` is untouched to stay orthogonal to #2199). ## Tests Added `unknown_page_leaves_existing_mappings_intact` and `failed_second_run_rolls_back_first_run` in `crates/victory-hle/src/modules/xmem.rs`. ## Verification - `cargo clippy --locked -p victory-hle --all-targets -- -D warnings` and `--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.
XMemMapPhysicalPages maps consecutive page runs one view at a time after unmapping the requested range. If a later run fails (unknown page or host map failure), previously mapped runs in the same call were left mapped in physical.views/physical.shown and the process address space. Unmap any runs mapped earlier in the call before returning null, and document the unmapped failure state.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:13:13 +00:00
Author
Owner

@⁠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.

**@⁠kotekompotek** on GitHub · 2026-11-25 20:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2742#issuecomment-7173208232) 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.
Author
Owner

@⁠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=1 and VICTORY_D3D12_WARP=1 set (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 of origin/main (merge-base = origin/main, so no temporary merge was needed).

Commands/results:

  • Baseline (origin/main): 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.
  • PR: cargo test --locked -p victory-hle --lib unknown_page_leaves and failed_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.
  • Negative controls (new tests kept, production change reverted in two parts, each restored afterwards, tree clean): (a) unmap moved back before the page validation (pre-PR order) -> unknown_page_leaves_existing_mappings_intact FAILED, 12 passed / 1 failed in modules::xmem::tests::; (b) partial-run rollback removed -> failed_second_run_rolls_back_first_run FAILED, 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).

**@⁠oni-swr** on GitHub · 2026-11-25 20:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2742#issuecomment-7173408390) Independent WARP/CPU verification for head 24ecb89dc9868cfe051d64c11aa3276fdd50476e against origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca. 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=1` and `VICTORY_D3D12_WARP=1` set (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 of `origin/main` (merge-base = `origin/main`, so no temporary merge was needed). Commands/results: - Baseline (origin/main): `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. - PR: `cargo test --locked -p victory-hle --lib unknown_page_leaves` and `failed_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. - Negative controls (new tests kept, production change reverted in two parts, each restored afterwards, tree clean): (a) unmap moved back before the page validation (pre-PR order) -> `unknown_page_leaves_existing_mappings_intact` FAILED, 12 passed / 1 failed in `modules::xmem::tests::`; (b) partial-run rollback removed -> `failed_second_run_rolls_back_first_run` FAILED, 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).
Author
Owner

@⁠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. XMemMapPhysicalPages in crates/victory-hle/src/modules/xmem.rs now keeps main's order (unmap the range first) and only adds the rollback: when a later run fails, on an unknown page or a host map failure, the runs mapped earlier in the same call are unmapped again, so physical.views/shown match the address space and the documented outcome (range unmapped, null returned) holds in both failure cases. The doc comment now says that, and failed_second_run_rolls_back_first_run covers the host-failure path. No change to what the title sees on success. It merges cleanly and CI check is passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2742#issuecomment-7177515196) · edited 2026-11-26 02:16 UTC <!-- victory-triage v1 head=284f50f247f22d490bae691240bce56b733967a7 verdict=merge-candidate at=2026-11-26T02:16:55Z --> Automated triage for the maintainers. **Merge candidate** (recommending a look, not an approval). Thanks for scoping it down. `XMemMapPhysicalPages` in `crates/victory-hle/src/modules/xmem.rs` now keeps `main`'s order (unmap the range first) and only adds the rollback: when a later run fails, on an unknown page or a host `map` failure, the runs mapped earlier in the same call are unmapped again, so `physical.views`/`shown` match the address space and the documented outcome (range unmapped, null returned) holds in both failure cases. The doc comment now says that, and `failed_second_run_rolls_back_first_run` covers the host-failure path. No change to what the title sees on success. It merges cleanly and CI `check` is passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 23:33 UTC · original

Rebased onto origin/main (842b0cb) and scoped down in 284f50f2 per triage feedback:

  • Removed the pre-unmap page validation change (keeping unmap(&mut physical, base, n * PAGE) up front, matching main) and dropped unknown_page_leaves_existing_mappings_intact.
  • Kept only the partial-run rollback (unmap(&mut physical, base, i * PAGE) if a later run fails on either an unknown page or a host map failure) with failed_second_run_rolls_back_first_run.
  • Updated the XMemMapPhysicalPages doc 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 + fidelityfx 1/1 + no_dll_planting 1/1), cargo clippy --locked -p victory-hle --all-targets -- -D warnings, and cargo xtask policy (191 files ok).

**@⁠fuzeofficlal** on GitHub · 2026-11-25 23:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2742#issuecomment-7177721501) Rebased onto `origin/main` (`842b0cb`) and scoped down in `284f50f2` per triage feedback: - Removed the pre-unmap page validation change (keeping `unmap(&mut physical, base, n * PAGE)` up front, matching `main`) and dropped `unknown_page_leaves_existing_mappings_intact`. - Kept only the partial-run rollback (`unmap(&mut physical, base, i * PAGE)` if a later run fails on either an unknown page or a host `map` failure) with `failed_second_run_rolls_back_first_run`. - Updated the `XMemMapPhysicalPages` doc 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 + `fidelityfx` 1/1 + `no_dll_planting` 1/1), `cargo clippy --locked -p victory-hle --all-targets -- -D warnings`, and `cargo xtask policy` (`191 files ok`).
Author
Owner

@⁠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 new failed_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).

**@⁠Dukestar69** on GitHub · 2026-11-26 04:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2742#pullrequestreview-6068723822) · **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 new `failed_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).
Author
Owner

@⁠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 base 842b0cb).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo 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.
  • The new tests ran and passed: failed_second_run_rolls_back_first_run.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#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_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-26 13:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2742#issuecomment-7193138567) 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 base `842b0cb`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo 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**. - The new tests ran and passed: `failed_second_run_rolls_back_first_run`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#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_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2742/head:github-bot/gh-2742'
git switch 'github-bot/gh-2742'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2742'
git switch 'github-bot/gh-2742'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2742'
git switch 'github-bot/gh-2742'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2742'
git switch 'main'
git merge --squash 'github-bot/gh-2742'
git switch 'main'
git merge --ff-only 'github-bot/gh-2742'
git switch 'main'
git merge 'github-bot/gh-2742'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2742
No description provided.