Skip to content

xmem: serve the seven missing imports (physical pages, default allocators, XMemIsToolsMemAvailable); XMemVirtualAlloc takes 2 MiB pages and placeholders - #6919

Merged
shayderrr merged 1 commit into
ItsNotRexed:mainfrom
NiiRoZz:rt-xmem-physical-pages
Nov 23, 2026

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #6750 (comment)

Depends on: none. Rebased onto #6908 (merged): its attribute-word recording and PAGE_GRAPHICS_* handling are kept as they are. Overlaps in part with #4531 (2 MiB pages), #5253 (XMemAllocDefault/XMemFreeDefault) and #5381 (the physical-page mechanism). Whichever lands first, I'll rebase this one onto it.

What and why

xmem.dll had seven imports with no shim, which a dry run listed as unimplemented. XMemVirtualAlloc still refused some of the calls a title actually makes: five ask for 2 MiB pages, and several reserve placeholder regions or carve windows out of them. This PR serves all seven imports and adds those XMemVirtualAlloc forms. The argument shapes were measured locally at a title's call sites. The comments in runtime/shims/xmem.cpp give each shape, as counts and argument roles only.

New imports

  • XMemAllocDefault / XMemFreeDefault take XMemAlloc's and XMemFree's arguments and share their heap, so a block from either allocator can be freed by either.
  • XMemAllocatePhysicalPages(attributes, UINT64* count, UINT64* pages) → BOOL, with an in/out count. Each call is backed by one pagefile-backed section of 64 KiB pages.
    • A page number is a 4 KiB frame number: a non-zero multiple of 16 below 2^25, because a caller packs them that way. 0 means "unmap".
    • Freed numbers are reused.
  • XMemMapPhysicalPages(address, UINT64 count, pages) → the address. A null array unmaps.
  • XMemMapPhysicalPagesScatter(addresses, UINT32 count, pages) → BOOL. A 0 entry, or a null array, unmaps.
  • XMemFreePhysicalPages(UINT64 count, pages) → BOOL.
  • Every mapped page is its own MapViewOfFile3 view in a 64 KiB placeholder. So a page keeps its contents across unmap and remap, can be mapped at several addresses, and can be remapped on its own.
  • XMemIsToolsMemAvailable() → FALSE: a PC has no devkit tools memory. Callers only ask on an out-of-memory path.

XMemVirtualAlloc

  • 2 MiB guest pages are committed 2 MiB-aligned through VirtualAlloc2, without the host's large-page privilege.
  • A reserve-only 64 KiB-page region becomes a placeholder window, and its protection (after xmem: record XMemVirtualAlloc's attribute word and drop the PAGE_GRAPHICS_* protection bits (retail exe GPU pools) #6908's host_protect) is recorded. Mapped pages take the window's protection, as AWE does. A window reserved PAGE_NOACCESS maps its pages read-write, because they are GPU memory the D3D12 layer reads on the CPU.
  • MEM_RESERVE_PLACEHOLDER and MEM_REPLACE_PLACEHOLDER are passed through. A reserve-only replacement stays a window.

The placeholder APIs are looked up in kernelbase.dll at run time, so nothing new is linked. A host without them gets ERROR_NOT_SUPPORTED.

ASSUMPTION (in the code and in docs/runtime_imports.md): nothing commits memory into a window through kernel32!VirtualAlloc, which a placeholder would refuse.

The startup trace records the default allocators in xmem_attributes and adds an xmem_physical_pages event. runtime/README.md (shim list, trace events) and docs/runtime_imports.md describe the new behaviour.

Tested

Windows 11, MSVC 19.44, scripts/build_runtime.ps1 (CPU build, no Vulkan headers):

  • xmem_test: 173 checks, OK (including xmem: record XMemVirtualAlloc's attribute word and drop the PAGE_GRAPHICS_* protection bits (retail exe GPU pools) #6908's). The old check that expected 2 MiB pages to be refused now checks that they succeed. New checks cover:
    • the default allocators, freed by either free function
    • physical pages: allocate, map, unmap, remap in reverse order with contents kept, aliasing across two windows, a 0 entry, scatter maps and unmaps, invalid addresses and page numbers, double free, and page numbers reused after a free
    • placeholder reservation and replacement, both reserve-only and committing
    • 2 MiB alignment and rounding
  • ctest: 107/107 passed. The skipped tests are the ones that need game files, the same as on main.
  • gta6rt --dry-run against a local copy: unimplemented imports went from 30 to 23, with none left in xmem.dll.

