Repository navigation
Runtime: serve the console's 2 MiB and 4 MiB pages in XMemVirtualAlloc and a title's VirtualAlloc, without the host's large-page privilege - #4531
Conversation
Kam471
left a comment
There was a problem hiding this comment.
Built and ran xmem_test at a57fa304 on Windows 11: 146 checks, 0 failures, exit 0.
The console's 2 MiB and 4 MiB page requests work through XMemVirtualAlloc and a title's VirtualAlloc without the host large-page privilege, including the 64 KiB one-page case and the expected Win32 failure. No blocking issue.
Flyander
left a comment
There was a problem hiding this comment.
The shim keeps console page-size bits away from Win32, validates unsupported combinations before allocation, and rounds the requested region with overflow checks. New reservations use VirtualAlloc2 alignment when available and a bounded release-and-retry fallback otherwise; existing-address commits are expanded to the requested guest page granularity. The tests cover both allocator entry points and the fallback. I found no correctness issue in the diff.
|
Tested a57fa30 merged with main d0835dd (merge 249f477c9, no conflicts) on native Windows 11, MSVC 14.51, full
|
|
One conflict with current main: runtime/test/xmem_test.cpp, where main added the attributes-trace test at the same spot as your page-size tests — keeping both resolves it (brace balance and both call sites verified in a test merge). Static soundness reads: zero-size rejected, overflow-guarded page rounding, invalid page-bit combinations refused; LEONIDA_XMEM_NO_VIRTUALALLOC2 documented so the env-var guard passes. Actual page-size behaviour is Windows-only; checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only review). |
…c and a title's VirtualAlloc The console's allocation type picks the page size with bits the host reads differently: 0x20000000 (2 MiB) is the host's MEM_LARGE_PAGES, which needs SeLockMemoryPrivilege, 0x80000000 (4 MiB) is rejected, and 0x20400000 (64 KiB) becomes MEM_LARGE_PAGES | MEM_PHYSICAL. XMemVirtualAlloc failed the 2 MiB mode and rejected 4 MiB, and the title VirtualAlloc shim forwarded all three. Both now share one path: the bits are decoded (other combinations stay ERROR_INVALID_PARAMETER), never forwarded, and every page size is served from ordinary host pages with the base aligned to the page size (VirtualAlloc2 with an alignment requirement, else a reserve/release/reserve probe with retry), sizes and addresses rounded to whole pages, and one host allocation per region so VirtualFree and VirtualQuery match what was returned. A title's VirtualAlloc still needs an operation; nonzero XMem attribute words still fail with ERROR_NOT_SUPPORTED. Page-size values as read in OpenScarlett (MIT, kernelx_abi.h, xmemory.cpp) and omonkeyz/xbox-emulator (GPL-3.0-or-later, crates/compat/xmem/src/virt.rs); the probe fallback follows xbox-emulator's reserve_aligned (sys.rs). xmem_test gains 2 MiB / 4 MiB / 64 KiB cases for both entry points (24 of 104 checks fail on main; 146/146 pass here), and xmem_probe reruns it with LEONIDA_XMEM_NO_VIRTUALALLOC2 set to cover the fallback. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a57fa30 to
fc1f8dd
Compare
|
Tested
Not checked: a title that actually requests these page sizes (no executable), and a host where AI-assisted (Claude Code). |
|
Thanks for the broader Windows run, @Krashgamer. A scratch trace adds direct confirmation of the requested 4 MiB path on fc1f8dd8 with 3faac557, Windows 11 x64 and MSVC 19.44.35230. All 18 default 4 MiB reservations succeeded through |
|
Tested fc1f8dd on NVIDIA GeForce RTX 4080, driver 617.42: xmem_test exits 0 with "xmem_test: OK (158 checks)". The log has PASS lines for the 2 MiB and 4 MiB VirtualAlloc cases, e.g. "PASS kernelbase.dll!VirtualAlloc, 4 MiB (0x80000000) pages, tags 0x50000000: aligned, two pages (error 0)". The xmem_probe leg with LEONIDA_XMEM_NO_VIRTUALALLOC2=1 was not run. AI-assisted. |
|
I checked the next startup allocation against the exact XMem and registry sources at
On our prepared Linux runtime, the second form is the next observed startup blocker after the two 64 KiB address reservations. This identifies a consumer for the aligned allocation work and a separate requirement for the CPU/GPU access and coherence flags. The control exercises #4531's existing aligned-page support. I have not established the full meaning of the access word or GPU coherence for ordinary host pages. AI-assisted. |
|
Windows/MSVC integration validation: combined this PR with the narrow reserve-only forms from #6709 and allocation-failure tracing from #6733. All 170 XMem checks passed on Windows x64, MSVC 14.44 / SDK 10.0.26100. The aligned-page implementation gets past its synthetic 2/4-MiB tests. The next startup allocation is still rejected with ERROR_NOT_SUPPORTED by the nonzero-access-attributes check. It is a reserve+commit graphics-coherent read/write request, rather than a reserve-only operation, so the reservation changes cannot cover it. No large-page alignment failure was observed for this case because validation rejects it first. No game data, binary excerpts, addresses or trace files are attached. AI-assisted with Codex. |
|
Tested The page-size handling works, but the startup 2 MiB reserve+commit (1.15 GiB) still fails here: Note: this PR currently conflicts with Windows 11 26200, AMD RX 9070 XT, MSVC 14.44, Windows SDK 10.0.26100, own Xbox 1.0.2.1 package (with AI-assisted (Claude Code). |
|
Tested on the retail engine Needed by the retail exe: its GPU pools are committed with 2 MiB pages (0x20003000) at exe+0x1e1d181/0x1e1d288/0x1e1d369 and elsewhere; they succeed with this PR once the attribute word (0x183/0x283/0x181) and the PAGE_GRAPHICS_* protect bits (0x22004) are accepted (see my note on #6709). It conflicts with #6709 in XMemVirtualAlloc; I resolved it by taking this PR's console_virtual_alloc path. |
|
Measured on the 1.0.2.1 package (own copy, Windows 11): with #6709 applied the title's third |
|
Rebased onto current main (1cc6e3c) with the conflict resolved: |
|
Data for this PR from the retail executable (RT-5). This is a static read of my own copy with The startup function that the first boot stops in (around
So once this PR is rebased, serving the 2 MiB commit form with attribute words AI-assisted (Claude Code). |
|
This PR now conflicts with What I decided in the conflicts:
Tested at |
|
Note 🤖 Claude Opus 5.5 responding on behalf of labj1987 #6919 should land first for the retail boot; I'll cut this PR down to what #6919 doesn't cover and rebase it onto #6919 once that merges, rather than push a second version of the same function. Checked on
What would be left for this PR after #6919:
I have a rebase of this PR on current |
Problem
The console's allocation type picks the page size with bits the PC reads differently:
0x20400000MEM_LARGE_PAGES | MEM_PHYSICAL0x20000000MEM_LARGE_PAGES(needsSeLockMemoryPrivilege)0x80000000(with or without0x20000000)MEM_4MB_PAGES, rejectedOn
main:XMemVirtualAllocfails the 2 MiB mode withERROR_NOT_SUPPORTED("needs an aligned reservation strategy that this shim does not provide") and rejects0x80000000as an unknown bit (ERROR_INVALID_PARAMETER).VirtualAllocshim (RT-217) strips onlyMEM_GRAPHICS/MEM_TITLE, so a page-size request goes to the host as the host's flags: 2 MiB and 4 MiB requests fail (no player account holds the lock-memory privilege), and0x20400000gets the host'sMEM_LARGE_PAGES | MEM_PHYSICALmeaning instead of 64 KiB pages.An engine that allocates its big pools with large pages gets
NULLat boot. Other console layers hit this with real titles before us; xbox-emulator and OpenScarlett both serve these page sizes.Fix
runtime/shims/xmem.cpp:ERROR_INVALID_PARAMETER.XMemVirtualAllocand the titleVirtualAllocshare one path (console_virtual_alloc). The bits are never forwarded; every page size is ordinary host pages, with what a title can observe kept:VirtualAlloc2withMEM_ADDRESS_REQUIREMENTS.Alignment(looked up at run time), falling back where it is missing or refuses the parameter (ERROR_INVALID_PARAMETER) to a reserve-size + alignment/ release / reserve-aligned probe that retries when another thread takes the range (the method of xbox-emulator'sreserve_aligned);MEM_TOP_DOWNis honoured in both;VirtualFree(base, 0, MEM_RELEASE)andVirtualQueryreport exactly the base and rounded size returned. NoVirtualFree/VirtualQueryshim is needed.XMemVirtualAllockeeps defaulting to reserve + commit with no operation bit; the titleVirtualAllockeeps Win32's rule that an operation is required.MEM_PHYSICALwithoutMEM_LARGE_PAGESin a title'sVirtualAllocstill goes to the host unchanged.XMemVirtualAllocattribute word still fails withERROR_NOT_SUPPORTED(that word is RT-202's, Runtime: xmem honours the attribute word's alignment and reports the memory kind (RT-202) #3601).Docs: a "Console page sizes" section in
docs/runtime_imports.md, and thexmem.dllline inruntime/README.md.Not covered: the page size comes from each call's bits and is not remembered per region, so a commit without the bits inside a 2 MiB reservation commits host pages only (documented); the host still pages 4 KiB at a time underneath (only TLB timing could tell), and no shim serves the physical-page calls (
XMemAllocatePhysicalPages,XMemMapPhysicalPages*), which take the same bits; nothing in the package imports them.Overlap
#3390 (RT-217) and #3601 (RT-202) edit the same file. Both leave the 2 MiB mode unsupported, so this does not duplicate either; whichever lands second needs a small rebase. #2401 (attribute-word trace) touches
XMemAlloconly.References
Facts and method, credited in the code comments:
include/openscarlett/kernel/kernelx_abi.h(MEM_LARGE_PAGES0x20000000,MEM_4MB_PAGES0x80000000) andsrc/kernel/xmemory.cpp(4 MiB =MEM_4MB_PAGES | MEM_LARGE_PAGES), commit2241564.crates/compat/xmem/src/virt.rs(page-size decode, aligned large-page reservation and its test) andsrc/sys.rs(reserve_aligned), commitad24144.No code is copied; the retry probe follows xbox-emulator's method (GPL-3.0-or-later, compatible with this repository's GPL-3.0).
Tested
Linux, Wine 10.0, clang-cl 21 + lld-link with the xwin Windows SDK 10.0.26100 (
runtime/cmake/clang-cl-xwin.cmake), RelWithDebInfo. CPU-only; no GPU involved.xmem_testwith the new cases againstmain'sxmem.cpp: FAILED, 24 failures of 104 checks before main added its attribute-trace test (2 MiB returnsNULLwith error 50, 4 MiB with error 87, and every titleVirtualAllocwith0x20000000,0x80000000,0xa0000000or0x20400000fails; the remaining large-page checks never run because the allocation isNULL). With the change: OK, 146 checks.xmem_proberunsxmem_testagain withLEONIDA_XMEM_NO_VIRTUALALLOC2=1, so the probe fallback is covered: OK, 158 checks (rebased on3faac557; 146 before main's 12 attribute-trace checks).xmem.cppand has a test:xmem,xmem_probe,loader,dll_thread_calls,run_tiny_game*and the rest of the loader set: 20/20 pass. The fullctestunder Wine passed apart from five Vulkan/D3D12 tests (vk_fence_dispatcher_sync,vk_presenter_sync,d3d12_fence_timing,allocator_proxy,d3d12_private_data) and two that did not finish (pipeline_cache_file,xbox_present); none of them linksxmem.cpp.python -m compileall -q make_game.py tools tests,tests/test_docs_*.py(10 files),scripts/check_no_game_data.pyon the changed files,git diff --check: pass.Not run on Windows itself: I have no Windows host with MSVC. A run of
xmem_testthere (and of the 4 MiB case on a machine where the host'sVirtualAlloc2alignment path is used) would be welcome.No game data: the tests use synthetic sizes and flag values only.
AI-assisted (Claude Code).
🤖 Generated with Claude Code