2004-08-30 03:22:48 +08:00
|
|
|
//===- Signals.cpp - Generic Unix Signals Implementation -----*- C++ -*-===//
|
2010-11-30 02:16:10 +08:00
|
|
|
//
|
2004-08-30 03:22:48 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2010-11-30 02:16:10 +08:00
|
|
|
//
|
2004-08-30 03:22:48 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines some helpful functions for dealing with the possibility of
|
2011-04-15 13:18:47 +08:00
|
|
|
// Unix signals occurring while your program is running.
|
2004-08-30 03:22:48 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Unix.h"
|
2007-09-07 12:06:50 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "llvm/Support/Mutex.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include <algorithm>
|
2012-06-16 08:09:41 +08:00
|
|
|
#include <string>
|
2004-08-30 03:22:48 +08:00
|
|
|
#include <vector>
|
2004-12-27 14:16:52 +08:00
|
|
|
#if HAVE_EXECINFO_H
|
2004-08-30 03:22:48 +08:00
|
|
|
# include <execinfo.h> // For backtrace().
|
|
|
|
#endif
|
2004-12-27 14:16:52 +08:00
|
|
|
#if HAVE_SIGNAL_H
|
2004-08-30 03:22:48 +08:00
|
|
|
#include <signal.h>
|
2004-12-27 14:16:52 +08:00
|
|
|
#endif
|
2007-04-08 02:52:17 +08:00
|
|
|
#if HAVE_SYS_STAT_H
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#endif
|
2013-04-28 06:12:32 +08:00
|
|
|
#if HAVE_CXXABI_H
|
|
|
|
#include cxxabi.h>
|
|
|
|
#endif
|
|
|
|
#if HAVE_DLFCN_H
|
2008-12-06 04:12:48 +08:00
|
|
|
#include <dlfcn.h>
|
|
|
|
#endif
|
2012-01-12 04:53:25 +08:00
|
|
|
#if HAVE_MACH_MACH_H
|
|
|
|
#include <mach/mach.h>
|
|
|
|
#endif
|
|
|
|
|
2006-08-02 01:59:14 +08:00
|
|
|
using namespace llvm;
|
2004-08-30 03:22:48 +08:00
|
|
|
|
2009-03-23 13:42:29 +08:00
|
|
|
static RETSIGTYPE SignalHandler(int Sig); // defined below.
|
|
|
|
|
2009-08-18 01:07:22 +08:00
|
|
|
static SmartMutex<true> SignalsMutex;
|
|
|
|
|
2005-08-02 10:14:22 +08:00
|
|
|
/// InterruptFunction - The function to call if ctrl-c is pressed.
|
2008-04-11 05:11:47 +08:00
|
|
|
static void (*InterruptFunction)() = 0;
|
2005-08-02 10:14:22 +08:00
|
|
|
|
2012-06-16 08:09:41 +08:00
|
|
|
static std::vector<std::string> FilesToRemove;
|
2010-03-17 15:08:12 +08:00
|
|
|
static std::vector<std::pair<void(*)(void*), void*> > CallBacksToRun;
|
2004-08-30 03:22:48 +08:00
|
|
|
|
2013-02-21 03:28:46 +08:00
|
|
|
// IntSigs - Signals that represent requested termination. There's no bug
|
|
|
|
// or failure, or if there is, it's not our direct responsibility. For whatever
|
|
|
|
// reason, our continued execution is no longer desirable.
|
2008-04-11 05:11:47 +08:00
|
|
|
static const int IntSigs[] = {
|
2013-02-21 03:15:01 +08:00
|
|
|
SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2
|
2004-08-30 03:22:48 +08:00
|
|
|
};
|
2008-05-14 08:42:30 +08:00
|
|
|
static const int *const IntSigsEnd =
|
|
|
|
IntSigs + sizeof(IntSigs) / sizeof(IntSigs[0]);
|
2004-08-30 03:22:48 +08:00
|
|
|
|
2013-02-21 03:28:46 +08:00
|
|
|
// KillSigs - Signals that represent that we have a bug, and our prompt
|
|
|
|
// termination has been ordered.
|
2008-04-11 05:11:47 +08:00
|
|
|
static const int KillSigs[] = {
|
2013-02-21 03:15:01 +08:00
|
|
|
SIGILL, SIGTRAP, SIGABRT, SIGFPE, SIGBUS, SIGSEGV, SIGQUIT
|
2010-02-12 08:37:46 +08:00
|
|
|
#ifdef SIGSYS
|
|
|
|
, SIGSYS
|
|
|
|
#endif
|
|
|
|
#ifdef SIGXCPU
|
|
|
|
, SIGXCPU
|
|
|
|
#endif
|
2010-02-15 02:20:09 +08:00
|
|
|
#ifdef SIGXFSZ
|
2010-02-12 08:37:46 +08:00
|
|
|
, SIGXFSZ
|
|
|
|
#endif
|
2004-08-30 03:22:48 +08:00
|
|
|
#ifdef SIGEMT
|
|
|
|
, SIGEMT
|
|
|
|
#endif
|
|
|
|
};
|
2008-05-14 08:42:30 +08:00
|
|
|
static const int *const KillSigsEnd =
|
|
|
|
KillSigs + sizeof(KillSigs) / sizeof(KillSigs[0]);
|
2004-08-30 03:22:48 +08:00
|
|
|
|
2009-03-23 13:55:36 +08:00
|
|
|
static unsigned NumRegisteredSignals = 0;
|
|
|
|
static struct {
|
|
|
|
struct sigaction SA;
|
|
|
|
int SigNo;
|
|
|
|
} RegisteredSignalInfo[(sizeof(IntSigs)+sizeof(KillSigs))/sizeof(KillSigs[0])];
|
|
|
|
|
|
|
|
|
2009-03-23 13:42:29 +08:00
|
|
|
static void RegisterHandler(int Signal) {
|
2009-03-23 13:55:36 +08:00
|
|
|
assert(NumRegisteredSignals <
|
|
|
|
sizeof(RegisteredSignalInfo)/sizeof(RegisteredSignalInfo[0]) &&
|
|
|
|
"Out of space for signal handlers!");
|
|
|
|
|
|
|
|
struct sigaction NewHandler;
|
2010-11-30 02:16:10 +08:00
|
|
|
|
2009-03-23 13:55:36 +08:00
|
|
|
NewHandler.sa_handler = SignalHandler;
|
|
|
|
NewHandler.sa_flags = SA_NODEFER|SA_RESETHAND;
|
2010-11-30 02:16:10 +08:00
|
|
|
sigemptyset(&NewHandler.sa_mask);
|
|
|
|
|
2009-03-23 13:55:36 +08:00
|
|
|
// Install the new handler, save the old one in RegisteredSignalInfo.
|
|
|
|
sigaction(Signal, &NewHandler,
|
|
|
|
&RegisteredSignalInfo[NumRegisteredSignals].SA);
|
|
|
|
RegisteredSignalInfo[NumRegisteredSignals].SigNo = Signal;
|
|
|
|
++NumRegisteredSignals;
|
2009-03-23 13:42:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void RegisterHandlers() {
|
2009-03-23 13:55:36 +08:00
|
|
|
// If the handlers are already registered, we're done.
|
|
|
|
if (NumRegisteredSignals != 0) return;
|
|
|
|
|
2009-03-23 13:42:29 +08:00
|
|
|
std::for_each(IntSigs, IntSigsEnd, RegisterHandler);
|
|
|
|
std::for_each(KillSigs, KillSigsEnd, RegisterHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UnregisterHandlers() {
|
2009-03-23 13:55:36 +08:00
|
|
|
// Restore all of the signal handlers to how they were before we showed up.
|
|
|
|
for (unsigned i = 0, e = NumRegisteredSignals; i != e; ++i)
|
2009-03-23 14:46:20 +08:00
|
|
|
sigaction(RegisteredSignalInfo[i].SigNo,
|
|
|
|
&RegisteredSignalInfo[i].SA, 0);
|
2009-03-23 13:55:36 +08:00
|
|
|
NumRegisteredSignals = 0;
|
2009-03-07 16:15:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-28 07:11:55 +08:00
|
|
|
/// RemoveFilesToRemove - Process the FilesToRemove list. This function
|
|
|
|
/// should be called with the SignalsMutex lock held.
|
2012-06-16 08:09:41 +08:00
|
|
|
/// NB: This must be an async signal safe function. It cannot allocate or free
|
|
|
|
/// memory, even in debug builds.
|
2010-05-28 07:11:55 +08:00
|
|
|
static void RemoveFilesToRemove() {
|
2012-10-18 00:30:54 +08:00
|
|
|
// We avoid iterators in case of debug iterators that allocate or release
|
2012-06-16 08:09:41 +08:00
|
|
|
// memory.
|
|
|
|
for (unsigned i = 0, e = FilesToRemove.size(); i != e; ++i) {
|
2012-10-18 00:30:54 +08:00
|
|
|
// We rely on a std::string implementation for which repeated calls to
|
|
|
|
// 'c_str()' don't allocate memory. We pre-call 'c_str()' on all of these
|
|
|
|
// strings to try to ensure this is safe.
|
|
|
|
const char *path = FilesToRemove[i].c_str();
|
|
|
|
|
|
|
|
// Get the status so we can determine if it's a file or directory. If we
|
|
|
|
// can't stat the file, ignore it.
|
|
|
|
struct stat buf;
|
|
|
|
if (stat(path, &buf) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If this is not a regular file, ignore it. We want to prevent removal of
|
|
|
|
// special files like /dev/null, even if the compiler is being run with the
|
|
|
|
// super-user permissions.
|
|
|
|
if (!S_ISREG(buf.st_mode))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Otherwise, remove the file. We ignore any errors here as there is nothing
|
|
|
|
// else we can do.
|
|
|
|
unlink(path);
|
2010-05-28 07:11:55 +08:00
|
|
|
}
|
|
|
|
}
|
2009-03-23 13:42:29 +08:00
|
|
|
|
2009-03-07 16:15:47 +08:00
|
|
|
// SignalHandler - The signal handler that runs.
|
2009-03-05 05:21:36 +08:00
|
|
|
static RETSIGTYPE SignalHandler(int Sig) {
|
2009-03-06 02:22:14 +08:00
|
|
|
// Restore the signal behavior to default, so that the program actually
|
|
|
|
// crashes when we return and the signal reissues. This also ensures that if
|
|
|
|
// we crash in our signal handler that the program will terminate immediately
|
|
|
|
// instead of recursing in the signal handler.
|
2009-03-23 13:42:29 +08:00
|
|
|
UnregisterHandlers();
|
2009-03-07 16:15:47 +08:00
|
|
|
|
|
|
|
// Unmask all potentially blocked kill signals.
|
|
|
|
sigset_t SigMask;
|
|
|
|
sigfillset(&SigMask);
|
|
|
|
sigprocmask(SIG_UNBLOCK, &SigMask, 0);
|
2009-03-06 02:22:14 +08:00
|
|
|
|
2009-08-18 01:07:22 +08:00
|
|
|
SignalsMutex.acquire();
|
2010-05-28 07:11:55 +08:00
|
|
|
RemoveFilesToRemove();
|
2009-03-05 05:21:36 +08:00
|
|
|
|
|
|
|
if (std::find(IntSigs, IntSigsEnd, Sig) != IntSigsEnd) {
|
|
|
|
if (InterruptFunction) {
|
|
|
|
void (*IF)() = InterruptFunction;
|
2009-08-18 01:07:22 +08:00
|
|
|
SignalsMutex.release();
|
2009-03-05 05:21:36 +08:00
|
|
|
InterruptFunction = 0;
|
|
|
|
IF(); // run the interrupt function.
|
|
|
|
return;
|
|
|
|
}
|
2010-11-30 02:16:10 +08:00
|
|
|
|
2009-08-18 01:07:22 +08:00
|
|
|
SignalsMutex.release();
|
2009-04-13 07:33:13 +08:00
|
|
|
raise(Sig); // Execute the default handler.
|
|
|
|
return;
|
2009-03-05 05:21:36 +08:00
|
|
|
}
|
|
|
|
|
2009-08-18 01:07:22 +08:00
|
|
|
SignalsMutex.release();
|
|
|
|
|
2009-03-05 05:21:36 +08:00
|
|
|
// Otherwise if it is a fault (like SEGV) run any handler.
|
2010-03-17 15:08:12 +08:00
|
|
|
for (unsigned i = 0, e = CallBacksToRun.size(); i != e; ++i)
|
|
|
|
CallBacksToRun[i].first(CallBacksToRun[i].second);
|
2009-03-05 05:21:36 +08:00
|
|
|
}
|
|
|
|
|
2010-05-08 10:10:34 +08:00
|
|
|
void llvm::sys::RunInterruptHandlers() {
|
2010-05-28 07:11:55 +08:00
|
|
|
SignalsMutex.acquire();
|
|
|
|
RemoveFilesToRemove();
|
|
|
|
SignalsMutex.release();
|
2010-05-08 10:10:34 +08:00
|
|
|
}
|
2009-03-05 05:21:36 +08:00
|
|
|
|
2009-03-09 03:13:45 +08:00
|
|
|
void llvm::sys::SetInterruptFunction(void (*IF)()) {
|
2009-08-18 01:07:22 +08:00
|
|
|
SignalsMutex.acquire();
|
2009-03-05 05:21:36 +08:00
|
|
|
InterruptFunction = IF;
|
2009-08-18 01:07:22 +08:00
|
|
|
SignalsMutex.release();
|
2009-03-23 13:42:29 +08:00
|
|
|
RegisterHandlers();
|
2009-03-05 05:21:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveFileOnSignal - The public API
|
2009-03-09 03:13:45 +08:00
|
|
|
bool llvm::sys::RemoveFileOnSignal(const sys::Path &Filename,
|
|
|
|
std::string* ErrMsg) {
|
2009-08-18 01:07:22 +08:00
|
|
|
SignalsMutex.acquire();
|
2012-06-16 08:44:07 +08:00
|
|
|
std::string *OldPtr = FilesToRemove.empty() ? 0 : &FilesToRemove[0];
|
2012-06-16 08:09:41 +08:00
|
|
|
FilesToRemove.push_back(Filename.str());
|
|
|
|
|
|
|
|
// We want to call 'c_str()' on every std::string in this vector so that if
|
|
|
|
// the underlying implementation requires a re-allocation, it happens here
|
|
|
|
// rather than inside of the signal handler. If we see the vector grow, we
|
|
|
|
// have to call it on every entry. If it remains in place, we only need to
|
|
|
|
// call it on the latest one.
|
|
|
|
if (OldPtr == &FilesToRemove[0])
|
|
|
|
FilesToRemove.back().c_str();
|
|
|
|
else
|
|
|
|
for (unsigned i = 0, e = FilesToRemove.size(); i != e; ++i)
|
|
|
|
FilesToRemove[i].c_str();
|
2009-03-05 05:21:36 +08:00
|
|
|
|
2009-08-18 01:07:22 +08:00
|
|
|
SignalsMutex.release();
|
|
|
|
|
2009-03-23 13:42:29 +08:00
|
|
|
RegisterHandlers();
|
2009-03-05 05:21:36 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-01 22:17:34 +08:00
|
|
|
// DontRemoveFileOnSignal - The public API
|
|
|
|
void llvm::sys::DontRemoveFileOnSignal(const sys::Path &Filename) {
|
|
|
|
SignalsMutex.acquire();
|
2012-06-16 08:09:41 +08:00
|
|
|
std::vector<std::string>::reverse_iterator RI =
|
|
|
|
std::find(FilesToRemove.rbegin(), FilesToRemove.rend(), Filename.str());
|
|
|
|
std::vector<std::string>::iterator I = FilesToRemove.end();
|
|
|
|
if (RI != FilesToRemove.rend())
|
|
|
|
I = FilesToRemove.erase(RI.base()-1);
|
|
|
|
|
|
|
|
// We need to call c_str() on every element which would have been moved by
|
|
|
|
// the erase. These elements, in a C++98 implementation where c_str()
|
|
|
|
// requires a reallocation on the first call may have had the call to c_str()
|
|
|
|
// made on insertion become invalid by being copied down an element.
|
|
|
|
for (std::vector<std::string>::iterator E = FilesToRemove.end(); I != E; ++I)
|
|
|
|
I->c_str();
|
|
|
|
|
2010-09-01 22:17:34 +08:00
|
|
|
SignalsMutex.release();
|
|
|
|
}
|
|
|
|
|
2009-03-05 05:21:36 +08:00
|
|
|
/// AddSignalHandler - Add a function to be called when a signal is delivered
|
|
|
|
/// to the process. The handler can have a cookie passed to it to identify
|
|
|
|
/// what instance of the handler it is.
|
2009-03-09 03:13:45 +08:00
|
|
|
void llvm::sys::AddSignalHandler(void (*FnPtr)(void *), void *Cookie) {
|
2010-03-17 15:08:12 +08:00
|
|
|
CallBacksToRun.push_back(std::make_pair(FnPtr, Cookie));
|
2009-03-23 13:42:29 +08:00
|
|
|
RegisterHandlers();
|
2009-03-05 05:21:36 +08:00
|
|
|
}
|
|
|
|
|
2004-08-30 03:22:48 +08:00
|
|
|
|
|
|
|
// PrintStackTrace - In the case of a program crash or fault, print out a stack
|
|
|
|
// trace so that the user has an indication of why and where we died.
|
|
|
|
//
|
|
|
|
// On glibc systems we have the 'backtrace' function, which works nicely, but
|
2010-11-30 02:16:10 +08:00
|
|
|
// doesn't demangle symbols.
|
2013-01-10 03:42:40 +08:00
|
|
|
void llvm::sys::PrintStackTrace(FILE *FD) {
|
2012-09-28 18:10:46 +08:00
|
|
|
#if defined(HAVE_BACKTRACE) && defined(ENABLE_BACKTRACES)
|
2009-03-05 05:21:36 +08:00
|
|
|
static void* StackTrace[256];
|
2004-08-30 03:22:48 +08:00
|
|
|
// Use backtrace() to output a backtrace on Linux systems with glibc.
|
2008-05-06 02:30:58 +08:00
|
|
|
int depth = backtrace(StackTrace,
|
|
|
|
static_cast<int>(array_lengthof(StackTrace)));
|
2008-12-06 04:12:48 +08:00
|
|
|
#if HAVE_DLFCN_H && __GNUG__
|
|
|
|
int width = 0;
|
|
|
|
for (int i = 0; i < depth; ++i) {
|
|
|
|
Dl_info dlinfo;
|
|
|
|
dladdr(StackTrace[i], &dlinfo);
|
2009-02-11 01:56:28 +08:00
|
|
|
const char* name = strrchr(dlinfo.dli_fname, '/');
|
2008-12-06 04:12:48 +08:00
|
|
|
|
|
|
|
int nwidth;
|
|
|
|
if (name == NULL) nwidth = strlen(dlinfo.dli_fname);
|
|
|
|
else nwidth = strlen(name) - 1;
|
|
|
|
|
|
|
|
if (nwidth > width) width = nwidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < depth; ++i) {
|
|
|
|
Dl_info dlinfo;
|
|
|
|
dladdr(StackTrace[i], &dlinfo);
|
|
|
|
|
2013-01-10 03:42:40 +08:00
|
|
|
fprintf(FD, "%-2d", i);
|
2008-12-06 04:12:48 +08:00
|
|
|
|
2009-02-11 01:56:28 +08:00
|
|
|
const char* name = strrchr(dlinfo.dli_fname, '/');
|
2013-01-10 03:42:40 +08:00
|
|
|
if (name == NULL) fprintf(FD, " %-*s", width, dlinfo.dli_fname);
|
|
|
|
else fprintf(FD, " %-*s", width, name+1);
|
2008-12-06 04:12:48 +08:00
|
|
|
|
2013-01-10 03:42:40 +08:00
|
|
|
fprintf(FD, " %#0*lx",
|
2008-12-06 07:39:24 +08:00
|
|
|
(int)(sizeof(void*) * 2) + 2, (unsigned long)StackTrace[i]);
|
2008-12-06 04:12:48 +08:00
|
|
|
|
|
|
|
if (dlinfo.dli_sname != NULL) {
|
|
|
|
int res;
|
2013-01-10 03:42:40 +08:00
|
|
|
fputc(' ', FD);
|
2013-04-28 06:12:32 +08:00
|
|
|
# if HAVE_CXXABI_H
|
2008-12-06 04:12:48 +08:00
|
|
|
char* d = abi::__cxa_demangle(dlinfo.dli_sname, NULL, NULL, &res);
|
2013-04-28 06:12:32 +08:00
|
|
|
# else
|
|
|
|
char* d = NULL;
|
|
|
|
# endif
|
2013-01-10 03:42:40 +08:00
|
|
|
if (d == NULL) fputs(dlinfo.dli_sname, FD);
|
|
|
|
else fputs(d, FD);
|
2008-12-06 04:12:48 +08:00
|
|
|
free(d);
|
|
|
|
|
2013-01-29 03:34:42 +08:00
|
|
|
// FIXME: When we move to C++11, use %t length modifier. It's not in
|
|
|
|
// C++03 and causes gcc to issue warnings. Losing the upper 32 bits of
|
|
|
|
// the stack offset for a stack dump isn't likely to cause any problems.
|
|
|
|
fprintf(FD, " + %u",(unsigned)((char*)StackTrace[i]-
|
|
|
|
(char*)dlinfo.dli_saddr));
|
2008-12-06 04:12:48 +08:00
|
|
|
}
|
2013-01-10 03:42:40 +08:00
|
|
|
fputc('\n', FD);
|
2008-12-06 04:12:48 +08:00
|
|
|
}
|
|
|
|
#else
|
2008-02-16 02:05:54 +08:00
|
|
|
backtrace_symbols_fd(StackTrace, depth, STDERR_FILENO);
|
2004-08-30 03:22:48 +08:00
|
|
|
#endif
|
2008-12-06 04:12:48 +08:00
|
|
|
#endif
|
2004-08-30 03:22:48 +08:00
|
|
|
}
|
|
|
|
|
2013-01-10 03:42:40 +08:00
|
|
|
static void PrintStackTraceSignalHandler(void *) {
|
|
|
|
PrintStackTrace(stderr);
|
|
|
|
}
|
|
|
|
|
2012-09-06 11:01:43 +08:00
|
|
|
/// PrintStackTraceOnErrorSignal - When an error signal (such as SIGABRT or
|
2004-08-30 03:22:48 +08:00
|
|
|
/// SIGSEGV) is delivered to the process, print a stack trace and then exit.
|
2009-03-09 03:13:45 +08:00
|
|
|
void llvm::sys::PrintStackTraceOnErrorSignal() {
|
2013-01-10 03:42:40 +08:00
|
|
|
AddSignalHandler(PrintStackTraceSignalHandler, 0);
|
2012-01-12 04:53:25 +08:00
|
|
|
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
// Environment variable to disable any kind of crash dialog.
|
|
|
|
if (getenv("LLVM_DISABLE_CRASH_REPORT")) {
|
|
|
|
mach_port_t self = mach_task_self();
|
|
|
|
|
|
|
|
exception_mask_t mask = EXC_MASK_CRASH;
|
|
|
|
|
2012-09-06 11:02:56 +08:00
|
|
|
kern_return_t ret = task_set_exception_ports(self,
|
2012-01-12 04:53:25 +08:00
|
|
|
mask,
|
2012-03-25 06:17:50 +08:00
|
|
|
MACH_PORT_NULL,
|
2012-09-06 11:02:56 +08:00
|
|
|
EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES,
|
2012-03-25 06:17:50 +08:00
|
|
|
THREAD_STATE_NONE);
|
2012-01-12 04:53:25 +08:00
|
|
|
(void)ret;
|
|
|
|
}
|
|
|
|
#endif
|
2004-08-30 03:22:48 +08:00
|
|
|
}
|
2009-03-05 05:21:36 +08:00
|
|
|
|
2010-08-20 07:45:39 +08:00
|
|
|
|
|
|
|
/***/
|
|
|
|
|
|
|
|
// On Darwin, raise sends a signal to the main thread instead of the current
|
|
|
|
// thread. This has the unfortunate effect that assert() and abort() will end up
|
|
|
|
// bypassing our crash recovery attempts. We work around this for anything in
|
|
|
|
// the same linkage unit by just defining our own versions of the assert handler
|
|
|
|
// and abort.
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
2011-04-30 00:12:17 +08:00
|
|
|
#include <signal.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
2010-09-23 01:46:10 +08:00
|
|
|
int raise(int sig) {
|
2010-10-09 02:31:34 +08:00
|
|
|
return pthread_kill(pthread_self(), sig);
|
2010-09-23 01:46:10 +08:00
|
|
|
}
|
|
|
|
|
2010-08-20 07:45:39 +08:00
|
|
|
void __assert_rtn(const char *func,
|
|
|
|
const char *file,
|
|
|
|
int line,
|
|
|
|
const char *expr) {
|
|
|
|
if (func)
|
|
|
|
fprintf(stderr, "Assertion failed: (%s), function %s, file %s, line %d.\n",
|
|
|
|
expr, func, file, line);
|
|
|
|
else
|
|
|
|
fprintf(stderr, "Assertion failed: (%s), file %s, line %d.\n",
|
|
|
|
expr, file, line);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
void abort() {
|
2010-09-23 01:46:10 +08:00
|
|
|
raise(SIGABRT);
|
2010-08-20 07:45:39 +08:00
|
|
|
usleep(1000);
|
|
|
|
__builtin_trap();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|