Skip to content

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 into
Zettrox:mainfrom
WHOISJARDAS:xmem/keep-low-4gib
Open

WHOISJARDAS wants to merge 1 commit into
Zettrox:mainfrom
WHOISJARDAS:xmem/keep-low-4gib

Conversation

@WHOISJARDAS

@WHOISJARDAS WHOISJARDAS commented Nov 25, 2026 •

Copy link
Copy Markdown

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

A port of Marvisak/VIctory#1009 (NuraadGit, with the bounded retry from
MichaelSmithAI). At startup the title asks XMemVirtualAlloc for a 185 MB
placeholder below 4 GiB. Windows places the host's own memory bottom up,
so the drivers' mapped shader caches, heaps and the image read can fill
that space first; the request is refused and the title stops at its own
assertion (int3 at +0x19f4f58), with nothing in the log. With the
system's bottom-up ASLR turned off (Exploit protection) it happens on
every start.

The free space below 4 GiB (but the lowest 256 MB) is reserved at the
start of `run`; a 32-bit request that finds no room releases guards one
at a time and tries again, guarding again what stays free. A request
still refused is logged.

RX 9070 XT, bottom-up ASLR off, 2.3 GB of the driver's shader cache
mapped below 4 GiB: main stopped at the assertion on 4 of 4 starts
(3 MB free below 4 GiB, largest hole 64 KiB); with this, 3 of 3 starts
reach the menus at 30 fps with 3.8 GB kept for the title.

Co-authored-by: NuraadGit <81594937+NuraadGit@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xmem: host memory fills the space below 4 GiB, so the title's 32-bit placeholder is refused at startup (fix on a branch)

2 participants