Bug 720704 - Avoid setting an alternative stack for signals if there is already one. r=ted
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 16 Feb 2012 09:00:53 +0100
changeset 86994 e9dcf2a2a097898c0e417d89fb13596c6add98cc
parent 86993 6d7033dc6480dc6bfd1d893581ebcd94af38a96c
child 86995 061557e27b59e3c2052790e8c7fec22a24862861
push id22071
push userbmo@edmorley.co.uk
push dateFri, 17 Feb 2012 11:08:28 +0000
treeherdermozilla-central@08e55f36b731 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs720704
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 720704 - Avoid setting an alternative stack for signals if there is already one. r=ted
toolkit/crashreporter/google-breakpad/src/client/linux/handler/exception_handler.cc
toolkit/crashreporter/google-breakpad/src/client/linux/handler/exception_handler.h
--- a/toolkit/crashreporter/google-breakpad/src/client/linux/handler/exception_handler.cc
+++ b/toolkit/crashreporter/google-breakpad/src/client/linux/handler/exception_handler.cc
@@ -185,24 +185,28 @@ void ExceptionHandler::Init(const std::s
 bool ExceptionHandler::InstallHandlers() {
   // We run the signal handlers on an alternative stack because we might have
   // crashed because of a stack overflow.
 
   // We use this value rather than SIGSTKSZ because we would end up overrunning
   // such a small stack.
   static const unsigned kSigStackSize = 8192;
 
-  signal_stack = malloc(kSigStackSize);
   stack_t stack;
-  memset(&stack, 0, sizeof(stack));
-  stack.ss_sp = signal_stack;
-  stack.ss_size = kSigStackSize;
+  // Only set an alternative stack if there isn't already one, or if the current
+  // one is too small.
+  if (sys_sigaltstack(NULL, &stack) == -1 || !stack.ss_sp ||
+      stack.ss_size < kSigStackSize) {
+    memset(&stack, 0, sizeof(stack));
+    stack.ss_sp = malloc(kSigStackSize);
+    stack.ss_size = kSigStackSize;
 
-  if (sys_sigaltstack(&stack, NULL) == -1)
-    return false;
+    if (sys_sigaltstack(&stack, NULL) == -1)
+      return false;
+  }
 
   struct sigaction sa;
   memset(&sa, 0, sizeof(sa));
   sigemptyset(&sa.sa_mask);
 
   // mask all exception signals when we're handling one of them.
   for (unsigned i = 0; kExceptionSignals[i] != -1; ++i)
     sigaddset(&sa.sa_mask, kExceptionSignals[i]);
--- a/toolkit/crashreporter/google-breakpad/src/client/linux/handler/exception_handler.h
+++ b/toolkit/crashreporter/google-breakpad/src/client/linux/handler/exception_handler.h
@@ -254,17 +254,16 @@ class ExceptionHandler {
   // Pointers to C-string representations of the above. These are set
   // when the above are set so we can avoid calling c_str during
   // an exception.
   const char* dump_path_c_;
   const char* next_minidump_path_c_;
   const char* next_minidump_id_c_;
 
   const bool handler_installed_;
-  void* signal_stack;  // the handler stack.
   HandlerCallback crash_handler_;
 
   // The global exception handler stack. This is need becuase there may exist
   // multiple ExceptionHandler instances in a process. Each will have itself
   // registered in this stack.
   static std::vector<ExceptionHandler*> *handler_stack_;
   // The index of the handler that should handle the next exception.
   static unsigned handler_stack_index_;