Skip to content

Commit 5cc544a

Browse files
Fix shutdown on foreign thread (#116233)
When a foreign thread running in .NET process is killed or crashes due to some hardware exception, the .NET code that performs shutdown gets called and incorrectly expects the thread to be a thread that's registered with the runtime. It calls GetThread on it and then calls a method on the thread. That leads to an assert in debug builds and crash in release ones. The function that is called is not needed for foreign threads though, so the fix is to skip calling it if the GetThreadNULLOk returns NULL (that means the thread is foreign and never registered with the runtime). Co-authored-by: Jan Vorlicek <[email protected]>
1 parent 0e6061f commit 5cc544a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/coreclr/vm/ceemain.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,11 @@ void EESocketCleanupHelper(bool isExecutingOnAltStack)
554554

555555
if (isExecutingOnAltStack)
556556
{
557-
GetThread()->SetExecutingOnAltStack();
557+
Thread *pThread = GetThreadNULLOk();
558+
if (pThread)
559+
{
560+
pThread->SetExecutingOnAltStack();
561+
}
558562
}
559563

560564
// Close the debugger transport socket first

0 commit comments

Comments
 (0)