Skip to content

xmem: serve the four physical-page exports as a CPU stand-in - #7042

Closed
kett1m wants to merge 1 commit into
ProjectLeonida:mainfrom
kett1m:xmem-physical-pages
Closed

kett1m wants to merge 1 commit into
ProjectLeonida:mainfrom
kett1m:xmem-physical-pages

Conversation

@kett1m

@kett1m kett1m commented Nov 23, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as a new item: xmem, the four physical-page exports as a CPU stand-in.

What and why

The retail executable reserves a range with MEM_PHYSICAL, allocates 64 KiB pages and maps them into it. docs/retail_boot_chain.md §2 has the shapes from its call sites, and it records that the CPU half (#5381) and the sparse mapper (#5378) are not wired to the exports. This wires them.

A PC has no page pool, so:

  • XMemAllocatePhysicalPages gives each page a committed 64 KiB block; the page number is a 1-based index into a table, and the count is written back.
  • XMemMapPhysicalPages commits the range at the VA it is handed. A null page array decommits it and leaves the reservation in place.
  • XMemMapPhysicalPagesScatter does the same with one address per page.
  • XMemFreePhysicalPages releases the blocks. An unknown page number fails.
  • XMemVirtualAlloc now drops MEM_PHYSICAL instead of refusing the call, so that reservation is an ordinary MEM_RESERVE.

Two mappings of the same page do not share content, and nothing binds the pages to the GPU yet. The page table is a table, not a pagefile section.

Tested

xmem_test covers allocate, map, unmap, the scatter form, free, an unknown page number and the count written back. 136 checks pass under Wine 11.22 on a clang-cl 23.1.5 + xwin Windows SDK 10.0.26100 cross build (Linux, RTX 3090, driver 595.99). python -I tests/test_docs_links.py passes.

No title run has reached these calls: on this machine the retail executable stops in the runtime before the shims (the XBox package DLLs are not in the folder, and under Wine the first static initializer faults). The Windows boot chain in §1 stops at XMemAllocatePhysicalPages before that.

AI-assisted: yes

Checklist

  • No game data, keys or decryption. Only export names, public SDK types and counts.
  • No translator change.

The retail executable reserves a range with MEM_PHYSICAL, allocates 64 KiB pages and maps them into that range.
docs/retail_boot_chain.md §2 has the shapes from its call sites. A PC has no page pool, so a page is a committed
64 KiB block and a page number indexes a table. A map commits the range at the VA it is handed, and a null page
array decommits it while leaving the reservation. MEM_PHYSICAL is dropped from XMemVirtualAlloc's type word, so the
reservation is an ordinary one.

xmem_test covers allocate, map, unmap, the scatter form, free and an unknown page number, and checks the count
written back. 136 checks pass under Wine 11.22 on a clang-cl 23.1.5 and xwin 10.0.26100 cross build (Linux,
RTX 3090, driver 595.99). No title run has reached these calls yet.
@kett1m

kett1m commented Nov 23, 2026

Copy link
Copy Markdown
Author

Duplicate of #6995, which was opened 15 minutes earlier with the same four exports and a larger test. I missed it when I claimed. Closing this one; #6995 is the one to review. The only piece here that #6995 may not have: dropping MEM_PHYSICAL from XMemVirtualAlloc's type word so the reservation is an ordinary one.

@kett1m kett1m closed this Nov 23, 2026
@kett1m
kett1m deleted the xmem-physical-pages branch November 23, 2026 15:48
@mrp1no

mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 54fe872b natively on Windows 11 (MSVC RelWithDebInfo, merged onto main bd3f061ad), since the PR ran it under Wine:

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants