From 74cf7dabcb69ea0608163ba84ecc3d798d5b0421 Mon Sep 17 00:00:00 2001 From: Ken Brown Date: Mon, 17 Aug 2020 16:24:59 -0400 Subject: [PATCH] Cygwin: main exception handler (64-bit): continue GCC exceptions This is necessary in order to be consistent with the following comment in the definition of _Unwind_RaiseException() in the GCC source file libgcc/unwind-seh.c: The exception handler installed in crt0 will continue any GCC exception that reaches there (and isn't marked non-continuable). Previously we failed to do this and, as a consequence, the C++ runtime didn't call std::terminate after an unhandled exception. This fixes the problem reported here: https://cygwin.com/pipermail/cygwin/2019-October/242795.html https://sourceware.org/pipermail/cygwin/2020-August/245897.html --- winsup/cygwin/exceptions.cc | 19 +++++++++++++++++++ winsup/cygwin/release/3.1.7 | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 0d9e8f70e..61406e5d1 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -762,6 +762,25 @@ exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in, handling. */ return ExceptionContinueExecution; +#ifdef __x86_64__ +/* From the GCC source file libgcc/unwind-seh.c. */ +#define STATUS_USER_DEFINED (1U << 29) +#define GCC_MAGIC (('G' << 16) | ('C' << 8) | 'C') +#define GCC_EXCEPTION(TYPE) \ + (STATUS_USER_DEFINED | ((TYPE) << 24) | GCC_MAGIC) +#define STATUS_GCC_THROW GCC_EXCEPTION (0) +#define STATUS_GCC_UNWIND GCC_EXCEPTION (1) +#define STATUS_GCC_FORCED GCC_EXCEPTION (2) + + case STATUS_GCC_THROW: + case STATUS_GCC_UNWIND: + case STATUS_GCC_FORCED: + /* According to a comment in the GCC function + _Unwind_RaiseException(), GCC expects us to continue all the + (continuable) GCC exceptions that reach us. */ + return ExceptionContinueExecution; +#endif + default: /* If we don't recognize the exception, we have to assume that we are doing structured exception handling, and we let diff --git a/winsup/cygwin/release/3.1.7 b/winsup/cygwin/release/3.1.7 index 2f4856495..83cff2b46 100644 --- a/winsup/cygwin/release/3.1.7 +++ b/winsup/cygwin/release/3.1.7 @@ -11,3 +11,7 @@ Bug Fixes: - Fix an mmap issue that could cause failure with errno EFBIG Partially addresses: https://sourceware.org/pipermail/cygwin/2020-July/245557.html + +- Fix the behavior of C++ apps after an unhandled exception (64-bit only) + Addresses: https://cygwin.com/pipermail/cygwin/2019-October/242795.html + https://cygwin.com/pipermail/cygwin/2020-August/245897.html