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

Fix mac module load address #44

Merged
merged 4 commits into from
Jul 15, 2022
Merged

Fix mac module load address #44

merged 4 commits into from
Jul 15, 2022

Conversation

Jake-Shadle
Copy link
Collaborator

@Jake-Shadle Jake-Shadle commented Jul 15, 2022

  • Fix module base address by always using a correct slide
  • Make mac crash context optional
  • Add some more API documentation

When calculating the image slide, the difference between the image's preferred load address and the TEXT segment, we faithfullly ported the Breakpad implementation:

breakpad

https://github.com/google/breakpad/blob/335e61656fa6034fabc3431a91e5800ba6fc3dc9/src/client/mac/handler/dynamic_images.cc#L269-L272

minidump-writer

let slide = if seg.file_off == 0 && seg.file_size != 0 {
image.load_address as isize - seg.vm_addr as isize
} else {
0
};

This was, however, a mistake, as that logic was just incorrect as shown by the crashpad implementation

crashpad

https://github.com/chromium/crashpad/blob/df86075acc33314e611b351b33bf1c671b8cbc2f/snapshot/mac/mach_o_image_reader.cc#L585-L589

When removing the if and unconditionally calculating the slide, the images_match test that I added started passing which gives me a bit more confidence that the implementation is (more) correct now than the one copied from Breakpad.

While I was here, the test code needed a bit of refactoring in the minidumpwriter since that was easier than pulling out the logic into a reusable piece (it's maybe a good idea to do....but I also don't want us to end up in a crashpad scenario with a mountain of obtuse abstractions), so this addresses the Mac part of #37, and I'll do the same for Windows in a separate PR to close the issue.

Part of: #37
Resolves: #43

@Jake-Shadle Jake-Shadle merged commit f84d6e5 into main Jul 15, 2022
@Jake-Shadle Jake-Shadle deleted the fix-mac-load-address branch July 15, 2022 09:24
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.

Some macOS modules have incorrect image bases
1 participant