runtime: check era_physical page ownership #1729
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1736"
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 Asimmimx on 2026-11-24T17:58:13Z.
Refs #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).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T18:14:36Z.
Review: COMMENTED
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.