Skip to content

hle: reserve low VA for known 32-bit startup placeholders - #61

Merged
simnJS merged 2 commits into
MiamiGame:mainfrom
PrivacyOnion:hle/low-va-reserve
Nov 25, 2026
Merged

simnJS merged 2 commits into
MiamiGame:mainfrom
PrivacyOnion:hle/low-va-reserve

Conversation

@PrivacyOnion

@PrivacyOnion PrivacyOnion commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What and why

On an RTX 5070 (driver 32.0.16.1664, Windows 11, 16 GB RAM), the known 1.0.2.1 build stops about three seconds into start-up, before its front end. This happens with a fresh data folder, every time, at the same place.

What fails:

  • While it sets up graphics, the title asks XMemVirtualAlloc for one 185 MiB (0x0b900000) placeholder reservation below 4 GiB.
  • XTP passes that request to VirtualAlloc2 with a highest address of 0xffffffff. It returns null, and the title's own check then breaks (int3).

Why there is no room:

  • The title's minidump shows two private 1 GiB reservations at 0x7fff0000 and 0xbfff0000. Only 16.4 MiB is left free below 4 GiB, and the largest hole is 7.19 MiB.
  • A standalone probe on the same PC reproduces both reservations around D3D12CreateDevice on that driver, and they go when the device is released. So they come from the host device, not from XTP or the title.
  • XTP's other reservations already sit at or above 4 GiB. There is no XTP-owned pair to move.

The change:

  • Before it maps the image or opens the host GPU, xtp run --execute now holds an uncommitted placeholder below 4 GiB. Its size is what the known build is measured to ask for (KnownBuild::low_va_reserve_mib, 185 for 1.0.2.1).
  • The first 32-bit placeholder request of that size takes it, so smaller requests cannot fragment it first.
  • The reserve costs address space only, no RAM and no commit. Unknown builds get none.
  • XTP_LOW_VA_RESERVE_MIB=<n> holds n MiB instead and hands it out in pieces to 32-bit placeholder requests that the host refuses. 0 turns the reserve off.
  • A failed early reservation falls back to the normal path.

With it, the title passes that point on the same machine:

  • it logs held a low VA placeholder mib=185 automatic=true, then used the low VA placeholder reserve size=193986560 ;
  • it shows its first-boot screens ;
  • it reaches the world (autopilot control handed back to the player).

Fixes: none
Depends on: none

Area

  • crates/xtp-hle/src/modules/xmem.rs : the low reserve (LowVaReserve), its hand-off in XMemVirtualAlloc, the override, and tests.
  • crates/xtp-game/src/lib.rs : KnownBuild::low_va_reserve_mib.
  • apps/xtp/src/run.rs : takes the reserve after identifying the build, in --execute mode.
  • README.md : XTP_LOW_VA_RESERVE_MIB.

Tests

  • cargo xtask pr-check passes on my machine. fmt, both clippy passes, policy and conventions ran. The test step was run per crate (below), because the app integration tests launch xtp.exe.
  • New or changed behaviour has tests that need no game files, or I explain below why it cannot

Tests:

  • cargo test -p xtp-hle --lib : 192 passed, 2 ignored benchmarks.
  • cargo test -p xtp-game : passed.
  • cargo test -p xtp --bin xtp : 28 passed.

What the new tests cover:

  • With real Windows placeholders and synthetic pages: an occupied range, a partial hand-off, the exact remainder, and independent mapping, unmapping and freeing of the pieces.
  • Exact-size hand-off, single use, and the override's bounds.

Ran on a title: yes, the 1.0.2.1 Xbox Series build in Series S mode, RTX 5070 12 GB, driver 32.0.16.1664, Ryzen 5 5600, 16 GB RAM.

  • Without the change: it stops at the same place three times out of three.
  • With it: it reaches the world in every run.
  • Low-memory behaviour in the world on this 16 GB machine is a separate topic, to be covered in its own PR.

Provenance

  • I wrote all of this change myself for XTP, or it only moves code already in XTP.
  • Some of it comes from elsewhere. Each source, its licence and the files concerned are listed here, and every licence is compatible with GPL-3.0-or-later:

Written for XTP from XTP's own code.

What was read to find the cause:

  • XTP's logs and crashes.log ;
  • the title's Breakpad minidump (address map only) ;
  • the title executable's import table and a few narrow code ranges, read locally to name the failing call. Only offsets, sizes and the build hash are used, as the asset policy allows. No bytes or disassembly are in the change.

xcl and AnyPS5 were not read for this.

