summaryrefslogtreecommitdiff
path: root/view/sharedcache/core/SharedCache.h
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-04-06 21:10:38 -0400
committerMason Reed <mason@vector35.com>2025-04-06 21:11:00 -0400
commit05e3335c27a477492fee6d031654dd3152f722b6 (patch)
tree7b85282b3f93662bf5ebcbde4a19ab462d8651c0 /view/sharedcache/core/SharedCache.h
parent833375c0199d4e7c2555e6e9f14862ddc3ca120c (diff)
[SharedCache] Add mutex to guard `m_namedSymbols`
It is modified on a worker thread so if a user tries to call `GetSymbolWithName` after view init but before the processing on the worker thread finishes, there would have been issues!
Diffstat (limited to 'view/sharedcache/core/SharedCache.h')
-rw-r--r--view/sharedcache/core/SharedCache.h6
1 files changed, 4 insertions, 2 deletions
diff --git a/view/sharedcache/core/SharedCache.h b/view/sharedcache/core/SharedCache.h
index ff329ecf..3211b90c 100644
--- a/view/sharedcache/core/SharedCache.h
+++ b/view/sharedcache/core/SharedCache.h
@@ -203,6 +203,9 @@ class SharedCache
// Quickly lookup a symbol by name, populated by `FinalizeSymbols`.
// `m_namedSymbols` is modified in a worker thread spawned by view init so we must not get a symbol until its populated.
std::unordered_map<std::string, uint64_t> m_namedSymbols {};
+ // Used to guard `m_namedSymbols` as it's accessed on multiple threads.
+ // NOTE: Wrapped in unique_ptr to keep SharedCache movable.
+ std::unique_ptr<std::shared_mutex> m_namedSymMutex;
bool ProcessEntryImage(const std::string& path, const dyld_cache_image_info& info);
@@ -225,7 +228,6 @@ public:
const AddressRangeMap<CacheRegion>& GetRegions() const { return m_regions; }
const std::unordered_map<uint64_t, CacheImage>& GetImages() const { return m_images; }
const std::unordered_map<uint64_t, CacheSymbol>& GetSymbols() const { return m_symbols; }
- const std::unordered_map<std::string, uint64_t>& GetNamedSymbols() const { return m_namedSymbols; }
void AddImage(CacheImage&& image);
@@ -266,7 +268,7 @@ public:
std::optional<CacheSymbol> GetSymbolAt(uint64_t address) const;
- std::optional<CacheSymbol> GetSymbolWithName(const std::string& name) const;
+ std::optional<CacheSymbol> GetSymbolWithName(const std::string& name);
};
// This constructs a Cache, give it a file path, and it will add all relevant cache entries.