Do not run managed pre-mortem callbacks for GC threads. (#80276)
authorVladimir Sadov <vsadov@microsoft.com>
Fri, 6 Jan 2023 04:09:53 +0000 (20:09 -0800)
committerGitHub <noreply@github.com>
Fri, 6 Jan 2023 04:09:53 +0000 (20:09 -0800)
src/coreclr/nativeaot/Runtime/thread.cpp
src/coreclr/nativeaot/Runtime/threadstore.cpp

index 9f568ff88eb8673509f7f7fb0913f4fbc51e10c4..9d9177191822d3f064d9033deaf1222ca233a7e0 100644 (file)
@@ -1125,6 +1125,10 @@ FORCEINLINE bool Thread::InlineTryFastReversePInvoke(ReversePInvokeFrame * pFram
         return false; // bad transition
     }
 
+    // this is an ordinary transition to managed code
+    // GC threads should not do that
+    ASSERT(!IsGCSpecial());
+
     // save the previous transition frame
     pFrame->m_savedPInvokeTransitionFrame = m_pTransitionFrame;
 
index 9185684a317401f99849228e3a01571a7ec1748a..e831e9ea2dde8c91d5b7a8f1cb51173f2840a479 100644 (file)
@@ -168,7 +168,9 @@ void ThreadStore::DetachCurrentThread()
     }
 
     // Run pre-mortem callbacks while we still can run managed code and not holding locks.
-    if (g_threadExitCallback != NULL)
+    // NOTE: background GC threads are attached/suspendable threads, but should not run ordinary
+    // managed code. Make sure that does not happen here.
+    if (g_threadExitCallback != NULL && !pDetachingThread->IsGCSpecial())
     {
         g_threadExitCallback();
     }