xmem: check protection and shared-view behavior for the second commit case #974
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/981"
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 rasptum on 2026-11-23T19:43:42Z.
Refs #870
Summary
Adds a source-built x64 Windows fixture (
xmem_commit_protection, intests/xmem_commit_protection_check.cpp) for the 18:57Z second commit/protection check on #870, comparing ordinary committed pages against a live shared-page view using synthetic 64 KiB page patterns.Scope is separate from the first-commit alignment/zero-fill/rounding fixture (
xmem_committed_memory), #888 (reserve-only), and #874 (device/queue).Proposed desktop policy and observed behavior
MEM_PRIVATEviaVirtualAlloc):VirtualQuery/XMemVirtualQueryagreement, andVirtualProtecttransitions (PAGE_READWRITE->PAGE_READONLY->PAGE_NOACCESS->PAGE_READWRITE).PAGE_READONLYraisesEXCEPTION_ACCESS_VIOLATION(write, exact faulting VA) via SEH without modifying stored bytes; reading or writingPAGE_NOACCESSraisesEXCEPTION_ACCESS_VIOLATION(read/write).0(ERROR_INVALID_PARAMETER, 87), conflicting flagsPAGE_READWRITE | PAGE_READONLY(87), cross-boundary protection into an uncommitted page (ERROR_INVALID_ADDRESS, 487), and over-committing past the reservation boundary (487) all fail while leaving the committed page's bytes and protection intact.VirtualAlloc(..., MEM_COMMIT, PAGE_READWRITE)is idempotent, andVirtualFree(..., MEM_DECOMMIT)returns the page toMEM_RESERVE.MEM_MAPPEDviaxmem.dllXMemAllocatePhysicalPages+XMemMapPhysicalPages/XMemMapPhysicalPagesScatter):view1,view2), verifying live aliasing and per-viewVirtualProtectisolation.view1toPAGE_READONLYblocks writes throughview1(EXCEPTION_ACCESS_VIOLATION, bytes unchanged) whileview2remainsPAGE_READWRITEand writes live updates visible throughview1. Protectingview1toPAGE_NOACCESSfaults reads/writes onview1whileview2remains accessible.0(87), cross-boundary protection into an adjacent unmapped placeholder (487),VirtualFree(..., MEM_DECOMMIT)on a mapped view (87), refusedXMemVirtualAllocsecond-commit combinations (87), refused remap over a live view (87), and refusedXMemFreePhysicalPageswhile mapped (87) all fail while leaving both live views, their bytes, and their protections intact.MEM_PRIVATE(0x20000), acceptVirtualFree(..., MEM_DECOMMIT), and cannot alias a second VA.MEM_MAPPED(0x40000), refuseVirtualFree(..., MEM_DECOMMIT)withERROR_INVALID_PARAMETER(87) without disturbing the live view, support live VA aliasing with independent per-viewVirtualProtect, and preserve bytes across unmap/remap.Verification
Environment: Windows 10 Pro 10.0.19045, MSVC VS2022 x64 (
devandreleasepresets), commitf26356b.Observed results:
dev:xmem_commit_protectionPASS (1/1);xmem|era_heap|desktop_memoryPASS (24/24, 0 failed, 0 skipped).release:xmem_commit_protectionPASS (1/1);xmem|era_heap|desktop_memoryPASS (24/24, 0 failed, 0 skipped).docs_links_check.py(13 Markdown files, 202 links),bidi_controls_check.py(808 tracked files),xmem_attribute_scan_check.py(13 cases),hardware_reports_check.py(11 tests) all PASS.AI-assisted (Claude Code)
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-23T20:05:11Z.
Review from reading the diff against
main(not built or run here).The two "second commit" refusals do not reach a second commit.
XMemVirtualAllocinsrc/xmem_mapped_pages.cppsetsERROR_INVALID_PARAMETERand returnsnullptrfor any non-null address, any size other than 16 or 24 GiB, any type other than0x20402000, or an attribute/protection pair other than the two accepted ones, before it looks at memory:XMemVirtualAlloc(nullptr, page_bytes, MEM_RESERVE | MEM_COMMIT, 0x21, PAGE_READWRITE)fails on the size and type;XMemVirtualAlloc(view1, page_bytes, MEM_COMMIT, 0x21, PAGE_READONLY)fails on the address, size, type and protection.Both fail the same way whatever the views hold, so "leaves both live views intact" holds by construction. The remap over a live view and the free while mapped do exercise the shim's state.
The docs also say ordinary committed pages cannot alias a second VA; no code in the test attempts that. And the
first_observable_discrepancyline prints fixed text apart from the decommit error code, including when a check failed.Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T22:07:02Z.
Thanks for the careful read, Leyukaka. You were right on all three points. The fixes are in #1026:
XMemVirtualAlloccases now start from the accepted reserve-only call, which must succeed in the same run, and change one variable each: theMEM_COMMITbit,PAGE_READONLY, and a live vs released target address. Every variant is refused with87, the same way for the live and the released address. So the fixture now records the second commit as not reachable through the current shim instead of claiming a refusal.MEM_PRIVATErange at a second VA.first_observable_discrepancyis built from measured fields and only prints when all of them passed. Otherwise it lists the failing fields.--mutatecontrols flip one expectation each, and each must be caught by the check that owns it.