Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/coreclr/pal/src/include/pal/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ namespace CorUnix
void* m_stackLimit;
// Signal handler's alternate stack to help with stack overflow
void* m_alternateStack;
size_t m_alternateStackSize;

//
// The thread entry routine (called from InternalCreateThread)
Expand Down Expand Up @@ -301,7 +302,8 @@ namespace CorUnix
m_fStartStatusSet(FALSE),
m_stackBase(NULL),
m_stackLimit(NULL),
m_alternateStack(NULL)
m_alternateStack(NULL),
m_alternateStackSize(0)
{
};

Expand Down
18 changes: 7 additions & 11 deletions src/coreclr/pal/src/thread/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2078,6 +2078,7 @@ CPalThread::EnsureSignalAlternateStack()
if (st == 0)
{
m_alternateStack = altStack;
m_alternateStackSize = altStackSize;
}
else
{
Expand Down Expand Up @@ -2109,27 +2110,22 @@ CPalThread::FreeSignalAlternateStack()
{
#ifndef TARGET_WASM // WebAssembly does not support alternate signal stacks.
void *altstack = m_alternateStack;
size_t altStackSize = m_alternateStackSize;
m_alternateStack = nullptr;
m_alternateStackSize = 0;

if (altstack != nullptr)
{
stack_t ss, oss;
stack_t ss;
// The man page for sigaltstack says that when the ss.ss_flags is set to SS_DISABLE,
// all other ss fields are ignored. However, MUSL implementation checks that the
// ss_size is >= MINSIGSTKSZ even in this case.
ss.ss_size = MINSIGSTKSZ;
ss.ss_flags = SS_DISABLE;
ss.ss_sp = NULL;
int st = sigaltstack(&ss, &oss);
if ((st == 0) && (oss.ss_flags != SS_DISABLE))
{
// Make sure this altstack is this PAL's before freeing.
if (oss.ss_sp == altstack)
{
int st = munmap(oss.ss_sp, oss.ss_size);
_ASSERTE(st == 0);
}
}
sigaltstack(&ss, nullptr);
Comment thread
jkotas marked this conversation as resolved.
Resolved
int st = munmap(altstack, altStackSize);
Comment thread
jkotas marked this conversation as resolved.
Resolved
_ASSERTE(st == 0);
}
#endif // !TARGET_WASM
}
Expand Down
Loading