Skip to content

Commit

Permalink
Enlarge stack overflow handling helper stack (dotnet#110068)
Browse files Browse the repository at this point in the history
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 dotnet#109499
  • Loading branch information
janvorli authored and mikelle-rogers committed Dec 4, 2024
1 parent 8c8745b commit bef126d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/coreclr/pal/src/exception/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions src/coreclr/vm/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit bef126d

Please sign in to comment.