9#ifndef LLVM_SUPPORT_CRASHRECOVERYCONTEXT_H
10#define LLVM_SUPPORT_CRASHRECOVERYCONTEXT_H
84 return RunSafely([&]() { Fn(UserData); });
96 unsigned RequestedStackSize = 0);
98 unsigned RequestedStackSize = 0) {
103 unsigned RequestedStackSize = 0);
164template<
typename Derived,
typename T>
179 return new Derived(
context, x);
256template <
typename T,
typename Cleanup = CrashRecoveryContextDeleteCleanup<T> >
262 : cleanup(
Cleanup::create(x)) {
264 cleanup->getContext()->registerCleanup(cleanup);
270 if (cleanup && !cleanup->cleanupFired)
271 cleanup->getContext()->unregisterCleanup(cleanup);
static void cleanup(BlockFrequencyInfoImplBase &BFI)
Clear all memory not needed downstream.
static const HTTPClientCleanup Cleanup
CrashRecoveryContextCleanupBase(CrashRecoveryContext *context, T *resource)
static Derived * create(T *x)
Creates cleanup handler.
~CrashRecoveryContextCleanupRegistrar()
CrashRecoveryContextCleanupRegistrar(T *x)
Abstract base class of cleanup handlers.
CrashRecoveryContextCleanup(CrashRecoveryContext *context)
virtual ~CrashRecoveryContextCleanup()
CrashRecoveryContext * context
virtual void recoverResources()=0
CrashRecoveryContext * getContext() const
friend class CrashRecoveryContext
CrashRecoveryContextDeleteCleanup(CrashRecoveryContext *context, T *resource)
void recoverResources() override
void recoverResources() override
CrashRecoveryContextDestructorCleanup(CrashRecoveryContext *context, T *resource)
void recoverResources() override
CrashRecoveryContextReleaseRefCleanup(CrashRecoveryContext *context, T *resource)
Crash recovery helper object.
static LLVM_ABI bool isCrash(int RetCode)
Return true if RetCode indicates that a signal or an exception occurred.
static LLVM_ABI CrashRecoveryContext * GetCurrent()
Return the active context, if the code is currently executing in a thread which is in a protected con...
LLVM_ABI void HandleExit(int RetCode)
Explicitly trigger a crash recovery in the current process, and return failure from RunSafely().
LLVM_ABI ~CrashRecoveryContext()
static LLVM_ABI void Enable()
Enable crash recovery.
LLVM_ABI bool RunSafelyOnNewStack(function_ref< void()>, unsigned RequestedStackSize=0)
bool DumpStackAndCleanupOnFailure
Selects whether handling of failures should be done in the same way as for regular crashes.
LLVM_ABI void unregisterCleanup(CrashRecoveryContextCleanup *cleanup)
LLVM_ABI bool RunSafely(function_ref< void()> Fn)
Execute the provided callback function (with the given arguments) in a protected context.
static LLVM_ABI void Disable()
Disable crash recovery.
int RetCode
In case of a crash, this is the crash identifier.
static LLVM_ABI bool isRecoveringFromCrash()
Return true if the current thread is recovering from a crash.
static LLVM_ABI bool throwIfCrash(int RetCode)
Throw again a signal or an exception, after it was catched once by a CrashRecoveryContext.
bool RunSafelyOnThread(void(*Fn)(void *), void *UserData, unsigned RequestedStackSize=0)
LLVM_ABI void registerCleanup(CrashRecoveryContextCleanup *cleanup)
Register cleanup handler, which is used when the recovery context is finished.
bool RunSafely(void(*Fn)(void *), void *UserData)
LLVM_ABI CrashRecoveryContext()
LLVM_ABI bool RunSafelyOnThread(function_ref< void()>, unsigned RequestedStackSize=0)
Execute the provide callback function (with the given arguments) in a protected context which is run ...
An efficient, type-erasing, non-owning reference to a callable.
This is an optimization pass for GlobalISel generic memory operations.