diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2011-02-20 12:57:14 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2011-02-20 12:57:14 +0000 | 
| commit | cf099d11218cb6f6c5cce947d6738e347f07fb12 (patch) | |
| tree | d2b61ce94e654cb01a254d2195259db5f9cc3f3c /lib/Support/CrashRecoveryContext.cpp | |
| parent | 49011b52fcba02a6051957b84705159f52fae4e4 (diff) | |
Notes
Diffstat (limited to 'lib/Support/CrashRecoveryContext.cpp')
| -rw-r--r-- | lib/Support/CrashRecoveryContext.cpp | 30 | 
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/Support/CrashRecoveryContext.cpp b/lib/Support/CrashRecoveryContext.cpp index 49258ede83c1..bf8ca3f844b4 100644 --- a/lib/Support/CrashRecoveryContext.cpp +++ b/lib/Support/CrashRecoveryContext.cpp @@ -10,8 +10,8 @@  #include "llvm/Support/CrashRecoveryContext.h"  #include "llvm/ADT/SmallString.h"  #include "llvm/Config/config.h" -#include "llvm/System/Mutex.h" -#include "llvm/System/ThreadLocal.h" +#include "llvm/Support/Mutex.h" +#include "llvm/Support/ThreadLocal.h"  #include <setjmp.h>  #include <cstdio>  using namespace llvm; @@ -128,6 +128,9 @@ static void CrashRecoverySignalHandler(int Signal) {      // This call of Disable isn't thread safe, but it doesn't actually matter.      CrashRecoveryContext::Disable();      raise(Signal); + +    // The signal will be thrown once the signal mask is restored. +    return;    }    // Unblock the signal we received. @@ -202,3 +205,26 @@ const std::string &CrashRecoveryContext::getBacktrace() const {    assert(CRC->Failed && "No crash was detected!");    return CRC->Backtrace;  } + +// + +namespace { +struct RunSafelyOnThreadInfo { +  void (*UserFn)(void*); +  void *UserData; +  CrashRecoveryContext *CRC; +  bool Result; +}; +} + +static void RunSafelyOnThread_Dispatch(void *UserData) { +  RunSafelyOnThreadInfo *Info = +    reinterpret_cast<RunSafelyOnThreadInfo*>(UserData); +  Info->Result = Info->CRC->RunSafely(Info->UserFn, Info->UserData); +} +bool CrashRecoveryContext::RunSafelyOnThread(void (*Fn)(void*), void *UserData, +                                             unsigned RequestedStackSize) { +  RunSafelyOnThreadInfo Info = { Fn, UserData, this, false }; +  llvm_execute_on_thread(RunSafelyOnThread_Dispatch, &Info, RequestedStackSize); +  return Info.Result; +}  | 
