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

Open
adritoyalser wants to merge 1 commit from upstream-pr/14 into main
adritoyalser commented 2026-11-25 11:52:49 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adritoyalser on 2026-11-25T11:52:49Z.


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.
<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:6603857923 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/14). Originally posted by [adritoyalser](https://github.com/adritoyalser) on 2026-11-25T11:52:49Z. --- ## 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**.
Ekabusto commented 2026-11-25 12:47:28 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by Ekabusto on 2026-11-25T12:47:28Z.


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).

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7162861315 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/14#issuecomment-7162861315). Originally posted by [Ekabusto](https://github.com/Ekabusto) on 2026-11-25T12:47:28Z. --- 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).
adritoyalser commented 2026-11-25 14:11:36 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adritoyalser on 2026-11-25T14:11:36Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7164898660 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/14#issuecomment-7164898660). Originally posted by [adritoyalser](https://github.com/adritoyalser) on 2026-11-25T14:11:36Z. --- 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`.
enriquebruno12 commented 2026-11-25 14:38:07 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by enriquebruno12 on 2026-11-25T14:38:07Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7165582841 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/14#issuecomment-7165582841). Originally posted by [enriquebruno12](https://github.com/enriquebruno12) on 2026-11-25T14:38:07Z. --- 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.
Adika713 commented 2026-11-25 15:20:52 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by Adika713 on 2026-11-25T15:20:52Z.


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.
<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7166698949 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/14#issuecomment-7166698949). Originally posted by [Adika713](https://github.com/Adika713) on 2026-11-25T15:20:52Z. --- 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.
Adika713 commented 2026-11-25 15:23:29 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by Adika713 on 2026-11-25T15:23:29Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7166768485 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/14#issuecomment-7166768485). Originally posted by [Adika713](https://github.com/Adika713) on 2026-11-25T15:23:29Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/14:upstream-pr/14'
git switch 'upstream-pr/14'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/14'
git switch 'upstream-pr/14'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/14'
git switch 'upstream-pr/14'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/14'
git switch 'main'
git merge --squash 'upstream-pr/14'
git switch 'main'
git merge --ff-only 'upstream-pr/14'
git switch 'main'
git merge 'upstream-pr/14'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Belobug/VIctory-Belobug-AMD!14
No description provided.