Skip to content

Commit

Permalink
Don't use alternate stack on illumos or Solaris.
Browse files Browse the repository at this point in the history
When .NET translates SIGSEV to NullReferenceException, it does not return
from the signal handler. Instead it resumes execution at the catch handler
for the exception. This is not recommend by the manpage for sigaction(2):

> It is not recommended that [the ucontext] arg be used by the handler to
> restore the context from before the signal delivery.

The practical effect of resuming execution without returning from a handler
is that the alternate stack will not be used for subsequent signal delivery.
This is in contrast to the behavior on linux, which will always use the
alternate stack if the stack pointer at the time of fault does not fall on
the alternate stack.

Since the alternate stack is only usable for a single exception, don't
bother using it for any exceptions.
  • Loading branch information
AustinWise committed Aug 19, 2024
1 parent 6ed5db5 commit 85b5c51
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/coreclr/pal/src/exception/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,13 @@ BOOL SEHInitializeSignals(CorUnix::CPalThread *pthrCurrent, DWORD flags)
handle_signal(SIGSEGV, sigsegv_handler, &g_previous_sigsegv);
#else
handle_signal(SIGTRAP, sigtrap_handler, &g_previous_sigtrap);
int additionalFlagsForSigSegv = 0;
#ifndef TARGET_SUNOS
// On platforms that support signal handlers that don't return,
// SIGSEGV handler runs on a separate stack so that we can handle stack overflow
handle_signal(SIGSEGV, sigsegv_handler, &g_previous_sigsegv, SA_ONSTACK);
additionalFlagsForSigSegv |= SA_ONSTACK;
#endif
handle_signal(SIGSEGV, sigsegv_handler, &g_previous_sigsegv, additionalFlagsForSigSegv);

if (!pthrCurrent->EnsureSignalAlternateStack())
{
Expand Down Expand Up @@ -344,7 +349,7 @@ Return :
--*/
bool IsRunningOnAlternateStack(void *context)
{
#if HAVE_MACH_EXCEPTIONS
#if HAVE_MACH_EXCEPTIONS || defined(TARGET_SUNOS)
return false;
#else
bool isRunningOnAlternateStack;
Expand Down

0 comments on commit 85b5c51

Please sign in to comment.