xmem: keep the space below 4 GiB for the title's 32-bit memory (port of VIctory#1009) #108

Open
WHOISJARDAS wants to merge 1 commit from upstream-pr/108 into main
WHOISJARDAS commented 2026-11-25 12:07:11 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by WHOISJARDAS on 2026-11-25T12:05:19Z.


A port of Marvisak/VIctory#1009 by NuraadGit (with MichaelSmithAI's bounded retry), which fixes Marvisak/VIctory#790 upstream and is not in this tree yet. On this machine, main cannot start the title at all.

What was wrong

At startup the title asks XMemVirtualAlloc for a 185 MB placeholder with the 32-bit address flag (size=193986560 kind=0x42000 flags=0x7), so address_range limits it to 0..4 GiB. Windows places the host's own memory bottom up, so the drivers' mapped shader caches, heap segments and the image read in run can fill that space first. VirtualAlloc2 then fails with ERROR_NOT_ENOUGH_MEMORY, nothing is logged, and the title stops at its own assertion: 0x80000003 at +0x19f4f58, about 1 s after start, right after the D3D12 device is made.

A temporary probe in the refusal path (not part of this PR) mapped 0..4 GiB at the failure:

below 4 GiB
free 3 MB, largest hole 64 KiB, 1,635 regions
mapped 2,381 MB, of it 2.3 GB the AMD driver's shader cache files (%LOCALAPPDATA%\AMD\DxcCache\*.parc, one of 1.5 GB)
private 1,711 MB (one 1 GB reservation, 11 x 32 MB, ...)

New detail: on this machine Windows Security, Exploit protection, Randomize memory allocations (Bottom-up ASLR) is Off system-wide (Get-ProcessMitigation -System shows BottomUp: OFF; the Windows default is On). With it off, every host allocation starts at the lowest free address, so the failure is deterministic. Starting the same unpatched build with bottom-up and high-entropy ASLR forced on for that one process (PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY, no system change) started the title normally. The guards fix it either way.

What this changes

Same as Marvisak/VIctory#1009:

  • xmem::low_guards::install() runs at the start of run when executing, before the image read, the device and the caches. It reserves the free space below 4 GiB except the lowest 256 MB, which stays with the host.
  • A refused 32-bit XMemVirtualAlloc releases guards one at a time (smallest that fits first, each tried once) and retries, then guards again whatever stays free in that guard. The normal path is unchanged.
  • Two tests: low_guards::tests::a_released_guard_is_guarded_again_around_what_took_it and a_refused_retry_leaves_the_guards_in_place.

Differences from Marvisak/VIctory#1009: the doc comment doesn't name the game, and a 32-bit request still refused after the retry logs one warn (this tree logs no refusal at all, which is why this took a probe to find).

Tested

AMD Radeon RX 9070 XT 16 GB (driver 32.0.32029.2010), Ryzen 7 9800X3D, 32 GB, Windows 11 Pro 26200, bottom-up ASLR off, diag build, Series X profile, Rust 1.98.1:

starts result
main (90b529f) 4 4 stopped at +0x19f4f58
this branch 3 3 reached the menus at 30 fps, space below 4 GiB kept for the title guards=2 mb=3797..3805
this branch + #109 (the AMD compiler fix) 1 18 min into the world (closed by hand), 0 exceptions, no no room below 4 GiB
  • cargo test --workspace --locked: 498 passed, 0 failed, 7 ignored, including the two low_guards tests
  • cargo clippy --workspace --all-targets --locked -- -D warnings and the --all-features run: clean
  • cargo xtask policy: ok

Not tested

