16# pragma GCC diagnostic push
17# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
20#if defined( CATCH_CONFIG_WINDOWS_SEH ) || defined( CATCH_CONFIG_POSIX_SIGNALS )
24 void reportFatal(
char const *
const message ) {
31#if defined( CATCH_CONFIG_WINDOWS_SEH )
34 struct SignalDefs { DWORD
id;
const char*
name; };
39 static SignalDefs signalDefs[] = {
40 {
static_cast<DWORD
>(EXCEPTION_ILLEGAL_INSTRUCTION),
"SIGILL - Illegal instruction signal" },
41 {
static_cast<DWORD
>(EXCEPTION_STACK_OVERFLOW),
"SIGSEGV - Stack overflow" },
42 {
static_cast<DWORD
>(EXCEPTION_ACCESS_VIOLATION),
"SIGSEGV - Segmentation violation signal" },
43 {
static_cast<DWORD
>(EXCEPTION_INT_DIVIDE_BY_ZERO),
"Divide by zero error" },
46 LONG CALLBACK FatalConditionHandler::handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) {
47 for (
auto const& def : signalDefs) {
48 if (ExceptionInfo->ExceptionRecord->ExceptionCode == def.id) {
49 reportFatal(def.name);
54 return EXCEPTION_CONTINUE_SEARCH;
61 guaranteeSize = 32 * 1024;
62 exceptionHandlerHandle =
nullptr;
64 exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException);
66 SetThreadStackGuarantee(&guaranteeSize);
71 RemoveVectoredExceptionHandler(exceptionHandlerHandle);
72 SetThreadStackGuarantee(&guaranteeSize);
73 exceptionHandlerHandle =
nullptr;
83ULONG FatalConditionHandler::guaranteeSize = 0;
84PVOID FatalConditionHandler::exceptionHandlerHandle =
nullptr;
89#elif defined( CATCH_CONFIG_POSIX_SIGNALS )
100 constexpr static std::size_t sigStackSize = 32768 >= MINSIGSTKSZ ? 32768 : MINSIGSTKSZ;
103 { SIGINT,
"SIGINT - Terminal interrupt signal" },
104 { SIGILL,
"SIGILL - Illegal instruction signal" },
105 { SIGFPE,
"SIGFPE - Floating point error signal" },
106 { SIGSEGV,
"SIGSEGV - Segmentation violation signal" },
107 { SIGTERM,
"SIGTERM - Termination request signal" },
108 { SIGABRT,
"SIGABRT - Abort (abnormal termination) signal" }
113 char const *
name =
"<unknown signal>";
114 for (
auto const& def : signalDefs) {
129 sigStack.ss_size = sigStackSize;
130 sigStack.ss_flags = 0;
132 struct sigaction sa = { };
135 sa.sa_flags = SA_ONSTACK;
136 for (std::size_t i = 0; i <
sizeof(signalDefs)/
sizeof(
SignalDefs); ++i) {
149 for( std::size_t i = 0; i <
sizeof(signalDefs)/
sizeof(
SignalDefs); ++i ) {
175# pragma GCC diagnostic pop
IContext & getCurrentContext()
static stack_t oldSigStack
static void handleSignal(int sig)
static char altStackMem[]
static struct sigaction oldSigActions[]
virtual IResultCapture * getResultCapture()=0
virtual void handleFatalErrorCondition(StringRef message)=0
c_gkp_out sizeof(template))