Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 1 | //===- Signals.cpp - Generic Unix Signals Implementation -----*- C++ -*-===// |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 2 | // |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 7 | // |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines some helpful functions for dealing with the possibility of |
Chris Lattner | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 11 | // Unix signals occurring while your program is running. |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "Unix.h" |
Owen Anderson | e2f23a3 | 2007-09-07 04:06:50 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/STLExtras.h" |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Format.h" |
Alexey Samsonov | 8a584bb | 2014-10-10 22:06:59 +0000 | [diff] [blame] | 18 | #include "llvm/Support/FileSystem.h" |
| 19 | #include "llvm/Support/FileUtilities.h" |
Alexey Samsonov | 8a584bb | 2014-10-10 22:06:59 +0000 | [diff] [blame] | 20 | #include "llvm/Support/MemoryBuffer.h" |
| 21 | #include "llvm/Support/Mutex.h" |
| 22 | #include "llvm/Support/Program.h" |
| 23 | #include "llvm/Support/UniqueLock.h" |
| 24 | #include "llvm/Support/raw_ostream.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 25 | #include <algorithm> |
Chandler Carruth | e6196eb | 2012-06-16 00:09:41 +0000 | [diff] [blame] | 26 | #include <string> |
Reid Spencer | d554bbc | 2004-12-27 06:16:52 +0000 | [diff] [blame] | 27 | #if HAVE_EXECINFO_H |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 28 | # include <execinfo.h> // For backtrace(). |
| 29 | #endif |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 30 | #if HAVE_SIGNAL_H |
| 31 | #include <signal.h> |
| 32 | #endif |
Reid Spencer | ceeb918 | 2007-04-07 18:52:17 +0000 | [diff] [blame] | 33 | #if HAVE_SYS_STAT_H |
| 34 | #include <sys/stat.h> |
| 35 | #endif |
Joerg Sonnenberger | 6624183 | 2013-04-27 22:12:32 +0000 | [diff] [blame] | 36 | #if HAVE_CXXABI_H |
Joerg Sonnenberger | 4474409 | 2013-04-27 22:32:54 +0000 | [diff] [blame] | 37 | #include <cxxabi.h> |
Joerg Sonnenberger | 6624183 | 2013-04-27 22:12:32 +0000 | [diff] [blame] | 38 | #endif |
| 39 | #if HAVE_DLFCN_H |
Dan Gohman | 7f079aa | 2008-12-05 20:12:48 +0000 | [diff] [blame] | 40 | #include <dlfcn.h> |
Dan Gohman | 7f079aa | 2008-12-05 20:12:48 +0000 | [diff] [blame] | 41 | #endif |
Argyrios Kyrtzidis | cd8fe08 | 2012-01-11 20:53:25 +0000 | [diff] [blame] | 42 | #if HAVE_MACH_MACH_H |
| 43 | #include <mach/mach.h> |
| 44 | #endif |
Alexey Samsonov | 8a584bb | 2014-10-10 22:06:59 +0000 | [diff] [blame] | 45 | #if HAVE_LINK_H |
| 46 | #include <link.h> |
| 47 | #endif |
Richard Smith | 14d9651 | 2016-05-20 21:18:12 +0000 | [diff] [blame] | 48 | #if HAVE_UNWIND_BACKTRACE |
| 49 | // FIXME: We should be able to use <unwind.h> for any target that has an |
| 50 | // _Unwind_Backtrace function, but on FreeBSD the configure test passes |
| 51 | // despite the function not existing, and on Android, <unwind.h> conflicts |
| 52 | // with <link.h>. |
| 53 | #ifdef __GLIBC__ |
| 54 | #include <unwind.h> |
| 55 | #else |
| 56 | #undef HAVE_UNWIND_BACKTRACE |
| 57 | #endif |
| 58 | #endif |
Argyrios Kyrtzidis | cd8fe08 | 2012-01-11 20:53:25 +0000 | [diff] [blame] | 59 | |
Chris Lattner | 80df7c4 | 2006-08-01 17:59:14 +0000 | [diff] [blame] | 60 | using namespace llvm; |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 61 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 62 | static RETSIGTYPE SignalHandler(int Sig); // defined below. |
Chris Lattner | f299a68 | 2009-03-23 05:42:29 +0000 | [diff] [blame] | 63 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 64 | static ManagedStatic<SmartMutex<true> > SignalsMutex; |
Owen Anderson | 820739d | 2009-08-17 17:07:22 +0000 | [diff] [blame] | 65 | |
Chris Lattner | 6a5d6ec | 2005-08-02 02:14:22 +0000 | [diff] [blame] | 66 | /// InterruptFunction - The function to call if ctrl-c is pressed. |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 67 | static void (*InterruptFunction)() = nullptr; |
Chris Lattner | 6a5d6ec | 2005-08-02 02:14:22 +0000 | [diff] [blame] | 68 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 69 | static ManagedStatic<std::vector<std::string>> FilesToRemove; |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 70 | |
Dan Gohman | f857cd7 | 2013-02-20 19:28:46 +0000 | [diff] [blame] | 71 | // IntSigs - Signals that represent requested termination. There's no bug |
| 72 | // or failure, or if there is, it's not our direct responsibility. For whatever |
| 73 | // reason, our continued execution is no longer desirable. |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 74 | static const int IntSigs[] = { |
Dan Gohman | 5cdb345 | 2013-02-20 19:15:01 +0000 | [diff] [blame] | 75 | SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2 |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 76 | }; |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 77 | |
Dan Gohman | f857cd7 | 2013-02-20 19:28:46 +0000 | [diff] [blame] | 78 | // KillSigs - Signals that represent that we have a bug, and our prompt |
| 79 | // termination has been ordered. |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 80 | static const int KillSigs[] = { |
Dan Gohman | 5cdb345 | 2013-02-20 19:15:01 +0000 | [diff] [blame] | 81 | SIGILL, SIGTRAP, SIGABRT, SIGFPE, SIGBUS, SIGSEGV, SIGQUIT |
Chris Lattner | 62f50da | 2010-02-12 00:37:46 +0000 | [diff] [blame] | 82 | #ifdef SIGSYS |
| 83 | , SIGSYS |
| 84 | #endif |
| 85 | #ifdef SIGXCPU |
| 86 | , SIGXCPU |
| 87 | #endif |
Chris Lattner | 3b38fd6 | 2010-02-14 18:20:09 +0000 | [diff] [blame] | 88 | #ifdef SIGXFSZ |
Chris Lattner | 62f50da | 2010-02-12 00:37:46 +0000 | [diff] [blame] | 89 | , SIGXFSZ |
| 90 | #endif |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 91 | #ifdef SIGEMT |
| 92 | , SIGEMT |
| 93 | #endif |
| 94 | }; |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 95 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 96 | static unsigned NumRegisteredSignals = 0; |
| 97 | static struct { |
Chris Lattner | fb95472 | 2009-03-23 05:55:36 +0000 | [diff] [blame] | 98 | struct sigaction SA; |
| 99 | int SigNo; |
Craig Topper | fac9057 | 2015-12-01 06:12:59 +0000 | [diff] [blame] | 100 | } RegisteredSignalInfo[array_lengthof(IntSigs) + array_lengthof(KillSigs)]; |
Chris Lattner | fb95472 | 2009-03-23 05:55:36 +0000 | [diff] [blame] | 101 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 102 | |
| 103 | static void RegisterHandler(int Signal) { |
Craig Topper | fac9057 | 2015-12-01 06:12:59 +0000 | [diff] [blame] | 104 | assert(NumRegisteredSignals < array_lengthof(RegisteredSignalInfo) && |
Chris Lattner | fb95472 | 2009-03-23 05:55:36 +0000 | [diff] [blame] | 105 | "Out of space for signal handlers!"); |
| 106 | |
| 107 | struct sigaction NewHandler; |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 108 | |
Chris Lattner | fb95472 | 2009-03-23 05:55:36 +0000 | [diff] [blame] | 109 | NewHandler.sa_handler = SignalHandler; |
| 110 | NewHandler.sa_flags = SA_NODEFER|SA_RESETHAND; |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 111 | sigemptyset(&NewHandler.sa_mask); |
| 112 | |
Chris Lattner | fb95472 | 2009-03-23 05:55:36 +0000 | [diff] [blame] | 113 | // Install the new handler, save the old one in RegisteredSignalInfo. |
| 114 | sigaction(Signal, &NewHandler, |
| 115 | &RegisteredSignalInfo[NumRegisteredSignals].SA); |
| 116 | RegisteredSignalInfo[NumRegisteredSignals].SigNo = Signal; |
| 117 | ++NumRegisteredSignals; |
Chris Lattner | 6acb4d6 | 2009-03-07 08:15:47 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Richard Smith | abab5d2 | 2016-05-20 21:26:00 +0000 | [diff] [blame^] | 120 | #if defined(HAVE_SIGALTSTACK) |
Richard Smith | e881134 | 2016-05-20 21:07:41 +0000 | [diff] [blame] | 121 | // Hold onto the old alternate signal stack so that it's not reported as a leak. |
| 122 | // We don't make any attempt to remove our alt signal stack if we remove our |
| 123 | // signal handlers; that can't be done reliably if someone else is also trying |
| 124 | // to do the same thing. |
| 125 | static struct sigaltstack OldAltStack; |
| 126 | |
| 127 | static void CreateSigAltStack() { |
| 128 | const size_t AltStackSize = MINSIGSTKSZ + 8192; |
| 129 | |
| 130 | // If we're executing on the alternate stack, or we already have an alternate |
| 131 | // signal stack that we're happy with, there's nothing for us to do. Don't |
| 132 | // reduce the size, some other part of the process might need a larger stack |
| 133 | // than we do. |
| 134 | if (sigaltstack(nullptr, &OldAltStack) != 0 || |
| 135 | OldAltStack.ss_flags & SS_ONSTACK || |
| 136 | (OldAltStack.ss_sp && OldAltStack.ss_size >= AltStackSize)) |
| 137 | return; |
| 138 | |
| 139 | struct sigaltstack AltStack = {}; |
| 140 | AltStack.ss_sp = malloc(AltStackSize); |
| 141 | AltStack.ss_size = AltStackSize; |
| 142 | if (sigaltstack(&AltStack, &OldAltStack) != 0) |
| 143 | free(AltStack.ss_sp); |
| 144 | } |
Richard Smith | abab5d2 | 2016-05-20 21:26:00 +0000 | [diff] [blame^] | 145 | #else |
| 146 | static void CreateSigAltStack() {} |
| 147 | #endif |
Richard Smith | e881134 | 2016-05-20 21:07:41 +0000 | [diff] [blame] | 148 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 149 | static void RegisterHandlers() { |
Chris Bieneman | 017ebf0 | 2015-04-27 20:45:35 +0000 | [diff] [blame] | 150 | // We need to dereference the signals mutex during handler registration so |
| 151 | // that we force its construction. This is to prevent the first use being |
| 152 | // during handling an actual signal because you can't safely call new in a |
| 153 | // signal handler. |
| 154 | *SignalsMutex; |
Mehdi Amini | 766d05b | 2015-11-05 02:29:53 +0000 | [diff] [blame] | 155 | |
Chris Lattner | fb95472 | 2009-03-23 05:55:36 +0000 | [diff] [blame] | 156 | // If the handlers are already registered, we're done. |
| 157 | if (NumRegisteredSignals != 0) return; |
| 158 | |
Richard Smith | e881134 | 2016-05-20 21:07:41 +0000 | [diff] [blame] | 159 | // Create an alternate stack for signal handling. This is necessary for us to |
| 160 | // be able to reliably handle signals due to stack overflow. |
| 161 | CreateSigAltStack(); |
| 162 | |
Chris Bieneman | b1cd51e | 2014-08-29 01:05:16 +0000 | [diff] [blame] | 163 | for (auto S : IntSigs) RegisterHandler(S); |
| 164 | for (auto S : KillSigs) RegisterHandler(S); |
Chris Lattner | f299a68 | 2009-03-23 05:42:29 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 167 | static void UnregisterHandlers() { |
Chris Lattner | fb95472 | 2009-03-23 05:55:36 +0000 | [diff] [blame] | 168 | // Restore all of the signal handlers to how they were before we showed up. |
| 169 | for (unsigned i = 0, e = NumRegisteredSignals; i != e; ++i) |
Chris Lattner | f2b6065 | 2009-03-23 06:46:20 +0000 | [diff] [blame] | 170 | sigaction(RegisteredSignalInfo[i].SigNo, |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 171 | &RegisteredSignalInfo[i].SA, nullptr); |
Chris Lattner | fb95472 | 2009-03-23 05:55:36 +0000 | [diff] [blame] | 172 | NumRegisteredSignals = 0; |
Chris Lattner | f299a68 | 2009-03-23 05:42:29 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 175 | |
Dan Gohman | 288999b | 2010-05-27 23:11:55 +0000 | [diff] [blame] | 176 | /// RemoveFilesToRemove - Process the FilesToRemove list. This function |
| 177 | /// should be called with the SignalsMutex lock held. |
Chandler Carruth | e6196eb | 2012-06-16 00:09:41 +0000 | [diff] [blame] | 178 | /// NB: This must be an async signal safe function. It cannot allocate or free |
| 179 | /// memory, even in debug builds. |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 180 | static void RemoveFilesToRemove() { |
Steven Wu | 9474669 | 2015-05-07 16:20:51 +0000 | [diff] [blame] | 181 | // Avoid constructing ManagedStatic in the signal handler. |
| 182 | // If FilesToRemove is not constructed, there are no files to remove. |
| 183 | if (!FilesToRemove.isConstructed()) |
| 184 | return; |
| 185 | |
Daniel Dunbar | 511479d | 2012-10-17 16:30:54 +0000 | [diff] [blame] | 186 | // We avoid iterators in case of debug iterators that allocate or release |
Chandler Carruth | e6196eb | 2012-06-16 00:09:41 +0000 | [diff] [blame] | 187 | // memory. |
Chris Bieneman | 186e7d1 | 2014-09-02 23:48:13 +0000 | [diff] [blame] | 188 | std::vector<std::string>& FilesToRemoveRef = *FilesToRemove; |
| 189 | for (unsigned i = 0, e = FilesToRemoveRef.size(); i != e; ++i) { |
Chris Bieneman | 186e7d1 | 2014-09-02 23:48:13 +0000 | [diff] [blame] | 190 | const char *path = FilesToRemoveRef[i].c_str(); |
Daniel Dunbar | 511479d | 2012-10-17 16:30:54 +0000 | [diff] [blame] | 191 | |
| 192 | // Get the status so we can determine if it's a file or directory. If we |
| 193 | // can't stat the file, ignore it. |
| 194 | struct stat buf; |
| 195 | if (stat(path, &buf) != 0) |
| 196 | continue; |
| 197 | |
| 198 | // If this is not a regular file, ignore it. We want to prevent removal of |
| 199 | // special files like /dev/null, even if the compiler is being run with the |
| 200 | // super-user permissions. |
| 201 | if (!S_ISREG(buf.st_mode)) |
| 202 | continue; |
Mehdi Amini | 766d05b | 2015-11-05 02:29:53 +0000 | [diff] [blame] | 203 | |
Daniel Dunbar | 511479d | 2012-10-17 16:30:54 +0000 | [diff] [blame] | 204 | // Otherwise, remove the file. We ignore any errors here as there is nothing |
| 205 | // else we can do. |
| 206 | unlink(path); |
Dan Gohman | 288999b | 2010-05-27 23:11:55 +0000 | [diff] [blame] | 207 | } |
| 208 | } |
Chris Lattner | 6acb4d6 | 2009-03-07 08:15:47 +0000 | [diff] [blame] | 209 | |
| 210 | // SignalHandler - The signal handler that runs. |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 211 | static RETSIGTYPE SignalHandler(int Sig) { |
Chris Lattner | bbbbbf3 | 2009-03-05 18:22:14 +0000 | [diff] [blame] | 212 | // Restore the signal behavior to default, so that the program actually |
| 213 | // crashes when we return and the signal reissues. This also ensures that if |
| 214 | // we crash in our signal handler that the program will terminate immediately |
| 215 | // instead of recursing in the signal handler. |
Chris Lattner | f299a68 | 2009-03-23 05:42:29 +0000 | [diff] [blame] | 216 | UnregisterHandlers(); |
Chris Lattner | 6acb4d6 | 2009-03-07 08:15:47 +0000 | [diff] [blame] | 217 | |
| 218 | // Unmask all potentially blocked kill signals. |
| 219 | sigset_t SigMask; |
| 220 | sigfillset(&SigMask); |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 221 | sigprocmask(SIG_UNBLOCK, &SigMask, nullptr); |
Chris Lattner | bbbbbf3 | 2009-03-05 18:22:14 +0000 | [diff] [blame] | 222 | |
Dylan Noblesmith | c4c5180 | 2014-08-23 23:07:14 +0000 | [diff] [blame] | 223 | { |
Chris Bieneman | 186e7d1 | 2014-09-02 23:48:13 +0000 | [diff] [blame] | 224 | unique_lock<SmartMutex<true>> Guard(*SignalsMutex); |
Dylan Noblesmith | c4c5180 | 2014-08-23 23:07:14 +0000 | [diff] [blame] | 225 | RemoveFilesToRemove(); |
Chris Lattner | 4fdd042 | 2009-03-04 21:21:36 +0000 | [diff] [blame] | 226 | |
Chris Bieneman | b1cd51e | 2014-08-29 01:05:16 +0000 | [diff] [blame] | 227 | if (std::find(std::begin(IntSigs), std::end(IntSigs), Sig) |
| 228 | != std::end(IntSigs)) { |
Dylan Noblesmith | c4c5180 | 2014-08-23 23:07:14 +0000 | [diff] [blame] | 229 | if (InterruptFunction) { |
| 230 | void (*IF)() = InterruptFunction; |
| 231 | Guard.unlock(); |
| 232 | InterruptFunction = nullptr; |
| 233 | IF(); // run the interrupt function. |
| 234 | return; |
| 235 | } |
| 236 | |
| 237 | Guard.unlock(); |
| 238 | raise(Sig); // Execute the default handler. |
Chris Lattner | 4fdd042 | 2009-03-04 21:21:36 +0000 | [diff] [blame] | 239 | return; |
Dylan Noblesmith | c4c5180 | 2014-08-23 23:07:14 +0000 | [diff] [blame] | 240 | } |
Chris Lattner | 4fdd042 | 2009-03-04 21:21:36 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | // Otherwise if it is a fault (like SEGV) run any handler. |
Yaron Keren | 2873810 | 2015-07-22 21:11:17 +0000 | [diff] [blame] | 244 | llvm::sys::RunSignalHandlers(); |
Ulrich Weigand | 90c9abd | 2013-05-03 12:22:11 +0000 | [diff] [blame] | 245 | |
| 246 | #ifdef __s390__ |
| 247 | // On S/390, certain signals are delivered with PSW Address pointing to |
| 248 | // *after* the faulting instruction. Simply returning from the signal |
| 249 | // handler would continue execution after that point, instead of |
| 250 | // re-raising the signal. Raise the signal manually in those cases. |
| 251 | if (Sig == SIGILL || Sig == SIGFPE || Sig == SIGTRAP) |
| 252 | raise(Sig); |
| 253 | #endif |
Chris Lattner | 4fdd042 | 2009-03-04 21:21:36 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Daniel Dunbar | 6827256 | 2010-05-08 02:10:34 +0000 | [diff] [blame] | 256 | void llvm::sys::RunInterruptHandlers() { |
Chris Bieneman | 186e7d1 | 2014-09-02 23:48:13 +0000 | [diff] [blame] | 257 | sys::SmartScopedLock<true> Guard(*SignalsMutex); |
Dan Gohman | 288999b | 2010-05-27 23:11:55 +0000 | [diff] [blame] | 258 | RemoveFilesToRemove(); |
Daniel Dunbar | 6827256 | 2010-05-08 02:10:34 +0000 | [diff] [blame] | 259 | } |
Chris Lattner | 4fdd042 | 2009-03-04 21:21:36 +0000 | [diff] [blame] | 260 | |
Chris Lattner | bb1ba7b | 2009-03-08 19:13:45 +0000 | [diff] [blame] | 261 | void llvm::sys::SetInterruptFunction(void (*IF)()) { |
Dylan Noblesmith | 4704ffe | 2014-08-23 22:49:17 +0000 | [diff] [blame] | 262 | { |
Chris Bieneman | 186e7d1 | 2014-09-02 23:48:13 +0000 | [diff] [blame] | 263 | sys::SmartScopedLock<true> Guard(*SignalsMutex); |
Dylan Noblesmith | 4704ffe | 2014-08-23 22:49:17 +0000 | [diff] [blame] | 264 | InterruptFunction = IF; |
| 265 | } |
Chris Lattner | f299a68 | 2009-03-23 05:42:29 +0000 | [diff] [blame] | 266 | RegisterHandlers(); |
Chris Lattner | 4fdd042 | 2009-03-04 21:21:36 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | // RemoveFileOnSignal - The public API |
Rafael Espindola | 4f35da7 | 2013-06-13 21:16:58 +0000 | [diff] [blame] | 270 | bool llvm::sys::RemoveFileOnSignal(StringRef Filename, |
Chris Lattner | bb1ba7b | 2009-03-08 19:13:45 +0000 | [diff] [blame] | 271 | std::string* ErrMsg) { |
Dylan Noblesmith | 4704ffe | 2014-08-23 22:49:17 +0000 | [diff] [blame] | 272 | { |
Chris Bieneman | 186e7d1 | 2014-09-02 23:48:13 +0000 | [diff] [blame] | 273 | sys::SmartScopedLock<true> Guard(*SignalsMutex); |
Yaron Keren | 4135e4c | 2015-07-23 05:49:29 +0000 | [diff] [blame] | 274 | FilesToRemove->push_back(Filename); |
Dylan Noblesmith | 4704ffe | 2014-08-23 22:49:17 +0000 | [diff] [blame] | 275 | } |
Owen Anderson | 820739d | 2009-08-17 17:07:22 +0000 | [diff] [blame] | 276 | |
Chris Lattner | f299a68 | 2009-03-23 05:42:29 +0000 | [diff] [blame] | 277 | RegisterHandlers(); |
Chris Lattner | 4fdd042 | 2009-03-04 21:21:36 +0000 | [diff] [blame] | 278 | return false; |
| 279 | } |
| 280 | |
Dan Gohman | e201c07 | 2010-09-01 14:17:34 +0000 | [diff] [blame] | 281 | // DontRemoveFileOnSignal - The public API |
Rafael Espindola | 4f35da7 | 2013-06-13 21:16:58 +0000 | [diff] [blame] | 282 | void llvm::sys::DontRemoveFileOnSignal(StringRef Filename) { |
Chris Bieneman | 186e7d1 | 2014-09-02 23:48:13 +0000 | [diff] [blame] | 283 | sys::SmartScopedLock<true> Guard(*SignalsMutex); |
Chandler Carruth | e6196eb | 2012-06-16 00:09:41 +0000 | [diff] [blame] | 284 | std::vector<std::string>::reverse_iterator RI = |
Chris Bieneman | 186e7d1 | 2014-09-02 23:48:13 +0000 | [diff] [blame] | 285 | std::find(FilesToRemove->rbegin(), FilesToRemove->rend(), Filename); |
| 286 | std::vector<std::string>::iterator I = FilesToRemove->end(); |
| 287 | if (RI != FilesToRemove->rend()) |
| 288 | I = FilesToRemove->erase(RI.base()-1); |
Dan Gohman | e201c07 | 2010-09-01 14:17:34 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Chris Lattner | 4fdd042 | 2009-03-04 21:21:36 +0000 | [diff] [blame] | 291 | /// AddSignalHandler - Add a function to be called when a signal is delivered |
| 292 | /// to the process. The handler can have a cookie passed to it to identify |
| 293 | /// what instance of the handler it is. |
Chris Lattner | bb1ba7b | 2009-03-08 19:13:45 +0000 | [diff] [blame] | 294 | void llvm::sys::AddSignalHandler(void (*FnPtr)(void *), void *Cookie) { |
Chris Bieneman | 186e7d1 | 2014-09-02 23:48:13 +0000 | [diff] [blame] | 295 | CallBacksToRun->push_back(std::make_pair(FnPtr, Cookie)); |
Chris Lattner | f299a68 | 2009-03-23 05:42:29 +0000 | [diff] [blame] | 296 | RegisterHandlers(); |
Chris Lattner | 4fdd042 | 2009-03-04 21:21:36 +0000 | [diff] [blame] | 297 | } |
| 298 | |
Reid Kleckner | 40aa9c6 | 2015-11-09 23:10:29 +0000 | [diff] [blame] | 299 | #if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) && HAVE_LINK_H && \ |
| 300 | (defined(__linux__) || defined(__FreeBSD__) || \ |
| 301 | defined(__FreeBSD_kernel__) || defined(__NetBSD__)) |
Alexey Samsonov | 8a584bb | 2014-10-10 22:06:59 +0000 | [diff] [blame] | 302 | struct DlIteratePhdrData { |
| 303 | void **StackTrace; |
| 304 | int depth; |
| 305 | bool first; |
| 306 | const char **modules; |
| 307 | intptr_t *offsets; |
| 308 | const char *main_exec_name; |
| 309 | }; |
| 310 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 311 | static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { |
Alexey Samsonov | 8a584bb | 2014-10-10 22:06:59 +0000 | [diff] [blame] | 312 | DlIteratePhdrData *data = (DlIteratePhdrData*)arg; |
| 313 | const char *name = data->first ? data->main_exec_name : info->dlpi_name; |
| 314 | data->first = false; |
| 315 | for (int i = 0; i < info->dlpi_phnum; i++) { |
| 316 | const auto *phdr = &info->dlpi_phdr[i]; |
| 317 | if (phdr->p_type != PT_LOAD) |
| 318 | continue; |
| 319 | intptr_t beg = info->dlpi_addr + phdr->p_vaddr; |
| 320 | intptr_t end = beg + phdr->p_memsz; |
| 321 | for (int j = 0; j < data->depth; j++) { |
| 322 | if (data->modules[j]) |
| 323 | continue; |
| 324 | intptr_t addr = (intptr_t)data->StackTrace[j]; |
| 325 | if (beg <= addr && addr < end) { |
| 326 | data->modules[j] = name; |
| 327 | data->offsets[j] = addr - info->dlpi_addr; |
| 328 | } |
| 329 | } |
| 330 | } |
| 331 | return 0; |
| 332 | } |
| 333 | |
Reid Kleckner | 40aa9c6 | 2015-11-09 23:10:29 +0000 | [diff] [blame] | 334 | /// If this is an ELF platform, we can find all loaded modules and their virtual |
| 335 | /// addresses with dl_iterate_phdr. |
Alexey Samsonov | 8a584bb | 2014-10-10 22:06:59 +0000 | [diff] [blame] | 336 | static bool findModulesAndOffsets(void **StackTrace, int Depth, |
| 337 | const char **Modules, intptr_t *Offsets, |
Reid Kleckner | ba5757d | 2015-11-05 01:07:54 +0000 | [diff] [blame] | 338 | const char *MainExecutableName, |
| 339 | StringSaver &StrPool) { |
Alexey Samsonov | 8a584bb | 2014-10-10 22:06:59 +0000 | [diff] [blame] | 340 | DlIteratePhdrData data = {StackTrace, Depth, true, |
| 341 | Modules, Offsets, MainExecutableName}; |
| 342 | dl_iterate_phdr(dl_iterate_phdr_cb, &data); |
| 343 | return true; |
| 344 | } |
| 345 | #else |
Reid Kleckner | 40aa9c6 | 2015-11-09 23:10:29 +0000 | [diff] [blame] | 346 | /// This platform does not have dl_iterate_phdr, so we do not yet know how to |
| 347 | /// find all loaded DSOs. |
Alexey Samsonov | 8a584bb | 2014-10-10 22:06:59 +0000 | [diff] [blame] | 348 | static bool findModulesAndOffsets(void **StackTrace, int Depth, |
| 349 | const char **Modules, intptr_t *Offsets, |
Mehdi Amini | 7ae928e | 2015-11-05 02:29:57 +0000 | [diff] [blame] | 350 | const char *MainExecutableName, |
| 351 | StringSaver &StrPool) { |
Alexey Samsonov | 8a584bb | 2014-10-10 22:06:59 +0000 | [diff] [blame] | 352 | return false; |
| 353 | } |
Reid Kleckner | 40aa9c6 | 2015-11-09 23:10:29 +0000 | [diff] [blame] | 354 | #endif // defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES) && ... |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 355 | |
Richard Smith | 14d9651 | 2016-05-20 21:18:12 +0000 | [diff] [blame] | 356 | #if defined(ENABLE_BACKTRACES) && defined(HAVE_UNWIND_BACKTRACE) |
| 357 | static int unwindBacktrace(void **StackTrace, int MaxEntries) { |
| 358 | if (MaxEntries < 0) |
| 359 | return 0; |
| 360 | |
| 361 | // Skip the first frame ('unwindBacktrace' itself). |
| 362 | int Entries = -1; |
| 363 | |
| 364 | auto HandleFrame = [&](_Unwind_Context *Context) -> _Unwind_Reason_Code { |
| 365 | // Apparently we need to detect reaching the end of the stack ourselves. |
| 366 | void *IP = (void *)_Unwind_GetIP(Context); |
| 367 | if (!IP) |
| 368 | return _URC_END_OF_STACK; |
| 369 | |
| 370 | assert(Entries < MaxEntries && "recursively called after END_OF_STACK?"); |
| 371 | if (Entries >= 0) |
| 372 | StackTrace[Entries] = IP; |
| 373 | |
| 374 | if (++Entries == MaxEntries) |
| 375 | return _URC_END_OF_STACK; |
| 376 | return _URC_NO_REASON; |
| 377 | }; |
| 378 | |
| 379 | _Unwind_Backtrace( |
| 380 | [](_Unwind_Context *Context, void *Handler) { |
| 381 | return (*static_cast<decltype(HandleFrame) *>(Handler))(Context); |
| 382 | }, |
| 383 | static_cast<void *>(&HandleFrame)); |
| 384 | return std::max(Entries, 0); |
| 385 | } |
| 386 | #endif |
| 387 | |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 388 | // PrintStackTrace - In the case of a program crash or fault, print out a stack |
| 389 | // trace so that the user has an indication of why and where we died. |
| 390 | // |
| 391 | // On glibc systems we have the 'backtrace' function, which works nicely, but |
Michael J. Spencer | 447762d | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 392 | // doesn't demangle symbols. |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 393 | void llvm::sys::PrintStackTrace(raw_ostream &OS) { |
Richard Smith | 14d9651 | 2016-05-20 21:18:12 +0000 | [diff] [blame] | 394 | #if defined(ENABLE_BACKTRACES) |
| 395 | static void *StackTrace[256]; |
| 396 | int depth = 0; |
| 397 | #if defined(HAVE_BACKTRACE) |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 398 | // Use backtrace() to output a backtrace on Linux systems with glibc. |
Richard Smith | 14d9651 | 2016-05-20 21:18:12 +0000 | [diff] [blame] | 399 | if (!depth) |
| 400 | depth = backtrace(StackTrace, static_cast<int>(array_lengthof(StackTrace))); |
| 401 | #endif |
| 402 | #if defined(HAVE_UNWIND_BACKTRACE) |
| 403 | // Try _Unwind_Backtrace() if backtrace() failed. |
| 404 | if (!depth) |
| 405 | depth = unwindBacktrace(StackTrace, |
Evan Cheng | 86cb318 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 406 | static_cast<int>(array_lengthof(StackTrace))); |
Richard Smith | 14d9651 | 2016-05-20 21:18:12 +0000 | [diff] [blame] | 407 | #endif |
| 408 | if (!depth) |
| 409 | return; |
| 410 | |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 411 | if (printSymbolizedStackTrace(StackTrace, depth, OS)) |
Alexey Samsonov | 8a584bb | 2014-10-10 22:06:59 +0000 | [diff] [blame] | 412 | return; |
Dan Gohman | 7f079aa | 2008-12-05 20:12:48 +0000 | [diff] [blame] | 413 | #if HAVE_DLFCN_H && __GNUG__ |
| 414 | int width = 0; |
| 415 | for (int i = 0; i < depth; ++i) { |
| 416 | Dl_info dlinfo; |
| 417 | dladdr(StackTrace[i], &dlinfo); |
Dan Gohman | 1f517dd | 2009-02-10 17:56:28 +0000 | [diff] [blame] | 418 | const char* name = strrchr(dlinfo.dli_fname, '/'); |
Dan Gohman | 7f079aa | 2008-12-05 20:12:48 +0000 | [diff] [blame] | 419 | |
| 420 | int nwidth; |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 421 | if (!name) nwidth = strlen(dlinfo.dli_fname); |
| 422 | else nwidth = strlen(name) - 1; |
Dan Gohman | 7f079aa | 2008-12-05 20:12:48 +0000 | [diff] [blame] | 423 | |
| 424 | if (nwidth > width) width = nwidth; |
| 425 | } |
| 426 | |
| 427 | for (int i = 0; i < depth; ++i) { |
| 428 | Dl_info dlinfo; |
| 429 | dladdr(StackTrace[i], &dlinfo); |
| 430 | |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 431 | OS << format("%-2d", i); |
Dan Gohman | 7f079aa | 2008-12-05 20:12:48 +0000 | [diff] [blame] | 432 | |
Dan Gohman | 1f517dd | 2009-02-10 17:56:28 +0000 | [diff] [blame] | 433 | const char* name = strrchr(dlinfo.dli_fname, '/'); |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 434 | if (!name) OS << format(" %-*s", width, dlinfo.dli_fname); |
| 435 | else OS << format(" %-*s", width, name+1); |
Dan Gohman | 7f079aa | 2008-12-05 20:12:48 +0000 | [diff] [blame] | 436 | |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 437 | OS << format(" %#0*lx", (int)(sizeof(void*) * 2) + 2, |
| 438 | (unsigned long)StackTrace[i]); |
Dan Gohman | 7f079aa | 2008-12-05 20:12:48 +0000 | [diff] [blame] | 439 | |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 440 | if (dlinfo.dli_sname != nullptr) { |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 441 | OS << ' '; |
Joerg Sonnenberger | 6624183 | 2013-04-27 22:12:32 +0000 | [diff] [blame] | 442 | # if HAVE_CXXABI_H |
Benjamin Kramer | 83e2a44 | 2013-04-28 07:47:04 +0000 | [diff] [blame] | 443 | int res; |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 444 | char* d = abi::__cxa_demangle(dlinfo.dli_sname, nullptr, nullptr, &res); |
Joerg Sonnenberger | 6624183 | 2013-04-27 22:12:32 +0000 | [diff] [blame] | 445 | # else |
| 446 | char* d = NULL; |
| 447 | # endif |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 448 | if (!d) OS << dlinfo.dli_sname; |
| 449 | else OS << d; |
Dan Gohman | 7f079aa | 2008-12-05 20:12:48 +0000 | [diff] [blame] | 450 | free(d); |
| 451 | |
Edwin Vane | 44338e0 | 2013-01-28 19:34:42 +0000 | [diff] [blame] | 452 | // FIXME: When we move to C++11, use %t length modifier. It's not in |
| 453 | // C++03 and causes gcc to issue warnings. Losing the upper 32 bits of |
| 454 | // the stack offset for a stack dump isn't likely to cause any problems. |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 455 | OS << format(" + %u",(unsigned)((char*)StackTrace[i]- |
| 456 | (char*)dlinfo.dli_saddr)); |
Dan Gohman | 7f079aa | 2008-12-05 20:12:48 +0000 | [diff] [blame] | 457 | } |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 458 | OS << '\n'; |
Dan Gohman | 7f079aa | 2008-12-05 20:12:48 +0000 | [diff] [blame] | 459 | } |
Richard Smith | 14d9651 | 2016-05-20 21:18:12 +0000 | [diff] [blame] | 460 | #elif defined(HAVE_BACKTRACE) |
Lauro Ramos Venancio | eab51d3 | 2008-02-15 18:05:54 +0000 | [diff] [blame] | 461 | backtrace_symbols_fd(StackTrace, depth, STDERR_FILENO); |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 462 | #endif |
Dan Gohman | 7f079aa | 2008-12-05 20:12:48 +0000 | [diff] [blame] | 463 | #endif |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 466 | static void PrintStackTraceSignalHandler(void *) { |
Zachary Turner | cd132c9 | 2015-03-05 19:10:52 +0000 | [diff] [blame] | 467 | PrintStackTrace(llvm::errs()); |
Argyrios Kyrtzidis | eb9ae76 | 2013-01-09 19:42:40 +0000 | [diff] [blame] | 468 | } |
| 469 | |
Michael J. Spencer | 89b0ad2 | 2015-01-29 17:20:29 +0000 | [diff] [blame] | 470 | void llvm::sys::DisableSystemDialogsOnCrash() {} |
| 471 | |
NAKAMURA Takumi | 8a54d81 | 2012-09-06 03:01:43 +0000 | [diff] [blame] | 472 | /// PrintStackTraceOnErrorSignal - When an error signal (such as SIGABRT or |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 473 | /// SIGSEGV) is delivered to the process, print a stack trace and then exit. |
Pete Cooper | 6bea2f4 | 2015-04-07 20:43:23 +0000 | [diff] [blame] | 474 | void llvm::sys::PrintStackTraceOnErrorSignal(bool DisableCrashReporting) { |
Craig Topper | e73658d | 2014-04-28 04:05:08 +0000 | [diff] [blame] | 475 | AddSignalHandler(PrintStackTraceSignalHandler, nullptr); |
Argyrios Kyrtzidis | cd8fe08 | 2012-01-11 20:53:25 +0000 | [diff] [blame] | 476 | |
Daniel Dunbar | eb6c708 | 2013-08-30 20:39:21 +0000 | [diff] [blame] | 477 | #if defined(__APPLE__) && defined(ENABLE_CRASH_OVERRIDES) |
Argyrios Kyrtzidis | cd8fe08 | 2012-01-11 20:53:25 +0000 | [diff] [blame] | 478 | // Environment variable to disable any kind of crash dialog. |
Pete Cooper | 6bea2f4 | 2015-04-07 20:43:23 +0000 | [diff] [blame] | 479 | if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT")) { |
Argyrios Kyrtzidis | cd8fe08 | 2012-01-11 20:53:25 +0000 | [diff] [blame] | 480 | mach_port_t self = mach_task_self(); |
| 481 | |
| 482 | exception_mask_t mask = EXC_MASK_CRASH; |
| 483 | |
NAKAMURA Takumi | ffa1571 | 2012-09-06 03:02:56 +0000 | [diff] [blame] | 484 | kern_return_t ret = task_set_exception_ports(self, |
Argyrios Kyrtzidis | cd8fe08 | 2012-01-11 20:53:25 +0000 | [diff] [blame] | 485 | mask, |
Jean-Daniel Dupas | a573b22 | 2012-03-24 22:17:50 +0000 | [diff] [blame] | 486 | MACH_PORT_NULL, |
NAKAMURA Takumi | ffa1571 | 2012-09-06 03:02:56 +0000 | [diff] [blame] | 487 | EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, |
Jean-Daniel Dupas | a573b22 | 2012-03-24 22:17:50 +0000 | [diff] [blame] | 488 | THREAD_STATE_NONE); |
Argyrios Kyrtzidis | cd8fe08 | 2012-01-11 20:53:25 +0000 | [diff] [blame] | 489 | (void)ret; |
| 490 | } |
| 491 | #endif |
Reid Spencer | 3d7a614 | 2004-08-29 19:22:48 +0000 | [diff] [blame] | 492 | } |
Chris Lattner | 4fdd042 | 2009-03-04 21:21:36 +0000 | [diff] [blame] | 493 | |
Duncan P. N. Exon Smith | 91d3cfe | 2016-04-05 20:45:04 +0000 | [diff] [blame] | 494 | |
| 495 | /***/ |
| 496 | |
Daniel Dunbar | f14d946 | 2010-08-19 23:45:39 +0000 | [diff] [blame] | 497 | // On Darwin, raise sends a signal to the main thread instead of the current |
| 498 | // thread. This has the unfortunate effect that assert() and abort() will end up |
| 499 | // bypassing our crash recovery attempts. We work around this for anything in |
| 500 | // the same linkage unit by just defining our own versions of the assert handler |
| 501 | // and abort. |
| 502 | |
Daniel Dunbar | eb6c708 | 2013-08-30 20:39:21 +0000 | [diff] [blame] | 503 | #if defined(__APPLE__) && defined(ENABLE_CRASH_OVERRIDES) |
Daniel Dunbar | f14d946 | 2010-08-19 23:45:39 +0000 | [diff] [blame] | 504 | |
Douglas Gregor | 0e50682 | 2011-04-29 16:12:17 +0000 | [diff] [blame] | 505 | #include <signal.h> |
| 506 | #include <pthread.h> |
| 507 | |
Daniel Dunbar | 18456f3 | 2010-09-22 17:46:10 +0000 | [diff] [blame] | 508 | int raise(int sig) { |
Daniel Dunbar | cc0e18d | 2010-10-08 18:31:34 +0000 | [diff] [blame] | 509 | return pthread_kill(pthread_self(), sig); |
Daniel Dunbar | 18456f3 | 2010-09-22 17:46:10 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Daniel Dunbar | f14d946 | 2010-08-19 23:45:39 +0000 | [diff] [blame] | 512 | void __assert_rtn(const char *func, |
| 513 | const char *file, |
| 514 | int line, |
| 515 | const char *expr) { |
| 516 | if (func) |
| 517 | fprintf(stderr, "Assertion failed: (%s), function %s, file %s, line %d.\n", |
| 518 | expr, func, file, line); |
| 519 | else |
| 520 | fprintf(stderr, "Assertion failed: (%s), file %s, line %d.\n", |
| 521 | expr, file, line); |
| 522 | abort(); |
| 523 | } |
| 524 | |
Daniel Dunbar | f14d946 | 2010-08-19 23:45:39 +0000 | [diff] [blame] | 525 | void abort() { |
Daniel Dunbar | 18456f3 | 2010-09-22 17:46:10 +0000 | [diff] [blame] | 526 | raise(SIGABRT); |
Daniel Dunbar | f14d946 | 2010-08-19 23:45:39 +0000 | [diff] [blame] | 527 | usleep(1000); |
| 528 | __builtin_trap(); |
| 529 | } |
| 530 | |
| 531 | #endif |