From 137dc78710a690f1769cba060a1d621a38a9d5fd Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:05:04 -0400 Subject: [PATCH] Improve dbghelp symbolization thread safety --- src/symbols/symbols_with_dbghelp.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/symbols/symbols_with_dbghelp.cpp b/src/symbols/symbols_with_dbghelp.cpp index c8e8361..d98fb37 100644 --- a/src/symbols/symbols_with_dbghelp.cpp +++ b/src/symbols/symbols_with_dbghelp.cpp @@ -321,11 +321,11 @@ namespace dbghelp { return true; } - std::mutex dbghelp_lock; + std::recursive_mutex dbghelp_lock; // TODO: Handle backtrace_pcinfo calling the callback multiple times on inlined functions stacktrace_frame resolve_frame(HANDLE proc, uintptr_t addr) { - const std::lock_guard lock(dbghelp_lock); // all dbghelp functions are not thread safe + const std::lock_guard lock(dbghelp_lock); // all dbghelp functions are not thread safe alignas(SYMBOL_INFO) char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)]; SYMBOL_INFO* symbol = (SYMBOL_INFO*)buffer; symbol->SizeOfStruct = sizeof(SYMBOL_INFO); @@ -402,6 +402,7 @@ namespace dbghelp { } std::vector resolve_frames(const std::vector& frames) { + const std::lock_guard lock(dbghelp_lock); // all dbghelp functions are not thread safe std::vector trace; trace.reserve(frames.size());