From a72b98ed5a357bb380d81f07f3f36946aa729bb2 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Mon, 23 Feb 2026 23:26:27 -0800 Subject: [DSC] Simplify file mapping to fix intermittent unrelocated pointers The `FileAccessorCache`'s LRU eviction could discard a file's mapped data after slide info had already been applied to it. Future accesses to the file produced a fresh mapping, but failed to reapply the slide info. This could result in pointers not correctly being slid, such as in https://github.com/Vector35/binaryninja-api/issues/7689. The LRU cache existed to stay within OS file descriptor limits, since the old `MappedFile` held its fd open for the lifetime of the mapping. There's no real reason for it to hold the file descriptor open like this. Closing it after `mmap` is sufficient to avoid the file descriptor limits. `MappedFileRegion` replaces the combination of `FileAccessorCache`, `WeakFileAccessor`, and `MappedFileAccessor`. It closes the fd immediately after mmap, so all files can stay mapped without consuming descriptors, making the cache unnecessary. `MappedFileRegion` is owned directly by the `CacheEntry` for its full lifetime. Slide info is applied exactly once to each `MappedFileRegion`. --- view/sharedcache/core/SharedCacheView.cpp | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'view/sharedcache/core/SharedCacheView.cpp') diff --git a/view/sharedcache/core/SharedCacheView.cpp b/view/sharedcache/core/SharedCacheView.cpp index dac39278..746bd7eb 100644 --- a/view/sharedcache/core/SharedCacheView.cpp +++ b/view/sharedcache/core/SharedCacheView.cpp @@ -3,8 +3,6 @@ #include #include "SharedCacheController.h" -#include "FileAccessorCache.h" -#include "MappedFileAccessor.h" #include "SharedCacheBuilder.h" using namespace BinaryNinja; @@ -17,12 +15,6 @@ SharedCacheViewType::SharedCacheViewType() : BinaryViewType(VIEW_NAME, VIEW_NAME // We register all our one-shot stuff here, such as the object destructor. void SharedCacheViewType::Register() { - auto fdLimit = AdjustFileDescriptorLimit(); - LogDebugF("Shared Cache processing initialized with a max file descriptor limit of {}", fdLimit); - - // Adjust the global accessor cache to the fdlimit. - FileAccessorCache::Global().SetCacheSize(fdLimit); - RegisterSharedCacheControllerDestructor(); static SharedCacheViewType type; @@ -874,10 +866,6 @@ bool SharedCacheView::InitController() std::chrono::duration elapsed = endTime - startTime; m_logger->LogInfoF("Processing {} entries took {:.3f} seconds", totalEntries, elapsed.count()); - // If we can't store all of our files for this cache in the accessor cache we might run into issues, warn the user. - if (totalEntries > FileAccessorCache::Global().GetCacheSize()) - m_logger->LogWarn("Cache contains more entries than the allowed number of opened file handles, this may impact reliability."); - // Verify that we are not missing any entries that were stored in the metadata. // If we are that means we should alert the user that a previously associated cache entry is missing. std::set missingCacheEntries = m_secondaryFileNames; -- cgit v1.3.1