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

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

@⁠WHOISJARDAS on GitHub · 2026-11-25 12:34 UTC · original
WHOISJARDAS:xmem/keep-low-4gib → main · +217 −2 · 2 files · 1 commits · open

On this machine (RX 9070 XT, Ryzen 7 9800X3D, Windows 11 26200) this fork's 4cbe9d7 cannot start the title: it stops at the title's own assertion, 0x80000003 at +0x19f4f58, about 1 s in. This is Marvisak/VIctory#790: the title's 185 MB 32-bit placeholder (XMemVirtualAlloc size=193986560 kind=0x42000 flags=0x7) finds no room below 4 GiB, because the host's memory got there first. Here 2.3 GB of it was the AMD driver's shader cache files (%LOCALAPPDATA%\AMD\DxcCache\*.parc) mapped below 4 GiB, and Exploit protection's Bottom-up ASLR is off system-wide, so it happens on every start.

This is a port of Marvisak/VIctory#1009 (NuraadGit, with MichaelSmithAI's bounded retry), the same change as Zettrox/ztrx#108:

  • xmem::low_guards::install() at the start of run reserves the free space below 4 GiB but the lowest 256 MB;
  • a refused 32-bit XMemVirtualAlloc releases guards one at a time and retries, guarding again what stays free;
  • a 32-bit request still refused logs one warn (nothing was logged before);
  • tests low_guards::tests::* (2).

Tested

RX 9070 XT (driver 32.0.32029.2010), Series X profile, this README's settings: 4cbe9d7 stopped at +0x19f4f58 at start; with this, it starts and reaches the world (space below 4 GiB kept for the title guards=2 mb=3722).

  • cargo test -p victory-hle --lib low_guards: 2 passed

AI use: Claude Code (Claude Opus 5.5) ported the change and ran the checks; the hardware and runs are mine.

🤖 Generated with Claude Code

**@⁠WHOISJARDAS** on GitHub · 2026-11-25 12:34 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/39) `WHOISJARDAS:xmem/keep-low-4gib` → `main` · +217 −2 · 2 files · 1 commits · open On this machine (RX 9070 XT, Ryzen 7 9800X3D, Windows 11 26200) this fork's `4cbe9d7` cannot start the title: it stops at the title's own assertion, `0x80000003` at `+0x19f4f58`, about 1 s in. This is Marvisak/VIctory#790: the title's 185 MB 32-bit placeholder (`XMemVirtualAlloc` `size=193986560 kind=0x42000 flags=0x7`) finds no room below 4 GiB, because the host's memory got there first. Here 2.3 GB of it was the AMD driver's shader cache files (`%LOCALAPPDATA%\AMD\DxcCache\*.parc`) mapped below 4 GiB, and Exploit protection's Bottom-up ASLR is off system-wide, so it happens on every start. This is a port of Marvisak/VIctory#1009 (NuraadGit, with MichaelSmithAI's bounded retry), the same change as Zettrox/ztrx#108: - `xmem::low_guards::install()` at the start of `run` reserves the free space below 4 GiB but the lowest 256 MB; - a refused 32-bit `XMemVirtualAlloc` releases guards one at a time and retries, guarding again what stays free; - a 32-bit request still refused logs one `warn` (nothing was logged before); - tests `low_guards::tests::*` (2). ## Tested RX 9070 XT (driver 32.0.32029.2010), Series X profile, this README's settings: `4cbe9d7` stopped at `+0x19f4f58` at start; with this, it starts and reaches the world (`space below 4 GiB kept for the title guards=2 mb=3722`). - `cargo test -p victory-hle --lib low_guards`: 2 passed AI use: Claude Code (Claude Opus 5.5) ported the change and ran the checks; the hardware and runs are mine. 🤖 Generated with [Claude Code](https://claude.com/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: this fork's 4cbe9d7 stopped at the assertion at
start; with this, it reaches the menus (3.7 GB kept for the title).

Co-authored-by: NuraadGit <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:34:16 +00:00
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 14:49 UTC · original · reviewed

AI-assisted static review (ChatGPT); I inspected the retry tests but did not run them.

**@⁠gut0to** on GitHub · 2026-11-27 14:49 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/39#pullrequestreview-6089894686) · **reviewed** AI-assisted static review (ChatGPT); I inspected the retry tests but did not run them.
@ -1737,0 +1880,4 @@
}
}
// SAFETY: sets this thread's last-error value.
unsafe { SetLastError(error) };
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 14:49 UTC · original

Could the refused-retry test also assert last-error preservation? Its allocation closure currently returns null without setting an error, so the tests cover guard restoration but not that retry restores the final VirtualAlloc error after the address queries and guard recreation. An injected closure can set a known error such as ERROR_NOT_ENOUGH_MEMORY, then assert GetLastError() returns it after retry; the caller relies on this value when reporting exhaustion.

**@⁠gut0to** on GitHub · 2026-11-27 14:49 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/39#discussion_r4720780869) Could the refused-retry test also assert last-error preservation? Its allocation closure currently returns null without setting an error, so the tests cover guard restoration but not that `retry` restores the final `VirtualAlloc` error after the address queries and guard recreation. An injected closure can set a known error such as `ERROR_NOT_ENOUGH_MEMORY`, then assert `GetLastError()` returns it after retry; the caller relies on this value when reporting exhaustion.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-39'
git switch 'github-bot/gh-39'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-39'
git switch 'github-bot/gh-39'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-39'
git switch 'main'
git merge --squash 'github-bot/gh-39'
git switch 'main'
git merge --ff-only 'github-bot/gh-39'
git switch 'main'
git merge 'github-bot/gh-39'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.