Crash recovery helper object.

Synopsis

Declared in <llvm/Support/CrashRecoveryContext.h>

class CrashRecoveryContext;

Description

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.

Member Functions

Name

Description

CrashRecoveryContext [constructor]

Create a crash recovery context.

~CrashRecoveryContext [destructor]

Destroy the crash recovery context and run remaining cleanups.

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

Execute the provided callback on another thread with an optional stack size, equivalent to RunSafelyOnThread.

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

Unregister a previously registered cleanup handler.

Static Member Functions

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.

Data Members

Name

Description

DumpStackAndCleanupOnFailure

Whether failures are handled like regular crashes.

RetCode

In case of a crash, this is the crash identifier.

Created with MrDocs