Skip to content

Commit 2a953c1

Browse files
igorpodgainoi-armgithub-cygwin
authored andcommitted
Cygwin: Fix SEH and signal handling on AArch64
This patch adds the SEH_CODE macro (defined in exception.h), allowing a single EXCEPTION_HANDLER_DATA metadata definition to be used on both AArch64 and x86_64 architectures. It also fixes an issue related to stack replacement in _dll_crt0 that impacts SEH and signal handling, where due to an epilogue optimization on AArch64 the epilogue might appear before _main_tls->call. However, after the stack replacement this optimization becomes broken. This patch prevents an epilogue from appearing before _main_tls->call on AArch64 by inserting a compiler barrier after _main_tls->call. Tests fixed on AArch64: winsup.api/mmaptest03.exe winsup.api/shmtest.exe (partially) winsup.api/ltp/mmap05.exe winsup.api/ltp/munmap01.exe winsup.api/ltp/munmap02.exe Signed-off-by: Evgeny Karpov <evgeny.karpov@arm.com> Signed-off-by: Igor Podgainoi <igor.podgainoi@arm.com>
1 parent 5f5462d commit 2a953c1

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

winsup/cygwin/dcrt0.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,12 @@ _dll_crt0 ()
10651065
fesetenv (FE_DFL_ENV);
10661066
_main_tls = &_my_tls;
10671067
_main_tls->call ((DWORD (*) (void *, void *)) dll_crt0_1, NULL);
1068+
#if defined(__aarch64__)
1069+
/* Add a compiler barrier to prevent the epilogue from appearing before
1070+
_main_tls->call. The epilogue optimization should not be applied after
1071+
the stack replacement. */
1072+
__asm__ ("");
1073+
#endif
10681074
}
10691075

10701076
void

winsup/cygwin/local_includes/exception.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ details. */
1010

1111
#if defined (__aarch64__)
1212
#define EXCEPTION_HANDLE_REF "_ZN9exception6handleEP17_EXCEPTION_RECORDPvP8_CONTEXTP25_DISPATCHER_CONTEXT_ARM64"
13-
#define EXCEPTION_HANDLER_DATA
14-
#else
13+
/* An SEH directive that switches back to the code section. */
14+
#define SEH_CODE ".text"
15+
#elif defined(__x86_64__)
1516
#define EXCEPTION_HANDLE_REF "_ZN9exception6handleEP17_EXCEPTION_RECORDPvP8_CONTEXTP19_DISPATCHER_CONTEXT"
17+
#define SEH_CODE ".seh_code"
18+
#endif
19+
1620
#define EXCEPTION_HANDLER_DATA \
1721
asm volatile ("\n\
1822
1: \n\
@@ -21,9 +25,8 @@ details. */
2125
@except \n\
2226
.seh_handlerdata \n\
2327
.long 1 \n\
24-
.rva 1b, 2f, 2f, 2f \n\
25-
.seh_code \n")
26-
#endif
28+
.rva 1b, 2f, 2f, 2f \n"\
29+
SEH_CODE " \n")
2730

2831
class exception
2932
{

0 commit comments

Comments
 (0)