runtime: commit startup blocks through XMemVirtualAlloc #1091
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1098"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-24T00:59:10Z.
Refs #870
Change
The desktop
XMemVirtualAllocaccepted only the two reserve-only startup calls (#888/#945). In the startup checkpoints on #870, the next calls ask for committed blocks and were refused. This adds one commit profile to the existing export insrc/xmem_mapped_pages.cpp, with no export or ordinal change.Accepted configurations, each with a null address and a nonzero size that is a multiple of 64 KiB:
0x200030000x1830x220040x200030000x2830x24040x204030000x181PAGE_READWRITEEach call commits a fresh private
PAGE_READWRITEblock of exactly the requested size (not rounded), zero-filled and released by the caller withVirtualFree. Alignment: theMEM_LARGE_PAGEStype0x20003000gets a 2 MiB-aligned base (VirtualAlloc2with an address requirement). TheMEM_64K_PAGEStype0x20403000(MEM_LARGE_PAGES | MEM_PHYSICALinwinnt.h) keeps the 64 KiB granularity ofVirtualAlloc. Sizes are not rounded to 2 MiB because two of the four pool sizes the caller requests are odd multiples of 1 MiB. TreatingMEM_LARGE_PAGESas a 2 MiB requirement is an assumption from the desktop definition. A local run of the startup sequence showed no difference between 64 KiB-only and 2 MiB-aligned pool bases up to its next stop, so it is no evidence either way. If Windows cannot commit the block, the call returns NULL with the Windows error. Every other argument set keeps the existingERROR_INVALID_PARAMETERrefusal, and the reserve-only profile is unchanged.This is a proposed desktop policy. No independent reference describes these attribute words. Large pages themselves, the console protection bits above
PAGE_READWRITE(0x2000,0x20000, and write-combining0x400) and any GPU visibility they request are not reproduced.The third configuration (call 7 in the sequence) was found by @mumba17 in their independent Windows 11 native-loader repeat on #870. Thanks for that; I added it here after reading the call sites.
Verification
Windows 10 Pro 22H2 (19045.6466), MSVC 19.44.35207.1 x64, CMake/Ninja, Python 3.13 venv. Tested head
96309447onmain072e85b6. The full release suite ran on4f52ce68(same change onmainc205cffd); after the final rebase (no XMem file changed onmain), the fixture and thexmem|configure_vm|vm_translation|era_families were rerun in both presets.New test
cpu_native_xmem_pool_commit(tests/cpu/xmem_pool_commit.asm+tests/cpu/xmem_pool_commit_check.py). The source-built EXE importsXMemVirtualAllocby name, and the same body runs under the Windows loader and frompe_map_run:VirtualQuerybase, allocation base,MEM_COMMIT,PAGE_READWRITE,MEM_PRIVATE; a region size equal to the requested size, with the byte just past the block outside the allocation (the 2 MiB + 64 KiB block exposes any rounding to 2 MiB); every byte reads zero; a block-specific pattern in the first and last QWORD of every 64 KiB page (so also the block's first and last QWORD) reads back; release withVirtualFree, after which the block reads asMEM_FREE.87: each type withoutMEM_COMMIT, the two pool pairs crossed, each type with a pair from the other, protection0x2004with0x183,PAGE_READONLYwith0x181, the live block as the address, size 0, and size 4 MiB + 4 KiB. All three blocks keep their patterns through these calls.87. Here it isERROR_NOT_ENOUGH_MEMORY(8).0xF02), the 2 MiB check applied to a 64 KiB-aligned, non-2-MiB base (MISALIGNED,0xF02), one nonzero QWORD at the end of the first block (0xF03), the accepted pair in place of a crossed one (0xF0F), a size that fits in place of the host failure (0xF17), and no release of the first block (0xF19). A provider withoutXMemVirtualAllocstopspe_mapat that import before entry.Results:
cpu_native_xmem_pool_commit:original0x870and every control at its expected code under both loaders; missing providerunresolved import xmem.dll!XMemVirtualAlloc.xmem|configure_vm|vm_translation|era_: 55 passed, 0 failed in each, plus 1 capability skip (vm_translation_range_warpon in-box WARP 10.0.19041, as documented).4f52ce68): 638 tests: 577 passed, 54 capability skips (reported separately), 7 failed, none in a test that exercises this change. Four were_hardwaretimeouts under-j 4(compute_store_aot_hardware,compute_store_aot_guard_read_hardware,compute_store_aot_lds_private_hardware,pixel_aot_blend_scalar_hardware) and all four passed when rerun serially (19 to 30 s each) on the RTX 3060 (driver 32.0.15.9636, debug layer on).gpu_alias_lookup_writes_warpandpixel_aot_title_loads_warpfail on in-box WARP 10.0.19041 inoffscreen_check, which does not linkxmem_shim(the first prints the documented array-atomics adapter defect).pe_package_import_closureneeds symlink privilege, which this account lacks (WinError 1314).Shim mutations (local, not committed). Each was caught under both loaders, and the restored shim passes:
0xF02);0xF06);0xF16);87: step 23 (0xF17);0xF02).Which validator each refusal reaches. With the commit profile's pair check forced to accept, steps 15 to 19 are accepted, so those refusals come from the new pair check. Steps 13, 14 and 20 stay refused, so they come from the reserve-only validator, and step 22 comes from the 64 KiB check (mutation above). The size-0 case (step 21) matches what
VirtualAllocreturns for size 0 on its own, so it does not isolate the shim's check.xmem_commit_protectionstill passes. ItsMEM_COMMITvariant (type0x20403000with attribute0x21) remains refused, and its header comment now describes both profiles.Evidence and follow-up
XMemVirtualAlloccalls succeed (two reservations, four pool slots, then the 20 MiB block), and no missing-import stub is reached.xcrdapi.dll!DStorageGetFactory. An earlier private harness crashed after that point instead, and that is not part of this PR.XMemVirtualAlloc, and it does not change this function or add this test.AI-assisted (Claude).
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-24T01:10:15Z.
Review: APPROVED
Independent Windows 11 run and review.
Environment
out/pe-env)36e010f1(branchruntime/xmem-reserve-commit)Verification & Test Results
Dev Preset:
cpu_native_xmem_pool_commit: Passed (0.76 sec).original: Windows launch0x870,pe_map0x870.reserve_only: Windows launch0xf02,pe_map0xf02.dirty: Windows launch0xf03,pe_map0xf03.accepted_refusal: Windows launch0xf0f,pe_map0xf0f.host_fit: Windows launch0xf17,pe_map0xf17.skip_release: Windows launch0xf19,pe_map0xf19.provider without XMemVirtualAlloc: caught before entry withunresolved import xmem.dll!XMemVirtualAlloc.xmem|configure_vmpassed (100% pass, real time 6.20s).Release Preset:
cpu_native_xmem_pool_commit: Passed (0.72 sec), identical exit codes and provider observations.xmem|configure_vmpassed (100% pass, real time 5.75s).Linters & Documentation:
The three startup configurations, the 10 neighbouring argument refusals, host error propagation, and all negative controls reproduce reliably across both loaders.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T01:18:47Z.
Review: CHANGES_REQUESTED
One boundary to settle before merging: the fixture currently requires only 64 KiB address alignment for the pool allocations. The existing commit comparison already exercises a separate 2 MiB-aligned profile. Please confirm which alignment these pool requests need and add a source-built test that would reject a 64 KiB-aligned but non-2-MiB base if 2 MiB is required. Also pin the reported size to the chosen byte-rounding policy, so the fixture distinguishes host page rounding from the requested guest alignment. Keep the independent later 64 KiB case and the existing refusal controls.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T02:24:24Z.
Review: APPROVED
The updated allocation profile passed 10/10 Windows Release checks. The source-built EXE agrees under the Windows loader and pe_map. The deliberately 64 KiB-aligned but non-2 MiB-aligned control hits the expected failure marker, and the 2 MiB plus 64 KiB allocation has the exact requested span. I added a documentation-only commit to describe the independently reproducible evidence and the Windows alignment policy. The branch now needs CI on that exact commit.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T01:12:39Z.
Maintainer verification of the source-built fixture
I ran Windows Release on the current candidate
36e010f1:10/10 passed. The original fixture returned the same success code under Windows and pe_map. All five deliberately incorrect variants hit their expected failure markers and the missing provider was rejected before entry. The separate protection checks also preserved the supported reserve and refusal behavior. This is evidence for the shim and source-built fixture.
Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-11-24T01:29:56Z.
Main-executable retest of this branch through the repository runner only, now that #1075 and #1085 are merged. No private harness and no local
xmem.dllpatch.Environment: Windows 11 Pro build 26300, MSVC 19.44.35207.1 x64,
devpreset, NVIDIA RTX 3090 (driver 32.0.16.1664). Runner andpe_map.dllfrommainata7710b7,xmem.dllbuilt from this branch at36e010f1, andd3d12_xs.dllfrommain.xmem.dllmainata7710b70x80000003after about 3 s, at the refused reserve+commit request; no trap reached36e010f1xcrdapi.dll!DStorageGetFactory, exit0xE7A00014after about 1.8 sWith this branch the run gets past the whole memory setup under
pe_mapand stops at the first missing function import. That matches the boundary in my native-loader checkpoint, where I used a lenient localxmem.dll, and it is now reproducible from the repository. The runner does not log the individualXMemVirtualAlloccalls, so this establishes the boundary, not which of the three profiles each call used.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-24T02:02:53Z.
@R0Y00 thanks. Addressed in a new commit on top; the branch head is now
96309447onmain072e85b6.1. Which alignment the pool requests need. The evidence:
winnt.h(10.0.26100) definesMEM_LARGE_PAGESas0x20000000andMEM_64K_PAGESasMEM_LARGE_PAGES | MEM_PHYSICAL(0x20400000, alreadyera_physical::mem_64k_pageshere). So the pool type0x20003000asks forMEM_LARGE_PAGES(2 MiB on desktop x64), and the later type0x20403000asks for 64 KiB pages.0x89700000,0x23300000), so they are not 2 MiB multiples. The other two are multiples of 4 MiB.xcrdapi.dll!DStorageGetFactory) with no difference before it.Chosen policy (desktop policy, an assumption from the desktop definition of
MEM_LARGE_PAGES; the console's own alignment for this type is not established):0x20003000: 2 MiB-aligned base, fromVirtualAlloc2with an address requirement.0x20403000: unchanged, the 64 KiB granularity ofVirtualAlloc.2. A test that rejects a 64 KiB-aligned, non-2-MiB base. The fixture now checks 2 MiB alignment for both large-page blocks (steps 2 and 6) and only 64 KiB for the 64 KiB-page block (step 10). There are two ways to show that the check can fail:
MISALIGNED: applies the 2 MiB check to the first block's base + 64 KiB. Result:0xF02under both loaders.0xF02) under both loaders.3. Size pinned to the rounding policy. Policy: commit exactly the requested size. It must be a nonzero multiple of 64 KiB and is not rounded to 2 MiB; a size that is not a multiple of 64 KiB is refused, not rounded to host pages (step 22).
VirtualQueryregion size must equal the requested size, and the byte just past the block must not belong to the same allocation.0xF06).4. Kept. The independent 64 KiB-page case (
0x20403000,0x181/PAGE_READWRITE) and all ten refusal controls, plus the host allocation failure (ERROR_NOT_ENOUGH_MEMORY) and the earlier controls.Each refusal reaches the path the docs name: with the commit profile's pair check forced to accept, the five pair refusals were accepted and the rest stayed refused. The size-0 case also matches Windows' own refusal of a zero size, so it does not isolate the shim's check; the PR body says so.
Environment: Windows 10 Pro 22H2 (19045.6466), MSVC 19.44.35207.1 x64.
Results: full release suite on
4f52ce68; everything else rerun on the final head96309447after rebasing past 25 unrelatedmaincommits.cpu_native_xmem_pool_commit:original0x870under both loaders. Controls:reserve_only0xF02,misaligned0xF02,dirty0xF03,accepted_refusal0xF0F,host_fit0xF17,skip_release0xF19. Missing provider stops atunresolved import xmem.dll!XMemVirtualAlloc.xmem|configure_vm|vm_translation|era_: 55 passed, 0 failed in each, plus 1 capability skip (vm_translation_range_warp, in-box WARP 10.0.19041).4f52ce68): 638 tests: 577 passed, 54 capability skips (reported separately), 7 failed, none in a test that exercises this change. Four were_hardwaretimeouts under-j 4(compute_store_aot_hardware,compute_store_aot_guard_read_hardware,compute_store_aot_lds_private_hardware,pixel_aot_blend_scalar_hardware) and all four passed when rerun serially (19 to 30 s each) on the RTX 3060 (driver 32.0.15.9636, debug layer on).gpu_alias_lookup_writes_warpandpixel_aot_title_loads_warpfail on in-box WARP 10.0.19041 inoffscreen_check, which does not linkxmem_shim(the first prints the documented array-atomics adapter defect).pe_package_import_closureneeds symlink privilege, which this account lacks (WinError 1314).Local shim mutants (not committed), each caught under both loaders and the restored shim passing:
0xF02)0xF06)0xF16)870xF17)0xF02)Overlap, checked right before pushing: only #888 (draft, reserve-only, other files) mentions
XMemVirtualAlloc.AI-assisted (Claude).