[newlib-cygwin/cygwin-3_6-branch] Cygwin: exceptions: check ExceptionFlags for EXCEPTION_NONCONTINUABLE

Corinna Vinschen via Cygwin-cvs <[email protected]>
Newsgroups gmane.os.cygwin.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=05387dd7a1ac8d4862471d7c59744da95f7835c8

commit 05387dd7a1ac8d4862471d7c59744da95f7835c8
Author:     Corinna Vinschen <[email protected]>
AuthorDate: Mon Mar 31 12:24:34 2025 +0200
Commit:     Corinna Vinschen <[email protected]>
CommitDate: Mon Mar 31 12:24:52 2025 +0200

    Cygwin: exceptions: check ExceptionFlags for EXCEPTION_NONCONTINUABLE
    
    So far, exception::handle returned prematurely if the value of
    EXCEPTION_RECORD::ExceptionFlags was non-0.
    
    Starting with Windows 11 we're getting into trouble with that,
    if the exception is software generated, for instance by calling
    "throw" in a C++ application.
    
    In that case EXCEPTION_SOFTWARE_ORIGINATE (0x80) is set in
    EXCEPTION_RECORD::ExceptionFlags.
    
    Change the condition for exiting prematurely to do this only if
    any other flag except EXCEPTION_SOFTWARE_ORIGINATE is set in
    EXCEPTION_RECORD::ExceptionFlags.
    
    Fixes: Silent change in Windows exception handling
    Signed-off-by: Corinna Vinschen <[email protected]>
    
    (cherry picked from commit 0d73c040676a44829a9a3614b4013fa50fdc56e8)

Diff:
---
 winsup/cygwin/exceptions.cc            | 2 +-
 winsup/cygwin/local_includes/winlean.h | 4 ++++
 winsup/cygwin/release/3.6.1            | 4 ++++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index a3aae2ce59df..49fc166ff5da 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -659,7 +659,7 @@ exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in,
 
   /* If we're exiting, tell Windows to keep looking for an
      exception handler.  */
-  if (exit_state || e->ExceptionFlags)
+  if (exit_state || (e->ExceptionFlags & ~EXCEPTION_SOFTWARE_ORIGINATE))
     return ExceptionContinueSearch;
 
   siginfo_t si = {};
diff --git a/winsup/cygwin/local_includes/winlean.h b/winsup/cygwin/local_includes/winlean.h
index 62b651be6ee7..500f56957aa9 100644
--- a/winsup/cygwin/local_includes/winlean.h
+++ b/winsup/cygwin/local_includes/winlean.h
@@ -111,6 +111,10 @@ details. */
 #define DOMAIN_ALIAS_RID_DEVICE_OWNERS		(__MSABI_LONG(0x00000247))
 #endif
 
+#ifndef EXCEPTION_SOFTWARE_ORIGINATE
+#define EXCEPTION_SOFTWARE_ORIGINATE		0x80
+#endif
+
 /* So-called "Microsoft Account" SIDs (S-1-11-...) have a netbios domain name
    "MicrosoftAccounts".  The new "Application Container SIDs" (S-1-15-...)
    have a netbios domain name "APPLICATION PACKAGE AUTHORITY"
diff --git a/winsup/cygwin/release/3.6.1 b/winsup/cygwin/release/3.6.1
index 7a6afe6b87e2..254cfdd9c74f 100644
--- a/winsup/cygwin/release/3.6.1
+++ b/winsup/cygwin/release/3.6.1
@@ -23,3 +23,7 @@ Fixes:
 
 - Disallow accounts from the BUILTIN, NT AUTHORITY, NT SERVICE domains
   as USER entry in a POSIX ACL.  Only allow USER_OBJ, GROUP_OBJ and GROUP.
+
+- Accommodate a change in Windows exception handling affecting software
+  generated exceptions.
+  Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257808.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.