[SharedCache] Improvements and fixes for MMappedFileAccessor
stuff
#6318
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
MMappedFileAccessor::Open
wasn't really behaving as I think it was intended. It tried to usefileAccessorSemaphore
to limit the number of concurrent files Binary Ninja could open. It didn't really confirm it had acquired a reference onfileAccessorSemaphore
but then would always release one back when aMMappedFileAccessor
was deallocated. This could actually inflate the count offileAccessorSemaphore
meaning it could end up with a higher file limit than originally set. Also using a worker to deallocate aMMappedFileAccessor
on another thread felt like a bit of a gross hack and made synchronizing dropping a ref and acquiring one onfileAccessorSemaphore
harder than it needed to be. This resulted in a bit of a rewrite ofMMappedFileAccessor::Open
to mitigate these issues. It now should respect the file limit set on startup but can go over it temporarily in extreme circumstances that I don't expect to occur in real world experiences.Additionally there seemed to be some insufficient use of locking to synchronize accesses to certain data structures. I believe this commit has cleaned those up. They were causing very intermittent crashes.