Improve stack overflow reporting (dotnet/coreclr#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)
commit8eb828408b7defd08a6c83a18e1f5dfed3e8ef54
treeda34fbf7182f23e96714dd661d570336e25d90c9
parent752085a12c9c1fc3bd4d8c87af19e35297224205
Improve stack overflow reporting (dotnet/coreclr#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.

Commit migrated from https://github.com/dotnet/coreclr/commit/f193024a5ef8f277f08bed3721e2e8e730aabdb9
18 files changed:
src/coreclr/src/pal/inc/unixasmmacrosarm64.inc
src/coreclr/src/pal/src/CMakeLists.txt
src/coreclr/src/pal/src/arch/amd64/callsignalhandlerwrapper.S [new file with mode: 0644]
src/coreclr/src/pal/src/arch/amd64/signalhandlerhelper.cpp [new file with mode: 0644]
src/coreclr/src/pal/src/arch/arm/callsignalhandlerwrapper.S [new file with mode: 0644]
src/coreclr/src/pal/src/arch/arm/signalhandlerhelper.cpp [new file with mode: 0644]
src/coreclr/src/pal/src/arch/arm64/callsignalhandlerwrapper.S [new file with mode: 0644]
src/coreclr/src/pal/src/arch/arm64/signalhandlerhelper.cpp [new file with mode: 0644]
src/coreclr/src/pal/src/arch/i386/callsignalhandlerwrapper.S [new file with mode: 0644]
src/coreclr/src/pal/src/arch/i386/signalhandlerhelper.cpp [new file with mode: 0644]
src/coreclr/src/pal/src/exception/seh.cpp
src/coreclr/src/pal/src/exception/signal.cpp
src/coreclr/src/pal/src/exception/signal.hpp [deleted file]
src/coreclr/src/pal/src/include/pal/context.h
src/coreclr/src/pal/src/include/pal/signal.hpp [new file with mode: 0644]
src/coreclr/src/pal/src/init/sxs.cpp
src/coreclr/src/pal/src/thread/context.cpp
src/coreclr/src/pal/src/thread/thread.cpp