blob: 66338f17d88fac41dc189fd46f4a91d02a75eee7 [file] [log] [blame]
Reid Spencer3d7a6142004-08-29 19:22:48 +00001//===- Signals.cpp - Generic Unix Signals Implementation -----*- C++ -*-===//
Michael J. Spencer447762d2010-11-29 18:16:10 +00002//
Reid Spencer3d7a6142004-08-29 19:22:48 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Michael J. Spencer447762d2010-11-29 18:16:10 +00007//
Reid Spencer3d7a6142004-08-29 19:22:48 +00008//===----------------------------------------------------------------------===//
9//
10// This file defines some helpful functions for dealing with the possibility of
Chris Lattner0ab5e2c2011-04-15 05:18:47 +000011// Unix signals occurring while your program is running.
Reid Spencer3d7a6142004-08-29 19:22:48 +000012//
13//===----------------------------------------------------------------------===//
14
15#include "Unix.h"
Owen Andersone2f23a32007-09-07 04:06:50 +000016#include "llvm/ADT/STLExtras.h"
Michael J. Spencer447762d2010-11-29 18:16:10 +000017#include "llvm/Support/Mutex.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000018#include <algorithm>
Chandler Carruthe6196eb2012-06-16 00:09:41 +000019#include <string>
Reid Spencer3d7a6142004-08-29 19:22:48 +000020#include <vector>
Reid Spencerd554bbc2004-12-27 06:16:52 +000021#if HAVE_EXECINFO_H
Reid Spencer3d7a6142004-08-29 19:22:48 +000022# include <execinfo.h> // For backtrace().
23#endif
Reid Spencerd554bbc2004-12-27 06:16:52 +000024#if HAVE_SIGNAL_H
Reid Spencer3d7a6142004-08-29 19:22:48 +000025#include <signal.h>
Reid Spencerd554bbc2004-12-27 06:16:52 +000026#endif
Reid Spencerceeb9182007-04-07 18:52:17 +000027#if HAVE_SYS_STAT_H
28#include <sys/stat.h>
29#endif
Dan Gohman7f079aa2008-12-05 20:12:48 +000030#if HAVE_DLFCN_H && __GNUG__
31#include <dlfcn.h>
Michael J. Spencer447762d2010-11-29 18:16:10 +000032#include <cxxabi.h>
Dan Gohman7f079aa2008-12-05 20:12:48 +000033#endif
Argyrios Kyrtzidiscd8fe082012-01-11 20:53:25 +000034#if HAVE_MACH_MACH_H
35#include <mach/mach.h>
36#endif
37
Chris Lattner80df7c42006-08-01 17:59:14 +000038using namespace llvm;
Reid Spencer3d7a6142004-08-29 19:22:48 +000039
Chris Lattnerf299a682009-03-23 05:42:29 +000040static RETSIGTYPE SignalHandler(int Sig); // defined below.
41
Owen Anderson820739d2009-08-17 17:07:22 +000042static SmartMutex<true> SignalsMutex;
43
Chris Lattner6a5d6ec2005-08-02 02:14:22 +000044/// InterruptFunction - The function to call if ctrl-c is pressed.
Dan Gohmanf4bc7822008-04-10 21:11:47 +000045static void (*InterruptFunction)() = 0;
Chris Lattner6a5d6ec2005-08-02 02:14:22 +000046
Chandler Carruthe6196eb2012-06-16 00:09:41 +000047static std::vector<std::string> FilesToRemove;
Jeffrey Yasskinc4e3f052010-03-17 07:08:12 +000048static std::vector<std::pair<void(*)(void*), void*> > CallBacksToRun;
Reid Spencer3d7a6142004-08-29 19:22:48 +000049
Dan Gohmanf857cd72013-02-20 19:28:46 +000050// IntSigs - Signals that represent requested termination. There's no bug
51// or failure, or if there is, it's not our direct responsibility. For whatever
52// reason, our continued execution is no longer desirable.
Dan Gohmanf4bc7822008-04-10 21:11:47 +000053static const int IntSigs[] = {
Dan Gohman5cdb3452013-02-20 19:15:01 +000054 SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2
Reid Spencer3d7a6142004-08-29 19:22:48 +000055};
Dan Gohman4e974ab2008-05-14 00:42:30 +000056static const int *const IntSigsEnd =
57 IntSigs + sizeof(IntSigs) / sizeof(IntSigs[0]);
Reid Spencer3d7a6142004-08-29 19:22:48 +000058
Dan Gohmanf857cd72013-02-20 19:28:46 +000059// KillSigs - Signals that represent that we have a bug, and our prompt
60// termination has been ordered.
Dan Gohmanf4bc7822008-04-10 21:11:47 +000061static const int KillSigs[] = {
Dan Gohman5cdb3452013-02-20 19:15:01 +000062 SIGILL, SIGTRAP, SIGABRT, SIGFPE, SIGBUS, SIGSEGV, SIGQUIT
Chris Lattner62f50da2010-02-12 00:37:46 +000063#ifdef SIGSYS
64 , SIGSYS
65#endif
66#ifdef SIGXCPU
67 , SIGXCPU
68#endif
Chris Lattner3b38fd62010-02-14 18:20:09 +000069#ifdef SIGXFSZ
Chris Lattner62f50da2010-02-12 00:37:46 +000070 , SIGXFSZ
71#endif
Reid Spencer3d7a6142004-08-29 19:22:48 +000072#ifdef SIGEMT
73 , SIGEMT
74#endif
75};
Dan Gohman4e974ab2008-05-14 00:42:30 +000076static const int *const KillSigsEnd =
77 KillSigs + sizeof(KillSigs) / sizeof(KillSigs[0]);
Reid Spencer3d7a6142004-08-29 19:22:48 +000078
Chris Lattnerfb954722009-03-23 05:55:36 +000079static unsigned NumRegisteredSignals = 0;
80static struct {
81 struct sigaction SA;
82 int SigNo;
83} RegisteredSignalInfo[(sizeof(IntSigs)+sizeof(KillSigs))/sizeof(KillSigs[0])];
84
85
Chris Lattnerf299a682009-03-23 05:42:29 +000086static void RegisterHandler(int Signal) {
Chris Lattnerfb954722009-03-23 05:55:36 +000087 assert(NumRegisteredSignals <
88 sizeof(RegisteredSignalInfo)/sizeof(RegisteredSignalInfo[0]) &&
89 "Out of space for signal handlers!");
90
91 struct sigaction NewHandler;
Michael J. Spencer447762d2010-11-29 18:16:10 +000092
Chris Lattnerfb954722009-03-23 05:55:36 +000093 NewHandler.sa_handler = SignalHandler;
94 NewHandler.sa_flags = SA_NODEFER|SA_RESETHAND;
Michael J. Spencer447762d2010-11-29 18:16:10 +000095 sigemptyset(&NewHandler.sa_mask);
96
Chris Lattnerfb954722009-03-23 05:55:36 +000097 // Install the new handler, save the old one in RegisteredSignalInfo.
98 sigaction(Signal, &NewHandler,
99 &RegisteredSignalInfo[NumRegisteredSignals].SA);
100 RegisteredSignalInfo[NumRegisteredSignals].SigNo = Signal;
101 ++NumRegisteredSignals;
Chris Lattner6acb4d62009-03-07 08:15:47 +0000102}
103
Chris Lattnerf299a682009-03-23 05:42:29 +0000104static void RegisterHandlers() {
Chris Lattnerfb954722009-03-23 05:55:36 +0000105 // If the handlers are already registered, we're done.
106 if (NumRegisteredSignals != 0) return;
107
Chris Lattnerf299a682009-03-23 05:42:29 +0000108 std::for_each(IntSigs, IntSigsEnd, RegisterHandler);
109 std::for_each(KillSigs, KillSigsEnd, RegisterHandler);
110}
111
Chris Lattnerf299a682009-03-23 05:42:29 +0000112static void UnregisterHandlers() {
Chris Lattnerfb954722009-03-23 05:55:36 +0000113 // Restore all of the signal handlers to how they were before we showed up.
114 for (unsigned i = 0, e = NumRegisteredSignals; i != e; ++i)
Chris Lattnerf2b60652009-03-23 06:46:20 +0000115 sigaction(RegisteredSignalInfo[i].SigNo,
116 &RegisteredSignalInfo[i].SA, 0);
Chris Lattnerfb954722009-03-23 05:55:36 +0000117 NumRegisteredSignals = 0;
Chris Lattnerf299a682009-03-23 05:42:29 +0000118}
119
120
Dan Gohman288999b2010-05-27 23:11:55 +0000121/// RemoveFilesToRemove - Process the FilesToRemove list. This function
122/// should be called with the SignalsMutex lock held.
Chandler Carruthe6196eb2012-06-16 00:09:41 +0000123/// NB: This must be an async signal safe function. It cannot allocate or free
124/// memory, even in debug builds.
Dan Gohman288999b2010-05-27 23:11:55 +0000125static void RemoveFilesToRemove() {
Daniel Dunbar511479d2012-10-17 16:30:54 +0000126 // We avoid iterators in case of debug iterators that allocate or release
Chandler Carruthe6196eb2012-06-16 00:09:41 +0000127 // memory.
128 for (unsigned i = 0, e = FilesToRemove.size(); i != e; ++i) {
Daniel Dunbar511479d2012-10-17 16:30:54 +0000129 // We rely on a std::string implementation for which repeated calls to
130 // 'c_str()' don't allocate memory. We pre-call 'c_str()' on all of these
131 // strings to try to ensure this is safe.
132 const char *path = FilesToRemove[i].c_str();
133
134 // Get the status so we can determine if it's a file or directory. If we
135 // can't stat the file, ignore it.
136 struct stat buf;
137 if (stat(path, &buf) != 0)
138 continue;
139
140 // If this is not a regular file, ignore it. We want to prevent removal of
141 // special files like /dev/null, even if the compiler is being run with the
142 // super-user permissions.
143 if (!S_ISREG(buf.st_mode))
144 continue;
145
146 // Otherwise, remove the file. We ignore any errors here as there is nothing
147 // else we can do.
148 unlink(path);
Dan Gohman288999b2010-05-27 23:11:55 +0000149 }
150}
Chris Lattner6acb4d62009-03-07 08:15:47 +0000151
152// SignalHandler - The signal handler that runs.
Chris Lattner4fdd0422009-03-04 21:21:36 +0000153static RETSIGTYPE SignalHandler(int Sig) {
Chris Lattnerbbbbbf32009-03-05 18:22:14 +0000154 // Restore the signal behavior to default, so that the program actually
155 // crashes when we return and the signal reissues. This also ensures that if
156 // we crash in our signal handler that the program will terminate immediately
157 // instead of recursing in the signal handler.
Chris Lattnerf299a682009-03-23 05:42:29 +0000158 UnregisterHandlers();
Chris Lattner6acb4d62009-03-07 08:15:47 +0000159
160 // Unmask all potentially blocked kill signals.
161 sigset_t SigMask;
162 sigfillset(&SigMask);
163 sigprocmask(SIG_UNBLOCK, &SigMask, 0);
Chris Lattnerbbbbbf32009-03-05 18:22:14 +0000164
Owen Anderson820739d2009-08-17 17:07:22 +0000165 SignalsMutex.acquire();
Dan Gohman288999b2010-05-27 23:11:55 +0000166 RemoveFilesToRemove();
Chris Lattner4fdd0422009-03-04 21:21:36 +0000167
168 if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd) {
169 if (InterruptFunction) {
170 void (*IF)() = InterruptFunction;
Owen Anderson820739d2009-08-17 17:07:22 +0000171 SignalsMutex.release();
Chris Lattner4fdd0422009-03-04 21:21:36 +0000172 InterruptFunction = 0;
173 IF(); // run the interrupt function.
174 return;
175 }
Michael J. Spencer447762d2010-11-29 18:16:10 +0000176
Owen Anderson820739d2009-08-17 17:07:22 +0000177 SignalsMutex.release();
Chris Lattnerce8b7d22009-04-12 23:33:13 +0000178 raise(Sig); // Execute the default handler.
179 return;
Chris Lattner4fdd0422009-03-04 21:21:36 +0000180 }
181
Owen Anderson820739d2009-08-17 17:07:22 +0000182 SignalsMutex.release();
183
Chris Lattner4fdd0422009-03-04 21:21:36 +0000184 // Otherwise if it is a fault (like SEGV) run any handler.
Jeffrey Yasskinc4e3f052010-03-17 07:08:12 +0000185 for (unsigned i = 0, e = CallBacksToRun.size(); i != e; ++i)
186 CallBacksToRun[i].first(CallBacksToRun[i].second);
Chris Lattner4fdd0422009-03-04 21:21:36 +0000187}
188
Daniel Dunbar68272562010-05-08 02:10:34 +0000189void llvm::sys::RunInterruptHandlers() {
Dan Gohman288999b2010-05-27 23:11:55 +0000190 SignalsMutex.acquire();
191 RemoveFilesToRemove();
192 SignalsMutex.release();
Daniel Dunbar68272562010-05-08 02:10:34 +0000193}
Chris Lattner4fdd0422009-03-04 21:21:36 +0000194
Chris Lattnerbb1ba7b2009-03-08 19:13:45 +0000195void llvm::sys::SetInterruptFunction(void (*IF)()) {
Owen Anderson820739d2009-08-17 17:07:22 +0000196 SignalsMutex.acquire();
Chris Lattner4fdd0422009-03-04 21:21:36 +0000197 InterruptFunction = IF;
Owen Anderson820739d2009-08-17 17:07:22 +0000198 SignalsMutex.release();
Chris Lattnerf299a682009-03-23 05:42:29 +0000199 RegisterHandlers();
Chris Lattner4fdd0422009-03-04 21:21:36 +0000200}
201
202// RemoveFileOnSignal - The public API
Chris Lattnerbb1ba7b2009-03-08 19:13:45 +0000203bool llvm::sys::RemoveFileOnSignal(const sys::Path &Filename,
204 std::string* ErrMsg) {
Owen Anderson820739d2009-08-17 17:07:22 +0000205 SignalsMutex.acquire();
Chandler Carruth52de2712012-06-16 00:44:07 +0000206 std::string *OldPtr = FilesToRemove.empty() ? 0 : &FilesToRemove[0];
Chandler Carruthe6196eb2012-06-16 00:09:41 +0000207 FilesToRemove.push_back(Filename.str());
208
209 // We want to call 'c_str()' on every std::string in this vector so that if
210 // the underlying implementation requires a re-allocation, it happens here
211 // rather than inside of the signal handler. If we see the vector grow, we
212 // have to call it on every entry. If it remains in place, we only need to
213 // call it on the latest one.
214 if (OldPtr == &FilesToRemove[0])
215 FilesToRemove.back().c_str();
216 else
217 for (unsigned i = 0, e = FilesToRemove.size(); i != e; ++i)
218 FilesToRemove[i].c_str();
Chris Lattner4fdd0422009-03-04 21:21:36 +0000219
Owen Anderson820739d2009-08-17 17:07:22 +0000220 SignalsMutex.release();
221
Chris Lattnerf299a682009-03-23 05:42:29 +0000222 RegisterHandlers();
Chris Lattner4fdd0422009-03-04 21:21:36 +0000223 return false;
224}
225
Dan Gohmane201c072010-09-01 14:17:34 +0000226// DontRemoveFileOnSignal - The public API
227void llvm::sys::DontRemoveFileOnSignal(const sys::Path &Filename) {
228 SignalsMutex.acquire();
Chandler Carruthe6196eb2012-06-16 00:09:41 +0000229 std::vector<std::string>::reverse_iterator RI =
230 std::find(FilesToRemove.rbegin(), FilesToRemove.rend(), Filename.str());
231 std::vector<std::string>::iterator I = FilesToRemove.end();
232 if (RI != FilesToRemove.rend())
233 I = FilesToRemove.erase(RI.base()-1);
234
235 // We need to call c_str() on every element which would have been moved by
236 // the erase. These elements, in a C++98 implementation where c_str()
237 // requires a reallocation on the first call may have had the call to c_str()
238 // made on insertion become invalid by being copied down an element.
239 for (std::vector<std::string>::iterator E = FilesToRemove.end(); I != E; ++I)
240 I->c_str();
241
Dan Gohmane201c072010-09-01 14:17:34 +0000242 SignalsMutex.release();
243}
244
Chris Lattner4fdd0422009-03-04 21:21:36 +0000245/// AddSignalHandler - Add a function to be called when a signal is delivered
246/// to the process. The handler can have a cookie passed to it to identify
247/// what instance of the handler it is.
Chris Lattnerbb1ba7b2009-03-08 19:13:45 +0000248void llvm::sys::AddSignalHandler(void (*FnPtr)(void *), void *Cookie) {
Jeffrey Yasskinc4e3f052010-03-17 07:08:12 +0000249 CallBacksToRun.push_back(std::make_pair(FnPtr, Cookie));
Chris Lattnerf299a682009-03-23 05:42:29 +0000250 RegisterHandlers();
Chris Lattner4fdd0422009-03-04 21:21:36 +0000251}
252
Reid Spencer3d7a6142004-08-29 19:22:48 +0000253
254// PrintStackTrace - In the case of a program crash or fault, print out a stack
255// trace so that the user has an indication of why and where we died.
256//
257// On glibc systems we have the 'backtrace' function, which works nicely, but
Michael J. Spencer447762d2010-11-29 18:16:10 +0000258// doesn't demangle symbols.
Argyrios Kyrtzidiseb9ae762013-01-09 19:42:40 +0000259void llvm::sys::PrintStackTrace(FILE *FD) {
Benjamin Kramer5651cbd2012-09-28 10:10:46 +0000260#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES)
Chris Lattner4fdd0422009-03-04 21:21:36 +0000261 static void* StackTrace[256];
Reid Spencer3d7a6142004-08-29 19:22:48 +0000262 // Use backtrace() to output a backtrace on Linux systems with glibc.
Evan Cheng86cb3182008-05-05 18:30:58 +0000263 int depth = backtrace(StackTrace,
264 static_cast<int>(array_lengthof(StackTrace)));
Dan Gohman7f079aa2008-12-05 20:12:48 +0000265#if HAVE_DLFCN_H && __GNUG__
266 int width = 0;
267 for (int i = 0; i < depth; ++i) {
268 Dl_info dlinfo;
269 dladdr(StackTrace[i], &dlinfo);
Dan Gohman1f517dd2009-02-10 17:56:28 +0000270 const char* name = strrchr(dlinfo.dli_fname, '/');
Dan Gohman7f079aa2008-12-05 20:12:48 +0000271
272 int nwidth;
273 if (name == NULL) nwidth = strlen(dlinfo.dli_fname);
274 else nwidth = strlen(name) - 1;
275
276 if (nwidth > width) width = nwidth;
277 }
278
279 for (int i = 0; i < depth; ++i) {
280 Dl_info dlinfo;
281 dladdr(StackTrace[i], &dlinfo);
282
Argyrios Kyrtzidiseb9ae762013-01-09 19:42:40 +0000283 fprintf(FD, "%-2d", i);
Dan Gohman7f079aa2008-12-05 20:12:48 +0000284
Dan Gohman1f517dd2009-02-10 17:56:28 +0000285 const char* name = strrchr(dlinfo.dli_fname, '/');
Argyrios Kyrtzidiseb9ae762013-01-09 19:42:40 +0000286 if (name == NULL) fprintf(FD, " %-*s", width, dlinfo.dli_fname);
287 else fprintf(FD, " %-*s", width, name+1);
Dan Gohman7f079aa2008-12-05 20:12:48 +0000288
Argyrios Kyrtzidiseb9ae762013-01-09 19:42:40 +0000289 fprintf(FD, " %#0*lx",
Dan Gohman35e2cfc2008-12-05 23:39:24 +0000290 (int)(sizeof(void*) * 2) + 2, (unsigned long)StackTrace[i]);
Dan Gohman7f079aa2008-12-05 20:12:48 +0000291
292 if (dlinfo.dli_sname != NULL) {
293 int res;
Argyrios Kyrtzidiseb9ae762013-01-09 19:42:40 +0000294 fputc(' ', FD);
Dan Gohman7f079aa2008-12-05 20:12:48 +0000295 char* d = abi::__cxa_demangle(dlinfo.dli_sname, NULL, NULL, &res);
Argyrios Kyrtzidiseb9ae762013-01-09 19:42:40 +0000296 if (d == NULL) fputs(dlinfo.dli_sname, FD);
297 else fputs(d, FD);
Dan Gohman7f079aa2008-12-05 20:12:48 +0000298 free(d);
299
Edwin Vane44338e02013-01-28 19:34:42 +0000300 // FIXME: When we move to C++11, use %t length modifier. It's not in
301 // C++03 and causes gcc to issue warnings. Losing the upper 32 bits of
302 // the stack offset for a stack dump isn't likely to cause any problems.
303 fprintf(FD, " + %u",(unsigned)((char*)StackTrace[i]-
304 (char*)dlinfo.dli_saddr));
Dan Gohman7f079aa2008-12-05 20:12:48 +0000305 }
Argyrios Kyrtzidiseb9ae762013-01-09 19:42:40 +0000306 fputc('\n', FD);
Dan Gohman7f079aa2008-12-05 20:12:48 +0000307 }
308#else
Lauro Ramos Venancioeab51d32008-02-15 18:05:54 +0000309 backtrace_symbols_fd(StackTrace, depth, STDERR_FILENO);
Reid Spencer3d7a6142004-08-29 19:22:48 +0000310#endif
Dan Gohman7f079aa2008-12-05 20:12:48 +0000311#endif
Reid Spencer3d7a6142004-08-29 19:22:48 +0000312}
313
Argyrios Kyrtzidiseb9ae762013-01-09 19:42:40 +0000314static void PrintStackTraceSignalHandler(void *) {
315 PrintStackTrace(stderr);
316}
317
NAKAMURA Takumi8a54d812012-09-06 03:01:43 +0000318/// PrintStackTraceOnErrorSignal - When an error signal (such as SIGABRT or
Reid Spencer3d7a6142004-08-29 19:22:48 +0000319/// SIGSEGV) is delivered to the process, print a stack trace and then exit.
Chris Lattnerbb1ba7b2009-03-08 19:13:45 +0000320void llvm::sys::PrintStackTraceOnErrorSignal() {
Argyrios Kyrtzidiseb9ae762013-01-09 19:42:40 +0000321 AddSignalHandler(PrintStackTraceSignalHandler, 0);
Argyrios Kyrtzidiscd8fe082012-01-11 20:53:25 +0000322
323#if defined(__APPLE__)
324 // Environment variable to disable any kind of crash dialog.
325 if (getenv("LLVM_DISABLE_CRASH_REPORT")) {
326 mach_port_t self = mach_task_self();
327
328 exception_mask_t mask = EXC_MASK_CRASH;
329
NAKAMURA Takumiffa15712012-09-06 03:02:56 +0000330 kern_return_t ret = task_set_exception_ports(self,
Argyrios Kyrtzidiscd8fe082012-01-11 20:53:25 +0000331 mask,
Jean-Daniel Dupasa573b222012-03-24 22:17:50 +0000332 MACH_PORT_NULL,
NAKAMURA Takumiffa15712012-09-06 03:02:56 +0000333 EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES,
Jean-Daniel Dupasa573b222012-03-24 22:17:50 +0000334 THREAD_STATE_NONE);
Argyrios Kyrtzidiscd8fe082012-01-11 20:53:25 +0000335 (void)ret;
336 }
337#endif
Reid Spencer3d7a6142004-08-29 19:22:48 +0000338}
Chris Lattner4fdd0422009-03-04 21:21:36 +0000339
Daniel Dunbarf14d9462010-08-19 23:45:39 +0000340
341/***/
342
343// On Darwin, raise sends a signal to the main thread instead of the current
344// thread. This has the unfortunate effect that assert() and abort() will end up
345// bypassing our crash recovery attempts. We work around this for anything in
346// the same linkage unit by just defining our own versions of the assert handler
347// and abort.
348
349#ifdef __APPLE__
350
Douglas Gregor0e506822011-04-29 16:12:17 +0000351#include <signal.h>
352#include <pthread.h>
353
Daniel Dunbar18456f32010-09-22 17:46:10 +0000354int raise(int sig) {
Daniel Dunbarcc0e18d2010-10-08 18:31:34 +0000355 return pthread_kill(pthread_self(), sig);
Daniel Dunbar18456f32010-09-22 17:46:10 +0000356}
357
Daniel Dunbarf14d9462010-08-19 23:45:39 +0000358void __assert_rtn(const char *func,
359 const char *file,
360 int line,
361 const char *expr) {
362 if (func)
363 fprintf(stderr, "Assertion failed: (%s), function %s, file %s, line %d.\n",
364 expr, func, file, line);
365 else
366 fprintf(stderr, "Assertion failed: (%s), file %s, line %d.\n",
367 expr, file, line);
368 abort();
369}
370
Daniel Dunbarf14d9462010-08-19 23:45:39 +0000371void abort() {
Daniel Dunbar18456f32010-09-22 17:46:10 +0000372 raise(SIGABRT);
Daniel Dunbarf14d9462010-08-19 23:45:39 +0000373 usleep(1000);
374 __builtin_trap();
375}
376
377#endif