Commit fa8e80da authored by scott snyder's avatar scott snyder
Browse files

CxxUtils: Make stack dumps more robust.

 - Make s_lastSP thread_local.  It's intended to prevent recursion,
   but multiple threads were confusing things.

 - When forking addr2line, use vfork rather than fork, to avoid interference
   from the atfork handler registered by openblas.
parent e2c1ebdb
......@@ -283,7 +283,7 @@ private:
static bool s_crashed;
static int s_inFatal;
static unsigned long s_lastSP;
static thread_local unsigned long s_lastSP;
static const char *s_applicationName;
static IOFD s_fatalFd;
static FatalHook s_fatalHook;
......@@ -150,7 +150,18 @@ int stacktracePopenFD (const char* cmd, pid_t& child_pid)
int parent_end = fds[0];
int child_end = fds[1];
#ifdef __linux__
// Use vfork rather than fork to avoid running pthread_atfork handlers.
// Openblas, for example, registers one unconditionally, but that can
// segfault if called with the program in a bad state.
// What we're doing here doesn't really comply with the restrictions
// in the vfork man page, which says that in the child after the vfork
// you can do only exec or _exit. This does in fact seem to work
// on linux, but put this within an ifdef.
child_pid = vfork();
child_pid = fork();
if (child_pid == 0) {
int child_std_end = 1;
close (parent_end);
......@@ -125,7 +125,7 @@ bool Signal::s_crashed = false;
int Signal::s_inFatal = 0;
/** Used to switch to a raw stack dump if we crash during a backtrace. */
unsigned long Signal::s_lastSP = 0;
thread_local unsigned long Signal::s_lastSP = 0;
/** The current application name. */
const char *Signal::s_applicationName = 0;
Supports Markdown
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