HLE xmem: support MEM_COMMIT inside 64 KiB placeholder reservations #2275

Open
Sidlik900 wants to merge 1 commit from upstream-pr/2277 into main
Sidlik900 commented 2026-11-25 09:29:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sidlik900 on 2026-11-25T09:29:06Z.


Claimed in https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7158026223.

Summary

  • Complete the documented MEM_COMMIT inside PAGES_64K placeholder shortcut in XMemVirtualAlloc (crates/victory-hle/src/modules/xmem.rs), which was also surfaced as a failing host case during diagnosis in #2025 (Windows 11 returns ERROR_INVALID_ADDRESS and other builds/Wine may return ERROR_INVALID_PARAMETER when committing directly into a MEM_RESERVE_PLACEHOLDER).
  • When VirtualAlloc2 rejects a non-null MEM_COMMIT (without MEM_RESERVE) with is_placeholder_commit_error, commit_in_placeholder:
    • pre-scans [base, base + size) with query_region (VirtualQueryEx) to confirm the entire range covers non-free MEM_PRIVATE memory, failing before mutating earlier placeholders if any chunk is free, out of bounds, or mapped;
    • commits already-private chunks directly on the fast path, and for PAGE-aligned MEM_RESERVE placeholders splits strictly smaller sub-ranges on 64 KiB PAGE boundaries with VirtualFree(..., MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER), replaces the isolated placeholder with MEM_RESERVE | MEM_REPLACE_PLACEHOLDER | MEM_WRITE_WATCH (PAGE_NOACCESS, falling back without MEM_WRITE_WATCH if unsupported), and commits [cursor, chunk_end) with kind and protect;
    • restores the thread's Win32 error via SetLastError on error before calling commit_refused.
  • Add synthetic regression test committing_all_or_part_of_a_64k_placeholder_succeeds (and release_range helper) covering partial 64 KiB placeholder commits, GetWriteWatch verification on replaced ranges, sibling placeholder XMemMapPhysicalPages compatibility, 4 KiB / unaligned-address sub-commits, commits straddling private and placeholder regions, boundary and mapped-view refusal without corrupting untouched placeholders, and whole-placeholder commits.
  • Note: This implements the placeholder-commit path only and does not claim live-title closure of #2025.

Verification

  • cargo xtask policy (asset policy: 182 files ok)
  • cargo test -p victory-hle --locked (144 unit tests including all 11 modules::xmem::tests::* tests + fidelityfx + no_dll_planting passed; one pre-existing timing race in modules::dstorage::tests::a_page_list_filled_after_its_request_starts failed on an initial run and passed cleanly on rerun)
  • cargo test -p victory-hle --all-features --locked (144 unit tests + fidelityfx + no_dll_planting passed)
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
  • rustfmt --edition 2024 --check crates/victory-hle/src/modules/xmem.rs (zero diffs on added/edited lines; 4 pre-existing untouched formatting diffs in xmem.rs left intact)

