From 52fbd47c6c92bf9aa819e6af8dbe4651a4d5f126 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Wed, 27 Aug 2025 19:30:26 -0700 Subject: [PATCH] Clear TS_GCSuspendRedirected at the end of thread redirection TS_GCSuspendRedirected is normally cleared in the slow path of pulsing GC mode (RareDisablePreemptiveGC). The problem is that we may not even get to that slow path if the thread gets rescheduled right after we switch to preemptive mode and gets scheduled back only after the GC completes and resumes execution. This change clears it explicitly. Fixes #119149 --- src/coreclr/vm/threadsuspend.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/coreclr/vm/threadsuspend.cpp b/src/coreclr/vm/threadsuspend.cpp index 1411e56ff39e7f..538d1f4b57783b 100644 --- a/src/coreclr/vm/threadsuspend.cpp +++ b/src/coreclr/vm/threadsuspend.cpp @@ -2713,6 +2713,11 @@ void __stdcall Thread::RedirectedHandledJITCase(RedirectReason reason) GCX_PREEMP_NO_DTOR_END(); } +#if defined(FEATURE_HIJACK) && !defined(TARGET_UNIX) + // Make sure that this is cleared to enable redirects again + pThread->ResetThreadState(Thread::TS_GCSuspendRedirected); +#endif + // Once we get here the suspension is over! // We will restore the state as it was at the point of redirection // and continue normal execution.