diff options
| author | Mason Reed <mason@vector35.com> | 2025-04-06 20:00:00 -0400 |
|---|---|---|
| committer | Mason Reed <mason@vector35.com> | 2025-04-06 20:00:37 -0400 |
| commit | c22d54c5d95f4d23629484579414387b0c7503ee (patch) | |
| tree | 933a58c8ed3518f507f5bd4d496364411273f5b9 /view/sharedcache/core/FileAccessorCache.h | |
| parent | 4f22a944d77f784b53ee3a37d9f1966ede1c98a4 (diff) | |
[SharedCache] Replace write log with callback registration for reapplying slide info
This improves performance by ~10x with the only real issue being a copy of the cache entry existing for each weak ref.
Also fixes
- Some old TODO's that are no longer relevant
- Some function signatures not being const
- FileAccessorCache not evicting enough accessors to fit under an adjusted cache size
- Added a warning if we are over the global cache size in view initialization
- Logger name not having a `.` in `SlideInfoProcessor::SlideInfoProcessor`
- Re-added the accessor dirty check before applying slide info to fix https://github.com/Vector35/binaryninja-api/issues/6570
Diffstat (limited to 'view/sharedcache/core/FileAccessorCache.h')
| -rw-r--r-- | view/sharedcache/core/FileAccessorCache.h | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/view/sharedcache/core/FileAccessorCache.h b/view/sharedcache/core/FileAccessorCache.h index 0ef6595a..811aea78 100644 --- a/view/sharedcache/core/FileAccessorCache.h +++ b/view/sharedcache/core/FileAccessorCache.h @@ -37,48 +37,36 @@ public: // Adjust the cache size limit. // This will NOT evict current cache entries, as they are already available. // Any subsequent call to `Open` will assume this cache size, evicting until the size is equal to the cache size. - void SetCacheSize(uint64_t size) { m_cacheSize = size; }; -}; - -// Write log to be used in conjunction with `WeakFileAccessor` to re-apply written data to a "revived" file. -struct FileAccessorWriteLog -{ - // To persist writes to a file accessor being revived (within the lock() function) - // we keep a list of writes that will be re-applied in the lock function. - std::shared_mutex m_persistedMutex; - std::vector<std::pair<size_t, uint64_t>> m_persistedPointers; - - FileAccessorWriteLog() = default; + void SetCacheSize(const uint64_t size) { m_cacheSize = size; }; - // Add the pointer to the persisted pointers. - void AddPointer(size_t address, size_t pointer); - - // Apply all logged writes to the given accessor. - void ApplyWrites(MappedFileAccessor& accessor); + size_t GetCacheSize() const { return m_cacheSize; } }; class WeakFileAccessor { + using ReviveCallback = std::function<void(MappedFileAccessor&)>; + // Weak pointer to the mapped file accessor, once this is expired we will re-open. std::weak_ptr<MappedFileAccessor> m_weakPtr; // File path for re-opening if needed std::string m_filePath; // Used to re-add writes once the file accessor is "revived". - std::shared_ptr<FileAccessorWriteLog> m_writeLog; + std::optional<ReviveCallback> m_reviveCallback; // TODO: Store a weak_ptr/shared_ptr to FileAccessorCache? That way we dont access Global() // TODO: Only need to do the above if we want multiple caches. public: explicit WeakFileAccessor(std::weak_ptr<MappedFileAccessor> weakPtr, std::string filePath) : - m_weakPtr(std::move(weakPtr)), m_filePath(std::move(filePath)), - m_writeLog(std::make_shared<FileAccessorWriteLog>()) + m_weakPtr(std::move(weakPtr)), m_filePath(std::move(filePath)) {} - std::shared_ptr<MappedFileAccessor> lock(); + // Register the function to be called once the file accessor is revived, this is typically + // used to re-apply writes such as from slide info. + void RegisterReviveCallback(const ReviveCallback& callback) { + m_reviveCallback = callback; + } - // Persists the written pointer within this weak file accessor. - // This works as we expect the weak file accessor to be stored per virtual memory region. - void WritePointer(size_t address, size_t pointer); + std::shared_ptr<MappedFileAccessor> lock(); }; |
