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

Use mach_vm_read_overwrite to read image infos for dyld_images #403

Merged
merged 4 commits into from
Nov 4, 2024

Conversation

Maaarcocr
Copy link
Contributor

As I've explained in #389 (comment) it seems like the mapped memory that samply relies on to read image infos for dyld_images is no longer kept up to date with the newest version of macOS.

This results in samply not being able to reconcile from where an address is coming from (as it was shown in the issue I already linked) and thus then we get no symbolication whatsover.

I have a simple solution for this (which I understand may not be desirable from a perf POV): for image infos just read them directly from the other process memory using mach_vm_read_overwrite. This may be slower, but it at least get samply working again when people use dlopen in the application code. Also, even if it is slower, hopefully people are not constantly dlopen-ing new libraries so this code should only be called few times at startup and that should be it hopefully?

samply/src/mac/proc_maps.rs Outdated Show resolved Hide resolved
samply/src/mac/proc_maps.rs Outdated Show resolved Hide resolved
samply/src/mac/proc_maps.rs Outdated Show resolved Hide resolved
mach_vm_read_overwrite(task, info_array_elem_addr, size, &mut image_info as *mut MaybeUninit<dyld_image_info> as u64, &mut size).into_result()?;
}

if size != mem::size_of::<dyld_image_info>() as u64 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also check that the result of mach_vm_read_overwrite was KERN_SUCCESS, I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

into_result does it

@casperisfine
Copy link

I just tried this, and while it now include symbols, they don't quite look correct
Capture d’écran 2024-11-04 à 10 42 33

@Maaarcocr
Copy link
Contributor Author

I just tried this, and while it now include symbols, they don't quite look correct Capture d’écran 2024-11-04 à 10 42 33

could you try again? I've pushed some new changes that make us of mach_vm_read_overwrite more and it seems to work for my native gem!

@casperisfine
Copy link

It works now ! ❤️

Capture d’écran 2024-11-04 à 12 39 44

@mstange
Copy link
Owner

mstange commented Nov 4, 2024

Thank you @Maaarcocr for the patch, @ianks for the review and @casperisfine for testing!

@mstange mstange merged commit 5110a08 into mstange:main Nov 4, 2024
15 checks passed
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.

4 participants