Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit dc18fee

Browse files
author
Konstantin Baladurin
committed
sigsegv_handler: handle case when it is called on original stack
If sigsegv_handler is called on original stack (for example, if segmentation fault occurs in native application's thread that hasn't alternate signal stack) we should call common_signal_handler directly othersize sigsegv_handler's stackframe will be corrupted.
1 parent 3d4bd1b commit dc18fee

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/pal/src/exception/signal.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,18 @@ static void sigsegv_handler(int code, siginfo_t *siginfo, void *context)
487487
if (contextInitialization)
488488
{
489489
contextInitialization = false;
490-
ExecuteHandlerOnOriginalStack(code, siginfo, context, &returnPoint);
491-
_ASSERTE(FALSE); // The ExecuteHandlerOnOriginalStack should never return
490+
if (GetCurrentPalThread())
491+
{
492+
ExecuteHandlerOnOriginalStack(code, siginfo, context, &returnPoint);
493+
_ASSERTE(FALSE); // The ExecuteHandlerOnOriginalStack should never return
494+
}
495+
else
496+
{
497+
// If thread isn't created by coreclr and has alternate signal stack GetCurrentPalThread() will return NULL too.
498+
// But since in this case we don't handle hardware exceptions (IsSafeToHandleHardwareException returns false)
499+
// we can call common_signal_handler on the alternate stack.
500+
returnPoint.returnFromHandler = common_signal_handler(code, siginfo, context, 2, (size_t)0, (size_t)siginfo->si_addr);
501+
}
492502
}
493503

494504
if (returnPoint.returnFromHandler)

0 commit comments

Comments
 (0)