AI assistance:

  • AI coding tools wrote this change and its tests, mainly OpenAI Codex.

Checklist

  • No game data, keys, console SDK code or headers, and nothing that circumvents DRM (asset policy)
  • No code copied from xcl or AnyPS5 (references only: read them to understand, write your own)
  • I agree to license this contribution under GPL-3.0-or-later
  • Title and every commit follow <area>: <summary>; one topic; under 400 changed lines, or the reason is above
  • Docs updated where behaviour, commands or variables changed (README, docs/)

@github-actions github-actions Bot added the overlap another open PR changes the same files label Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Other open pull requests change the same files. Check that they do not do the same work, and agree with their authors on which lands first: the other one will then need a rebase.

Pull request Files changed by both
#47 apps/xtp/src/run.rs
#48 README.md

This comment is kept up to date automatically and removed when the overlap ends.

@github-actions github-actions Bot added area/hle touches crates/xtp-hle area/game touches crates/xtp-game area/app apps/ area/docs docs/, Markdown size/M 100 to 399 changed lines labels Nov 25, 2026

@simnJS simnJS left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the careful investigation and the clear write-up. The approach looks right:

  • The title receives the same kind of placeholder as on the normal path, so mapping and releasing behave the same.
  • The split uses MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER on a strict prefix only.
  • A failed early reservation falls back cleanly, and the last error is preserved.
  • The title-specific size lives in xtp-game.

The tests with real placeholders are appreciated.

Non-blocking suggestions:

  1. If the 185 MiB request never comes (for example in Series X mode, which is untested), the reserve is held for the whole run. Could the doc on low_va_reserve_mib say the size was measured in Series S mode, and could an unused reserve be released?
  2. Capping the reserve's HighestEndingAddress below 0x7fff0000 would guarantee it never overlaps the range the driver was seen to take.
  3. XTP_LOW_VA_RESERVE_MIB=185 switches to the on-failure mode instead of reproducing the default. One README sentence would help.
  4. Per CONTRIBUTING, the title could name every area: hle, game, app: reserve low VA for known 32-bit startup placeholders.
  5. Nit: the SAFETY comment on allocate_virtual could say why calling it with any address and flags is sound.

The failing gpu-debug-layer job (message 1419 in draw::tests::a_cbv_fill_reads_an_in_flight_shaders_output_on_the_gpu, xtp-gpu) also fails on main and is unrelated to this PR. We're fixing it on main. I'll merge once that job is green again; no action needed from you.

On an RTX 5070 (driver 32.0.16.1664) the known 1.0.2.1 build stopped about
three seconds into start-up, before its front end. While it set up graphics,
the title asked XMemVirtualAlloc for one 185 MiB (0x0b900000) placeholder
reservation below 4 GiB. VirtualAlloc2 with a highest address of 0xffffffff
returned null, and the title's own check broke on it. Creating the host
D3D12 device on that driver had left two private 1 GiB reservations at
0x7fff0000 and 0xbfff0000. The largest hole left below 4 GiB was 7.19 MiB.
A standalone probe reproduces both reservations around D3D12CreateDevice,
and they go when the device is released.

Before it maps the image or opens the host GPU, `xtp run --execute` now holds
an uncommitted placeholder below 4 GiB of the size the known build is
measured to ask for (KnownBuild::low_va_reserve_mib). The first matching
32-bit placeholder request then takes it. The reserve costs address space
only, no RAM or commit. Unknown builds get none.
XTP_LOW_VA_RESERVE_MIB=<n> holds n MiB instead and hands it out in pieces to
32-bit placeholder requests that the host refuses. 0 turns the reserve off.

With the reserve, the title passes that point, shows its first-boot screens
and reaches the world on the same machine.
@simnJS

simnJS commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the update. I checked a99cc04: its tree is identical to the approved 742e168, and only the commit message changed (the Co-Authored-By trailer was dropped), so my approval stands. The description still says AI tools wrote the change, which covers what CONTRIBUTING asks. The five earlier suggestions remain open and non-blocking, and would be welcome as a follow-up PR. Unless you'd rather do it yourself, I'll rename the title to hle, game, app: … before merging. The only red check is the known gpu-debug-layer failure (message 1419), which also fails on main; I'll merge once it is fixed there.

@simnJS
simnJS merged commit 725c007 into MiamiGame:main Nov 25, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/app apps/ area/docs docs/, Markdown area/game touches crates/xtp-game area/hle touches crates/xtp-hle overlap another open PR changes the same files size/M 100 to 399 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants