runtime: define the physical-page allocation contract for startup #880

Closed
opened 2026-11-26 22:25:23 +00:00 by github-bot · 9 comments
Owner

@⁠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

  • Establish argument widths, return semantics, output fields, page-count units, and matching release using shareable evidence or an independently reproducible fixture.
  • Record the expected behavior for a valid allocation, failure, and cleanup. Add a source-built control that can detect incorrect ownership or page-count handling.
  • Treat mapping, scatter mapping and transfer as follow-ups with their own evidence. Link #870 with the tested behavior and remaining contract questions.

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:24 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/880) 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** - Establish argument widths, return semantics, output fields, page-count units, and matching release using shareable evidence or an independently reproducible fixture. - Record the expected behavior for a valid allocation, failure, and cleanup. Add a source-built control that can detect incorrect ownership or page-count handling. - Treat mapping, scatter mapping and transfer as follow-ups with their own evidence. Link #870 with the tested behavior and remaining contract questions. 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.
github-bot 2026-11-26 22:25:23 +00:00
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:25:23 +00:00
Author
Owner

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

**@⁠R0Y00** on GitHub · 2026-11-23 15:30 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/880#issuecomment-7105670201) The public [Microsoft GDK DirectStorage overview](https://learn.microsoft.com/en-us/gaming/gdk/docs/features/console/storage/directstorage/directstorage-overview?view=gdk-2604) 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.
Author
Owner

@⁠rasptum on GitHub · 2026-11-23 15:37 UTC · original

Claiming this.

  • Milestone: #870, reaching the next startup import after the default allocator.
  • Interface: desktop xmem.dll exports XMemAllocatePhysicalPages and XMemFreePhysicalPages (src/xmem_shim.cpp/.def), backed by a new page-number registry. Stacked on #879, which owns the same files.
  • Evidence for the pair (MIT, Microsoft, pinned at b1e77b6):
    • AdvancedESRAM/PageAllocator.cpp L197–232: BOOL XMemAllocatePhysicalPages(MEM_64K_PAGES, &count, pagePtr) with a ULONG_PTR count and a PULONG_PTR page array. Release is XMemFreePhysicalPages(count, pagePtr) with the same count and array.
    • AMDFidelityFX_FSR3FrameInterpolation/FSR3FrameInterpolation.cpp L146–167: the flag argument is cast to ULONG_PTR (XMEM_2MB_CLUSTERS or MEM_64K_PAGES). The count is in/out, and the caller asserts it comes back unchanged. XMemFreePhysicalPages returns BOOL.
    • SlimEra kernelx.cpp (MIT) implements the kernelx-level AllocateTitlePhysicalPages/FreeTitlePhysicalPages. They return 64 KiB page indices and set *NumberOfPages = 0 with ERROR_INVALID_PARAMETER on bad flags.
  • Plan: accept only MEM_64K_PAGES (the 64 KiB case from the DirectStorage note above) and allocate all or nothing. Fail closed, returning FALSE, *count = 0 and 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.
  • Environment: Windows 10 Pro 10.0.19045, MSVC VS2022 x64, dev and release presets.
  • Related: #875/#879 (default pair), #126/#134 (era_heap attribute word; physical memory types still refused there), #874 (D3D12 VA startup contract, GPU VA side).

AI-assisted (Claude Code).

**@⁠rasptum** on GitHub · 2026-11-23 15:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/880#issuecomment-7105847780) Claiming this. - **Milestone:** #870, reaching the next startup import after the default allocator. - **Interface:** desktop `xmem.dll` exports `XMemAllocatePhysicalPages` and `XMemFreePhysicalPages` (`src/xmem_shim.cpp`/`.def`), backed by a new page-number registry. Stacked on #879, which owns the same files. - **Evidence for the pair** (MIT, Microsoft, pinned at `b1e77b6`): - [`AdvancedESRAM/PageAllocator.cpp` L197–232](https://github.com/microsoft/Xbox-GDK-Samples/blob/b1e77b6ac10f95b07296025fda171ca2ddc42dbe/Samples/Graphics/AdvancedESRAM/PageAllocator.cpp#L197-L232): `BOOL XMemAllocatePhysicalPages(MEM_64K_PAGES, &count, pagePtr)` with a `ULONG_PTR` count and a `PULONG_PTR` page array. Release is `XMemFreePhysicalPages(count, pagePtr)` with the same count and array. - [`AMDFidelityFX_FSR3FrameInterpolation/FSR3FrameInterpolation.cpp` L146–167](https://github.com/microsoft/Xbox-GDK-Samples/blob/b1e77b6ac10f95b07296025fda171ca2ddc42dbe/Samples/Graphics/AMDFidelityFX_FSR3FrameInterpolation/FSR3FrameInterpolation.cpp#L146-L167): the flag argument is cast to `ULONG_PTR` (`XMEM_2MB_CLUSTERS` or `MEM_64K_PAGES`). The count is in/out, and the caller asserts it comes back unchanged. `XMemFreePhysicalPages` returns `BOOL`. - SlimEra `kernelx.cpp` (MIT) implements the kernelx-level `AllocateTitlePhysicalPages`/`FreeTitlePhysicalPages`. They return 64 KiB page indices and set `*NumberOfPages = 0` with `ERROR_INVALID_PARAMETER` on bad flags. - **Plan:** accept only `MEM_64K_PAGES` (the 64 KiB case from the DirectStorage note above) and allocate all or nothing. Fail closed, returning `FALSE`, `*count = 0` and 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. - **Environment:** Windows 10 Pro 10.0.19045, MSVC VS2022 x64, `dev` and `release` presets. - **Related:** #875/#879 (default pair), #126/#134 (`era_heap` attribute word; physical memory types still refused there), #874 (D3D12 VA startup contract, GPU VA side). AI-assisted (Claude Code).
Author
Owner

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

**@⁠R0Y00** on GitHub · 2026-11-23 15:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/880#issuecomment-7105952032) 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.
Author
Owner

@⁠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 (commits 7dcc36d and 3d206a1, 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.exe imports XMemAllocatePhysicalPages and XMemFreePhysicalPages by name from the desktop xmem.dll. The same EXE runs under the Windows loader and pe_map, and the exits match.
  • Valid 64 KiB allocate/free, in/out count unchanged, distinct nonzero PFNs.
  • Refusals for a null count, a null array, a large-page count that is not a multiple of 32, and a count above the desktop cap. The PFN array is pre-filled with canaries and must be unchanged on refusal.
  • Double free, unknown PFN and duplicate PFN are refused. The unit scenario confirms a valid release still succeeds after a refusal.
  • The missing-provider control fails before entry on the first xmem import in table order.
  • Dev and Release: 6/6 focused tests pass, including cpu_native_xmem_physical; the existing cpu_native_shim_startup passes 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:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/880#issuecomment-7106127383) 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` (commits 7dcc36d and 3d206a1, 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.exe` imports `XMemAllocatePhysicalPages` and `XMemFreePhysicalPages` by name from the desktop `xmem.dll`. The same EXE runs under the Windows loader and `pe_map`, and the exits match. - Valid 64 KiB allocate/free, in/out count unchanged, distinct nonzero PFNs. - Refusals for a null count, a null array, a large-page count that is not a multiple of 32, and a count above the desktop cap. The PFN array is pre-filled with canaries and must be unchanged on refusal. - Double free, unknown PFN and duplicate PFN are refused. The unit scenario confirms a valid release still succeeds after a refusal. - The missing-provider control fails before entry on the first xmem import in table order. - Dev and Release: 6/6 focused tests pass, including `cpu_native_xmem_physical`; the existing `cpu_native_shim_startup` passes 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.
Author
Owner

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

**@⁠triggered02** on GitHub · 2026-11-23 15:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/880#issuecomment-7106308050) 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.
Author
Owner

@⁠rasptum on GitHub · 2026-11-23 16:14 UTC · original

Result: #892.

Tested: commit 729bfa1 on origin/main 406e14a. 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 gives 0x880 under both the Windows loader and pe_map_run. The full_count and skip_release mutations give 0xf04 and 0xf06 under 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_pages checks canaries on refusal and that a valid release still succeeds after refusals. It also covers exhaustion with cleanup.
  • dev and release: 19/19 each, including the existing era_heap, desktop_memory_query and xmem_shim sets.

Established by the Microsoft samples: 64 KiB allocate/free pairing, the in/out count with a page array, and the BOOL success check.

Proposed desktop policy (labeled in code and docs): MEM_64K_PAGES only, all or nothing, *count = 0 and an untouched array on failure, release of whole live grants only.

Open contract questions:

  • Flag width (ULONG_PTR vs DWORD).
  • The value of XMEM_2MB_CLUSTERS and its count units.
  • Count and array state on failure, and partial grants.
  • What page numbers encode, and whether partial release is allowed.
  • Console error codes and the physical-page budget.

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:14 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/880#issuecomment-7106841153) Result: #892. **Tested:** commit `729bfa1` on `origin/main` `406e14a`. 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 gives `0x880` under both the Windows loader and `pe_map_run`. The `full_count` and `skip_release` mutations give `0xf04` and `0xf06` under 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_pages` checks canaries on refusal and that a valid release still succeeds after refusals. It also covers exhaustion with cleanup. - dev and release: 19/19 each, including the existing `era_heap`, `desktop_memory_query` and `xmem_shim` sets. **Established by the Microsoft samples:** 64 KiB allocate/free pairing, the in/out count with a page array, and the `BOOL` success check. **Proposed desktop policy (labeled in code and docs):** `MEM_64K_PAGES` only, all or nothing, `*count = 0` and an untouched array on failure, release of whole live grants only. **Open contract questions:** - Flag width (`ULONG_PTR` vs `DWORD`). - The value of `XMEM_2MB_CLUSTERS` and its count units. - Count and array state on failure, and partial grants. - What page numbers encode, and whether partial release is allowed. - Console error codes and the physical-page budget. 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).
Author
Owner

@⁠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/.def and both reference this issue.

Suggested split, following the claims already on #870/#880:

  • #892: the allocate/free pair only (this issue's scope). It has R0Y00's review commit d0bf29a on it.
  • Mapping (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).

**@⁠rasptum** on GitHub · 2026-11-23 16:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/880#issuecomment-7107440484) · edited 2026-11-23 16:40 UTC Coordination note on the overlap between #892 and #901. Both edit `src/xmem_shim.cpp`/`.def` and both reference this issue. Suggested split, following the claims already on #870/#880: - **#892:** the allocate/free pair only (this issue's scope). It has R0Y00's review commit `d0bf29a` on it. - **Mapping** (`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).
Author
Owner

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

**@⁠R0Y00** on GitHub · 2026-11-23 16:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/880#issuecomment-7107575686) 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.
Author
Owner

@⁠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!

**@⁠stan495** on GitHub · 2026-11-23 16:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/880#issuecomment-7107611076) 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!
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/R0Y00--Xbox2Windows#880
No description provided.