AI-assisted: yes (Claude Code)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No translator change.)

🤖 Generated with Claude Code

@jlric

jlric commented Nov 23, 2026 •

Copy link
Copy Markdown

Tested c9c90632 on CachyOS x86-64, Wine 11.22, clang-cl/xwin. xmem_test: 156/156 checks passed, exit 0. Synthetic, CPU-only. AI-assisted.

@theswiss24

Copy link
Copy Markdown

Tested c9c906327 against the retail executable (gta6rt --run, Windows 11, RTX 4070, LEONIDA_D3D12=vulkan, five runs). The game's own code was only looked at locally; nothing of it is in this comment.

Result: every XMemVirtualAlloc the title makes at startup now succeeds. That's five requests in the trace:

  • the CPU and GPU 64 KiB reservations (attributes 0x21 and 3),
  • the 2 MiB commit (0x20003000, attributes 0x283, protect 0x2404),
  • a 20 MiB 64 KiB commit (0x20403000, attributes 0x181).

The title no longer stops at any of its allocation checks.

Where it stops next: the first operator new after these allocations. In 3 runs it reads 0xffffffffffffffff; in 2 it exits with 127 at the same point and no exception is recorded. That isn't an xmem problem: the title's allocator fetches the current thread's heap from its static TLS through ThreadLocalStoragePointer[0], which on main is gta6rt.exe's own block. That's what #4313 (RT-259) fixes, so the next useful test is this PR together with #4313. #4313 conflicts with main right now.

Tested and written by Claude (Claude Code).

@IAmNotSiob IAmNotSiob left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tested on win10 VM (RTX 6000 passthrough, MSVC, RelWithDebInfo) at this pr's head: builds clean, xmem test passes. full ctest 255/260; the 5 failures are gameinput_host, root_signature_oracle, d3d12_indirect_dispatch_count, d3d12_close_parity, d3d12_indirect_rt, none of which touch xmem (that VM has no controller / its own d3d12 quirks). didn't rerun them on main, so treat those as "not caused by this", not "known".

code read, looks careful:

  • placeholder windows + section-backed 64 KiB pages under one mutex is the right model for map/unmap, and page numbers as non-zero multiples of 16 below 2^25 match what #6824 describes
  • freed slots reused, so a long run can't exhaust page numbers
  • VirtualAlloc2/MapViewOfFile3 resolved at run time with ERROR_NOT_SUPPORTED otherwise, nice, no onecore.lib
  • dropping PAGE_WRITECOMBINE too is a good call given the D3D12 layer reads these pages on the CPU

small things, non-blocking:

  • the ASSUMPTION that nobody kernel32!VirtualAlloc-commits inside a window: if the title ever does, the placeholder refuses it with a fairly opaque error. a one-line trace there would make that obvious from a boot log
  • XMemIsToolsMemAvailable logging once to stderr is fine, but the title hits it right before a deliberate int3 on OOM, so maybe mention that in the message (so people reading a boot log know the break after it is expected)

also: this covers what #6709, #6814, #6878, #6908 and #6733 do for XMemVirtualAlloc (attribute words, protection bits, error/trace), and it's the only one that unblocks the #6824 stop. all six touch xmem.cpp, so i'll point those at this one.

AI-assisted (Claude Code).

TL;DR: approve: builds and xmem test passes on Windows, design is sound, two optional logging nits. it supersedes five other xmem prs.

@Vencite

Vencite commented Nov 23, 2026

Copy link
Copy Markdown

Independently tested c9c906327 on native Windows with Visual Studio 2022, MSVC 19.44.35230, Windows SDK 10.0.26100.0, x64 RelWithDebInfo. ctest -R "^xmem$" -V passed all 156 checks, including 2 MiB alignment, placeholder replacement, scatter mapping, and content preservation across remaps. This was a synthetic, CPU-only test. AI-assisted.

@ICUMADETHIS

Copy link
Copy Markdown
Contributor

