runtime: check era_gpu_alias refusals without a GPU #1728
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1735"
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:04Z.
Refs #1149.
Change
src/era_gpu_alias.hturns an existingVirtualAllocallocation into a D3D12 heap with one placed buffer over it (ID3D12Device3::OpenExistingHeapFromAddress), so the GPU sees title memory at a desktop GPU address without copies. Before it calls D3D12,era_gpu_alias::openwalks[base, base + size)withVirtualQuery. The header promisesE_INVALIDARGwithout calling D3D12 when the span is not the start of one committed, accessible allocation (interior pointer, uncommitted,PAGE_NOACCESSorPAGE_GUARDtail, oversized or wrapping span). It also promisesE_NOTIMPLwhen the device does not support existing heaps.Tests that reach the header today:
gpu_alias_warp/_hardware(offscreen_check --gpu-alias) opens a real allocation and makes the refusals listed above;gpu_alias_window_*,gpu_alias_lookup_*,gpu_alias_lookup_writes_*andgpu_alias_registry_*go throughopenon successful spans (the registry also with one interior block);era_title_gpu_alloclinks the file but never attaches a device.All of these need a D3D12 device. D3D12 refuses most of the bad spans with
E_INVALIDARGitself, so thehr == E_INVALIDARGchecks ingpu_alias_warpalso pass whenopenforwards the span. Only the debug layer's error count shows that D3D12 was reached (the experiments table already says so for message 1088).offscreen_checkruns on without the layer and printsdebug_layer=unavailablewhen Graphics Tools are missing. Six of the 20 single-point mutants below were killed only through that count. Eleven survived every test, among them a missing reset of the caller'sAlias, an ignoredSupportedflag, andE_FAIL/E_NOINTERFACEwhere the header saysE_NOTIMPL.This PR adds
era_gpu_alias_open, a device-free check, registered directly after thegpu_alias.cppsource line inCMakeLists.txt:tests/era_gpu_alias_fake_device.{h,cpp}is a recording stand-in forID3D12Device. The.cppis compiled withCINTERFACE, so its vtable is the typed C struct fromd3d12.h. OnlyCheckFeatureSupportandQueryInterfacehave real entries (both are answered as configured and recorded). Every other slot counts an unexpected call and returnsE_FAIL.QueryInterfacealways returnsE_NOINTERFACE, soopennever gets further than theID3D12Device3query, and no heap or resource is needed.tests/era_gpu_alias_check.cppholds the cases below. Each open starts with anAliaswhosesizeis a stale 7.E_INVALIDARG, no device call0x1000into an allocation; its second 64 KiB pageE_INVALIDARG, no device callE_INVALIDARG, no device callE_INVALIDARG, no device callUINT64_MAXE_INVALIDARG, no device callE_INVALIDARG, no device callPAGE_NOACCESS; thenPAGE_READWRITE | PAGE_GUARD(whole tail, and its first byte alone)E_INVALIDARG, no device call0x10003bytes, the committed head of the reserved tailCheckFeatureSupport(D3D12_FEATURE_EXISTING_HEAPS, ..., sizeof(D3D12_FEATURE_DATA_EXISTING_HEAPS)), thenE_NOTIMPLREADWRITE,READONLY,EXECUTE_READ), whole and one byte into the secondSupported = FALSEE_NOTIMPL, noQueryInterfaceSupported = TRUEQueryInterfaceforID3D12Device3, thenE_NOTIMPLAliasleft empty (heap,buffernull,size0)Negative control:
era_gpu_alias_open_base_controlbuilds the same check against a copy ofera_gpu_alias.cppgenerated at configure time withoutinfo.AllocationBase != base ||. 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: interior pointer: passed to D3D12", so only that specific report passes it. A crash does not. In that build the check reports three failures: the interior pointer, the second page, and the byte past the end, which happened to be committed by the next allocation.docs/experiments.mdgets two rows in the CTest table of the title GPU address section, directly aftergpu_alias_warp. No existing test, case or source file is changed.Mutation probe
I applied each mutant to
src/era_gpu_alias.cppalone, rebuilt, ran the tests, then reverted. "Existing tests" meansgpu_alias_warp,gpu_alias_window_warp,gpu_alias_lookup_warp,gpu_alias_lookup_writes_warp,gpu_alias_registry_warpandera_title_gpu_alloc, on WARP with the debug layer enabled. "Debug layer" means the run failed only ondebug_errors, and every explicitE_INVALIDARGexpectation held. For G4 and G12 the "existing" column was measured without this PR's CMake change, and the "new" column without the configure dependency, because the mutant removes the control's anchor. None of this is committed.era_gpu_alias_openalias = {}on entry droppedCreatePlacedResourcewidth)AllocationBasenot comparedState != MEM_COMMITdroppedProtect == 0droppedPAGE_NOACCESSacceptedPAGE_GUARDacceptedcursor < region_basedroppedRegionSize <= offsetdroppedBaseAddresscompared instead ofAllocationBaseSupportedignoredE_FAILinstead ofE_NOTIMPLafter the feature queryD3D12_OPTIONS)E_NOINTERFACEinstead ofE_NOTIMPLwithoutID3D12Device3alias.sizenot set on successNot pinned
cursorcan wrap. G5 and G6: a reserved region reports bothMEM_RESERVEand protection 0, so each check covers the other. G9 and G10:VirtualQueryreturns the region holding the cursor, so these defensive checks cannot fail.ID3D12Device3query: the heap size check, the resource description andalias.sizeon success (G17 to G20). A fake would have to stand in forOpenExistingHeapFromAddress,ID3D12Heap::GetDescandCreatePlacedResourceand would only repeat what the code passes. The WARP tests run the real calls and already kill G18 and G19. G17 and G20 stay open. Checkingalias.sizeafter a successful open ingpu_alias_warpwould close G20. That is a device test and outside this change.openaccepts any committed allocation base, including aMEM_IMAGEorMEM_MAPPEDregion. The header only says the base should come fromVirtualAlloc, so this check does not pin refusing or accepting them.Verification
Commit
7fb32427on branchtests/era-gpu-alias-check, based on18a2942a(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), in-box WARP 10.0.26100.9818 with the debug layer enabled. No_hardwaretest was run.era_gpu_alias_check.exepassed 50 of 50 repeated runs, and the control build printed the expected line in 50 of 50.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:06:30Z.
Review: COMMENTED
Peer review of PR #1735 at head
7fb32427ae17e951c47cb0a3ce4f455b11f1f795.Summary
CMakeLists.txt,docs/experiments.md,tests/era_gpu_alias_check.cpp,tests/era_gpu_alias_fake_device.cpp, andtests/era_gpu_alias_fake_device.h. Nosrc/files were modified. Title-neutral, MIT clean-room.era_gpu_alias_checkexercisesera_gpu_alias::openagainst aCINTERFACErecordingID3D12Devicefake (FakeDevice), verifying 13E_INVALIDARGrefusal cases with zero device calls (includingVirtualQuerybase, state,PAGE_NOACCESS,PAGE_GUARD, and address-wrap checks), 7 accepted spans reachingCheckFeatureSupport(D3D12_FEATURE_EXISTING_HEAPS)once,Aliasclearing on failure, andID3D12Device3QueryInterfacegating.era_gpu_alias_open_base_controlstripsinfo.AllocationBase != base ||from a build-tree copy ofsrc/era_gpu_alias.cpp(guarded byCMAKE_CONFIGURE_DEPENDSandFATAL_ERROR) and requiresPASS_REGULAR_EXPRESSION "FAIL: interior pointer: passed to D3D12".Checks executed
prep-verify 1735):python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py prep-verify 1735 --dir /tmp/rev-x2w-84/1735 --json->git_diff_check: PASS,docs_links_check: PASS,bidi_controls_check: PASS,py_compile: PASS./O2(win2025 1735, Build 26100, MSVC 14.44.35207):python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1735 --targets era_gpu_alias_base_control_check,era_gpu_alias_check --regex "^(era_gpu_alias_open|era_gpu_alias_open_base_control)$"--preset dev): 2/2 passed (era_gpu_alias_open0.02s,era_gpu_alias_open_base_control0.01s)./O2(--preset release): 2/2 passed (era_gpu_alias_open0.02s,era_gpu_alias_open_base_control0.01s).src/era_gpu_alias.cpp(Win2025 Debug):python3 /root/.local/state/xbox2windows/pipeline/x2w_pipe.py win2025 1735 --targets era_gpu_alias_check --regex "^era_gpu_alias_open$" --skip-release --patch /tmp/rev-x2w-84/mut_1735.patch(removing| PAGE_GUARDfrom theinfo.Protectcheck insrc/era_gpu_alias.cpp) -> Mutant killed:era_gpu_alias_openfailed withFAIL: PAGE_GUARD tail: passed to D3D12andFAIL: PAGE_GUARD tail, last byte: passed to D3D12(era_gpu_alias_check: 2 FAILED).AI-assisted; commands listed were executed locally.