summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2016-12-08 20:38:19 +0000
committerGreg Clayton <gclayton@apple.com>2016-12-08 20:38:19 +0000
commitb5cd6e7b7ec244d8f8f4fdfd1f802e42ff48c34b (patch)
tree24f623dd42c3db5f60803bdb05c8209cdb8abfac
parent77a45576efa853c52feb48560ab1c7a6210b5878 (diff)
downloadbcm5719-llvm-b5cd6e7b7ec244d8f8f4fdfd1f802e42ff48c34b.tar.gz
bcm5719-llvm-b5cd6e7b7ec244d8f8f4fdfd1f802e42ff48c34b.zip
Fixed a crasher that has been borking out heap for a long time.
ThreadList had an assignment operator that didn't lock the "rhs" thread list object. This means a thread list can be mutated while it is being copied. The copy constructor calls the assignment operator as well. So this fixes the unsafe threaded access to ThreadList which we believe is responsible for a lot of crashes. <rdar://problem/28075793> llvm-svn: 289100
-rw-r--r--lldb/include/lldb/Target/ThreadCollection.h4
-rw-r--r--lldb/include/lldb/Target/ThreadList.h2
-rw-r--r--lldb/source/Target/ThreadList.cpp3
3 files changed, 5 insertions, 4 deletions
diff --git a/lldb/include/lldb/Target/ThreadCollection.h b/lldb/include/lldb/Target/ThreadCollection.h
index 5b0267d76d4..e3965b57e7a 100644
--- a/lldb/include/lldb/Target/ThreadCollection.h
+++ b/lldb/include/lldb/Target/ThreadCollection.h
@@ -48,11 +48,11 @@ public:
return ThreadIterable(m_threads, GetMutex());
}
- virtual std::recursive_mutex &GetMutex() { return m_mutex; }
+ virtual std::recursive_mutex &GetMutex() const { return m_mutex; }
protected:
collection m_threads;
- std::recursive_mutex m_mutex;
+ mutable std::recursive_mutex m_mutex;
};
} // namespace lldb_private
diff --git a/lldb/include/lldb/Target/ThreadList.h b/lldb/include/lldb/Target/ThreadList.h
index d0779d81016..9e3c940c3c2 100644
--- a/lldb/include/lldb/Target/ThreadList.h
+++ b/lldb/include/lldb/Target/ThreadList.h
@@ -135,7 +135,7 @@ public:
void SetStopID(uint32_t stop_id);
- std::recursive_mutex &GetMutex() override;
+ std::recursive_mutex &GetMutex() const override;
void Update(ThreadList &rhs);
diff --git a/lldb/source/Target/ThreadList.cpp b/lldb/source/Target/ThreadList.cpp
index 15388a5afa1..1e474518aac 100644
--- a/lldb/source/Target/ThreadList.cpp
+++ b/lldb/source/Target/ThreadList.cpp
@@ -44,6 +44,7 @@ const ThreadList &ThreadList::operator=(const ThreadList &rhs) {
// Lock both mutexes to make sure neither side changes anyone on us
// while the assignment occurs
std::lock_guard<std::recursive_mutex> guard(GetMutex());
+ std::lock_guard<std::recursive_mutex> rhs_guard(rhs.GetMutex());
m_process = rhs.m_process;
m_stop_id = rhs.m_stop_id;
@@ -749,7 +750,7 @@ void ThreadList::Flush() {
(*pos)->Flush();
}
-std::recursive_mutex &ThreadList::GetMutex() {
+std::recursive_mutex &ThreadList::GetMutex() const {
return m_process->m_thread_mutex;
}
OpenPOWER on IntegriCloud