Improve stack overflow reporting (#9650)
authorJan Vorlicek <janvorli@microsoft.com>
Wed, 22 Feb 2017 22:18:01 +0000 (23:18 +0100)
committerGitHub <noreply@github.com>
Wed, 22 Feb 2017 22:18:01 +0000 (23:18 +0100)
commitf193024a5ef8f277f08bed3721e2e8e730aabdb9
treed024acb0e60824a57771e2380116ecfa20fefeb7
parent09fd5fbd08d376aa0d7b2602e5115aaabcd7b352
Improve stack overflow reporting (#9650)

* Improve stack overflow reporting

This change modifies the SIGSEGV handling to use an alternate stack so that
we can safely detect and report stack overflow even in case when we are
really out of stack. Before, we were able to detect stack overflow and report
it only when JIT inserted stack probes (for functions with frames larger than
4kB) and so there was still space on the stack to run the sigsegv handler.
It brings in some additional complexity, since we need to switch to the original
stack of the thread once we figure out the sigsegv is not a stack overflow and
if we return from the hardware exception handler, we need to switch back to the
alternate stack before returning from the sigsegv handler.
Also, the alternate stack is created per thread and so we need to correctly destroy
it when a thread terminates and also install it on foreign threads that enter PAL.
This also requires creating fake stack frames to enable the libunwind to walk
the stack from the exception handler to the sigsegv location.

* Fix stack unwinding in CallDescrWorkerInternal

While testing the change to enable stack overflow handling, I've noticed that
the PROLOG_SAVE_REG_PAIR and PROLOG_SAVE_REG_PAIR_INDEXED macros are missing
.cfi_def_cfa_register fp. That resulted in inability to unwind through the
CallDescrWorkerInternal, since this function dynamically allocates stack slots
and so the default sp based frame doesn't work.
18 files changed:
src/pal/inc/unixasmmacrosarm64.inc
src/pal/src/CMakeLists.txt
src/pal/src/arch/amd64/callsignalhandlerwrapper.S [new file with mode: 0644]
src/pal/src/arch/amd64/signalhandlerhelper.cpp [new file with mode: 0644]
src/pal/src/arch/arm/callsignalhandlerwrapper.S [new file with mode: 0644]
src/pal/src/arch/arm/signalhandlerhelper.cpp [new file with mode: 0644]
src/pal/src/arch/arm64/callsignalhandlerwrapper.S [new file with mode: 0644]
src/pal/src/arch/arm64/signalhandlerhelper.cpp [new file with mode: 0644]
src/pal/src/arch/i386/callsignalhandlerwrapper.S [new file with mode: 0644]
src/pal/src/arch/i386/signalhandlerhelper.cpp [new file with mode: 0644]
src/pal/src/exception/seh.cpp
src/pal/src/exception/signal.cpp
src/pal/src/exception/signal.hpp [deleted file]
src/pal/src/include/pal/context.h
src/pal/src/include/pal/signal.hpp [new file with mode: 0644]
src/pal/src/init/sxs.cpp
src/pal/src/thread/context.cpp
src/pal/src/thread/thread.cpp