diff options
| author | Mason Reed <mason@vector35.com> | 2025-04-28 13:58:20 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-04-28 18:28:31 -0400 |
| commit | 4b04f93ad0161bef8434300a153aed4f5ec100f9 (patch) | |
| tree | 0b48471b529715244fd991bf56cc1dddb7799c43 /view/sharedcache | |
| parent | 080495bb84cf76f549a79b27957b561453452695 (diff) | |
Misc shared cache performance improvements
Diffstat (limited to 'view/sharedcache')
| -rw-r--r-- | view/sharedcache/core/SharedCacheController.cpp | 7 | ||||
| -rw-r--r-- | view/sharedcache/workflow/SharedCacheWorkflow.cpp | 6 |
2 files changed, 9 insertions, 4 deletions
diff --git a/view/sharedcache/core/SharedCacheController.cpp b/view/sharedcache/core/SharedCacheController.cpp index 41118d7a..ff688f3c 100644 --- a/view/sharedcache/core/SharedCacheController.cpp +++ b/view/sharedcache/core/SharedCacheController.cpp @@ -160,7 +160,10 @@ bool SharedCacheController::ApplyRegion(BinaryView& view, const CacheRegion& reg // TODO: We can use the AddRemoteMemoryRegion if we want to reload on view init. // TODO: ^ The above is only useful if we assume that all files will be available across database loads. // TODO: we might allow a user to select non-persisted memory regions as an option. - view.GetMemoryMap()->AddDataMemoryRegion(memoryRegionName, region.start, buffer, region.flags); + bool addedMemoryRegion = view.GetMemoryMap()->AddDataMemoryRegion(memoryRegionName, region.start, buffer, region.flags); + if (!addedMemoryRegion) + return false; + // TODO: We might want to make this auto if we decide to "reload" all loaded region in view init. // If we are not associated with an image we can create a section here to set the semantics. // This is important for stub regions, as they will deref non image data that we want to retrieve the value of. @@ -195,10 +198,12 @@ bool SharedCacheController::ApplyImage(BinaryView& view, const CacheImage& image { // Load all regions of an image and mark the image as loaded. // NOTE: The regions lock m_loadMutex themselves, so we do not hold it up here. + view.BeginBulkAddSegments(); bool loadedRegion = false; for (const auto& regionStart : image.regionStarts) if (ApplyRegionAtAddress(view, regionStart)) loadedRegion = true; + view.EndBulkAddSegments(); // The ApplyRegionAtAddress no longer holds the lock, we can take it now. std::unique_lock<std::shared_mutex> lock(m_loadMutex); diff --git a/view/sharedcache/workflow/SharedCacheWorkflow.cpp b/view/sharedcache/workflow/SharedCacheWorkflow.cpp index c0c90f87..7f63866a 100644 --- a/view/sharedcache/workflow/SharedCacheWorkflow.cpp +++ b/view/sharedcache/workflow/SharedCacheWorkflow.cpp @@ -120,7 +120,7 @@ void AnalyzeStubFunction(Ref<Function> func, Ref<MediumLevelILFunction> mlil, Sh auto view = func->GetView(); auto loadStubIslandRegion = [&](uint64_t regionAddr) { auto region = controller.GetRegionContaining(regionAddr); - if (!region.has_value()) + if (!region.has_value() || controller.IsRegionLoaded(*region)) return false; // Only interested in non image regions, we DON'T want to implicitly load image regions (with functions presumably). if (region->type == SharedCacheRegionTypeImage) @@ -133,7 +133,7 @@ void AnalyzeStubFunction(Ref<Function> func, Ref<MediumLevelILFunction> mlil, Sh // We allow the user to automatically load the directly referenced objc images as having the calls inlined is extremely useful for objc. auto loadTargetImage = [&](uint64_t imageAddr) { const auto image = controller.GetImageContaining(imageAddr); - if (!image.has_value()) + if (!image.has_value() || controller.IsImageLoaded(*image)) return false; return controller.ApplyImage(*view, *image); }; @@ -242,7 +242,7 @@ void AnalyzeStandardFunction(Ref<Function> func, Ref<MediumLevelILFunction> mlil if (view->IsValidOffset(regionAddr)) return false; auto region = controller.GetRegionContaining(regionAddr); - if (!region.has_value()) + if (!region.has_value() || controller.IsRegionLoaded(*region)) return false; // Only interested in non image regions, we DON'T want to implicitly load image regions (with functions presumably). if (region->type == SharedCacheRegionTypeImage) |
