Commit a65693ba authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Include FOLLY_FIBERS_STACK_OVERFLOW_DETECTED in the stack

Summary: Make sure that fiber stack overflow is immediatelly discoverable from the crash stack trace, not just from the error log.

Reviewed By: spalamarchuk

Differential Revision: D18702739

fbshipit-source-id: c0a05081e67b12c94b20a929b2d10396bc1b6949
parent 80bef0fa
...@@ -199,7 +199,26 @@ namespace { ...@@ -199,7 +199,26 @@ namespace {
struct sigaction oldSigsegvAction; struct sigaction oldSigsegvAction;
void sigsegvSignalHandler(int signum, siginfo_t* info, void*) { FOLLY_NOINLINE void FOLLY_FIBERS_STACK_OVERFLOW_DETECTED(
int signum,
siginfo_t* info,
void* ucontext) {
std::cerr << "folly::fibers Fiber stack overflow detected." << std::endl;
// Let the old signal handler handle the signal, but make this function name
// present in the stack trace.
if (oldSigsegvAction.sa_flags & SA_SIGINFO) {
oldSigsegvAction.sa_sigaction(signum, info, ucontext);
} else {
oldSigsegvAction.sa_handler(signum);
}
// Prevent tail call optimization.
std::cerr << "";
}
void sigsegvSignalHandler(int signum, siginfo_t* info, void* ucontext) {
// Restore old signal handler
sigaction(signum, &oldSigsegvAction, nullptr);
if (signum != SIGSEGV) { if (signum != SIGSEGV) {
std::cerr << "GuardPageAllocator signal handler called for signal: " std::cerr << "GuardPageAllocator signal handler called for signal: "
<< signum; << signum;
...@@ -208,11 +227,11 @@ void sigsegvSignalHandler(int signum, siginfo_t* info, void*) { ...@@ -208,11 +227,11 @@ void sigsegvSignalHandler(int signum, siginfo_t* info, void*) {
if (info && if (info &&
StackCache::isProtected(reinterpret_cast<intptr_t>(info->si_addr))) { StackCache::isProtected(reinterpret_cast<intptr_t>(info->si_addr))) {
std::cerr << "folly::fibers Fiber stack overflow detected." << std::endl; FOLLY_FIBERS_STACK_OVERFLOW_DETECTED(signum, info, ucontext);
return;
} }
// Restore old signal handler and let it handle the signal. // Let the old signal handler handle the signal.
sigaction(signum, &oldSigsegvAction, nullptr);
raise(signum); raise(signum);
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <folly/init/Init.h> #include <folly/init/Init.h>
void f(int* p) { void f(int* p) {
LOG(INFO) << "f()";
// Make sure recursion is not optimized out // Make sure recursion is not optimized out
int a[100]; int a[100];
for (size_t i = 0; i < 100; ++i) { for (size_t i = 0; i < 100; ++i) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment