/// \brief Disable crash recovery.
static void Disable();
+ /// \brief Return the active context, if the code is currently executing in a
+ /// thread which is in a protected context.
+ static CrashRecoveryContext *GetCurrent();
+
/// \brief Execute the provide callback function (with the given arguments) in
/// a protected context.
///
static sys::ThreadLocal<const CrashRecoveryContextImpl> CurrentContext;
struct CrashRecoveryContextImpl {
+ CrashRecoveryContext *CRC;
std::string Backtrace;
::jmp_buf JumpBuffer;
volatile unsigned Failed : 1;
public:
- CrashRecoveryContextImpl() : Failed(false) {
+ CrashRecoveryContextImpl(CrashRecoveryContext *CRC) : CRC(CRC),
+ Failed(false) {
CurrentContext.set(this);
}
~CrashRecoveryContextImpl() {
delete CRCI;
}
+CrashRecoveryContext *CrashRecoveryContext::GetCurrent() {
+ const CrashRecoveryContextImpl *CRCI = CurrentContext.get();
+ if (!CRCI)
+ return 0;
+
+ return CRCI->CRC;
+}
+
#ifdef LLVM_ON_WIN32
// FIXME: No real Win32 implementation currently.
// If crash recovery is disabled, do nothing.
if (gCrashRecoveryEnabled) {
assert(!Impl && "Crash recovery context already initialized!");
- CrashRecoveryContextImpl *CRCI = new CrashRecoveryContextImpl;
+ CrashRecoveryContextImpl *CRCI = new CrashRecoveryContextImpl(this);
Impl = CRCI;
if (setjmp(CRCI->JumpBuffer) != 0) {