From 1b8518435bde23806d850ab399828f8f594e95a0 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Fri, 22 Nov 2024 10:27:23 +0100 Subject: [PATCH] Enlarge stack overflow handling helper stack (#110068) The stack overflow coreclr tests started to fail recently. It turns out that was caused by the size of the helper stack allocated for stack overflow handling case is no longer sufficient. Moreover, there is a bug in `Thread::CreateUtilityThread` that calls the `SetThreadName` even when the thread creation fails. Close #109499 --- src/coreclr/pal/src/exception/signal.cpp | 2 +- src/coreclr/vm/threads.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/coreclr/pal/src/exception/signal.cpp b/src/coreclr/pal/src/exception/signal.cpp index 3dc0e541f6a8af..6ec3f69854510d 100644 --- a/src/coreclr/pal/src/exception/signal.cpp +++ b/src/coreclr/pal/src/exception/signal.cpp @@ -206,7 +206,7 @@ BOOL SEHInitializeSignals(CorUnix::CPalThread *pthrCurrent, DWORD flags) } // Allocate the minimal stack necessary for handling stack overflow - int stackOverflowStackSize = ALIGN_UP(sizeof(SignalHandlerWorkerReturnPoint), 16) + 7 * 4096; + int stackOverflowStackSize = ALIGN_UP(sizeof(SignalHandlerWorkerReturnPoint), 16) + 8 * 4096; // Align the size to virtual page size and add one virtual page as a stack guard stackOverflowStackSize = ALIGN_UP(stackOverflowStackSize, GetVirtualPageSize()) + GetVirtualPageSize(); int flags = MAP_ANONYMOUS | MAP_PRIVATE; diff --git a/src/coreclr/vm/threads.cpp b/src/coreclr/vm/threads.cpp index bf85aa797c46ca..e89b6c7d94c1d0 100644 --- a/src/coreclr/vm/threads.cpp +++ b/src/coreclr/vm/threads.cpp @@ -2015,10 +2015,13 @@ HANDLE Thread::CreateUtilityThread(Thread::StackSizeBucket stackSizeBucket, LPTH DWORD threadId; HANDLE hThread = CreateThread(NULL, stackSize, start, args, flags, &threadId); - SetThreadName(hThread, pName); + if (hThread != INVALID_HANDLE_VALUE) + { + SetThreadName(hThread, pName); - if (pThreadId) - *pThreadId = threadId; + if (pThreadId) + *pThreadId = threadId; + } return hThread; }