Skip to content
Snippets Groups Projects
Commit d523cdcc authored by scott snyder's avatar scott snyder
Browse files

CxxUtils: Avoid thread_local during fast stack dump.

Accessing a thread_local variable may result in a call to malloc.
Avoid using thread_local in code that runs as part of the fast stack dump,
so that the dump will work even if the heap is corrupt.

See ATR-22583.
parent eddd9fd1
No related branches found
No related tags found
4 merge requests!58791DataQualityConfigurations: Modify L1Calo config for web display,!46784MuonCondInterface: Enable thread-safety checking.,!46776Updated LArMonitoring config file for WD to match new files produced using MT,!44427CxxUtils: Avoid thread_local during fast stack dump.
......@@ -26,6 +26,7 @@
# include <signal.h>
# include <sys/types.h>
# include <climits>
#include <atomic>
// Hacks for fields we might not have in siginfo_t. Just print zero.
......@@ -286,7 +287,7 @@ private:
static bool s_crashed;
static int s_inFatal;
static thread_local unsigned long s_lastSP;
static std::atomic<unsigned long> s_lastSP;
static const char *s_applicationName;
static IOFD s_fatalFd;
static FatalHook s_fatalHook;
......
......@@ -125,7 +125,11 @@ bool Signal::s_crashed = false;
int Signal::s_inFatal = 0;
/** Used to switch to a raw stack dump if we crash during a backtrace. */
thread_local unsigned long Signal::s_lastSP = 0;
// This would in principle be better as a thread_local, but then
// accessing it might allocate memory, which we don't to happen
// during error handling.
// Doing it like this should be good enough.
std::atomic<unsigned long> Signal::s_lastSP (0);
/** The current application name. */
const char *Signal::s_applicationName = 0;
......@@ -1542,8 +1546,8 @@ Signal::fatalDump ATLAS_NOT_THREAD_SAFE (int sig, siginfo_t *info, void *extra,
MYWRITE (fd, buf, sprintf(buf,"\nstack trace:\n"));
if (s_lastSP) {
MYWRITE (fd, buf, sprintf(buf,"\n(backtrace failed; raw dump follows)\n"));
MYWRITE (fd, buf, sprintf(buf,"%016lx:", s_lastSP));
dumpMemory (fd, buf, reinterpret_cast<void*>(s_lastSP), 1024);
MYWRITE (fd, buf, sprintf(buf,"%016lx:", s_lastSP.load()));
dumpMemory (fd, buf, reinterpret_cast<void*>(s_lastSP.load()), 1024);
MYWRITE (fd, buf, sprintf(buf,"\n\n"));
}
else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment