From 2e855275732aed00486ca100f4151f4074d9949e Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Fri, 4 Apr 2025 23:45:06 -0400 Subject: [SharedCache] Add a named symbol map Fixes https://github.com/Vector35/binaryninja-api/issues/6561 - Also tightens the SharedCache class to move only, to prevent accidental copies. - Also removes some extra copies in FFI when should pass by ref - Also adds `get_symbol_with_name` to python API The current named symbol map is populated in a worker thread spawned in the view init. This is because populating the map can take about 1 second. If we are fine with another 1 second added to the view init time then we can add it serially but I don't think this way is _that_ bad, no analysis consults this, however a user might add a workflow that would be racing this. So we need to add a mutex. --- view/sharedcache/core/SharedCacheView.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'view/sharedcache/core/SharedCacheView.cpp') diff --git a/view/sharedcache/core/SharedCacheView.cpp b/view/sharedcache/core/SharedCacheView.cpp index d07d8614..a3e494e2 100644 --- a/view/sharedcache/core/SharedCacheView.cpp +++ b/view/sharedcache/core/SharedCacheView.cpp @@ -842,6 +842,19 @@ bool SharedCacheView::Init() auto cacheController = SharedCacheController::Initialize(*this, std::move(sharedCache)); + { + // Load up all the symbols into the named symbols lookup map. + // NOTE: We do this on a separate thread as image & region loading does not consult this. + WorkerPriorityEnqueue([logger, cacheController]() { + auto& sharedCache = cacheController->GetCache(); + auto startTime = std::chrono::high_resolution_clock::now(); + sharedCache.ProcessSymbols(); + auto endTime = std::chrono::high_resolution_clock::now(); + std::chrono::duration elapsed = endTime - startTime; + logger->LogInfo("Processing %zu symbols took %.3f seconds (separate thread)", sharedCache.GetSymbols().size(), elapsed.count()); + }); + } + // Users can adjust which images are loaded by default using the `loader.dsc.autoLoadPattern` setting. std::string autoLoadPattern = ".*libsystem_c.dylib"; if (settings && settings->Contains("loader.dsc.autoLoadPattern")) -- cgit v1.3.1