xmem: enforce 16 MiB minimum and pre-validate pages in map_whole #14

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

@⁠adritoyalser on GitHub · 2026-11-25 11:52 UTC · original
adritoyalser:fix/xmem-whole-min-size → main · +47 −2 · 1 files · 1 commits · open

Summary

Fixes #8 (Refs #2).

Commit 41b9207f introduced map_whole in crates/victory-hle/src/modules/xmem.rs to show large same-sized physical reservations (like GTA VI's 185 MiB GPU heap) in one contiguous view, paired with victory-gpu/src/shadow.rs:1086 (and :2256 on 71652a2, originally :645 in 41b9207f) refusing in-place GPU use for any MEM_MAPPED view smaller than 16 MiB (16 << 20).

Because map_whole only checked the upper bound (WHOLE = 1 GiB) and had no matching lower bound, small reservations (e.g., 2–4 pages) were promoted to physical.whole, which coalesced caller-split placeholders, committed unrequested pages, made partial unmap calls no-ops, and broke all 5 xmem tests reported in #8 and #2.

Changes

  • crates/victory-hle/src/modules/xmem.rs:
    • Added WHOLE_MIN = 16 * MIB (matching victory-gpu's 16 MiB in-place view threshold) and gated map_whole on (WHOLE_MIN..=WHOLE).contains(&len).
    • Verified all requested pages exist and belong to first.section before calling VirtualFree(..., COALESCE) / map_view, preventing an invalid initial mapping call from leaving a reservation mapped whole.
    • Returned true early for len == 0 in map_alias before checking in_whole (consistent with unmap).
    • Added large_reservation_is_shown_whole and whole_map_rejects_invalid_page_without_mapping_whole regression tests.

Verification

  • cargo test -q -p victory-hle --lib --locked xmem -- --test-threads=1 — 16 passed, 0 failed (all 5 failing tests from #8 / #2 now pass, plus 2 new tests).
  • cargo clippy -q -p victory-hle --lib --locked --no-deps -- -D warnings — 0 warnings.
**@⁠adritoyalser** on GitHub · 2026-11-25 11:52 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/14) `adritoyalser:fix/xmem-whole-min-size` → `main` · +47 −2 · 1 files · 1 commits · open ## Summary Fixes #8 (Refs #2). Commit `41b9207f` introduced `map_whole` in `crates/victory-hle/src/modules/xmem.rs` to show large same-sized physical reservations (like GTA VI's 185 MiB GPU heap) in one contiguous view, paired with `victory-gpu/src/shadow.rs:1086` (and `:2256` on `71652a2`, originally `:645` in `41b9207f`) refusing in-place GPU use for any `MEM_MAPPED` view smaller than **16 MiB** (`16 << 20`). Because `map_whole` only checked the upper bound (`WHOLE = 1 GiB`) and had no matching lower bound, small reservations (e.g., 2–4 pages) were promoted to `physical.whole`, which coalesced caller-split placeholders, committed unrequested pages, made partial `unmap` calls no-ops, and broke all 5 `xmem` tests reported in #8 and #2. ### Changes - **`crates/victory-hle/src/modules/xmem.rs`**: - Added `WHOLE_MIN = 16 * MIB` (matching `victory-gpu`'s 16 MiB in-place view threshold) and gated `map_whole` on `(WHOLE_MIN..=WHOLE).contains(&len)`. - Verified all requested pages exist and belong to `first.section` before calling `VirtualFree(..., COALESCE)` / `map_view`, preventing an invalid initial mapping call from leaving a reservation mapped whole. - Returned `true` early for `len == 0` in `map_alias` before checking `in_whole` (consistent with `unmap`). - Added `large_reservation_is_shown_whole` and `whole_map_rejects_invalid_page_without_mapping_whole` regression tests. ## Verification - `cargo test -q -p victory-hle --lib --locked xmem -- --test-threads=1` — **16 passed, 0 failed** (all 5 failing tests from #8 / #2 now pass, plus 2 new tests). - `cargo clippy -q -p victory-hle --lib --locked --no-deps -- -D warnings` — **0 warnings**.
Commit 41b9207f added `map_whole` to map large same-sized reservations
(such as GTA VI's 185 MiB GPU heap) in a single contiguous view, matching
`victory-gpu`'s 16 MiB minimum for in-place mapped views (`shadow.rs:645`).
Because `map_whole` only enforced an upper bound (`WHOLE = 1 GiB`) with no
lower bound, small physical reservations were coalesced into whole views
that `victory-gpu` refuses to use in place anyway — breaking placeholder
preservation, partial unmaps, and aliasing across 5 `xmem` unit tests.

- Add `WHOLE_MIN = 16 * MIB` and require `(WHOLE_MIN..=WHOLE).contains(&len)`
  in `map_whole`.
- Validate that every requested page exists and belongs to `first.section`
  before coalescing placeholders and mapping the whole reservation.
- Handle `len == 0` early in `map_alias` before checking `in_whole`.
- Add regression tests for `>= 16 MiB` whole mapping and invalid initial
  pages.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:33:08 +00:00
Author
Owner

@⁠Ekabusto on GitHub · 2026-11-25 12:47 UTC · original

Checked locally: cargo test -p victory-hle --lib passes (104 passed, 1 ignored), with the tests running in parallel (not only --test-threads=1). Clippy reports what it does on main and nothing new.

Overlap: this and #16 (mine) fix the same five xmem failures from #2 and #8 in different ways, and they conflict. #16 keeps map_whole for any size and changes the tests; this PR limits it to 16 MiB and up and adds page validation. Both include the same len == 0 early return in map_alias. I think this one is the better fix for the title: a whole view under 16 MiB gains nothing on the GPU side, which uses mapped views in place only from 16 MiB up, and it still commits the whole section. If this is merged, #16 should be closed; its new test maps 3 pages, under this minimum.

One small correction to the description: the GPU side's 16 MiB check is at victory-gpu/src/shadow.rs:1086 on 71652a2 (and :2256), not :645.

Reviewed on Windows 11 (build 26300), Rust 1.98.1, each PR in its own worktree; no game data, not run in the game. AI-assisted (Claude Code).

**@⁠Ekabusto** on GitHub · 2026-11-25 12:47 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/14#issuecomment-7162861315) Checked locally: `cargo test -p victory-hle --lib` passes (104 passed, 1 ignored), with the tests running in parallel (not only `--test-threads=1`). Clippy reports what it does on `main` and nothing new. **Overlap:** this and #16 (mine) fix the same five `xmem` failures from #2 and #8 in different ways, and they conflict. #16 keeps `map_whole` for any size and changes the tests; this PR limits it to 16 MiB and up and adds page validation. Both include the same `len == 0` early return in `map_alias`. I think this one is the better fix for the title: a whole view under 16 MiB gains nothing on the GPU side, which uses mapped views in place only from 16 MiB up, and it still commits the whole section. If this is merged, #16 should be closed; its new test maps 3 pages, under this minimum. One small correction to the description: the GPU side's 16 MiB check is at `victory-gpu/src/shadow.rs:1086` on `71652a2` (and `:2256`), not `:645`. Reviewed on Windows 11 (build 26300), Rust 1.98.1, each PR in its own worktree; no game data, not run in the game. AI-assisted (Claude Code).
Author
Owner

@⁠adritoyalser on GitHub · 2026-11-25 14:11 UTC · original

Thanks for testing this in parallel and catching the line-number drift @⁠Ekabusto! Updated the PR description to point to victory-gpu/src/shadow.rs:1086 (and :2256) on 71652a2.

**@⁠adritoyalser** on GitHub · 2026-11-25 14:11 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/14#issuecomment-7164898660) Thanks for testing this in parallel and catching the line-number drift @⁠Ekabusto! Updated the PR description to point to `victory-gpu/src/shadow.rs:1086` (and `:2256`) on `71652a2`.
Author
Owner

@⁠enriquebruno12 on GitHub · 2026-11-25 14:38 UTC · original

Tested this patch on Windows against my local checkout. Before applying it, five xmem tests failed. With the patch, all 16 xmem tests passed both in parallel and with --test-threads=1. The only failure in the full victory-hle library run was only_loopback_is_reachable, which also failed with the original test binary in the same environment.

**@⁠enriquebruno12** on GitHub · 2026-11-25 14:38 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/14#issuecomment-7165582841) Tested this patch on Windows against my local checkout. Before applying it, five xmem tests failed. With the patch, all 16 xmem tests passed both in parallel and with --test-threads=1. The only failure in the full victory-hle library run was only_loopback_is_reachable, which also failed with the original test binary in the same environment.
Author
Owner

@⁠Adika713 on GitHub · 2026-11-25 15:20 UTC · original

Verified on the machine from #2/#107: AMD Radeon RX 6950 XT (RDNA2),
Ryzen 5 3600, 32 GB RAM, Windows 11, Rust 1.98.1 / Cargo 1.98.1.
No game data; the title was not run.

I fetched PR head 5dc3396dbd374650de5e621519c0a82154256a20 into a detached
worktree and used an isolated CARGO_TARGET_DIR for each tree. Reusing one
target dir across main and a worktree can silently run the main test binary,
so these numbers are from separate target dirs (_agent_tmp\target-main-verify
and _agent_tmp\target-pr14-verify, both under F:\VIctory-Belobug-AMD).

Before, at upstream/main 01aadd193d57e71fb4d57810eb2fdd1bc95c950b, from
F:\VIctory-Belobug-AMD with CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-main-verify:

cargo test -p victory-hle modules::xmem::tests -- --test-threads=1
cargo test -p victory-hle --lib -- --test-threads=1
xmem module: exit 101 — test result: FAILED. 9 passed; 5 failed; 0 ignored; 0 measured; 89 filtered out.
full victory-hle lib: exit 101 — test result: FAILED. 97 passed; 5 failed; 1 ignored; 0 measured; 0 filtered out.
The five failures were a_run_keeps_the_placeholders_it_spans, a_run_maps_across_two_placeholders, a_run_maps_again_after_a_partial_unmap, mapping_no_pages_changes_nothing, and physical_pages_map_alias_and_unmap.
After, at PR head 5dc3396dbd374650de5e621519c0a82154256a20, from a detached worktree at F:\VIctory-Belobug-AMD\_agent_tmp\pr-14 with CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-pr14-verify:

cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-14\Cargo.toml -p victory-hle modules::xmem::tests -- --test-threads=1
cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-14\Cargo.toml -p victory-hle --lib -- --test-threads=1
xmem module: exit 0 — test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 89 filtered out (plus doc-tests: 0 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out).
full victory-hle lib: exit 0 — test result: ok. 104 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out.
All five tests from #2/#107 now pass.
Overlap check: I also ran the same five-test command on PR heads #93 (0cbedb9) and #16 (83cce99); both pass. #99 (5c0efcc), #39 (73e6eac) and #52 still fail all five. #89 and #100 do not touch crates/victory-hle/src/modules/xmem.rs. I did not write a competing fix.

Not tested: the game, because no game files or paths were supplied.

AI-assisted: OpenCode, model Big Pickle. No game data.
**@⁠Adika713** on GitHub · 2026-11-25 15:20 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/14#issuecomment-7166698949) Verified on the machine from #2/#107: AMD Radeon RX 6950 XT (RDNA2), Ryzen 5 3600, 32 GB RAM, Windows 11, Rust 1.98.1 / Cargo 1.98.1. No game data; the title was not run. I fetched PR head `5dc3396dbd374650de5e621519c0a82154256a20` into a detached worktree and used an isolated `CARGO_TARGET_DIR` for each tree. Reusing one target dir across main and a worktree can silently run the main test binary, so these numbers are from separate target dirs (`_agent_tmp\target-main-verify` and `_agent_tmp\target-pr14-verify`, both under `F:\VIctory-Belobug-AMD`). Before, at `upstream/main` `01aadd193d57e71fb4d57810eb2fdd1bc95c950b`, from `F:\VIctory-Belobug-AMD` with `CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-main-verify`: ```powershell cargo test -p victory-hle modules::xmem::tests -- --test-threads=1 cargo test -p victory-hle --lib -- --test-threads=1 xmem module: exit 101 — test result: FAILED. 9 passed; 5 failed; 0 ignored; 0 measured; 89 filtered out. full victory-hle lib: exit 101 — test result: FAILED. 97 passed; 5 failed; 1 ignored; 0 measured; 0 filtered out. The five failures were a_run_keeps_the_placeholders_it_spans, a_run_maps_across_two_placeholders, a_run_maps_again_after_a_partial_unmap, mapping_no_pages_changes_nothing, and physical_pages_map_alias_and_unmap. After, at PR head 5dc3396dbd374650de5e621519c0a82154256a20, from a detached worktree at F:\VIctory-Belobug-AMD\_agent_tmp\pr-14 with CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-pr14-verify: cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-14\Cargo.toml -p victory-hle modules::xmem::tests -- --test-threads=1 cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-14\Cargo.toml -p victory-hle --lib -- --test-threads=1 xmem module: exit 0 — test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 89 filtered out (plus doc-tests: 0 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out). full victory-hle lib: exit 0 — test result: ok. 104 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out. All five tests from #2/#107 now pass. Overlap check: I also ran the same five-test command on PR heads #93 (0cbedb9) and #16 (83cce99); both pass. #99 (5c0efcc), #39 (73e6eac) and #52 still fail all five. #89 and #100 do not touch crates/victory-hle/src/modules/xmem.rs. I did not write a competing fix. Not tested: the game, because no game files or paths were supplied. AI-assisted: OpenCode, model Big Pickle. No game data.
Author
Owner

@⁠Adika713 on GitHub · 2026-11-25 15:23 UTC · original

Verified on the machine from #2/#107: AMD Radeon RX 6950 XT (RDNA2),
Ryzen 5 3600, 32 GB RAM, Windows 11, Rust 1.98.1 / Cargo 1.98.1.
No game data; the title was not run.

I fetched PR head 5dc3396dbd374650de5e621519c0a82154256a20 into a detached
worktree and used an isolated CARGO_TARGET_DIR for each tree. Reusing one
target dir across main and a worktree can silently run the main test binary,
so these numbers are from separate target dirs (_agent_tmp\target-main-verify
and _agent_tmp\target-pr14-verify, both under F:\VIctory-Belobug-AMD).

Before, at upstream/main 01aadd193d57e71fb4d57810eb2fdd1bc95c950b, from
F:\VIctory-Belobug-AMD with CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-main-verify:

cargo test -p victory-hle modules::xmem::tests -- --test-threads=1
cargo test -p victory-hle --lib -- --test-threads=1
  • xmem module: exit 101 — test result: FAILED. 9 passed; 5 failed; 0 ignored; 0 measured; 89 filtered out.
  • full victory-hle lib: exit 101 — test result: FAILED. 97 passed; 5 failed; 1 ignored; 0 measured; 0 filtered out.
  • The five failures were a_run_keeps_the_placeholders_it_spans,
    a_run_maps_across_two_placeholders, a_run_maps_again_after_a_partial_unmap,
    mapping_no_pages_changes_nothing, and physical_pages_map_alias_and_unmap.

After, at PR head 5dc3396dbd374650de5e621519c0a82154256a20, from a detached
worktree at F:\VIctory-Belobug-AMD\_agent_tmp\pr-14 with
CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-pr14-verify:

cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-14\Cargo.toml -p victory-hle modules::xmem::tests -- --test-threads=1
cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-14\Cargo.toml -p victory-hle --lib -- --test-threads=1
  • xmem module: exit 0 — test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 89 filtered out
    (plus doc-tests: 0 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out).
  • full victory-hle lib: exit 0 — test result: ok. 104 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out.
  • All five tests from #2/#107 now pass.

Overlap check: I also ran the same five-test command on PR heads #93 (0cbedb9)
and #16 (83cce99); both pass. #99 (5c0efcc), #39 (73e6eac) and #52 still
fail all five. #89 and #100 do not touch crates/victory-hle/src/modules/xmem.rs.
I did not write a competing fix.

Not tested: the game, because no game files or paths were supplied.

AI-assisted: OpenCode, model Big Pickle. No game data.

**@⁠Adika713** on GitHub · 2026-11-25 15:23 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/14#issuecomment-7166768485) Verified on the machine from #2/#107: AMD Radeon RX 6950 XT (RDNA2), Ryzen 5 3600, 32 GB RAM, Windows 11, Rust 1.98.1 / Cargo 1.98.1. No game data; the title was not run. I fetched PR head `5dc3396dbd374650de5e621519c0a82154256a20` into a detached worktree and used an isolated `CARGO_TARGET_DIR` for each tree. Reusing one target dir across main and a worktree can silently run the main test binary, so these numbers are from separate target dirs (`_agent_tmp\target-main-verify` and `_agent_tmp\target-pr14-verify`, both under `F:\VIctory-Belobug-AMD`). Before, at `upstream/main` `01aadd193d57e71fb4d57810eb2fdd1bc95c950b`, from `F:\VIctory-Belobug-AMD` with `CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-main-verify`: ```powershell cargo test -p victory-hle modules::xmem::tests -- --test-threads=1 cargo test -p victory-hle --lib -- --test-threads=1 ``` - xmem module: exit 101 — `test result: FAILED. 9 passed; 5 failed; 0 ignored; 0 measured; 89 filtered out`. - full `victory-hle` lib: exit 101 — `test result: FAILED. 97 passed; 5 failed; 1 ignored; 0 measured; 0 filtered out`. - The five failures were `a_run_keeps_the_placeholders_it_spans`, `a_run_maps_across_two_placeholders`, `a_run_maps_again_after_a_partial_unmap`, `mapping_no_pages_changes_nothing`, and `physical_pages_map_alias_and_unmap`. After, at PR head `5dc3396dbd374650de5e621519c0a82154256a20`, from a detached worktree at `F:\VIctory-Belobug-AMD\_agent_tmp\pr-14` with `CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-pr14-verify`: ```powershell cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-14\Cargo.toml -p victory-hle modules::xmem::tests -- --test-threads=1 cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-14\Cargo.toml -p victory-hle --lib -- --test-threads=1 ``` - xmem module: exit 0 — `test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 89 filtered out` (plus doc-tests: `0 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out`). - full `victory-hle` lib: exit 0 — `test result: ok. 104 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out`. - All five tests from #2/#107 now pass. Overlap check: I also ran the same five-test command on PR heads #93 (`0cbedb9`) and #16 (`83cce99`); both pass. #99 (`5c0efcc`), #39 (`73e6eac`) and #52 still fail all five. #89 and #100 do not touch `crates/victory-hle/src/modules/xmem.rs`. I did not write a competing fix. Not tested: the game, because no game files or paths were supplied. AI-assisted: OpenCode, model Big Pickle. No game data.
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/14/head:github-bot/gh-14'
git switch 'github-bot/gh-14'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-14'
git switch 'github-bot/gh-14'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-14'
git switch 'github-bot/gh-14'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-14'
git switch 'main'
git merge --squash 'github-bot/gh-14'
git switch 'main'
git merge --ff-only 'github-bot/gh-14'
git switch 'main'
git merge 'github-bot/gh-14'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.