NVIDIA and Intel cards; a machine with bottom-up ASLR on (there the failure needs a large driver cache, as in the RTX 2080 and RTX 3060 Ti reports on Marvisak/VIctory#790 and Marvisak/VIctory#1009); Linux/Wine.

AI use

Claude Code (Claude Opus 5.5) found the refusal with a probe, ported and adapted the upstream change and ran the checks. The hardware, the title copy and the runs are mine.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Zettrox/ztrx:issue:6604072872 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/108). Originally posted by [WHOISJARDAS](https://github.com/WHOISJARDAS) on 2026-11-25T12:05:19Z. --- A port of Marvisak/VIctory#1009 by NuraadGit (with MichaelSmithAI's bounded retry), which fixes Marvisak/VIctory#790 upstream and is not in this tree yet. On this machine, `main` cannot start the title at all. ## What was wrong At startup the title asks `XMemVirtualAlloc` for a 185 MB placeholder with the 32-bit address flag (`size=193986560 kind=0x42000 flags=0x7`), so `address_range` limits it to `0..4 GiB`. Windows places the host's own memory bottom up, so the drivers' mapped shader caches, heap segments and the image read in `run` can fill that space first. `VirtualAlloc2` then fails with `ERROR_NOT_ENOUGH_MEMORY`, nothing is logged, and the title stops at its own assertion: `0x80000003` at `+0x19f4f58`, about 1 s after start, right after the D3D12 device is made. A temporary probe in the refusal path (not part of this PR) mapped `0..4 GiB` at the failure: | below 4 GiB | | |---|---| | free | 3 MB, largest hole 64 KiB, 1,635 regions | | mapped | 2,381 MB, of it 2.3 GB the AMD driver's shader cache files (`%LOCALAPPDATA%\AMD\DxcCache\*.parc`, one of 1.5 GB) | | private | 1,711 MB (one 1 GB reservation, 11 x 32 MB, ...) | **New detail:** on this machine Windows Security, Exploit protection, *Randomize memory allocations (Bottom-up ASLR)* is **Off** system-wide (`Get-ProcessMitigation -System` shows `BottomUp: OFF`; the Windows default is On). With it off, every host allocation starts at the lowest free address, so the failure is deterministic. Starting the same unpatched build with bottom-up and high-entropy ASLR forced on for that one process (`PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY`, no system change) started the title normally. The guards fix it either way. ## What this changes Same as Marvisak/VIctory#1009: - `xmem::low_guards::install()` runs at the start of `run` when executing, before the image read, the device and the caches. It reserves the free space below 4 GiB except the lowest 256 MB, which stays with the host. - A refused 32-bit `XMemVirtualAlloc` releases guards one at a time (smallest that fits first, each tried once) and retries, then guards again whatever stays free in that guard. The normal path is unchanged. - Two tests: `low_guards::tests::a_released_guard_is_guarded_again_around_what_took_it` and `a_refused_retry_leaves_the_guards_in_place`. Differences from Marvisak/VIctory#1009: the doc comment doesn't name the game, and a 32-bit request still refused after the retry logs one `warn` (this tree logs no refusal at all, which is why this took a probe to find). ## Tested AMD Radeon RX 9070 XT 16 GB (driver 32.0.32029.2010), Ryzen 7 9800X3D, 32 GB, Windows 11 Pro 26200, bottom-up ASLR off, diag build, Series X profile, Rust 1.98.1: | | starts | result | |---|---|---| | `main` (`90b529f`) | 4 | 4 stopped at `+0x19f4f58` | | this branch | 3 | 3 reached the menus at 30 fps, `space below 4 GiB kept for the title guards=2 mb=3797..3805` | | this branch + #109 (the AMD compiler fix) | 1 | 18 min into the world (closed by hand), 0 exceptions, no `no room below 4 GiB` | - `cargo test --workspace --locked`: 498 passed, 0 failed, 7 ignored, including the two `low_guards` tests - `cargo clippy --workspace --all-targets --locked -- -D warnings` and the `--all-features` run: clean - `cargo xtask policy`: ok ## Not tested NVIDIA and Intel cards; a machine with bottom-up ASLR on (there the failure needs a large driver cache, as in the RTX 2080 and RTX 3060 Ti reports on Marvisak/VIctory#790 and Marvisak/VIctory#1009); Linux/Wine. ## AI use Claude Code (Claude Opus 5.5) found the refusal with a probe, ported and adapted the upstream change and ran the checks. The hardware, the title copy and the runs are mine. 🤖 Generated with [Claude Code](https://claude.com/claude-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/108:upstream-pr/108'
git switch 'upstream-pr/108'

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/108'
git switch 'upstream-pr/108'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/108'
git switch 'upstream-pr/108'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/108'
git switch 'main'
git merge --squash 'upstream-pr/108'
git switch 'main'
git merge --ff-only 'upstream-pr/108'
git switch 'main'
git merge 'upstream-pr/108'
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
Zettrox/ztrx!108
No description provided.