LLVM: include/llvm/Support/CrashRecoveryContext.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9#ifndef LLVM_SUPPORT_CRASHRECOVERYCONTEXT_H

10#define LLVM_SUPPORT_CRASHRECOVERYCONTEXT_H

11

14

15namespace llvm {

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

48 void *Impl = nullptr;

50

51public:

54

55

56

57

59

61

62

64

65

67

68

69

71

72

74

75

76

77

78

79

80

81

83

84

85

86

87

88

89

90

91

93 unsigned RequestedStackSize = 0);

94

96 unsigned RequestedStackSize = 0);

97

98

99

101

102

104

105

106

108

109

111

112

113

114

116};

117

118

119

120

121

122

123

124

126protected:

130

131public:

133

136

140

141private:

144};

145

146

147

148

149

150

151

152

153

154

155

156

157template<typename Derived, typename T>

159protected:

163

164public:

165

166

167

168

170 if (x) {

172 return new Derived(context, x);

173 }

174 return nullptr;

175 }

176};

177

178

179template

192

193

194template

204

205

206template

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249template <typename T, typename Cleanup = CrashRecoveryContextDeleteCleanup >

252

253public:

255 : cleanup(Cleanup::create(x)) {

256 if (cleanup)

257 cleanup->getContext()->registerCleanup(cleanup);

258 }

259

261

263 if (cleanup && !cleanup->cleanupFired)

264 cleanup->getContext()->unregisterCleanup(cleanup);

265 cleanup = nullptr;

266 }

267};

268}

269

270#endif

static void cleanup(BlockFrequencyInfoImplBase &BFI)

Clear all memory not needed downstream.

static const HTTPClientCleanup Cleanup

CrashRecoveryContextCleanupBase(CrashRecoveryContext *context, T *resource)

Definition CrashRecoveryContext.h:161

T * resource

Definition CrashRecoveryContext.h:160

static Derived * create(T *x)

Creates cleanup handler.

Definition CrashRecoveryContext.h:169

~CrashRecoveryContextCleanupRegistrar()

Definition CrashRecoveryContext.h:260

void unregister()

Definition CrashRecoveryContext.h:262

CrashRecoveryContextCleanupRegistrar(T *x)

Definition CrashRecoveryContext.h:254

Abstract base class of cleanup handlers.

Definition CrashRecoveryContext.h:125

CrashRecoveryContextCleanup(CrashRecoveryContext *context)

Definition CrashRecoveryContext.h:128

virtual ~CrashRecoveryContextCleanup()

CrashRecoveryContext * context

Definition CrashRecoveryContext.h:127

virtual void recoverResources()=0

CrashRecoveryContext * getContext() const

Definition CrashRecoveryContext.h:137

friend class CrashRecoveryContext

Definition CrashRecoveryContext.h:142

bool cleanupFired

Definition CrashRecoveryContext.h:132

CrashRecoveryContextDeleteCleanup(CrashRecoveryContext *context, T *resource)

Definition CrashRecoveryContext.h:198

void recoverResources() override

Definition CrashRecoveryContext.h:202

void recoverResources() override

Definition CrashRecoveryContext.h:188

CrashRecoveryContextDestructorCleanup(CrashRecoveryContext *context, T *resource)

Definition CrashRecoveryContext.h:183

void recoverResources() override

Definition CrashRecoveryContext.h:215

CrashRecoveryContextReleaseRefCleanup(CrashRecoveryContext *context, T *resource)

Definition CrashRecoveryContext.h:210

Crash recovery helper object.

Definition CrashRecoveryContext.h:47

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.

Definition CrashRecoveryContext.h:115

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.

Definition CrashRecoveryContext.h:110

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.

LLVM_ABI void registerCleanup(CrashRecoveryContextCleanup *cleanup)

Register cleanup handler, which is used when the recovery context is finished.

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.