9#ifndef LLVM_SUPPORT_CRASHRECOVERYCONTEXT_H
10#define LLVM_SUPPORT_CRASHRECOVERYCONTEXT_H
15class CrashRecoveryContextCleanup;
83 return RunSafely([&]() { Fn(UserData); });
96 unsigned RequestedStackSize = 0) {
159template<
typename Derived,
typename T>
174 return new Derived(
context, x);
251template <
typename T,
typename Cleanup = CrashRecoveryContextDeleteCleanup<T> >
257 : cleanup(
Cleanup::create(x)) {
static void cleanup(BlockFrequencyInfoImplBase &BFI)
Clear all memory not needed downstream.
static const HTTPClientCleanup Cleanup
Base class of cleanup handler that controls recovery of resources of the given type.
CrashRecoveryContextCleanupBase(CrashRecoveryContext *context, T *resource)
static Derived * create(T *x)
Creates cleanup handler.
Helper class for managing resource cleanups.
~CrashRecoveryContextCleanupRegistrar()
CrashRecoveryContextCleanupRegistrar(T *x)
Abstract base class of cleanup handlers.
CrashRecoveryContextCleanup(CrashRecoveryContext *context)
virtual ~CrashRecoveryContextCleanup()
CrashRecoveryContext * context
virtual void recoverResources()=0
CrashRecoveryContext * getContext() const
Cleanup handler that reclaims resource by calling 'delete' on it.
CrashRecoveryContextDeleteCleanup(CrashRecoveryContext *context, T *resource)
void recoverResources() override
Cleanup handler that reclaims resource by calling destructor on it.
void recoverResources() override
CrashRecoveryContextDestructorCleanup(CrashRecoveryContext *context, T *resource)
Cleanup handler that reclaims resource by calling its method 'Release'.
void recoverResources() override
CrashRecoveryContextReleaseRefCleanup(CrashRecoveryContext *context, T *resource)
Crash recovery helper object.
static bool isCrash(int RetCode)
Return true if RetCode indicates that a signal or an exception occurred.
static CrashRecoveryContext * GetCurrent()
Return the active context, if the code is currently executing in a thread which is in a protected con...
void HandleExit(int RetCode)
Explicitly trigger a crash recovery in the current process, and return failure from RunSafely().
static void Enable()
Enable crash recovery.
bool DumpStackAndCleanupOnFailure
Selects whether handling of failures should be done in the same way as for regular crashes.
void unregisterCleanup(CrashRecoveryContextCleanup *cleanup)
bool RunSafely(function_ref< void()> Fn)
Execute the provided callback function (with the given arguments) in a protected context.
static void Disable()
Disable crash recovery.
int RetCode
In case of a crash, this is the crash identifier.
static bool isRecoveringFromCrash()
Return true if the current thread is recovering from a crash.
static 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)
void registerCleanup(CrashRecoveryContextCleanup *cleanup)
Register cleanup handler, which is used when the recovery context is finished.
bool RunSafely(void(*Fn)(void *), void *UserData)
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.