Repository navigation
xmem: serve the seven missing imports (physical pages, default allocators, XMemIsToolsMemAvailable); XMemVirtualAlloc takes 2 MiB pages and placeholders - #6919
Conversation
|
Tested |
|
Tested Result: every
The title no longer stops at any of its allocation checks. Where it stops next: the first Tested and written by Claude (Claude Code). |
IAmNotSiob
left a comment
There was a problem hiding this comment.
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
XMemIsToolsMemAvailablelogging 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.
|
Independently tested |
|
On |
|
Tested Local integration branch: From the startup trace (
Counts, API names and offsets only. AI-assisted (Claude Code). |
|
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 The startup trace shows every xmem call succeeding, with no
The run then gets through AI-assisted (Claude Code). |
c9c9063 to
94fe02a
Compare
shayderrr
left a comment
There was a problem hiding this comment.
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
|
Summary Why merge Verdict: Approve |
…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
…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>
94fe02a to
36936f3
Compare
|
Retail-exe validation on Windows 11 / RTX 5070 Ti,
This is the fix that gets the retail title past its boot-time virtual-memory allocation. Thank you. |
…1cc6e3c snapshot tupacfan04: the page still said seven imports had no shim and that XMemVirtualAlloc refused all 23 calls, while docs/xcl_compare.md (this PR) and docs/runtime_imports.md say the four physical-page calls are served. 042c5f3 (ItsNotRexed#6919) did give all 12 imports a shim and made XMemVirtualAlloc accept the attribute word, so the old text was stale, not a different measurement. The call-site counts stay measured at 1cc6e3c (they are properties of the exe); the shim column is relabelled as the current state and all 12 rows read yes. Five of the 23 allocations are still refused, but for the allocation type, not the attributes: 0x20406000 carries MEM_PHYSICAL, which the shim does not forward. The physical-page section now describes the pagefile-backed pool that ItsNotRexed#6919 implements instead of proposing one.
…gainst main Update docs/retail_boot_chain.md "What clears it" column against current main: - Stops 1, 2, 6, 10, 11 landed on main (ItsNotRexed#6919, 042c5f3: physical pages, 2 MiB pages, and placeholder reservations). - Stop 3 landed on main (e417570: XErrorReport in runtime/shims/xgameruntime.cpp). - Replace closed unmerged PR ItsNotRexed#4313 (Stop 4) with tracking open PRs ItsNotRexed#8379, ItsNotRexed#7524. - Replace closed unmerged PR ItsNotRexed#4348 (Stop 5) with active takeover PR ItsNotRexed#8461, ItsNotRexed#7784. - Link open tracking PRs for Stops 7, 9, 12 (ItsNotRexed#8851, ItsNotRexed#9061, ItsNotRexed#2490, ItsNotRexed#9045, ItsNotRexed#8414). Addresses agulerman's finding in ItsNotRexed#8868.
…hitelist PR 6709 proposed a whitelist for XMemVirtualAlloc: attributes 0x21 with PAGE_READWRITE, or 0x03 with 0x801, everything else ERROR_NOT_SUPPORTED. The branch has moved past that: ItsNotRexed#6908 records whatever attribute word the title passes (note_attributes) and ItsNotRexed#6919 serves physical pages, 2 MiB pages and placeholders, with host_protect dropping the PAGE_GRAPHICS_* bits. The whitelist is a restriction, not a capability, and it would reject the calls the retail executive actually makes next (0x183, 0x283, 0x181: 2 MiB reserve plus commit) - the ones the PR's own comments document. So the general implementation stays, and what the PR knew is kept where it belongs: a comment on why the two 64 KiB reservation forms need no special case, and two tests that pin both attribute pairs, the 65,537-byte size resolving to two 64 KiB regions, the alignment, and the release.
…tion forms reached at startup Squashed from ItsNotRexed#6709 by Stalkerino, head ecee287 (security scan PASS). Conflicts: xmem.cpp, xmem_test.cpp, docs/runtime_imports.md. Main (ItsNotRexed#6908/ItsNotRexed#6919) already accepts every attribute word and strips PAGE_GRAPHICS_* bits, a superset of the PR's two-pair allowlist, and reserves 64 KiB reserve-only regions as placeholders for physical pages. Kept main's code and docs; dropped the PR's allowlist and its checks that other pairs and commit forms are refused, which contradict main. Kept the PR's alignment/rounding/reserve-only check for both forms, without the AllocationProtect check (a placeholder reports PAGE_NOACCESS).
…lAlloc with console page-size bits (what ItsNotRexed#6919 leaves) Squashed from ItsNotRexed#4531 by labj1987, head 01fc4b1 (security scan PASS). Rescan of the new commit only (007ae5e..01fc4b1, a test-only variable rename): sec_prescan flags=0, Haiku read PASS. Superset check: the head is already cut down to what ItsNotRexed#6908/ItsNotRexed#6919 leave (4 MiB pages, page-size bits on the title's VirtualAlloc, aligned reservations without the placeholder API) and keeps main's attribute acceptance and PAGE_GRAPHICS_* stripping, so it is taken whole. Conflict: xmem.cpp, where the PR turns XMemVirtualAlloc into a wrapper over xmem_virtual_alloc next to ItsNotRexed#7584's map_view; kept both (wrapper, then ItsNotRexed#7584's per-placeholder map_view; the old unmap_page body ItsNotRexed#7584 replaced stays gone). xmem_test under Wine 11.22: 592 checks OK.
ItsNotRexed#6919 The row still said the shim refuses it. main reserves it 2 MiB-aligned through VirtualAlloc2 and refuses it only without the placeholder API; the placeholder calls (0x4000, 0x40000) are made as windows too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.dllhad seven imports with no shim, which a dry run listed as unimplemented.XMemVirtualAllocstill 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 thoseXMemVirtualAllocforms. The argument shapes were measured locally at a title's call sites. The comments inruntime/shims/xmem.cppgive each shape, as counts and argument roles only.New imports
XMemAllocDefault/XMemFreeDefaulttakeXMemAlloc's andXMemFree'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.0means "unmap".XMemMapPhysicalPages(address, UINT64 count, pages)→ the address. A null array unmaps.XMemMapPhysicalPagesScatter(addresses, UINT32 count, pages)→BOOL. A0entry, or a null array, unmaps.XMemFreePhysicalPages(UINT64 count, pages)→BOOL.MapViewOfFile3view 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.XMemVirtualAllocVirtualAlloc2, without the host's large-page privilege.host_protect) is recorded. Mapped pages take the window's protection, as AWE does. A window reservedPAGE_NOACCESSmaps its pages read-write, because they are GPU memory the D3D12 layer reads on the CPU.MEM_RESERVE_PLACEHOLDERandMEM_REPLACE_PLACEHOLDERare passed through. A reserve-only replacement stays a window.The placeholder APIs are looked up in
kernelbase.dllat run time, so nothing new is linked. A host without them getsERROR_NOT_SUPPORTED.ASSUMPTION (in the code and in
docs/runtime_imports.md): nothing commits memory into a window throughkernel32!VirtualAlloc, which a placeholder would refuse.The startup trace records the default allocators in
xmem_attributesand adds anxmem_physical_pagesevent.runtime/README.md(shim list, trace events) anddocs/runtime_imports.mddescribe 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:0entry, scatter maps and unmaps, invalid addresses and page numbers, double free, and page numbers reused after a freectest: 107/107 passed. The skipped tests are the ones that need game files, the same as onmain.gta6rt --dry-runagainst a local copy: unimplemented imports went from 30 to 23, with none left inxmem.dll.AI-assisted: yes (Claude Code)
Checklist
docs/design.md, with how it was confirmed. (No translator change.)🤖 Generated with Claude Code