runtime: check era_physical page ownership #1736
No reviewers
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!1736
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1736/head"
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?
@Asimmimx on GitHub · 2026-11-24 17:58 UTC · original
Asimmimx:tests/era-physical-check→main· +91 −1 · 3 files · 1 commits · merged 2026-11-24 20:08 UTCRefs #1149.
Change
src/era_physical.his the desktop bookkeeping for title physical pages behindXMemAllocatePhysicalPages/XMemFreePhysicalPages. Pages are opaque nonzero numbers from 1 to 2^18 (16 GiB of 64 KiB pages). Allocation is all or nothing, and a release must name whole live grants. The header also exportsowns(page), whichXMemMapPhysicalPages/XMemMapPhysicalPagesScatter(src/xmem_mapped_pages.cpp) call for every page token before they map it.Device-free tests that reach the file today:
era_physical_controlsandera_physical_lifetime(tests/era_physical_check.cpp): seven release controls against a lenient build, plus exact totals, exhaustion and argument refusals;xmem_shim_physical_pages: the same policy through thexmem.dllexports, including a full 2^18 grant;xmem_shim_mapped_pages,xmem_shim_page_runs,xmem_commit_protection,xmem_page_stats: mapping throughxmem.dll.era_physical_checknever callsowns. The mapping tests only show that released page tokens are no longer accepted. 5 of 24 single-point mutants survived all seven tests (table below). Three of them are inowns: the last page number refused, the number compared by its low 32 bits only, and every number owned before the first grant. The fourth is a release on the never-created registry reported as success. Each test runs in its own process and grants pages before it releases any, so no test hits that path.This PR adds an
ownsscenario toera_physical_check, registered asera_physical_ownsin the existingforeachnext tocontrolsandlifetime:owns(0),owns(1),owns(2^18)false;release(1, {1})isinvalid; total 0ownsreads the grant table2^32 | lowest grantedrelease(2, b)(short count)invalid, all ofbstill ownedawholeanot owned,bstill ownedbplus the new pages are exactly 1..2^18, each once;owns(1)andowns(2^18)true; all ownedexhausted, count 0Negative control:
era_physical_owns_last_page_controlbuilds the same check against a copy ofera_physical.cppgenerated at configure time, whoseownsusespage < capacity_pages. This follows thestartup_gamesave_publish_unlockedpattern. CMake stops withFATAL_ERRORif the anchor is gone, and lists the source as a configure dependency so the copy follows edits. The test usesPASS_REGULAR_EXPRESSION "FAIL: owns: last page", so only that specific report passes it. A crash does not.The change touches
tests/era_physical_check.cpp(one new function and one scenario branch; no existing case changed), theera_physicalblock ofCMakeLists.txt, and two new rows afterera_physical_lifetimein the physical-page CTest table ofdocs/experiments.md.src/is unchanged.Mutation probe
I applied each mutant to
src/era_physical.cpporsrc/era_physical.halone, rebuiltera_physical_check,xmem_shim,xmem_shim_check,xmem_commit_protection_checkandxmem_shim_test_controls, and ran the seven existing tests, then reverted. The "new" column addsera_physical_owns. For that run the configure dependency was left out, because theownsmutants remove the control's anchor. None of this is committed.era_physical_ownsowns:page < capacity_pagesowns: page number cut to 32 bitsowns: true while the registry is emptyokowns: any in-range numberxmem_shim_mapped_pages)>= capacityrefused>=exhaustedreported asinvalid>= capacityrefused>= capacityrefusedcount - 1granted_pagesreturns 0mem_64k_pages=0x20000000capacity_pages= 2^17page_bytes= 32 KiBNot pinned
bad_allocpaths inallocate/releasewould need an allocation-failure harness likeera_title_gpu_alloc. They are out of scope.Verification
Commit
c7ea6059on branchtests/era-physical-check, based onbfe9158d(main). Environment: Windows 11 Pro build 26300.9974, MSVC 19.51.36260 (Visual Studio), Windows SDK 10.0.26100.0, CMake 3.30.4,devpreset (Debug). No GPU is involved.era_physical_check ownspassed 20 of 20 repeated runs.tests/docs_links_check.py(17 Markdown files, 364 links),tests/bidi_controls_check.pyandgit diff --checkpassed.Checklist
AI-assisted (Claude Code).
era_physical::owns is what XMemMapPhysicalPages asks for each page it maps, but era_physical_check never calls it. Of 24 single-point mutants of src/era_physical.{h,cpp}, five survived every device-free test that reaches the file (era_physical_*, xmem_shim_physical_pages, xmem_shim_mapped_pages, xmem_shim_page_runs, xmem_commit_protection, xmem_page_stats): owns refusing page 2^18, owns comparing only the low 32 bits of the page number, owns answering true before the first grant, a release before the first grant accepted, and a page search that always restarts at page 1. The last one is not pinned: the header makes no promise about which free numbers are issued. xmem_shim_mapped_pages only checks that released pages are no longer accepted for mapping. The new era_physical_owns scenario runs from an empty registry: nothing is owned and a release is refused before the first grant; granted pages are owned and never-issued, zero, out-of-range and live-plus-2^32 numbers are not; a refused release changes no ownership and a whole release ends it for its grant only; a full registry holds each number 1..2^18 once, all owned; after cleanup nothing is owned. era_physical_owns_last_page_control builds the check against a configure-time copy of era_physical.cpp whose owns refuses page 2^18 and passes only on "FAIL: owns: last page". Refs #1149.@tedin7 on GitHub · 2026-11-24 18:14 UTC · original · reviewed
Peer review of PR #1736 at head
c7ea6059227ff6039849f79d0168f43aa70b4002.Summary
CMakeLists.txt,docs/experiments.md, andtests/era_physical_check.cpp. Nosrc/files were modified. Title-neutral, MIT clean-room.era_physical_ownsexercisesera_physical::owns()against the live registry from empty state (!owns(0),!owns(1),!owns(capacity_pages)), through two grants (4and3pages, rejecting unissued pages and out-of-range numbers including0,capacity_pages + 1,~0, and(1ULL << 32) | live.front()), refused and valid releases, full-capacity saturation (1..capacity_pagesall owned, exhaustion returnsStatus::exhausted), and cleanup (all released pages unowned).era_physical_owns_last_page_controlmutatespage <= capacity_pagestopage < capacity_pagesin a build-tree copy ofsrc/era_physical.cpp(guarded byCMAKE_CONFIGURE_DEPENDSandFATAL_ERROR) and requiresPASS_REGULAR_EXPRESSION "FAIL: owns: last page".Checks executed
prep-verify 1736):python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py prep-verify 1736 --dir /tmp/rev-x2w-84/1736 --json->git_diff_check: PASS,docs_links_check: PASS,bidi_controls_check: PASS,py_compile: PASS./O2(win2025 1736, Build 26100, MSVC 14.44.35207):python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1736 --wait 600 --targets era_physical_check,era_physical_last_page_check --regex "^(era_physical_controls|era_physical_lifetime|era_physical_owns|era_physical_owns_last_page_control)$"--preset dev): 4/4 passed (era_physical_controls0.02s,era_physical_lifetime0.21s,era_physical_owns0.28s,era_physical_owns_last_page_control0.28s)./O2(--preset release): 4/4 passed (era_physical_controls0.02s,era_physical_lifetime0.08s,era_physical_owns0.09s,era_physical_owns_last_page_control0.09s).src/era_physical.cpp(Win2025 Debug):python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1736 --targets era_physical_check --regex "^era_physical_owns$" --skip-release --patch /tmp/rev-x2w-84/mut_1736.patch(dropping&& r.grant[page] != 0inera_physical::owns) -> Mutant killed:era_physical_ownsfailed withFAIL: owns: a page that was never issued is owned,FAIL: owns: a release did not end ownership of exactly its grant, andFAIL: owns: a released page is still owned.AI-assisted; commands listed were executed locally.