From 3f3d75ab20d7f12383c6f0223c60d456f87e5c9b Mon Sep 17 00:00:00 2001 From: eloparco Date: Thu, 14 Sep 2023 23:40:12 +0100 Subject: [PATCH] fix: allow custom signal handler from non-main thread --- core/shared/platform/common/posix/posix_thread.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/core/shared/platform/common/posix/posix_thread.c b/core/shared/platform/common/posix/posix_thread.c index 4fb566d6ef..b1460f6b53 100644 --- a/core/shared/platform/common/posix/posix_thread.c +++ b/core/shared/platform/common/posix/posix_thread.c @@ -509,8 +509,8 @@ mask_signals(int how) pthread_sigmask(how, &set, NULL); } -static os_thread_local_attribute struct sigaction prev_sig_act_SIGSEGV; -static os_thread_local_attribute struct sigaction prev_sig_act_SIGBUS; +static struct sigaction prev_sig_act_SIGSEGV; +static struct sigaction prev_sig_act_SIGBUS; /* ASAN is not designed to work with custom stack unwind or other low-level \ things. > Ignore a function that does some low-level magic. (e.g. walking \ @@ -540,11 +540,16 @@ signal_callback(int sig_num, siginfo_t *sig_info, void *sig_ucontext) if (prev_sig_act && (prev_sig_act->sa_flags & SA_SIGINFO)) { prev_sig_act->sa_sigaction(sig_num, sig_info, sig_ucontext); } - else if (prev_sig_act - && ((void *)prev_sig_act->sa_sigaction == SIG_DFL - || (void *)prev_sig_act->sa_sigaction == SIG_IGN)) { + else if (prev_sig_act && (void *)prev_sig_act->sa_handler == SIG_DFL) { + /* Default action */ sigaction(sig_num, prev_sig_act, NULL); } + else if (prev_sig_act && (void *)prev_sig_act->sa_handler == SIG_IGN) { + /* Ignore this signal */ + } + else if (prev_sig_act && prev_sig_act->sa_handler) { + prev_sig_act->sa_handler(sig_num); + } /* Output signal info and then crash if signal is unhandled */ else { switch (sig_num) {