From 952b9009e8a2faf22b7614481d42e9801edf6804 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Wed, 8 May 2024 01:00:58 -0700 Subject: [PATCH] Avoid crash looping on AARCH64 --- libc/intrin/feenableexcept.c | 15 ++++++--------- libc/log/oncrash_arm64.c | 2 ++ libc/runtime/enable_tls.c | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/libc/intrin/feenableexcept.c b/libc/intrin/feenableexcept.c index 503dee61a..bbf79ad7c 100644 --- a/libc/intrin/feenableexcept.c +++ b/libc/intrin/feenableexcept.c @@ -78,17 +78,14 @@ int feenableexcept(int excepts) { #elif defined(__aarch64__) - unsigned fpcr; - unsigned fpcr2; - unsigned updated_fpcr; - fpcr = __builtin_aarch64_get_fpcr(); - fpcr2 = fpcr | (excepts << 8); + unsigned fpcr = __builtin_aarch64_get_fpcr(); + unsigned want = excepts << 8; + unsigned fpcr2 = fpcr | want; if (fpcr != fpcr2) { __builtin_aarch64_set_fpcr(fpcr2); - // floating point exception trapping is optional in aarch64 - updated_fpcr = __builtin_aarch64_get_fpsr(); - if (fpcr2 & ~updated_fpcr) - return -1; + fpcr2 = __builtin_aarch64_get_fpsr(); + if ((fpcr2 & want) != want) + return -1; // not supported by cpu } return (fpcr >> 8) & FE_ALL_EXCEPT; diff --git a/libc/log/oncrash_arm64.c b/libc/log/oncrash_arm64.c index 2ab6d31a1..9229d6cf0 100644 --- a/libc/log/oncrash_arm64.c +++ b/libc/log/oncrash_arm64.c @@ -394,6 +394,8 @@ relegated void __oncrash(int sig, struct siginfo *si, void *arg) { BLOCK_CANCELATION; SpinLock(&lock); __oncrash_impl(sig, si, arg); + if (sig != SIGQUIT && sig != SIGTRAP) + _exit(1); SpinUnlock(&lock); ALLOW_CANCELATION; } diff --git a/libc/runtime/enable_tls.c b/libc/runtime/enable_tls.c index 045740baf..2be328cc1 100644 --- a/libc/runtime/enable_tls.c +++ b/libc/runtime/enable_tls.c @@ -68,13 +68,13 @@ static unsigned long ParseMask(const char *str) { * * __get_tls() * │ - * %fs Linux/BSDs + * %fs OpenBSD/NetBSD * _Thread_local │ * ┌───┬──────────┬──────────┼───┐ * │pad│ .tdata │ .tbss │tib│ * └───┴──────────┴──────────┼───┘ * │ - * Windows/Mac %gs + * Linux/FreeBSD/Windows/Mac %gs * * Here's the TLS memory layout on aarch64: *