AI-assisted (Antigravity); synthetic tests only, no game data.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6601358160 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2277). Originally posted by [Sidlik900](https://github.com/Sidlik900) on 2026-11-25T09:29:06Z. --- Claimed in https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7158026223. ### Summary - Complete the documented `MEM_COMMIT` inside `PAGES_64K` placeholder shortcut in `XMemVirtualAlloc` (`crates/victory-hle/src/modules/xmem.rs`), which was also surfaced as a failing host case during diagnosis in #2025 (Windows 11 returns `ERROR_INVALID_ADDRESS` and other builds/Wine may return `ERROR_INVALID_PARAMETER` when committing directly into a `MEM_RESERVE_PLACEHOLDER`). - When `VirtualAlloc2` rejects a non-null `MEM_COMMIT` (without `MEM_RESERVE`) with `is_placeholder_commit_error`, `commit_in_placeholder`: - pre-scans `[base, base + size)` with `query_region` (`VirtualQueryEx`) to confirm the entire range covers non-free `MEM_PRIVATE` memory, failing before mutating earlier placeholders if any chunk is free, out of bounds, or mapped; - commits already-private chunks directly on the fast path, and for `PAGE`-aligned `MEM_RESERVE` placeholders splits strictly smaller sub-ranges on 64 KiB `PAGE` boundaries with `VirtualFree(..., MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)`, replaces the isolated placeholder with `MEM_RESERVE | MEM_REPLACE_PLACEHOLDER | MEM_WRITE_WATCH` (`PAGE_NOACCESS`, falling back without `MEM_WRITE_WATCH` if unsupported), and commits `[cursor, chunk_end)` with `kind` and `protect`; - restores the thread's Win32 error via `SetLastError` on error before calling `commit_refused`. - Add synthetic regression test `committing_all_or_part_of_a_64k_placeholder_succeeds` (and `release_range` helper) covering partial 64 KiB placeholder commits, `GetWriteWatch` verification on replaced ranges, sibling placeholder `XMemMapPhysicalPages` compatibility, 4 KiB / unaligned-address sub-commits, commits straddling private and placeholder regions, boundary and mapped-view refusal without corrupting untouched placeholders, and whole-placeholder commits. - Note: This implements the placeholder-commit path only and does not claim live-title closure of #2025. ### Verification - `cargo xtask policy` (`asset policy: 182 files ok`) - `cargo test -p victory-hle --locked` (`144` unit tests including all `11` `modules::xmem::tests::*` tests + `fidelityfx` + `no_dll_planting` passed; one pre-existing timing race in `modules::dstorage::tests::a_page_list_filled_after_its_request_starts` failed on an initial run and passed cleanly on rerun) - `cargo test -p victory-hle --all-features --locked` (`144` unit tests + `fidelityfx` + `no_dll_planting` passed) - `cargo clippy --workspace --all-targets --locked -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` - `rustfmt --edition 2024 --check crates/victory-hle/src/modules/xmem.rs` (zero diffs on added/edited lines; 4 pre-existing untouched formatting diffs in `xmem.rs` left intact) AI-assisted (Antigravity); synthetic tests only, no game data.
catminou4 commented 2026-11-25 10:07:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T09:35:45Z.

Review: COMMENTED


xmem: support MEM_COMMIT inside 64 KiB placeholder reservations — split/replace placeholder ranges on commit (+388). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Substantial HLE memory work; placeholder semantics need Windows validation.

<!-- greyfinch-sync:Marvisak/VIctory:review:6055075737 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2277#pullrequestreview-6055075737). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T09:35:45Z. **Review:** COMMENTED --- xmem: support MEM_COMMIT inside 64 KiB placeholder reservations — split/replace placeholder ranges on commit (+388). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Substantial HLE memory work; placeholder semantics need Windows validation.
Marvisak commented 2026-11-25 14:07:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:32:20Z.


Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main (conflict in crates/victory-hle/src/modules/xmem.rs). It will be reviewed again once it is rebased.

From the earlier needs-work note, still open: evidence the title commits into a placeholder reservation, keeping the title's later MEM_RELEASE of the whole reservation working, and a CI run.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163921891 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2277#issuecomment-7163921891). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:32:20Z. --- <!-- victory-triage v1 head=68e0e763651b31810b83ba62c3f4d42b9ac78d93 verdict=needs-rebase at=2026-11-25T22:27:30Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main` (conflict in `crates/victory-hle/src/modules/xmem.rs`). It will be reviewed again once it is rebased. From the earlier needs-work note, still open: evidence the title commits into a placeholder reservation, keeping the title's later `MEM_RELEASE` of the whole reservation working, and a CI run. --- _Generated by [Claude Code](https://claude.ai/code)_
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/2277:upstream-pr/2277'
git switch 'upstream-pr/2277'

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/2277'
git switch 'upstream-pr/2277'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2277'
git switch 'upstream-pr/2277'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2277'
git switch 'main'
git merge --squash 'upstream-pr/2277'
git switch 'main'
git merge --ff-only 'upstream-pr/2277'
git switch 'main'
git merge 'upstream-pr/2277'
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
Marvisak/VIctory!2275
No description provided.