runtime: keep XMem allocation failures inside the shim #3697
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3697"
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 lambirou on 2026-12-01T03:03:27Z.
Problem
xmem.dllis called by the title through a C ABI, and the title does not install C++ exception handlers. A long run onmainstopped at 478.39 s with0xe06d7363; the return-address chain went throughXMemMapPhysicalPages, the GPU-mirror batch andsection_for. Any failed allocation in the backing table, the slab record, the mirror vectors or a mapping batch therefore ended the process instead of returning a Win32 error.Change
SlabSlots::take_freshreleases the new slab and returnsfalseonstd::bad_allocinstead of rethrowing.section_forhandles both backing-tableemplacesites, unwinds a fresh slot and returnsnullptrwithERROR_NOT_ENOUGH_MEMORY.local_mirror_lockedis best-effort: an allocation failure in the GPU mirror is logged and skipped, while the CPU mapping the title asked for remains successful.local_apply,XMemMapPhysicalPages,XMemMapPhysicalPagesScatterandXMemFreePhysicalPagestranslatestd::exceptioninto a failed call withERROR_NOT_ENOUGH_MEMORY; unknown exceptions are also caught at the apply boundary.X2W_XMEM_TEST_ALLOC_FAILURE_BATCH,X2W_XMEM_TEST_ALLOC_FAILURE_SECTION). The newxmem_mapped_pages_allocationscenario checks the error code and the control mapping from the same process.No GDK or game file is included.
Tests
ctest --test-dir out/build/release -R '^xmem': 73 tests, 0 failed (3 placeholder tests skipped).Negative control: with the
XMemMapPhysicalPagesboundary catch changed tothrow;,xmem_mapped_pages_check.py --allocation-failurefails withOSError: [WinError -529697949] Windows Error 0xe06d7363; restoring the catch makes it pass.Long runs on
main(1a9ccbc4, 32 GiB job, lazy commit/startup/shared views):gta6-main-20261201-5reached 11 630 frames at 23 fps, 1 446 textures and 341 coherent.s57mesh captures, past the previous 478 s crash point. The remaining mesh refusals are missing reviewed.mesh57-stateprofiles, not an XMem allocation.Limitations
The change reports allocation failure; it does not make more memory available.
section_forcallers already test its return value. The GPU mirror remains an addition to the CPU mapping and can be skipped under memory pressure.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T05:43:39Z.
Review: COMMENTED
I merged current main into the PR branch and resolved the only conflict in
CMakePresets.json, retaining all main selections and addingxmem_mapped_pages_allocationtopr. The selection is present inctest --preset pr -N --no-tests=error -R '^xmem_mapped_pages_allocation$'.ctest --preset dev --no-tests=error -j 2 -R '^xmem_(mapped_pages_allocation|shim_mapped_pages)$' --output-on-failurepassed on the integrated head. New hosted checks and review can now run on it.Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-12-02T14:44:00Z.
Review: COMMENTED
Reviewed
7361b5a9after the maintainer'smainmerge; read the diff, not built here.Verdict: approve. The allocation-failure conversion is in the right places: the C ABI exports now return failure with
ERROR_NOT_ENOUGH_MEMORYinstead of lettingstd::bad_alloccross into the title, and the new control covers both the batch-vector and section-table injection points.local_apply()catches an exception afterlocal_apply_locked()may already have applied some pages. The comment says "the batch has not been applied in this path", but that is only guaranteed when the allocation fails before the first page. Either document that a failed batch can be partially applied, or restructure the apply path to stage all allocations before the first mutation.XMemFreePhysicalPagesreportsera_physical::Status::exhaustedfor an internal allocation failure. That is a reasonable conservative result, but a short comment would make it clear that the failure is the shim's, not the title's invalid input.take_freshreleases the fresh slab and reports failure onbad_alloc;section_forreleases the slot before returning; the test covers both allocation points and then verifies the same page maps successfully once the injection is removed.xmem_mapped_pages_allocationis in theprfilter.The PR is
MERGEABLE/CLEANat this head.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T19:01:53Z.
Review: APPROVED
Reviewed
003609d9after the main update. The change handles allocation failures before they can cross the permissive mapping C ABI, unwinds the fresh slab on backing-table allocation failure, and keeps the CPU mapping successful when the optional GPU mirror throws. Independent Windows 11 build 26300 and MSVC Debugctest --preset dev --no-tests=error -V -j 1 -R '^xmem_mapped_pages_(allocation|commit|commit_failure)$'passed 3/3. Both injected sites returned ERROR_NOT_ENOUGH_MEMORY, and the same-process control mapping and readback passed. The main merge was clean.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T19:19:20Z.
Review: COMMENTED
The focused XMem checks passed 3/3 on this head. After #3725 landed, the current main trial merge conflicts in
CMakePresets.json. I paused auto-merge so the resolved head can be checked first. Please keepxmem_mapped_pages_allocationand the Mesh86 additions in the PR preset when refreshing the branch.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T20:09:44Z.
Review: APPROVED
Revalidated
0ed14675. I updated the contributor branch without rewriting it. The only conflict resolution preserves main's PR selections and addsxmem_mapped_pages_allocation; the runtime changes are those reviewed earlier.ctest --preset pr -Nlists the new check. Independent Windows/MSVC Debugctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^xmem_mapped_pages_(allocation|commit|commit_failure)$'passed 3/3 on the exact head, including both injectedERROR_NOT_ENOUGH_MEMORYpaths and the control mapping. The export catalog passed all 476 checks and six mutation controls.