about summary refs log tree commit diff
path: root/absl/debugging/internal/stack_consumption.cc
diff options
context:
space:
mode:
Diffstat (limited to 'absl/debugging/internal/stack_consumption.cc')
-rw-r--r--absl/debugging/internal/stack_consumption.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/absl/debugging/internal/stack_consumption.cc b/absl/debugging/internal/stack_consumption.cc
index 4b05f4955ee0..d4703264a666 100644
--- a/absl/debugging/internal/stack_consumption.cc
+++ b/absl/debugging/internal/stack_consumption.cc
@@ -115,10 +115,11 @@ int GetSignalHandlerStackConsumption(void (*signal_handler)(int)) {
   // Set up the alt-signal-stack (and save the older one).
   stack_t sigstk;
   memset(&sigstk, 0, sizeof(sigstk));
-  stack_t old_sigstk;
   sigstk.ss_sp = altstack;
   sigstk.ss_size = kAlternateStackSize;
   sigstk.ss_flags = 0;
+  stack_t old_sigstk;
+  memset(&old_sigstk, 0, sizeof(old_sigstk));
   ABSL_RAW_CHECK(sigaltstack(&sigstk, &old_sigstk) == 0,
                  "sigaltstack() failed");
 
@@ -152,6 +153,15 @@ int GetSignalHandlerStackConsumption(void (*signal_handler)(int)) {
   int signal_handler_stack_consumption = GetStackConsumption(altstack);
 
   // Now restore the old alt-signal-stack and signal handlers.
+  if (old_sigstk.ss_sp == nullptr && old_sigstk.ss_size == 0 &&
+      (old_sigstk.ss_flags & SS_DISABLE)) {
+    // https://git.musl-libc.org/cgit/musl/commit/src/signal/sigaltstack.c?id=7829f42a2c8944555439380498ab8b924d0f2070
+    // The original stack has ss_size==0 and ss_flags==SS_DISABLE, but some
+    // versions of musl have a bug that rejects ss_size==0. Work around this by
+    // setting ss_size to MINSIGSTKSZ, which should be ignored by the kernel
+    // when SS_DISABLE is set.
+    old_sigstk.ss_size = MINSIGSTKSZ;
+  }
   ABSL_RAW_CHECK(sigaltstack(&old_sigstk, nullptr) == 0,
                  "sigaltstack() failed");
   ABSL_RAW_CHECK(sigaction(SIGUSR1, &old_sa1, nullptr) == 0,