runtime: keep new thread stacks out of the 2^40 boundary window #3458
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3458"
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 Not-Saii on 2026-11-29T13:59:18Z.
Change
xmem_startup_below_40failed once in the Debug job of main at0614f68c: the boundary allocation was refused with error 8 after 4 blocker reservations (check_failed: boundary_allocated). I could not reproduce that failure on its own, so this is hardening, not a confirmed fix. Refs #3426.check_boundary()reserves every free range below 2^40 except the 4 MiB window[2^40 - 4 MiB, 2^40), then asksxmem.dllfor exactly 4 MiB there. Anything else that lands in the window between those two steps makes the call fail with that output.What I measured: if the fixture starts a thread right after the window is set up, the thread's stack lands at the base of the window, and the test fails 200 of 200 times with the CI output. An unconstrained
VirtualAlloclands above 2^40 and doesn't interfere. What I did not measure: that any thread actually starts in this process at that moment on CI. Locally the process has exactly one thread at start, at the boundary setup and at exit (1000 runs under load). A loader or thread-pool worker on the slower runner is a hypothesis.The test now leaves eight free ranges of 4 MiB - 64 KiB directly below the window, separated by reserved 64 KiB. A new stack takes one of those first. None of them can hold a 2 MiB-aligned block of 4 MiB or more, so the checks are unchanged: 4 MiB + 64 KiB is still refused, and the 4 MiB block must still land exactly at
2^40 - 4 MiB. TheLowRangeBlockersconstructor now takes a list of holes instead of one;check_exhaustedstill passes none. The runtime is unchanged.Verification
Measured at base
212d4b5fwith the change asb16519ab. The branch is rebased ontoe3f9a64fwithout conflicts (6f10a2be); main has not changed the below-2^40 path since. Windows 11 build 26300; Windows SDK 10.0.26100. Builds:dev(Debug) andrelease(/O2) presets.Each loop runs
ctest --preset <dev|release> --no-tests=error -R '^xmem_startup_below_40$'a fixed number of times and counts failures. "load 24" adds 24 busy-loop processes on a 24-thread CPU. "2 cores" pins ctest, the test and 4 busy-loop processes to affinity mask0x3.xmem_startup_below_40, failures out of 1000:212d4b5f)One after-fix run failed with error 32 loading
xmem.dllbecause I relinked the DLL during the loop; it is excluded.Forced control (Debug, 200 runs, an experiment-only block that starts N threads right after the blockers are reserved, not part of this PR):
All five
xmem_startup_below_40*tests pass in both presets with the change, including the mutant controls andxmem_startup_below_40_deployed_ignores_mutants.Evidence and follow-up
If the CI failure came from something other than a new thread stack, this change does not cover it. The other two failures in #3426 are separate; the retire one is #3457.
AI-assisted.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-29T14:16:18Z.
Review of head
6f10a2be(one commit onmaine3f9a64f).git merge-tree --write-tree origin/main 6f10a2beagainstmain0ed385dcexits 0. The diff is intests/xmem_startup_below_40_check.cpponly. The runtime is unchanged.X2W_XMEM_STARTUP_BELOW_40stays opt-in:run.ps1 -StartupBelow40,run.sh --startup-below-40, andstartup_below_40in thebaserun preset.Semantics
decoys_below(hole, 8)makes eight ranges[hole - k·4 MiB, hole - (k-1)·4 MiB - 64 KiB). Each is 4 MiB - 64 KiB. The blockers reserve the 64 KiB above each range, including the 64 KiB just below the window, and everything below the lowest one. So no free range below 2^40 other than the window can hold 4 MiB, aligned or not.boundary_overflow_*(4 MiB + 64 KiB refused) andboundary_last_byte(4 MiB placed exactly at2^40 - 4 MiB) test the same thing as before.LowRangeBlockershandles a hole that overlaps a region's start or end:reserve(start, hole)is a no-op whenhole <= start, and so is the finalreserve(start, stop)whenhole_end >= stop.check_exhaustedpasses no holes and is unchanged.X2W_XMEM_TEST_BELOW_40mutants only nameexhausted_*checks. Under Wine they also failboundary_overflow_*, with the same check names at both heads (table below). So the decoys hide nothing the overflow check caught before.Measured under Wine (Linux, Proton Experimental
wine-11.0, private prefix). The test was built with clang-cl 19 (/O2 /MT) frommainand from this head.xmem.dllcame from a cross build ofmain, and the mutants used a cross-builtxmem-test-controlsDLL. In both DLLs the below-2^40 code matchesmain. "Forced" is the control from your body: oneCreateThreadright afterboundary_setup, waited until the thread runs.maintestcheck_failed: boundary_allocated(error 8 after 4 blocker reservations, as in CI)no_limit/no_limit+no_check/no_limit+no_releaseSo Wine places a new thread's stack the way your Windows run did. In the
maintest it lands in the window. Its region starts at0xFFFFC00000(1 MiB committed), with the stack at0xFFFFD00000. With the decoys it lands in the lowest decoy (0xFFFDD00000), and the 4 MiB block still goes to0xFFFFC00000.MUST: none.
NIT
decoys_belowdoesn't say so. Under Wine each new thread takes 2 MiB (1 MiB committed, then the 1 MiB stack), split across the decoys. With 12 forced threads the test passes. With 13 the 13th lands in the window (allocation base0xFFFFD00000) andboundary_allocatedfails again. You measured 12 on Windows. One line such as "about a dozen thread stacks fit" would tell the next reader when this hardening runs out. Optional.runtime: keep new thread stacks …reads like a runtime change. The change is test-only.tests:would match how this repo labels test-only commits. Optional.CI note: CI on
6f10a2beis green. But the Windows job runs the 82-testprpreset, and its log has noxmem_startup_below_40line (grep -cgives 0). So CI did not run this test. Your Windows loops and the Wine runs above are the evidence. There are no WARP reports on the PR yet (this test doesn't need a GPU).No reviews or change requests. No binary files, no title-specific inputs.
Merging.
AI-assisted.