runtime: define the physical-page allocation contract for startup #880
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#880
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@R0Y00 on GitHub · 2026-11-23 15:24 UTC · original
Refs #870 and #875. After binding the default allocator, the startup mapping probe reached
XMemAllocatePhysicalPages. The next slice is to verify the ABI and lifetime of the physical-page allocation and release pair.Acceptance
Available to claim. Comment with the environment you can test and links to related GPU VA work. Keep local inputs and raw logs off the tracker.
@R0Y00 on GitHub · 2026-11-23 15:30 UTC · original
The public Microsoft GDK DirectStorage overview identifies one consumer of arrays of 64 KiB physical pages returned by this allocation path. That supports a 64 KiB case for a source-built fixture. It does not establish the declaration, output-array layout, other supported page sizes, or the release call. Those are still the open items. Please link evidence for the pair and include a failure/cleanup check before proposing shim behavior.
@rasptum on GitHub · 2026-11-23 15:37 UTC · original
Claiming this.
xmem.dllexportsXMemAllocatePhysicalPagesandXMemFreePhysicalPages(src/xmem_shim.cpp/.def), backed by a new page-number registry. Stacked on #879, which owns the same files.b1e77b6):AdvancedESRAM/PageAllocator.cppL197–232:BOOL XMemAllocatePhysicalPages(MEM_64K_PAGES, &count, pagePtr)with aULONG_PTRcount and aPULONG_PTRpage array. Release isXMemFreePhysicalPages(count, pagePtr)with the same count and array.AMDFidelityFX_FSR3FrameInterpolation/FSR3FrameInterpolation.cppL146–167: the flag argument is cast toULONG_PTR(XMEM_2MB_CLUSTERSorMEM_64K_PAGES). The count is in/out, and the caller asserts it comes back unchanged.XMemFreePhysicalPagesreturnsBOOL.kernelx.cpp(MIT) implements the kernelx-levelAllocateTitlePhysicalPages/FreeTitlePhysicalPages. They return 64 KiB page indices and set*NumberOfPages = 0withERROR_INVALID_PARAMETERon bad flags.MEM_64K_PAGES(the 64 KiB case from the DirectStorage note above) and allocate all or nothing. Fail closed, returningFALSE,*count = 0and the array untouched, on unknown flags or upper bits, a null pointer, a zero count, or a count above the desktop capacity. Release must name whole live grants. Negative controls: a short or long count on release, a double free, never-issued or forged page numbers, and duplicate entries are each refused with no state change. Forced exhaustion is followed by cleanup. Mapping, scatter mapping and transfer stay out.devandreleasepresets.era_heapattribute word; physical memory types still refused there), #874 (D3D12 VA startup contract, GPU VA side).AI-assisted (Claude Code).
@R0Y00 on GitHub · 2026-11-23 15:41 UTC · original
Thanks for taking this and for the two pinned Microsoft samples. I checked the calls: they establish the 64 KiB allocate/free pairing, the in/out count and page array, and use a Boolean success check. The examples do not settle count/array mutation on failure or whether partial release is permitted. Keep those cases explicitly labelled as proposed desktop policies until there is independent evidence.
Please take the independent source-built comparison and negative controls first. Startup integration is already being checked, so coordinate here before adding another implementation in the XMem shim. A fixture that checks real page lifetime, preserves a canary on refusal, then confirms that a valid release still succeeds would be directly reusable.
@triggered02 on GitHub · 2026-11-23 15:48 UTC · original
Independent source-built evidence, not a claim. rasptum owns #880.
I built an independent fixture in parallel before seeing the claim. It is uploaded at
triggered02/Xbox2Windows: xmem-physical-pages(commits7dcc36dand3d206a1, on top of the now-merged #879). I am not opening a competing shim PR.The reusable part is the source-built comparison, not the local shim policy:
cpu_xmem_physical.exeimportsXMemAllocatePhysicalPagesandXMemFreePhysicalPagesby name from the desktopxmem.dll. The same EXE runs under the Windows loader andpe_map, and the exits match.cpu_native_xmem_physical; the existingcpu_native_shim_startuppasses in Release.The fixture checks registry lifetime and cleanup, not mapped-page lifetime; mapping, scatter mapping and transfer remain out of scope. I can rebase the fixture and canary checks onto rasptum's implementation after it lands, or hand over the MASM/Python check. The local shim in the branch is only what proved the import can be passed.
AI-assisted.
@triggered02 on GitHub · 2026-11-23 15:54 UTC · original
Opened draft #887 with the fixture and negative controls described above. It is explicitly not a competing implementation; I will reduce it to the fixture and canary checks once rasptum's #880 implementation lands, or close it in favour of theirs.
@rasptum on GitHub · 2026-11-23 16:14 UTC · original
Result: #892.
Tested: commit
729bfa1onorigin/main406e14a. Windows 10 Pro 10.0.19045.6466, MSVC 19.44.35207.1 x64. Synthetic inputs only.Source-built comparison first:
cpu_native_xmem_physical_pair: an EXE that imports the pair by name gives0x880under both the Windows loader andpe_map_run. Thefull_countandskip_releasemutations give0xf04and0xf06under both. A provider missing either export stops the mapping before entry.era_physical_controls: short count, long count, a single page of a grant, double free, never-issued page, forged mix and duplicate entry are each refused by the policy with state unchanged, and accepted by a lenient SlimEra-style release.xmem_shim_physical_pageschecks canaries on refusal and that a valid release still succeeds after refusals. It also covers exhaustion with cleanup.era_heap,desktop_memory_queryandxmem_shimsets.Established by the Microsoft samples: 64 KiB allocate/free pairing, the in/out count with a page array, and the
BOOLsuccess check.Proposed desktop policy (labeled in code and docs):
MEM_64K_PAGESonly, all or nothing,*count = 0and an untouched array on failure, release of whole live grants only.Open contract questions:
ULONG_PTRvsDWORD).XMEM_2MB_CLUSTERSand its count units.The EXE comparison follows @triggered02's independent fixture (credited in the PR, with Co-authored-by). Their observation, not mine: with both pairs bound, their local binding probe moved the first unresolved import to
xmem.dll!XMemIsToolsMemAvailable.AI-assisted (Claude Code).
@rasptum on GitHub · 2026-11-23 16:38 UTC · original · edited 2026-11-23 16:40 UTC
Coordination note on the overlap between #892 and #901. Both edit
src/xmem_shim.cpp/.defand both reference this issue.Suggested split, following the claims already on #870/#880:
d0bf29aon it.XMemMapPhysicalPages,...Scatter,XMemTransferMemory): thegl0w claimed the follow-up here at 16:19Z, and R0Y00's #901 review (shared backing through unmap/remap, rejecting unowned tokens, validating the whole list before release) applies to that part.XMemVirtualAlloc: descent81's #888.XMemIsToolsMemAvailable: Holastor's #896 is the single landing PR (R0Y00, 16:34Z on #870, after triggered02 consolidated #900 into it).@stan495 would you be open to rebasing #901 onto #892 once it lands and reducing it to whatever isn't covered above, or pairing with thegl0w on the mapping slice? If you'd rather #901 carry the allocate/free pair instead, I'm fine folding #892's fixture and controls into yours with credit. Either way, one PR per piece keeps review simple.
AI-assisted (Claude Code).
@R0Y00 on GitHub · 2026-11-23 16:43 UTC · original
Completed by #892 (merged at
3dfe3a9). The bounded desktop registry implements the named allocation and matching release pair for 64 KiB page identifiers. The same source-built EXE passed under Windows and pe_map. Ownership, count, canary, missing-export and cleanup controls passed, and both Windows CI builds were green. These are bookkeeping identifiers. Shared backing, mapping/scatter, transfer and reservation semantics remain separate work under #870, #901 and #888.@stan495 on GitHub · 2026-11-23 16:44 UTC · original
Thanks @rasptum for the heads-up.
I've already closed #901, so please feel free to proceed with #892 for the allocate/free pair. Leaving the mapping slice to @thegl0w sounds good to me as well. Thanks!