setup signal handler with SA_ONSTACK
authorPhilip Pronin <philipp@fb.com>
Fri, 11 Dec 2015 00:15:37 +0000 (16:15 -0800)
committerfacebook-github-bot-0 <folly-bot@fb.com>
Fri, 11 Dec 2015 01:20:24 +0000 (17:20 -0800)
Summary:
By default signal handlers are run on the signaled thread's stack.
In case of stack overflow running the `SIGSEGV` signal handler on
the same stack leads to another `SIGSEGV` and crashes the program
Use `SA_ONSTACK`, so alternate stack is used (only if configured via
`sigaltstack`).

Reviewed By: luciang

Differential Revision: D2747021

fb-gh-sync-id: 48388acd6147e2919412ec32acfca1ca76f22a16

folly/experimental/symbolizer/SignalHandler.cpp

index 5ec13bdf646f0d0f2e8bb0c54e0096d62142b960..86434f8b80e1c12576da43d45c29fe1a695ac950 100644 (file)
@@ -322,7 +322,12 @@ void installFatalSignalHandler() {
   struct sigaction sa;
   memset(&sa, 0, sizeof(sa));
   sigemptyset(&sa.sa_mask);
-  sa.sa_flags |= SA_SIGINFO;
+  // By default signal handlers are run on the signaled thread's stack.
+  // In case of stack overflow running the SIGSEGV signal handler on
+  // the same stack leads to another SIGSEGV and crashes the program.
+  // Use SA_ONSTACK, so alternate stack is used (only if configured via
+  // sigaltstack).
+  sa.sa_flags |= SA_SIGINFO | SA_ONSTACK;
   sa.sa_sigaction = &signalHandler;
 
   for (auto p = kFatalSignals; p->name; ++p) {