10 #ifndef LLVM_SUPPORT_CRASHRECOVERYCONTEXT_H
11 #define LLVM_SUPPORT_CRASHRECOVERYCONTEXT_H
17 class CrashRecoveryContextCleanup;
79 return RunSafely([&]() { Fn(UserData); });
92 unsigned RequestedStackSize = 0) {
128 template<
typename DERIVED,
typename T>
138 return new DERIVED(
context, x);
144 template <
typename T>
158 template <
typename T>
169 template <
typename T>
177 T>(context, resource) {}
182 template <
typename T,
typename Cleanup = CrashRecoveryContextDeleteCleanup<T> >
187 : cleanup(
Cleanup::create(x)) {
An efficient, type-erasing, non-owning reference to a callable.
static CrashRecoveryContext * GetCurrent()
Return the active context, if the code is currently executing in a thread which is in a protected con...
void recoverResources() override
static void cleanup(BlockFrequencyInfoImplBase &BFI)
Clear all memory not needed downstream.
void recoverResources() override
~CrashRecoveryContextCleanupRegistrar()
virtual void recoverResources()
void HandleCrash()
Explicitly trigger a crash recovery in the current process, and return failure from RunSafely()...
CrashRecoveryContextDeleteCleanup(CrashRecoveryContext *context, T *resource)
const std::string & getBacktrace() const
Return a string containing the backtrace where the crash was detected; or empty if the backtrace wasn...
void unregisterCleanup(CrashRecoveryContextCleanup *cleanup)
virtual ~CrashRecoveryContextCleanup()
static void Enable()
Enable crash recovery.
CrashRecoveryContextCleanup(CrashRecoveryContext *context)
bool RunSafelyOnThread(function_ref< void()>, unsigned RequestedStackSize=0)
Execute the provide callback function (with the given arguments) in a protected context which is run ...
bool RunSafelyOnThread(void(*Fn)(void *), void *UserData, unsigned RequestedStackSize=0)
void registerCleanup(CrashRecoveryContextCleanup *cleanup)
static DERIVED * create(T *x)
bool RunSafely(void(*Fn)(void *), void *UserData)
CrashRecoveryContextReleaseRefCleanup(CrashRecoveryContext *context, T *resource)
virtual void recoverResources()=0
CrashRecoveryContext * context
bool RunSafely(function_ref< void()> Fn)
Execute the provide callback function (with the given arguments) in a protected context.
Crash recovery helper object.
CrashRecoveryContext * getContext() const
CrashRecoveryContextCleanupBase(CrashRecoveryContext *context, T *resource)
static bool isRecoveringFromCrash()
Return true if the current thread is recovering from a crash.
CrashRecoveryContextCleanupRegistrar(T *x)
static void Disable()
Disable crash recovery.
CrashRecoveryContextDestructorCleanup(CrashRecoveryContext *context, T *resource)