[llvm] r184380 - [Support/CrashRecoveryContext] Make sure CrashRecoveryContext does not clear the thread-local "CurrentContext"
Argyrios Kyrtzidis
akyrtzi at gmail.com
Wed Jun 19 15:53:45 PDT 2013
Author: akirtzidis
Date: Wed Jun 19 17:53:45 2013
New Revision: 184380
URL: http://llvm.org/viewvc/llvm-project?rev=184380&view=rev
Log:
[Support/CrashRecoveryContext] Make sure CrashRecoveryContext does not clear the thread-local "CurrentContext"
in the "parent" thread, when we are using CrashRecoveryContext::RunSafelyOnThread.
When using CrashRecoveryContext::RunSafelyOnThread, we would set a CrashRecoveryContextImpl* to a thread-local variable
for the "child" thread, but CrashRecoveryContext would erroneously clear it in the "parent" thread.
The result was that if CrashRecoveryContext::RunSafelyOnThread was called again in the "child" thread it would mess up
crash-recovery for its parent.
A test for this will be added in the clang repository.
rdar://14204560
Modified:
llvm/trunk/lib/Support/CrashRecoveryContext.cpp
Modified: llvm/trunk/lib/Support/CrashRecoveryContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CrashRecoveryContext.cpp?rev=184380&r1=184379&r2=184380&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CrashRecoveryContext.cpp (original)
+++ llvm/trunk/lib/Support/CrashRecoveryContext.cpp Wed Jun 19 17:53:45 2013
@@ -28,16 +28,23 @@ struct CrashRecoveryContextImpl {
std::string Backtrace;
::jmp_buf JumpBuffer;
volatile unsigned Failed : 1;
+ unsigned SwitchedThread : 1;
public:
CrashRecoveryContextImpl(CrashRecoveryContext *CRC) : CRC(CRC),
- Failed(false) {
+ Failed(false),
+ SwitchedThread(false) {
CurrentContext.set(this);
}
~CrashRecoveryContextImpl() {
- CurrentContext.erase();
+ if (!SwitchedThread)
+ CurrentContext.erase();
}
+ /// \brief Called when the separate crash-recovery thread was finished, to
+ /// indicate that we don't need to clear the thread-local CurrentContext.
+ void setSwitchedThread() { SwitchedThread = true; }
+
void HandleCrash() {
// Eliminate the current context entry, to avoid re-entering in case the
// cleanup code crashes.
@@ -342,5 +349,7 @@ bool CrashRecoveryContext::RunSafelyOnTh
unsigned RequestedStackSize) {
RunSafelyOnThreadInfo Info = { Fn, UserData, this, false };
llvm_execute_on_thread(RunSafelyOnThread_Dispatch, &Info, RequestedStackSize);
+ if (CrashRecoveryContextImpl *CRC = (CrashRecoveryContextImpl *)Impl)
+ CRC->setSwitchedThread();
return Info.Result;
}
More information about the llvm-commits
mailing list