[PATCH] Cygwin: aarch64 SEH fixes and handler refactoring
Thirumalai Nagalingam
thirumalai.nagalingam@multicorewareinc.com
Tue Mar 24 12:42:48 GMT 2026
Hi all,
The previously posted patches for aarch64 SEH support and handler refactoring were marked as work-in-progress. Now they should be ready for upstream review.
This series [2 patches] includes changes related to:
* Proper symbol references for exception handlers on aarch64
* Refactoring of SEH handler data setup via macros
* Guarding altstack_wrapper in exceptions.cc for supported architectures
These patches will unblock merging of patch from Igor Podgainoi [SEH: Fix crash and handle second unwind phase on aarch64]( https://cygwin.com/pipermail/cygwin-patches/2026q1/014741.html)
Thanks & regards
Thirumalai Nagalingam
In-lined patch:
[PATCH 1/2] Cygwin: Add ARM64 support for SEH handler symbol references
winsup/cygwin/local_includes/cygtls.h | 8 +++++++-
winsup/cygwin/local_includes/exception.h | 11 ++++++++---
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/winsup/cygwin/local_includes/cygtls.h b/winsup/cygwin/local_includes/cygtls.h
index 9f83c134c..336c72a06 100644
--- a/winsup/cygwin/local_includes/cygtls.h
+++ b/winsup/cygwin/local_includes/cygtls.h
@@ -344,6 +344,12 @@ public:
void leave () __attribute__ ((returns_twice));
};
+#if defined (__aarch64__)
+#define EXCEPTION_MYFAULT_REF "_ZN9exception7myfaultEP17_EXCEPTION_RECORDPvP8_CONTEXTP25_DISPATCHER_CONTEXT_ARM64"
+#else
+#define EXCEPTION_MYFAULT_REF "_ZN9exception7myfaultEP17_EXCEPTION_RECORDPvP8_CONTEXTP19_DISPATCHER_CONTEXT"
+#endif
+
/* Exception handling macros. This is a handmade SEH try/except. */
#define __mem_barrier __asm__ __volatile__ ("" ::: "memory")
#define __try \
@@ -352,7 +358,7 @@ public:
__mem_barrier; \
san __sebastian (&&__l_except); \
__asm__ goto ("\n" \
- " .seh_handler _ZN9exception7myfaultEP17_EXCEPTION_RECORDPvP8_CONTEXTP19_DISPATCHER_CONTEXT, @except \n" \
+ " .seh_handler " EXCEPTION_MYFAULT_REF ", @except \n" \
" .seh_handlerdata \n" \
" .long 1 \n" \
" .rva %l[__l_try],%l[__l_endtry],%l[__l_except],%l[__l_except] \n" \
diff --git a/winsup/cygwin/local_includes/exception.h b/winsup/cygwin/local_includes/exception.h
index 13159d17b..19bb109de 100644
--- a/winsup/cygwin/local_includes/exception.h
+++ b/winsup/cygwin/local_includes/exception.h
@@ -7,7 +7,12 @@ details. */
#pragma once
#define exception_list void
-typedef struct _DISPATCHER_CONTEXT *PDISPATCHER_CONTEXT;
+
+#if defined (__aarch64__)
+#define EXCEPTION_HANDLE_REF "_ZN9exception6handleEP17_EXCEPTION_RECORDPvP8_CONTEXTP25_DISPATCHER_CONTEXT_ARM64"
+ #else
+#define EXCEPTION_HANDLE_REF "_ZN9exception6handleEP17_EXCEPTION_RECORDPvP8_CONTEXTP19_DISPATCHER_CONTEXT"
+#endif
class exception
{
@@ -21,8 +26,8 @@ public:
/* Install SEH handler. */
asm volatile ("\n\
1: \n\
- .seh_handler \
- _ZN9exception6handleEP17_EXCEPTION_RECORDPvP8_CONTEXTP19_DISPATCHER_CONTEXT, \
+ .seh_handler " \
+ EXCEPTION_HANDLE_REF ", \
@except \n\
.seh_handlerdata \n\
.long 1 \n\
--
2.53.0.windows.2
[PATCH 2/2] Cygwin: Add SEH workaround for aarch64 compilation
winsup/cygwin/exceptions.cc | 2 ++
winsup/cygwin/local_includes/cygtls.h | 17 ++++++++++-------
winsup/cygwin/local_includes/exception.h | 23 +++++++++++++----------
3 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 158d8675b..badb11da7 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -1696,6 +1696,7 @@ done:
}
+#if defined(__x86_64__) || defined(__aarch64__)
static void
altstack_wrapper (int sig, siginfo_t *siginfo, ucontext_t *sigctx,
void (*handler) (int, siginfo_t *, void *))
@@ -1746,6 +1747,7 @@ altstack_wrapper (int sig, siginfo_t *siginfo, ucontext_t *sigctx,
teb->Tib.StackLimit = old_limit;
}
}
+#endif
int
_cygtls::call_signal_handler ()
diff --git a/winsup/cygwin/local_includes/cygtls.h b/winsup/cygwin/local_includes/cygtls.h
index 336c72a06..a07e143c7 100644
--- a/winsup/cygwin/local_includes/cygtls.h
+++ b/winsup/cygwin/local_includes/cygtls.h
@@ -346,8 +346,17 @@ public:
#if defined (__aarch64__)
#define EXCEPTION_MYFAULT_REF "_ZN9exception7myfaultEP17_EXCEPTION_RECORDPvP8_CONTEXTP25_DISPATCHER_CONTEXT_ARM64"
+#define TRY_HANDLER_DATA (void) &&__l_try;
#else
#define EXCEPTION_MYFAULT_REF "_ZN9exception7myfaultEP17_EXCEPTION_RECORDPvP8_CONTEXTP19_DISPATCHER_CONTEXT"
+#define TRY_HANDLER_DATA \
+ __asm__ goto ("\n" \
+ " .seh_handler " EXCEPTION_MYFAULT_REF ", @except \n" \
+ " .seh_handlerdata \n" \
+ " .long 1 \n" \
+ " .rva %l[__l_try],%l[__l_endtry],%l[__l_except],%l[__l_except] \n" \
+ " .seh_code \n" \
+ : : : : __l_try, __l_endtry, __l_except)
#endif
/* Exception handling macros. This is a handmade SEH try/except. */
@@ -357,13 +366,7 @@ public:
__label__ __l_try, __l_except, __l_endtry; \
__mem_barrier; \
san __sebastian (&&__l_except); \
- __asm__ goto ("\n" \
- " .seh_handler " EXCEPTION_MYFAULT_REF ", @except \n" \
- " .seh_handlerdata \n" \
- " .long 1 \n" \
- " .rva %l[__l_try],%l[__l_endtry],%l[__l_except],%l[__l_except] \n" \
- " .seh_code \n" \
- : : : : __l_try, __l_endtry, __l_except); \
+ TRY_HANDLER_DATA; \
{ \
__l_try: \
__mem_barrier;
diff --git a/winsup/cygwin/local_includes/exception.h b/winsup/cygwin/local_includes/exception.h
index 19bb109de..b26f8ba17 100644
--- a/winsup/cygwin/local_includes/exception.h
+++ b/winsup/cygwin/local_includes/exception.h
@@ -10,8 +10,19 @@ details. */
#if defined (__aarch64__)
#define EXCEPTION_HANDLE_REF "_ZN9exception6handleEP17_EXCEPTION_RECORDPvP8_CONTEXTP25_DISPATCHER_CONTEXT_ARM64"
- #else
+#define EXCEPTION_HANDLER_DATA
+#else
#define EXCEPTION_HANDLE_REF "_ZN9exception6handleEP17_EXCEPTION_RECORDPvP8_CONTEXTP19_DISPATCHER_CONTEXT"
+#define EXCEPTION_HANDLER_DATA \
+ asm volatile ("\n\
+ 1: \n\
+ .seh_handler " \
+ EXCEPTION_HANDLE_REF ", \
+ @except \n\
+ .seh_handlerdata \n\
+ .long 1 \n\
+ .rva 1b, 2f, 2f, 2f \n\
+ .seh_code \n")
#endif
class exception
@@ -24,15 +35,7 @@ public:
exception () __attribute__ ((always_inline))
{
/* Install SEH handler. */
- asm volatile ("\n\
- 1: \n\
- .seh_handler " \
- EXCEPTION_HANDLE_REF ", \
- @except \n\
- .seh_handlerdata \n\
- .long 1 \n\
- .rva 1b, 2f, 2f, 2f \n\
- .seh_code \n");
+ EXCEPTION_HANDLER_DATA;
};
~exception () __attribute__ ((always_inline))
{
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Cygwin-Add-ARM64-support-for-SEH-handler-symbol-refe.patch
Type: application/octet-stream
Size: 2952 bytes
Desc: 0001-Cygwin-Add-ARM64-support-for-SEH-handler-symbol-refe.patch
URL: <https://cygwin.com/pipermail/cygwin-patches/attachments/20260324/5e9a93bc/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Cygwin-Add-SEH-workaround-for-aarch64-compilation.patch
Type: application/octet-stream
Size: 4028 bytes
Desc: 0002-Cygwin-Add-SEH-workaround-for-aarch64-compilation.patch
URL: <https://cygwin.com/pipermail/cygwin-patches/attachments/20260324/5e9a93bc/attachment-0001.obj>
More information about the Cygwin-patches
mailing list