Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(mach headers): refactor to linked list to avoid threading issues #728

Merged
merged 6 commits into from
Jun 30, 2020

Conversation

tomlongridge
Copy link
Contributor

@tomlongridge tomlongridge commented Jun 28, 2020

Goal

The current implementation of the Mach Headers cache using an expandable array is not easy to make work in a thread-safe way, so wouldn't be usable if threads were not suspended before accessing.

Design

Refactored to a linked list so that there is no realloc and less change when new elements are added. Also changed removal so the library is simply marked as removed rather than deleted so that locking is not required for this operation.

Changeset

  • BSG_KSMachHeaders - amended implementation to a linked list; renamed functions for internal consistency; amended removal to simply mark the library as removed rather than mutate the list and so removed the lock around the operation; refactored lock functions to work in a cleaner way.
  • BSG_KSCrash - moved initialisation code to BSG_KSCrashC, closer to other initialisation code and moved the registering of changes into the initialisation function of the mach header code.
  • BSG_KSDynamicLinker - moved several functions to BSG_KSMachHeaders to avoid passing indexes around.

Tests

  • Manually tested the reports remain symbolicated
  • Amended existing unit tests accordingly - including added a free call during initialization so that the list of headers doesn't grow between each test.

The layout of the MachHeaders module is not optimal as it exposes unnecessary implementation
detail. This means the index of the image in the list is passed around and increases the
chances of this changing if used in multi-threaded context.
@tomlongridge tomlongridge marked this pull request as ready for review June 28, 2020 19:13
@tomlongridge tomlongridge changed the base branch from master to next June 30, 2020 12:09
@tomlongridge tomlongridge merged commit 551da1b into next Jun 30, 2020
@tomlongridge tomlongridge deleted the tom/improve-mach-headers-encapsulation branch June 30, 2020 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants