Skip to content

Commit b4d8ba7

Browse files
committed
Fix test failure
Somehow a test reached Thread::CooperativeCleanup() with m_pRuntimeThreadLocals==NULL. Looking at the code I expected that would mean GetThread()==NULL or ThreadState contains TS_Dead, but neither of those conditions were true so it is unclear how it executed to that state. The callstack was: > coreclr.dll!Thread::CooperativeCleanup() Line 2762 C++ coreclr.dll!Thread::DetachThread(int fDLLThreadDetach) Line 936 C++ coreclr.dll!TlsDestructionMonitor::~TlsDestructionMonitor() Line 1745 C++ coreclr.dll!__dyn_tls_dtor(void * __formal, const unsigned long dwReason, void * __formal) Line 122 C++ ntdll.dll!_LdrxCallInitRoutine@16() Unknown ntdll.dll!LdrpCallInitRoutine() Unknown ntdll.dll!LdrpCallTlsInitializers() Unknown ntdll.dll!LdrShutdownThread() Unknown ntdll.dll!RtlExitUserThread() Unknown Regardless, the previous code wouldn't have hit that issue because it obtained the pointer through t_runtime_thread_locals rather than m_pRuntimeThreadLocals. I restored using t_runtime_thread_locals in the Cleanup routine. Out of caution I also searched for any other places that were previously accessing the alloc_context through the thread local address and ensured they don't switch to use m_pRuntimeThreadLocals either.
1 parent 2a99c34 commit b4d8ba7

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/coreclr/vm/threads.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2755,7 +2755,7 @@ void Thread::CooperativeCleanup()
27552755

27562756
if (GCHeapUtilities::IsGCHeapInitialized())
27572757
{
2758-
gc_alloc_context* gc_alloc_context = GetAllocContext();
2758+
gc_alloc_context* gc_alloc_context = &t_runtime_thread_locals.alloc_context.gc_allocation_context;
27592759
// If the GC heap is initialized, we need to fix the alloc context for this detaching thread.
27602760
// GetTotalAllocatedBytes reads dead_threads_non_alloc_bytes, but will suspend EE, being in COOP mode we cannot race with that
27612761
// however, there could be other threads terminating and doing the same Add.

src/coreclr/vm/threadsuspend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,7 @@ void Thread::PerformPreemptiveGC()
23782378
// BUG(github #10318) - when not using allocation contexts, the alloc lock
23792379
// must be acquired here. Until fixed, this assert prevents random heap corruption.
23802380
_ASSERTE(GCHeapUtilities::UseThreadAllocationContexts());
2381-
GCHeapUtilities::GetGCHeap()->StressHeap(GetAllocContext());
2381+
GCHeapUtilities::GetGCHeap()->StressHeap(&t_runtime_thread_locals.alloc_context.gc_allocation_context);
23822382
m_bGCStressing = FALSE;
23832383
}
23842384
m_GCOnTransitionsOK = TRUE;

0 commit comments

Comments
 (0)