Skip to content

Fix mac module load address#44

Merged
Jake-Shadle merged 4 commits intomainfrom
fix-mac-load-address
Jul 15, 2022
Merged

Fix mac module load address#44
Jake-Shadle merged 4 commits intomainfrom
fix-mac-load-address

Conversation

@Jake-Shadle
Copy link
Copy Markdown
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