llvm.org GIT mirror llvm / f8254d6
CrashRecoveryContext: Add RunSafelyOnThread helper function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@118272 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 9 years ago
2 changed file(s) with 31 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
6666 /// the backtrace of the crash on failures.
6767 bool RunSafely(void (*Fn)(void*), void *UserData);
6868
69 /// \brief Execute the provide callback function (with the given arguments) in
70 /// a protected context which is run in another thread (optionally with a
71 /// requested stack size).
72 ///
73 /// See RunSafely() and llvm_execute_on_thread().
74 bool RunSafelyOnThread(void (*Fn)(void*), void *UserData,
75 unsigned RequestedStackSize = 0);
76
6977 /// \brief Explicitly trigger a crash recovery in the current process, and
7078 /// return failure from RunSafely(). This function does not return.
7179 void HandleCrash();
204204 assert(CRC->Failed && "No crash was detected!");
205205 return CRC->Backtrace;
206206 }
207
208 //
209
210 namespace {
211 struct RunSafelyOnThreadInfo {
212 void (*UserFn)(void*);
213 void *UserData;
214 CrashRecoveryContext *CRC;
215 bool Result;
216 };
217 }
218
219 static void RunSafelyOnThread_Dispatch(void *UserData) {
220 RunSafelyOnThreadInfo *Info =
221 reinterpret_cast(UserData);
222 Info->Result = Info->CRC->RunSafely(Info->UserFn, Info->UserData);
223 }
224 bool CrashRecoveryContext::RunSafelyOnThread(void (*Fn)(void*), void *UserData,
225 unsigned RequestedStackSize) {
226 RunSafelyOnThreadInfo Info = { Fn, UserData, this, false };
227 llvm_execute_on_thread(RunSafelyOnThread_Dispatch, &Info, RequestedStackSize);
228 return Info.Result;
229 }