On c9c90632 merged onto 1cc6e3c1, I reserved two 64 KiB pages and replaced only the first. VirtualQuery confirmed the second page was still reserved, yet XMemMapPhysicalPages returned ERROR_INVALID_ADDRESS (487) for it. record_window() removes the entire original range from the shim’s bookkeeping. Please preserve the unaffected range when splitting a tracked reservation and add a test for mapping both pages afterward.

@Vyral1978

Copy link
Copy Markdown
Contributor

Tested c9c90632 with my own 1.0.2.1 copy (game_scarlett_master.exe, SHA-256 e95020b2…a08993) under gta6rt --run. Setup: Windows 11, NVIDIA RTX 3070, LEONIDA_D3D12=vulkan, MSVC (VS 18) + Ninja, writes sent to an --overlay folder. Pass: the boot gets past XMemAllocatePhysicalPages.

Local integration branch: main 1cc6e3c1 + this PR + #6582 + #4313 + #4348. #4313 and #4348 had add/add conflicts with main, resolved by keeping both sides. I left out #6709 and #4531: #6709 conflicts with this PR in XMemVirtualAlloc, and this PR already covers what both were needed for.

From the startup trace (--trace):

Counts, API names and offsets only. AI-assisted (Claude Code).

@0klavair

Copy link
Copy Markdown
Contributor

Tested on the retail executable: pass, and on its own it covers the whole xmem part of the startup.

Own 1.0.2.1 copy (exe sha256 e95020b2…08993), Windows 11 23H2, RTX 5060 / 621.01, Ryzen 9 5950X, LEONIDA_D3D12=vulkan, LEONIDA_UNIMPLEMENTED=stop, MSVC 19.44. Base: main 1cc6e3c1 with #4313, #6792, #6582, #6733, #4348 and #6803 merged. For this test, this PR's xmem.cpp was taken whole, in place of #6709/#3390/#6814 and my local 2 MiB / physical-page stand-ins. Local stand-ins for device slots 26/48/73 (#6964, #6954 and #6935 cover them).

The startup trace shows every xmem call succeeding, with no xmem_virtual_alloc_failed:

call type attributes protect size
XMemVirtualAlloc 0x20402000 0x21 0x4 24 GiB
XMemVirtualAlloc 0x20402000 0x3 0x801 24 GiB
XMemVirtualAlloc 0x20003000 0x183 0x22004 1,228,931,072
XMemVirtualAlloc 0x20003000 0x283 0x2404 2,305,818,624
XMemVirtualAlloc 0x20403000 0x181 0x4 20 MiB
XMemAllocatePhysicalPages 0x280 11,360 pages
XMemVirtualAlloc 0x20401000 0x283 0x42404 64 KiB (from the D3D12 setup function, +0x24786be)

