public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: main exception handler (64-bit): continue GCC exceptions
@ 2020-08-17 20:44 Ken Brown
  2020-08-18  7:45 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Ken Brown @ 2020-08-17 20:44 UTC (permalink / raw)
  To: cygwin-patches

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://sourceware.org/pipermail/cygwin/2020-August/245897.html
---
 winsup/cygwin/exceptions.cc | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 0d9e8f70e..f8da7529b 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -647,6 +647,17 @@ exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in,
   if (exit_state || e->ExceptionFlags)
     return ExceptionContinueSearch;
 
+/* From the GCC source file libgcc/unwind-seh.c. */
+#ifdef __x86_64__
+#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)
+#endif
+
   siginfo_t si = {};
   si.si_code = SI_KERNEL;
   /* Coerce win32 value to posix value.  */
@@ -762,6 +773,16 @@ exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in,
 	 handling.  */
       return ExceptionContinueExecution;
 
+#ifdef __x86_64__
+      /* According to a comment in the GCC function
+	 _Unwind_RaiseException(), GCC expects us to continue all the
+	 (continuable) GCC exceptions that reach us. */
+    case STATUS_GCC_THROW:
+    case STATUS_GCC_UNWIND:
+    case STATUS_GCC_FORCED:
+      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
-- 
2.28.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Cygwin: main exception handler (64-bit): continue GCC exceptions
  2020-08-17 20:44 [PATCH] Cygwin: main exception handler (64-bit): continue GCC exceptions Ken Brown
@ 2020-08-18  7:45 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2020-08-18  7:45 UTC (permalink / raw)
  To: cygwin-patches

On Aug 17 16:44, Ken Brown via Cygwin-patches wrote:
> 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://sourceware.org/pipermail/cygwin/2020-August/245897.html
> ---
>  winsup/cygwin/exceptions.cc | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)

Thanks a lot!  Please push.


Corinna

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-18  7:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-17 20:44 [PATCH] Cygwin: main exception handler (64-bit): continue GCC exceptions Ken Brown
2020-08-18  7:45 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).