From 9987646057d9748514662f96c869a5f87e463bc6 Mon Sep 17 00:00:00 2001 From: Med Ismail Bennani Date: Mon, 3 Jul 2023 11:48:11 -0700 Subject: [lldb] Fix data race when interacting with python scripts This patch should fix some data races when a python script (i.e. a Scripted Process) has a nested call to another python script (i.e. a OperatingSystem Plugin), which can cause concurrent writes to the python lock count. This patch also fixes a data race happening when resetting the operating system unique pointer. To address these issues, both accesses is guarded by a mutex. rdar://109413039 Differential Revision: https://reviews.llvm.org/D154271 Signed-off-by: Med Ismail Bennani --- .../ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h') diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h index fe75f69..55ade49 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h @@ -378,11 +378,18 @@ public: void LeaveSession(); - uint32_t IsExecutingPython() const { return m_lock_count > 0; } + uint32_t IsExecutingPython() { + std::lock_guard guard(m_mutex); + return m_lock_count > 0; + } - uint32_t IncrementLockCount() { return ++m_lock_count; } + uint32_t IncrementLockCount() { + std::lock_guard guard(m_mutex); + return ++m_lock_count; + } uint32_t DecrementLockCount() { + std::lock_guard guard(m_mutex); if (m_lock_count > 0) --m_lock_count; return m_lock_count; @@ -422,6 +429,7 @@ public: bool m_pty_secondary_is_open; bool m_valid_session; uint32_t m_lock_count; + std::mutex m_mutex; PyThreadState *m_command_thread_state; }; -- cgit v1.1