Repository navigation
Conversation
…e debug CRT In a Debug build the heap-lock section of xmem_test hung on every run: a toucher held HeapLock and called the debug CRT's _aligned_free, which waits for the CRT's own heap lock, while another thread held that lock in _calloc_dbg (vcruntime's exception dispatch allocates there, past the heap gate) and waited for the process heap. xmem's fault lock was not in the cycle, and RelWithDebInfo passed. The title's _aligned_malloc comes down to HeapAlloc, so the touchers now HeapAlloc and HeapFree on the process heap while they hold its lock: the block headers are still written under the lock, without the debug CRT's lock order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ss heap The same Debug-only cycle as xmem_test's: the touchers held HeapLock and called the debug CRT's _aligned_malloc, which takes the CRT's heap lock, while the allocator threads hold that lock and wait for the process heap. The watchdog fired in all three variants in a Debug build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
abnalstlll-byte
approved these changes
Nov 25, 2026
abnalstlll-byte
left a comment
Contributor
There was a problem hiding this comment.
Clean-Room & Technical Verification
- Mergeability: 3-way merge against upstream
main(bcaa13dad) is 100% clean with zero merge conflicts. - Clean-Room Compliance: 100% clean-room. Test harness synchronization fix only; zero retail code, game data, or keys (
check_no_game_data.pyclean). - Technical Analysis & Root Cause:
- In MSVC Debug builds,
_aligned_malloc/_aligned_freeroute into_free_dbg/_calloc_dbgwhich acquires the debug CRT heap lock. - When test touchers held
HeapLock(GetProcessHeap())and invoked_aligned_malloc, this inverted the lock hierarchy with CRT exception dispatch threads (in__CxxFrameHandler3/_calloc_dbgallocating from CRT heap lock and subsequently waiting on the process heap lock), leading to an unrecoverable deadlock in Debug builds (xmem_testandd3d12_existing_heap_test). - Replacing test touchers' allocation calls with direct Win32
HeapAlloc(heap, 0, ...)andHeapFree(heap, 0, ...)eliminates the CRT lock acquisition while maintaining valid heap header manipulation and fault induction underHeapLock. - Thoroughly tested under both Debug and RelWithDebInfo builds.
- In MSVC Debug builds,
LGTM! Approved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as: RT-XMEM-HEAP-LOCK-DEADLOCK (#1608)
Item: RT-XMEM-HEAP-LOCK-DEADLOCK (kotekompotek's finding in #1608:
xmem_testhangs in the "xmem heap-lock faults" section in a Debug build on Windows, all three variants).Cause (measured, not xmem)
At the hang I walked every test thread's stack from the watchdog (temporary instrumentation, not committed):
HeapLock(GetProcessHeap())and is in the debug CRT's_aligned_free→_free_dbg→EnterCriticalSection, waiting for the CRT's own heap lock;__CxxFrameHandler3→_calloc_dbg, which holds that CRT lock, →RtlAllocateHeap, waiting for the process heap.xmem's
g_fault_lockisn't in the cycle, and the heap gate can't stop it because the CRT's internalcallocdoesn't go throughoperator new. A release CRT's_aligned_mallocis justHeapAllocand takes no lock of its own, which is why RelWithDebInfo passes, and why the title'sXMemAlloc(its own release CRT) can't hit this. So the bug is in the test's emulation, not in the fault handler.d3d12_existing_heap_test'scheck_heap_lock_faultshas the same pattern and hangs the same way in Debug (all three variants: "vulkan slot-133 heap-lock faults: no progress for 30 s"). Its allocator threads take the CRT lock and then the heap lock directly.Fix
The touchers in both tests
HeapAlloc/HeapFreeon the process heap while they hold its lock, instead of the test binary's_aligned_malloc/_aligned_free. They still write heap block headers under the heap's lock while faulting, which is what the section tests. Nothing is skipped and no check changes. The comments say why.Tested
Windows 11 Pro (26300), MSVC 14.52, RTX 4070 SUPER, no game files:
xmem_test xmemexit 3 on every run (watchdog). After: no hang in 105 runs of the threexmem*variants. Debug ctestxmem*andd3d12_existing_heap*: 6/6 pass.ctest400/402. The two failures werexmem_write_watch("the reader of the views' last pages never faults or misreads") and anapi_ref_state30 s timeout. Both then passed--repeat until-fail:3together with the other heap-lock tests (7/7 ×3).vk_presenter_sync_test.cpp(C1128, needs/bigobj), and the Debugrun_tiny_*andreplay_*tests fail on this machine. None of them link the two test files changed here.python -I scripts/check_no_game_data.pyon both files: clean.djrolfes' Wine 11.22 read-only XMem findings in #1608 have a different cause (VirtualQuery state under Wine). This PR doesn't touch them, and the Wine skip of the heap-lock section stays as it is.
AI-assisted (Claude Code).
GPUs tested: NVIDIA GeForce RTX 4070 SUPER, driver 621.01, Windows 11 Pro 26300
AI-assisted: yes (Claude Code)
🤖 Generated with Claude Code