gazelle/0316-SIGNAL-block-SIGSEGV-during-exit-process.patch
yinbin 2ad4d8b8db sync SIGNAL: block SIGSEGV during exit process
(cherry picked from commit 0997bc86367e1038eec8bbdc0ec0773b3a95c331)
2025-03-04 20:06:35 +08:00

59 lines
1.7 KiB
Diff

From 5d7e406a138567a9959c994af4fb574f7f075bed Mon Sep 17 00:00:00 2001
From: yinbin <yinbin8@huawei.com>
Date: Wed, 15 Jan 2025 11:16:43 +0800
Subject: [PATCH] SIGNAL: block SIGSEGV during exit process
---
src/lstack/api/lstack_unistd.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/lstack/api/lstack_unistd.c b/src/lstack/api/lstack_unistd.c
index d8b5d8e..e3b9b1f 100644
--- a/src/lstack/api/lstack_unistd.c
+++ b/src/lstack/api/lstack_unistd.c
@@ -58,6 +58,15 @@ bool sig_need_dump(int sig)
return true;
}
+static void pthread_block_sig(int sig)
+{
+ sigset_t mask;
+
+ sigemptyset(&mask);
+ sigaddset(&mask, sig);
+ pthread_sigmask(SIG_BLOCK, &mask, NULL);
+}
+
static void lstack_sigaction_default_handler(int sig, siginfo_t *info, void *context)
{
static bool skip_process_exit = false;
@@ -81,6 +90,9 @@ static void lstack_sigaction_default_handler(int sig, siginfo_t *info, void *con
dump_lstack();
}
+ /* App sig_handler may access invalid memory address in gazelle threads,
+ * so we block this signal avoiding getting stuck during exit. */
+ pthread_block_sig(SIGSEGV);
if (sig_is_registered(sig)) {
if (g_register_sigactions[sig].sa_flags & SA_SIGINFO) {
g_register_sigactions[sig].sa_sigaction(sig, info, context);
@@ -106,15 +118,6 @@ static void lstack_sig_default_handler(int sig)
lstack_sigaction_default_handler(sig, NULL, NULL);
}
-static void pthread_block_sig(int sig)
-{
- sigset_t mask;
-
- sigemptyset(&mask);
- sigaddset(&mask, sig);
- pthread_sigmask(SIG_BLOCK, &mask, NULL);
-}
-
static void pthread_unblock_sig(int sig)
{
sigset_t mask;
--
2.33.0