Crash recovery helper object.
Declared in <llvm/Support/CrashRecoveryContext.h>
class CrashRecoveryContext;
This class implements support for running operations in a safe context so that crashes (memory errors, stack overflow, assertion violations) can be detected and control restored to the crashing thread. Crash detection is purely "best effort", the exact set of failures which can be recovered from is platform dependent.
Clients make use of this code by first calling CrashRecoveryContext::Enable(), and then executing unsafe operations via a CrashRecoveryContext object. For example:
void actual_work(void *);
void foo() {
CrashRecoveryContext CRC;
if (!CRC.RunSafely(actual_work, 0)) {
... a crash was detected, report error to user ...
}
... no crash was detected ...
}
To assist recovery the class allows specifying set of actions that will be executed in any case, whether crash occurs or not. These actions may be used to reclaim resources in the case of crash.
| Name | Description |
|---|---|
CrashRecoveryContext [constructor] | Default constructor |
~CrashRecoveryContext [destructor] | Destructor |
HandleExit [noreturn] | Explicitly trigger a crash recovery in the current process, and return failure from RunSafely(). This function does not return. |
RunSafely | Execute the provided callback function (with the given arguments) in a protected context. |
RunSafelyOnNewStack | |
RunSafelyOnThread | Execute the provide callback function (with the given arguments) in a protected context which is run in another thread (optionally with a requested stack size). |
registerCleanup | Register cleanup handler, which is used when the recovery context is finished. The recovery context owns the handler. |
unregisterCleanup |
| Name | Description |
|---|---|
Disable | Disable crash recovery. |
Enable | Enable crash recovery. |
GetCurrent | Return the active context, if the code is currently executing in a thread which is in a protected context. |
isCrash | Return true if RetCode indicates that a signal or an exception occurred. |
isRecoveringFromCrash | Return true if the current thread is recovering from a crash. |
throwIfCrash | Throw again a signal or an exception, after it was catched once by a CrashRecoveryContext. |
| Name | Description |
|---|---|
DumpStackAndCleanupOnFailure | Selects whether handling of failures should be done in the same way as for regular crashes. When this is active, a crash would print the callstack, clean-up any temporary files and create a coredump/minidump. |
RetCode | In case of a crash, this is the crash identifier. |