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

[SharedCache] Fix handling of relative selectors in macOS shared caches #6192

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

bdash
Copy link
Contributor

@bdash bdash commented Nov 25, 2024

Find the relative selector base address in the Objective-C optimization data pointed to by the shared cache header, rather than via __objc_scoffs. That section is only present on iOS, and not for every iOS version that encodes selectors via direct offsets.

This also includes some related improvements:

  1. Direct selectors get their own pointer type so they're rendered correctly in the view.
  2. Method lists encoded as lists of lists are now handled.
  3. The dyld_cache_header type added to the view is truncated to the length of the header in the loaded cache. This ensures it is correctly applied to the view.
  4. A couple of methods that process method IMPs and selectors are updated to check whether the address is valid before attempting to process them. They would otherwise fail by throwing an exception if they proceed. Checking for validity is quicker and makes exception breakpoints usable for investigating incorrect behavior.

Additionally, SharedCache now tracks whether non-image regions are data vs code. This means it can avoid marking some regions as containing code when they don't, reducing the amount of analysis work that has to be done.

`BackingCache` now tracks the `dyld_cache_mapping_info` for its mappings
so it has access to the memory protections for the region. This means it
can avoid marking some regions as containing code when they don't,
reducing the amount of analysis work that has to be done.

Using `dyld_cache_mapping_info` also makes references to mappings easier
to understand due to its named fields vs the nested `std::pair`s that
were previously in use.
Find the relative selector base address in the Objective-C optimization
data pointed to by the shared cache header, rather than via
`__objc_scoffs`. This is only present on iOS, and not for every iOS
version that encodes selectors via direct offsets.

This also includes some related improvements:
1. Direct selectors get their own pointer type so they're rendered
   correctly in the view.
2. Method lists encoded as lists of lists are now handled.
3. The `dyld_cache_header` type added to the view is truncated to the
   length in the loaded cache. This ensures it is applied to the view.
4. A couple of methods that process method IMPs and selectors are
   updated to check whether the address is valid before attempting to
   process them. They would otherwise fail by throwing an exception if
   they proceed, but checking for validity is quicker and makes
   exception breakpoints usable.
@bdash
Copy link
Contributor Author

bdash commented Nov 25, 2024

This requires the fixes from #6172. Without those fixes a lot of the class / method data hasn't been rebased appropriately and so is impossible to correctly interpret.

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.

1 participant