diff options
Diffstat (limited to 'contrib/llvm/lib/System/Unix')
-rw-r--r-- | contrib/llvm/lib/System/Unix/Path.inc | 12 | ||||
-rw-r--r-- | contrib/llvm/lib/System/Unix/Signals.inc | 44 | ||||
-rw-r--r-- | contrib/llvm/lib/System/Unix/ThreadLocal.inc | 1 |
3 files changed, 51 insertions, 6 deletions
diff --git a/contrib/llvm/lib/System/Unix/Path.inc b/contrib/llvm/lib/System/Unix/Path.inc index bc104a3..47e4d1a 100644 --- a/contrib/llvm/lib/System/Unix/Path.inc +++ b/contrib/llvm/lib/System/Unix/Path.inc @@ -276,20 +276,20 @@ Path::GetCurrentDirectory() { char pathname[MAXPATHLEN]; if (!getcwd(pathname,MAXPATHLEN)) { assert (false && "Could not query current working directory."); - return Path(""); + return Path(); } return Path(pathname); } -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__minix) static int test_dir(char buf[PATH_MAX], char ret[PATH_MAX], const char *dir, const char *bin) { struct stat sb; - snprintf(buf, PATH_MAX, "%s//%s", dir, bin); + snprintf(buf, PATH_MAX, "%s/%s", dir, bin); if (realpath(buf, ret) == NULL) return (1); if (stat(buf, &sb) != 0) @@ -334,7 +334,7 @@ getprogpath(char ret[PATH_MAX], const char *bin) free(pv); return (NULL); } -#endif // __FreeBSD__ +#endif // __FreeBSD__ || __NetBSD__ /// GetMainExecutable - Return the path to the main executable, given the /// value of argv[0] from program startup. @@ -350,7 +350,7 @@ Path Path::GetMainExecutable(const char *argv0, void *MainAddr) { if (realpath(exe_path, link_path)) return Path(std::string(link_path)); } -#elif defined(__FreeBSD__) +#elif defined(__FreeBSD__) || defined (__NetBSD__) || defined(__minix) char exe_path[PATH_MAX]; if (getprogpath(exe_path, argv0) != NULL) @@ -408,7 +408,7 @@ Path::getSuffix() const { std::string::size_type dot = path.rfind('.'); if (dot == std::string::npos || dot < slash) - return StringRef(""); + return StringRef(); else return StringRef(path).substr(dot + 1); } diff --git a/contrib/llvm/lib/System/Unix/Signals.inc b/contrib/llvm/lib/System/Unix/Signals.inc index 1e74647..7b7c43e 100644 --- a/contrib/llvm/lib/System/Unix/Signals.inc +++ b/contrib/llvm/lib/System/Unix/Signals.inc @@ -182,6 +182,16 @@ bool llvm::sys::RemoveFileOnSignal(const sys::Path &Filename, return false; } +// DontRemoveFileOnSignal - The public API +void llvm::sys::DontRemoveFileOnSignal(const sys::Path &Filename) { + SignalsMutex.acquire(); + std::vector<sys::Path>::reverse_iterator I = + std::find(FilesToRemove.rbegin(), FilesToRemove.rend(), Filename); + if (I != FilesToRemove.rend()) + FilesToRemove.erase(I.base()-1); + SignalsMutex.release(); +} + /// 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. @@ -253,3 +263,37 @@ void llvm::sys::PrintStackTraceOnErrorSignal() { AddSignalHandler(PrintStackTrace, 0); } + +/***/ + +// 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__ + +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(); +} + +#include <signal.h> +#include <pthread.h> + +void abort() { + pthread_kill(pthread_self(), SIGABRT); + usleep(1000); + __builtin_trap(); +} + +#endif diff --git a/contrib/llvm/lib/System/Unix/ThreadLocal.inc b/contrib/llvm/lib/System/Unix/ThreadLocal.inc index 83d554d3..6769520 100644 --- a/contrib/llvm/lib/System/Unix/ThreadLocal.inc +++ b/contrib/llvm/lib/System/Unix/ThreadLocal.inc @@ -22,4 +22,5 @@ ThreadLocalImpl::ThreadLocalImpl() { } ThreadLocalImpl::~ThreadLocalImpl() { } void ThreadLocalImpl::setInstance(const void* d) { data = const_cast<void*>(d);} const void* ThreadLocalImpl::getInstance() { return data; } +void ThreadLocalImpl::removeInstance() { setInstance(0); } } |