runtime: cap the permissive XMemMapPhysicalPages page count #1518
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1525"
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 RenzoWit35 on 2026-11-24T13:37:56Z.
Change
With
X2W_XMEM_PERMISSIVE=1,XMemMapPhysicalPagesallocatesstd::vectors sized by the caller'scount, andto_pages(also used byXMemMapPhysicalPagesScatter) doespages.resize(count). Only an address-overflow guard boundedcount(about 2^48), unlike the strict path (map_pages,free_pages), which rejectscount > era_physical::capacity_pages. A huge count therefore threwstd::bad_allocout of anextern "C"function.This rejects
count > era_physical::capacity_pagesup front in the permissiveXMemMapPhysicalPagesand into_pages, returning NULL/FALSE withERROR_INVALID_PARAMETER, the strict path's convention. No behavior changes for counts up to the capacity (including the zero-count null-array unmap).Verification
Windows 11, MSVC 14.51.36231,
cmake --preset dev, baseorigin/main60c72330.X2W_XMEM_PERMISSIVE=1withXMemMapPhysicalPages(0x10000, 1 << 40, NULL)in a child process raised C++ exception 0xE06D7363 (ctypes reports it asOSError; a native caller would terminate).check_permissive_countintests/xmem_mapped_pages_check.py: with count1 << 40the map call (null and non-null token array) must return NULL with error 87 and scatter must return FALSE with error 87; control: a zero-count permissive call still returns the base. Negative control: on unmodifiedmainthe child dies and the check fails; with the fix it passes.cmake --build out/build/dev --target xmem_shimthenctest --test-dir out/build/dev -R xmem_shim_mapped_pages: Passed.Not run: other xmem CTests whose helper executables/DLLs were not built here (
xmem_shim_page_runs,xmem_attribute_scan,cpu_native_xmem_*); they were "Not Run"/missing-file, not failures of this change.Evidence and follow-up
Follow-up (separate behavior, not changed here):
map_pagesinsrc/xmem_mapped_pages.cpp(if (!section_for(page)) return FALSE;, around line 398) returns FALSE without callingSetLastError.AI-assisted.