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

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

@⁠Sidlik900 on GitHub · 2026-11-25 09:29 UTC · original
Sidlik900:xmem/placeholder-commit → main · +388 −19 · 1 files · 1 commits · open

Claimed in #1633.

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.

**@⁠Sidlik900** on GitHub · 2026-11-25 09:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2277) `Sidlik900:xmem/placeholder-commit` → `main` · +388 −19 · 1 files · 1 commits · open Claimed in https://git.gtahub.st/github/Marvisak--VIctory/issues/1633. ### 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:00:45 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:32 UTC · original · edited 2026-11-25 22:21 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 13:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2277#issuecomment-7163921891) · edited 2026-11-25 22:21 UTC <!-- 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 has changes conflicting with the target branch.
  • crates/victory-hle/src/modules/xmem.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2277'
git switch 'github-bot/gh-2277'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2277'
git switch 'github-bot/gh-2277'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2277'
git switch 'main'
git merge --squash 'github-bot/gh-2277'
git switch 'main'
git merge --ff-only 'github-bot/gh-2277'
git switch 'main'
git merge 'github-bot/gh-2277'
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!2277
No description provided.