From f193024a5ef8f277f08bed3721e2e8e730aabdb9 Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Wed, 22 Feb 2017 23:18:01 +0100 Subject: 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. --- src/pal/src/CMakeLists.txt | 40 ++++++++++++---------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) (limited to 'src/pal/src/CMakeLists.txt') diff --git a/src/pal/src/CMakeLists.txt b/src/pal/src/CMakeLists.txt index 16c9d8bd6f..dae0f3fe3f 100644 --- a/src/pal/src/CMakeLists.txt +++ b/src/pal/src/CMakeLists.txt @@ -101,35 +101,19 @@ set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -Wl,--no add_compile_options(-fPIC) -if(PAL_CMAKE_PLATFORM_ARCH_AMD64) - set(ARCH_SOURCES - arch/amd64/context2.S - arch/amd64/debugbreak.S - arch/amd64/exceptionhelper.S - arch/amd64/processor.cpp - ) -elseif(PAL_CMAKE_PLATFORM_ARCH_ARM) - set(ARCH_SOURCES - arch/arm/context2.S - arch/arm/debugbreak.S - arch/arm/exceptionhelper.S - arch/arm/processor.cpp - ) -elseif(PAL_CMAKE_PLATFORM_ARCH_ARM64) - set(ARCH_SOURCES - arch/arm64/context2.S - arch/arm64/debugbreak.S - arch/arm64/exceptionhelper.S - arch/arm64/processor.cpp - ) -elseif(PAL_CMAKE_PLATFORM_ARCH_I386) - set(ARCH_SOURCES - arch/i386/context2.S - arch/i386/debugbreak.S - arch/i386/exceptionhelper.S - arch/i386/processor.cpp +set(ARCH_SOURCES + arch/${ARCH_SOURCES_DIR}/context2.S + arch/${ARCH_SOURCES_DIR}/debugbreak.S + arch/${ARCH_SOURCES_DIR}/exceptionhelper.S + arch/${ARCH_SOURCES_DIR}/processor.cpp +) + +if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) + list(APPEND PLATFORM_SOURCES + arch/${ARCH_SOURCES_DIR}/callsignalhandlerwrapper.S + arch/${ARCH_SOURCES_DIR}/signalhandlerhelper.cpp ) -endif() +endif(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) if(PAL_CMAKE_PLATFORM_ARCH_ARM) set_source_files_properties(exception/seh.cpp PROPERTIES COMPILE_FLAGS -Wno-error=inline-asm) -- cgit v1.2.3