runtime: diagnose failed XMem scatter mappings #2217
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2225"
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-25T06:14:21Z.
Refs #874.
Report the first failed permissive XMem mapping step with the caller's index, destination address, page ID, Windows error, and virtual-memory region.
X2W_XMEM_TRACE_FAILED_BATCH=1also records the affected address ranges in the failed call so a later fault can be checked for membership. The range trace reports truncation when either operation exceeds 2,048 ranges.Verification
Built both XMem libraries and the protection fixture in Release with MSVC 19.51.36244.0 on Windows. All 10 selected tests passed.
The source-built control passes reversed destination order, a misaligned address, and a Windows reservation that cannot be replaced. It checks the reported caller index and page ID, host error, affected range, and rollback of the earlier mapping. The previous DLL refuses both calls and permits retry after rollback, but fails the new assertion because it emits only the batch summary.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T06:17:51Z.
Review: COMMENTED
Review of head
d3ebc7b9339df8d28ce994e6f61214050c94de0a(2 files, +159/-21:src/xmem_mapped_pages.cpp,tests/xmem_mapped_pages_check.py).Verdict: no blocking findings (P1=0). Two minor notes (P2=2).
State at review time: the Linux checks and the gfx1013 fixtures job pass. The
Build and test on Windowsjob was still pending, and the/O2job was skipped. I did not run the Windows build.What I checked
map_runnow reportsfailed_address. It points at the failing per-page view after the group fallback, sobatch.at(failed_address)inmap_pagesalways finds an entry.MapFailure::recordis first-failure-wins.unmap-viewis recorded before anyrestore-view, so the root cause is kept.memory.views.at(at + done)in therestore-viewpath is safe. The page was found inmemory.viewsearlier in the same loop.unmap_view()is behavior-equivalent to the inlinedUnmapViewOfFile2(..., MEM_PRESERVE_PLACEHOLDER)call it replaces. Test injection (test.hit(1)) keeps theERROR_INVALID_ADDRESSmapping.log_apply_failureindex lookup: the last occurrence wins, which matches the apply semantics. The run-containment fallback uses unsigned subtractionaddresses[i] - failure.address < view_bytes, which is correct and has no underflow problem.log_failed_rangesis capped at 2048 ranges and prints an explicittruncated omitted_pages=line, as the body says. It is only enabled byX2W_XMEM_TRACE_FAILED_BATCHand only on failure, so the hot path is unchanged.baseafterward.Notes
tests/xmem_mapped_pages_check.py(scatter_failure/check_scatter_diagnostic): themap-viewassertion only requireserrorto be non-zero, so it does not pin the Windows error. The test never exercises theunmap-vieworrestore-viewstages, or theview_bytes > page_bytescontainment branch oflog_apply_failure. One more test through the existingtest.hit(1)injection would cover those.src/xmem_mapped_pages.cpp(MapFailure::record):SetLastError(code)is called afterVirtualQuery. That is deliberate and correct. A short comment saying the call preserves the caller'sGetLastError()would help the next reader.Commands run locally (Linux, in a clean worktree at the head SHA)
UnmapViewOfFile2,VirtualQuery), so I could not build or run the XMem test on Linux. I did no runtime mutation. Please rely on the Windows CI result for the new assertions.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by SuperCraft3M on 2026-11-25T20:13:16Z.
I ran the source-built replacement fixture from
bf1c2518against two Windows 11 x64 Release builds. The baseline was a local integration ofacde511e(base11f11e84). The second build additionally backported the #2225 diagnostics and the scatter preflight frombf1c2518.The baseline returned error 87 and dropped the original view when the batch contained an unowned replacement token. The first failed assertion was
ReadProcessMemoryon that view. Both CTests passed with preflight. The fixture also confirmed that an unaligned replacement preserves the alias and that a corrected retry succeeds. These checks use synthetic pages and cover the preflight rejection path. Windows mapping failures after preflight remain a separate case.This is a verification of the existing scatter preflight commit.