The run then gets through D3D12XboxCreateDevice, four queues, fences, an allocator and the first command list. It stops where my other runs stop: the new list's console slots 131/132, which @tedin7's command-list order item covers (#6750 (comment)). The other xmem PRs reach the same point with more pieces.

AI-assisted (Claude Code).

@shayderrr shayderrr 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.

Summary
runtime/shims/xmem.cpp adds seven measured xmem.dll imports: XMemAllocDefault/XMemFreeDefault share a heap with the existing allocators, XMemIsToolsMemAvailable returns FALSE, and physical-page calls use Windows placeholders (VirtualAlloc2, MapViewOfFile3, UnmapViewOfFile2) for pagefile-backed 64 KiB pages. XMemVirtualAlloc now accepts the attribute word, strips console graphics/write-combine bits and commits 2 MiB-aligned pages; new xmem_virtual_alloc/xmem_physical_pages trace events and SHIM_TABLE entries, with tests in xmem_test.cpp and docs in runtime_imports.md/runtime/README.md.

Why merge
Grounds the runtime's memory shim in measured title behavior, unblocking physical-page and large-page paths during static recompilation. Thoroughly tested and documented.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary
runtime/shims/xmem.cpp adds seven measured xmem.dll imports: XMemAllocDefault/XMemFreeDefault share a heap with the existing allocators, XMemIsToolsMemAvailable returns FALSE, and physical-page calls use Windows placeholders (VirtualAlloc2, MapViewOfFile3, UnmapViewOfFile2) for pagefile-backed 64 KiB pages. XMemVirtualAlloc now accepts the attribute word, strips console graphics/write-combine bits and commits 2 MiB-aligned pages; new xmem_virtual_alloc/xmem_physical_pages trace events and SHIM_TABLE entries, with tests in xmem_test.cpp and docs in runtime_imports.md/runtime/README.md.

Why merge
Grounds the runtime's memory shim in measured title behavior, unblocking physical-page and large-page paths during static recompilation. Thoroughly tested and documented.

Verdict: Approve

ASTROWwwW pushed a commit to ASTROWwwW/Leonida that referenced this pull request Nov 23, 2026
…orts (physical pages, default allocators, XMemIsToolsMemAvailable)

Author: NiiRoZz

Conflicts with ItsNotRexed#6709 in xmem.cpp, xmem_test.cpp and
docs/runtime_imports.md, resolved to this PR's side: it accepts every
attribute word and reserves 64 KiB-page regions as placeholders, which
replaces the two allow-listed reservation forms of 6709 and the tests that
expected the other forms to be refused. Not built here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UkEUa9YfGQH4p9g1Guw9gq
@NiiRoZz NiiRoZz changed the title xmem: serve the seven missing imports (physical pages, default allocators, XMemIsToolsMemAvailable); XMemVirtualAlloc takes attributes, 2 MiB pages and placeholders xmem: serve the seven missing imports (physical pages, default allocators, XMemIsToolsMemAvailable); XMemVirtualAlloc takes 2 MiB pages and placeholders Nov 23, 2026
…emVirtualAlloc takes 2 MiB pages and placeholders

Serve the seven xmem.dll imports the shim table lacked, with argument shapes
measured at a title's call sites:

- XMemAllocDefault / XMemFreeDefault share XMemAlloc's heap.
- XMemAllocatePhysicalPages / XMemFreePhysicalPages / XMemMapPhysicalPages /
  XMemMapPhysicalPagesScatter: 64 KiB pages of pagefile-backed sections, one
  MapViewOfFile3 view per page in a placeholder window, so pages keep their
  contents across remaps and can alias. Page numbers are non-zero multiples
  of 16 below 2^25; 0 unmaps.
- XMemIsToolsMemAvailable returns FALSE.

XMemVirtualAlloc no longer refuses 2 MiB pages (aligned through
VirtualAlloc2), makes reserve-only 64 KiB regions placeholder windows, and
passes MEM_RESERVE_PLACEHOLDER and MEM_REPLACE_PLACEHOLDER through. The
attribute word and PAGE_GRAPHICS_* handling from ItsNotRexed#6908 is kept as is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Kam471

Kam471 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Retail-exe validation on Windows 11 / RTX 5070 Ti, game_scarlett_master.exe SHA-256 E95020B2..., with the change cherry-picked onto the exe-day integration branch:

  • Before: the game called XMemVirtualAlloc with type=0x20003000, attributes=0x183, protect=0x22004, size ~1.2 GiB (and a second 2.3 GiB call); the old shim returned null, and the game hit its own int3 at game+0x1e1d01b.
  • After: three XMemVirtualAlloc calls succeed (0x20003000/0x183, 0x20003000/0x283, 0x20403000/0x181; 20 MiB 64 KiB-page call included) and the game advances to XCRDAPI!DStorageGetFactory. No assert on the xmem path.
  • Local xmem_test: 167/167 checks after merging the hook-aware XMemAlloc/XMemFree in our branch (the two initial failures were only double xmem_attributes tracing from calling the default allocator internally; fixed).
  • No game data included; RVAs/counts only.

This is the fix that gets the retail title past its boot-time virtual-memory allocation. Thank you.

@Zombins2

Copy link
Copy Markdown

AI-assisted. No game files used.

A compatibility/test-coverage question: reserve-then-commit inside a 64 KiB-page reservation worked on main f5ff1546, but fails at 36936f3b, including through XMemVirtualAlloc itself.

For each attribute word (0 and 0x21), the probe first calls XMemVirtualAlloc(nullptr, 1 MiB, MEM_RESERVE | 0x20400000, attributes, PAGE_READWRITE). It then requests a 64 KiB commit at three separate pages inside that reservation: base + 64 KiB, +128 KiB and +192 KiB, using the three paths below. At both revisions the reserve succeeds. Main reports committed, writable memory for all six requests; the PR returns null with ERROR_INVALID_ADDRESS (487) for all six:

commit of one page inside the reservation main f5ff154, attributes 0 / 0x21 #6919 36936f3, attributes 0 / 0x21
XMemVirtualAlloc, MEM_COMMIT | 0x20400000 ok / ok 487 / 487
XMemVirtualAlloc, MEM_COMMIT ok / ok 487 / 487
title kernel32!VirtualAlloc, MEM_COMMIT ok / ok 487 / 487
  • The source explains the changed host behavior: a reserve-only page-mode request becomes a placeholder, while these ordinary commit requests still reach host VirtualAlloc. The ASSUMPTION above struct Window names kernel32!VirtualAlloc; the restriction also affects XMemVirtualAlloc's own commit path.
  • This includes attribute word 0, which the baseline already accepts. The existing PR test does exercise an explicit MEM_REPLACE_PLACEHOLDER commit; it does not cover the ordinary reserve-then-commit sequence above.
  • I have not established that this sequence is required by the console API or reached by the title, at startup or later. The retail startup successes reported here are useful evidence, but do not settle that question. This is a synthetic compatibility change, not a demonstrated retail failure or a claim about the title's current stop.

Should ordinary MEM_COMMIT inside these page-mode reservations remain supported? If so, a test through both shim entry points would pin the behavior. If they are intentionally map-only windows, please make that limitation explicit for XMemVirtualAlloc too. This extends the kernel32-only assumption already noted in review; it is separate from @ICUMADETHIS's unaffected-window bookkeeping report.

Setup:

  • A local probe, not in either branch, resolves XMemVirtualAlloc and kernel32!VirtualAlloc through rt::shims::find, as xmem_test does.
  • It is compiled with each tree's own xmem.cpp, registry.cpp and shim headers, using the same MSVC 19.50 command lines as xmem_test. Windows 11 build 26200, CPU only.
  • Both trees' own xmem_test pass: main 116 checks, this PR 173. I independently reran the two probes and these two suites with the same results.
  • The prior head 94fe02a8 also gives six 487s; its xmem.cpp and xmem_test.cpp are byte-identical to 36936f3b.
  • I didn't run the retail executable. I can share the probe.

@ramenbellic

Copy link
Copy Markdown

Tested 36936f3b against the retail executable. Linux under Proton Experimental (wine 11.0), RTX 3070 (driver 620.70.06), Ryzen 5 5600X; gta6rt cross-built with clang-cl 23.1.6 + xwin SDK 10.0.26100 (RelWithDebInfo), LEONIDA_D3D12=vulkan, own 1.0.2.1 executable, gta6rt --run. Base: main 8575d36ed + #4313 + #6582 + #4348 (what it takes on Wine to get past the static initializers and XGameRuntimeInitialize).

AI-assisted (Claude Code); outcomes only, no game data.

@sneylol

sneylol commented Nov 23, 2026

Copy link
Copy Markdown

Tested on the retail executable: pass. this PR carries the whole memory sequence the title runs before slot 133: the placeholder reservation, its splits by the host VirtualFree(MEM_PRESERVE_PLACEHOLDER), the MEM_REPLACE_PLACEHOLDER 64 KiB windows, the 2 MiB commits, and XMemAllocatePhysicalPages/XMemMapPhysicalPages into the windows. Before it, I needed a local stand-in at each of those steps.

Setup: own Xbox 1.0.2.1 copy (exe 120,181,760 bytes), Windows 11 26200, RX 9070 XT (AMD Windows driver), MSVC 14.44 RelWithDebInfo, LEONIDA_D3D12=vulkan, gta6rt --run with --overlay, --trace and --trace-d3d12. Integration branch: main 8575d36 + #6919 (36936f3) + #6964 + #4313 + #6582 + #4348 + #7076 + #7183, plus the console-flags drop from #7037 (now closed in favour of #6954, which does the same for these calls). No local stand-ins: every stop below is the PRs' own behaviour. Counts and API names only.

Result (one run): the device is created; 5 queues (4 through slot 48), 5 fences and 7 allocators; 581 command lists created and closed through slot 73 (list slots 132 and 131 reached on the console-IID lists); slots 78/79 answered; then the xmem placeholder window, its 2 MiB commits and the physical-page maps all succeed (xmem_attributes x7, xmem_physical_pages); the title then calls device slot 133 (a buffer at a title address: unified memory, #313 (comment)), which is refused with E_NOTIMPL, and the title stops on its own assert. That is the next blocker; it is not in any of these PRs.

AI-assisted (Claude Code).

@jtrudeau1530

Copy link
Copy Markdown

Independent Linux/Wine validation of current head 36936f3bf43e33a60e36cff942fa0862e7474645, merged without conflicts onto main 8575d36edc479218972497a7bded8651a42856c0. The resulting runtime/shims/xmem.cpp and runtime/test/xmem_test.cpp are byte-identical to this PR head.

Arch Linux, Wine 11.18, clang-cl 23.1.6, xwin MSVC 14.44.17.14 / SDK 10.0.26100, Ninja RelWithDebInfo, Vulkan and SDL3 enabled. Ryzen 7 9800X3D, Radeon RX 7900 XT, RADV Mesa 26.2.3; the startup failure below occurs before GPU work.

Targeted synthetic comparison:

Test Clean main Main + this PR
xmem 116 checks, pass 173 checks, pass
loader 86 checks, pass 86 checks, pass
pe_loader 79 checks, pass 79 checks, pass
loader_tls 85 checks, pass 85 checks, pass
run_tiny_game pass pass

The targeted CTest selection passes 5/5 on both builds. The full suite was not run.

With the local package, --dry-run maps five modules on both builds; unresolved imports decrease 29 → 22, with none remaining in xmem.dll. --init exits 0 on both builds with no exception or unimplemented-call event.

--run hits the same earlier access-violation class on both builds, in the host library_loader.cpp:75 map lookup inside host_module_name. The PR build was symbolized with its matching PDB. Neither run reaches an xmem_attributes event, so this setup does not yet establish that the retail allocation sequence succeeds. Each run was bounded to 30 seconds and terminated while Wine's debugger was active. The TLS/static-initializer relationship is under separate investigation; #4313 was not applied in this comparison.

No game files, raw traces, or executable data attached. AI-assisted.

@hiddenblur

Copy link
Copy Markdown

Checked 36936f3bf on Windows 11 with MSVC (VS 18, /std:c++20 /W4 /permissive- /utf-8, same sources as the CMake target): xmem_test builds with 0 warnings, 173/173 checks.

To give the open reports one place, I wrote a probe that calls everything through rt::shims::find("xmem.dll", …) and ran it unchanged against this head, #6995 (e282ed2a3) and main (8575d36ed). Synthetic, CPU-only, no game files.

Check #6919 #6995 main
A. page keeps its contents across unmap/remap pass pass n/a
B. invalid replacement page number leaves the existing mapping alone fail: VA unreadable afterwards pass n/a
C. contiguous [valid, invalid] over two mapped pages is refused with no change fail: page 0 replaced, page 1 unmapped pass n/a
D. same through XMemMapPhysicalPagesScatter fail, same way pass n/a
E. free a page mapped at two VAs returns TRUE, both views stay mapped, and the next allocation gets the same page number unmaps both, then reuses the number n/a
F. carve the first page of a two-page window, map the second fail, ERROR_INVALID_ADDRESS carve refused, ERROR_INVALID_PARAMETER n/a
G. reserve 1 MiB with 0x20400000, commit one page inside (XMemVirtualAlloc and kernel32!VirtualAlloc, attributes 0 and 0x21) fail, 487 fail, 487 ok

So B–F reproduce the reports above from @editrice, @Zunraz, @ICUMADETHIS and @byPreaZy on the current head. #6995's map/scatter/free handling is a working reference for B–E (prevalidate, and unmap on free like FreeUserPhysicalPages). G is new in one respect: @Zombins2's regression is in #6995 as well, so it belongs to the placeholder model, not just this PR. It may not affect the retail title (every startup call succeeds in the runs above), but it's a regression from main worth a test either way. #6995 refuses F's MEM_REPLACE_PLACEHOLDER carve outright, so it doesn't cover the placeholder windows this PR serves.

AI-assisted. Synthetic inputs only, no game files.

@ramenbellic

Copy link
Copy Markdown

Follow-up on 36936f3b under Wine/Proton. Same setup as above, now with #3410, #6964, #7037 and #7076 merged as well, so the boot reaches the title's descriptor and physical-page setup.

One XMemMapPhysicalPages call fails on Wine, and it ends the boot. The title allocates a second batch of physical pages (2,960) and maps 752 of them into the carved sub-range whose protection is 0x2404. host_protect keeps PAGE_WRITECOMBINE (0x400, below kPageGraphicsMask), so the window's protection is PAGE_READWRITE | PAGE_WRITECOMBINE. view_protect hands that to MapViewOfFile3, which fails on Wine with ERROR_INVALID_PARAMETER. The title then unmaps the other ranges, its device init returns false, and it asserts.

With the cache modifiers dropped for the view, all five maps succeed (752, 1600, 160, 16 and 432 pages) and the boot goes on to the next known stop (device slot 133, a call through a null pointer):

DWORD view_protect(const Window& window) {
    // A section view takes no cache modifier: MapViewOfFile3 refuses PAGE_WRITECOMBINE / PAGE_NOCACHE (Wine with
    // ERROR_INVALID_PARAMETER), and they are only a caching hint for these pagefile-backed CPU views.
    const DWORD protect = window.protect & ~(PAGE_WRITECOMBINE | PAGE_NOCACHE);
    return protect == PAGE_NOACCESS ? PAGE_READWRITE : protect;
}

I measured this only on Wine. I haven't checked whether Windows accepts PAGE_WRITECOMBINE on a placeholder-replacing view, but dropping it changes nothing there except the caching hint.

AI-assisted (Claude Code); outcomes only, no game data.

@gkissel

gkissel commented Nov 23, 2026

Copy link
Copy Markdown

Tested 36936f3b under Wine 11.21 (Linux, clang-cl + xwin, GTX 1650 Mobile), retail 1.0.2.1 executable (own copy), stacked locally with #4313, #6582, #4348, #6964, #7037, #2490, #7076 and #7216. Outcomes only.

Works: every XMemVirtualAlloc at startup, the 2 MiB pools, XMemAllocatePhysicalPages (0x2c60, then 0x5c80 pages), the 185 MiB placeholder, its four VirtualFree(MEM_PRESERVE_PLACEHOLDER) splits and the five MEM_REPLACE_PLACEHOLDER | MEM_PHYSICAL | MEM_LARGE_PAGES windows. With the D3D12 PRs above, the run reaches 1,181 D3D12 calls (581 command lists, SetFrameIntervalX / ScheduleFrameEventX), the same point as docs/retail_boot_chain.md.

One Wine-only failure, with a fix: the first XMemMapPhysicalPages into the descriptor pool (0x2f0 pages into the fourth window) returns NULL, and the title's device init returns false. The windows are reserved PAGE_READWRITE | PAGE_WRITECOMBINE (0x404). view_protect passes that to MapViewOfFile3, and Wine refuses any cache modifier on a view with ERROR_INVALID_PARAMETER. A local diagnostic showed map_view3 … prot 0x404 failed 87 on page 0. Windows accepts it, which is why it doesn't show there.

Fix + test on top of this branch, one commit: gkissel@34c7135e9 (branch gkissel:fix/xmem-view-cache-modifiers, based on 36936f3b).

  • view_protect drops PAGE_WRITECOMBINE | PAGE_NOCACHE. The comment above it already says the D3D12 layer reads these pages on the CPU, where write-combined memory is uncached on Windows too.
  • xmem_test gains the pool's measured shape (sizes, flags, attribute words and page counts as above). Under Wine 11.21 it fails at page 0 with error 87 before the change; after it, xmem_test: OK (179 checks).

With it, the boot goes past the pool and on to the next stop, device slot 133 (stop 12 in the boot-chain doc). Feel free to cherry-pick it, or I can open it as a PR against your branch.

AI-assisted (Claude Code). No game files, bytes or code addresses here.

@DavidM1911

Copy link
Copy Markdown

Tested 36936f3 alone and stacked under #7132 (6324dec, all 30 console imports bound) against the retail 1.0.2.1 package, Windows 11, MSVC 14.50, SDK 10.0.26100.

Dry-run: alone this leaves 23 unimplemented imports (the AcpHal/xapu/chad/xg_xs/DStorage/D3D12ConfigureVirtualMemoryX groups); stacked under #7132 it is 0 unimplemented, 5 modules mapped.

gta6rt --run results, both exit by fault rather than the deliberate int3:

  • This PR alone: gets past the three large reservations that stop main, then issues a fourth XMemVirtualAlloc (attributes 0x283, ~2.15 GiB — the 2 MiB/placeholder path) and a fifth (0x181, 20 MiB from a different caller), then faults: read access violation at address -1 inside the executable, through the CRT entry path. Same fault on both runs.
  • Stacked under runtime: bind the 30 console imports the executable actually takes #7132 (identical xmem.cpp, all imports bound): identical trace and identical fault at the same point — so the crash is not an unimplemented-import return value; it is downstream of the physical-page path this PR adds.

Reading -1 as a pointer right after the placeholder/physical-page sequence suggests one of the page calls returns or leaves a value the title dereferences (e.g. an out-parameter page number the shim does not write, or a BOOL-vs-handle signature mismatch). The five XMemVirtualAlloc events above are the last trace lines before the fault in both runs.

AI-assisted. Counts and API names only, no game data (no addresses, RVAs or dumps).

@jlric

jlric commented Nov 23, 2026

Copy link
Copy Markdown

Wine 11.22 / CachyOS retail result on a local boot stack with this XMem implementation: the per-page path is still mapping at roughly 32 s, when the startup watchdog faults. It had logged 73,728 of 99,776 pages. An opt-in diagnostic mapped the same contiguous section as one view in 10 ms and reached the next D3D12 call. Partial remaps of that view need separate handling. AI-assisted testing.

@Vencite

Vencite commented Nov 23, 2026

Copy link
Copy Markdown

Compared 413ffd6eb (parent) and 36936f3bf (PR) on Windows 11 with the same retail 1.0.2.1 executable. One --run per build, Vulkan selected, separate overlays, and outbound traffic blocked for the loader in both runs.

Result Parent PR
Unimplemented imports at map time 30 23
xmem_attributes events 3 5
Exception 0x80000003 (breakpoint) 0xC0000005 (access violation)
D3D12 trace entries 0 0

The parent reproduced our earlier breakpoint at the same location. With the PR, the exception occurred at a different location after two additional XMem events. The cause of the access violation is still undetermined. AI-assisted.

@shayderrr
shayderrr merged commit 042c5f3 into ItsNotRexed:main Nov 23, 2026
0 of 5 checks passed
@EmreO33

EmreO33 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

A count to check against the docs line here ("the same dry run lists 23"). On current main (8575d36e), gta6rt --dry-run on the retail game_scarlett_master.exe (SHA-256 e95020b2...a08993, the hash in docs/runtime_imports.md) already lists 29 unimplemented imports, not 30: #6792 made d3d12_xs.dll!D3D12ConfigureVirtualMemoryX a shim, so the executable's row reads shim 54, host 432, module 72, unimplemented 29.

The 29 are the doc table's list minus that one: xmem.dll 7, xg_xs.dll 2, XCRDAPI.dll 1, chad.dll 5, xapu.dll 5, AcpHal.dll 9. With this PR's seven xmem.dll imports served, the dry run should list 22, not 23. The doc table's d3d12_xs.dll row and its sentence "they hold 8 of the 30" are also from before #6792.

--init on the same files matches the doc: exit 0, 15 trace events, 4 TLS callbacks and 4 DllMains returning 1, nothing unimplemented called.

Windows 11 26300, MSVC 19.44, clean runtime build (299/299). Counts only, nothing from the game. AI-assisted (Claude Code).

@kormocicsaba

Copy link
Copy Markdown

Tested 36936f3bf, merged alone into main 8575d36: pass. 257/259; the two failures are the main baseline.
Next to #6995 it covers more of the boot chain, so I'd merge this one first. #6995's TitleVirtualFree is still worth having on top: without it a window released with kernel32!VirtualFree is assumed gone (your comment at g_windows), while its views can still be mapped on the host.

Setup: RTX 4070 (driver 621.01), Windows 11 Pro 26300, MSVC (VS 18) RelWithDebInfo with Ninja, Vulkan SDK 1.4.363.0. The PR head was merged alone into main 8575d36 and runtime/ was built. I ran the full ctest -j8 --timeout 300; no game files were used.
Baseline on main: d3d12_vulkan_device and d3d12_indirect_dispatch_count fail on main 8575d36 as well. d3d12_bindless_churn fails now and then under -j8 on main too: it failed in main's -j8 run and passed 3 of 3 times run alone there.

AI-assisted review (Claude Code). How this compares with the other boot-chain PRs: #7333 (comment)

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.