SEH _Unwind_Resume_or_Rethrow invokes abort directly if
_Unwind_RaiseException doesn't manage to find a handler for the rethrown
exception; this is incorrect, as in this case std::terminate should be
invoked, allowing an application-provided terminate handler to handle
the situation instead of straight crashing the application through
abort.
The bug can be demonstrated with this simple test case:
===
static void custom_terminate_handler() {
fprintf(stderr, "custom_terminate_handler invoked\n");
std::exit(1);
}
int main(int argc, char *argv[]) {
std::set_terminate(&custom_terminate_handler);
if (argc < 2) return 1;
const char *mode = argv[1];
fprintf(stderr, "%s\n", mode);
if (strcmp(mode, "throw") == 0) {
throw std::exception();
} else if (strcmp(mode, "rethrow") == 0) {
try {
throw std::exception();
} catch (...) {
throw;
}
} else {
return 1;
}
return 0;
}
===
On all gcc builds with non-SEH exceptions, this will print
"custom_terminate_handler invoked" both if launched as ./a.out throw or
as ./a.out rethrow, on SEH builds instead if will work as expected only
with ./a.exe throw, but will crash with the "built-in" abort message
with ./a.exe rethrow.
This patch fixes the problem, forwarding back the error code to the
caller (__cxa_rethrow), that calls std::terminate if
_Unwind_Resume_or_Rethrow returns.
The change makes the code path coherent with SEH _Unwind_RaiseException,
and with the generic _Unwind_Resume_or_Rethrow from libgcc/unwind.inc
(used for SjLj and Dw2 exception backend).
libgcc/ChangeLog:
PR libgcc/113337
* unwind-seh.c (_Unwind_Resume_or_Rethrow): forward
_Unwind_RaiseException return code back to caller instead of
calling abort, allowing __cxa_rethrow to invoke std::terminate
in case of uncaught rethrown exception
Previously, the SEH version of _Unwind_Backtrace did unwind
the stack and call the provided callback function as intended,
but there was little the caller could do within the callback to
actually get any info about that particular level in the unwind.
Set the ra and cfa pointers, which are used by _Unwind_GetIP
and _Unwind_GetCFA, to allow using these functions from the
callacb to inspect the state at each stack frame.
2020-09-08 Martin Storsjö <martin@martin.st>
libgcc/
* unwind-seh.c (_Unwind_Backtrace): Set the ra and cfa pointers
before calling the callback.
Currently it is not possible to build GCC's libjava support on Cygwin-64.
This patch fixes the current build-problems on Cygwin-64 and the most
fundamental bugs on that platform.
Note you must still add --enable-threads=posix to successfully build the
java language support.
boehm-gc/ChangeLog:
2014-05-13 Bernd Edlinger <bernd.edlinger@hotmail.de>
Fix current cygwin-64 build problems.
* include/gc_config_macros.h (GC_PTHREADS): Use __CYGWIN__ instead
of __CYGWIN32__ here.
* win32_threads.c (GC_push_all_stacks): Push all X86_64 registers.
(GC_get_thread_stack_base): Get the stack base for X86_64.
libffi/ChangeLog:
2014-05-13 Bernd Edlinger <bernd.edlinger@hotmail.de>
Fix current cygwin-64 build problems.
* src/java_raw_api.c: Remove if !defined(FFI_NO_RAW_API).
* src/x86/ffi.c: Add if defined(__CYGWIN__).
* src/x86/win64.S (ffi_closure_win64, ffi_call_win64): Added
handling for FFI_TYPE_UINT64, FFI_TYPE_POINTER and FFI_TYPE_INT.
Added SEH information. Fixed formatting.
libgcc/ChangeLog:
2014-05-13 Bernd Edlinger <bernd.edlinger@hotmail.de>
* unwind-seh.c (_Unwind_Backtrace): Uncommented, finished
implementation.
libjava/ChangeLog:
2014-05-13 Bernd Edlinger <bernd.edlinger@hotmail.de>
Fix current cygwin-64 build problems.
* configure.host: Added handling for x86_64-*-cygwin/mingw.
* boehm.cc (_Jv_GCAttachThread, _Jv_GCDetachThread): Don't compile if
GC_WIN32_THREADS is defined.
* java/lang/natClass.cc (_Jv_InterfaceAssignableFrom): Rename interface
to source_interface.
libjava/classpath/ChangeLog:
2014-05-13 Bernd Edlinger <bernd.edlinger@hotmail.de>
Fix current cygwin-64 build problems.
* native/fdlibm/mprec.c (_REENT_CHECK_MP, _REENT_MP_FREELIST,
_REENT_MP_P5S, __ULong, __Long): Undefine previous definitions.
From-SVN: r210386
2014-02-18 Kai Tietz <ktietz@redhat.com>
Jonathan Schleifer <js@webkeks.org>
PR objc/56870
* unwind-seh.c (_GCC_specific_handler): Pass proper
value to unwind-handler.
Co-Authored-By: Jonathan Schleifer <js@webkeks.org>
From-SVN: r207849