runtime: share physical page backing across XMem views #927
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/934"
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 R0Y00 on 2026-11-23T17:48:09Z.
Refs #870, #892 and #902.
Give live physical-page grants shared Windows section backing. Contiguous and scatter operations map those sections into caller-owned page-sized placeholders. Unmapping preserves the reservation and the page contents. Existing grants keep their ownership rules, and release refuses any grant with a live view.
The source-built test observes shared data between addresses, scatter ordering, remap persistence, bad page numbers, release with a live view and rollback after a later destination fails. This desktop profile requires Windows placeholders from the caller.
Windows x64, MSVC 19.51, Release:
4/4 passed. The strict package preflight resolved two additional imports, with execution still blocked by unresolved external providers.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T17:53:27Z.
I tested
7716a09together with the #888 reservation draft on Windows x64 Release. Five focused CTests passed. For both 16 GiB and 24 GiB reservations, the combined control split 64 KiB prefixes, mapped the same live grant with contiguous and scatter calls, observed a write through the other address, checked that release refused an active view, then unmounted and remapped to verify persistence. After the final unmap, release and coalescing both succeeded, and remapping the released identifier was refused. This uses the real XMem exports.Imported from R0Y00/Xbox2Windows. Originally posted by thegl0w on 2026-11-23T18:42:49Z.
Independent review of #934, as asked on #870, at main
0f0c3eb, which includes #945's placeholder split inmap_view.Environment: Windows 11 build 26300, VS 2022 x64,
devandreleasepresets, CPU only (no GPU involved).Existing tests:
ctest --preset <dev|release> --no-tests=error -R '^xmem_shim_(mapped_pages|physical_pages|exports|tools_memory)$'passes 4/4 on both presets.Finding: a map inside an
XMemVirtualAllocreservation can discard the caller's committed memorymap_viewfalls back toVirtualFree(target, page_bytes, MEM_RELEASE | MEM_PRESERVE_PLACEHOLDER)wheneverMapViewOfFile3fails at an address inside a tracked reservation. It doesn't check that the target is still a placeholder. A private allocation that replaced a placeholder (VirtualAlloc2withMEM_REPLACE_PLACEHOLDER) is also accepted by that call. It is released back to a placeholder, and its bytes are lost.To reproduce, using a source-built probe that drives
xmem.dllthrough ctypes, the same waytests/xmem_mapped_pages_check.pydoes:XMemVirtualAlloc(nullptr, 16 GiB, 0x20402000, 0x21, PAGE_READWRITE).whole + 5 × 64 KiB, replace it with a committed private allocation, and write0xDEADBEEFthere.XMemMapPhysicalPages(whole + 4 × 64 KiB, 2, pages).MEM_COMMIT/MEM_PRIVATE,0xDEADBEEFMEM_COMMIT/MEM_MAPPED,0x0MEM_RESERVEplaceholder; the caller's allocation is goneThe same result appears on
devandrelease. The existing test doesn't catch it because its rollback case places the non-placeholder page in an ordinary reservation, outside the tracked ranges.Suggested guard (local patch): split only when
VirtualQueryreportsMEM_RESERVEat the target, and otherwise fail withERROR_INVALID_ADDRESS. With it:MEM_COMMIT/MEM_PRIVATEwith0xDEADBEEF;A caller allocation that is reserved but not committed also reads as
MEM_RESERVE, so the guard still converts that one back to a placeholder. No bytes are lost, but the caller loses its reservation. Telling those two apart would need the shim to track which pages it split itself. I can open that as a focused PR with the probe as a test if you want it.Other controls I checked, all of which pass at
0f0c3eb:scatter(destinations, 2, invalid)targets addresses that are already mapped, so it is refused by the live-view check before the token check runs. The fresh-destination case above covers the token check.These are desktop-profile observations from source-built inputs only. They say nothing about console behaviour.