I'm investigating the Mach dynamic linker dyld. This question applies to all Apple platforms but happy for an answer to be platform specific; I'm using ObjC but also happy to translate Swift if that works for you. The relevant Apple docs can be found here.
I'm trying to address a deadlocking issue in a library I maintain and so need to capture information about loaded binary images. (for the uninitiated these are not the JPEG kind of images).
I've registered a callback to watch for binary image addition via _dyld_register_func_for_add_image() and this is being called as images are loaded. I can see the mach_header structure being passed in as well as the vmaddr_slide value.
For various deadlock-avoidance reasons I don't want to iterate over images using _dyld_image_count()/_dyld_get_image_header() post-hoc, but instead want to keep track of images as they're loaded/unloaded solely using the add()/remove() callbacks. Ordinarily I'd be able to call _dyld_get_image_name(index) to retrieve an image name as I iterated over images but, like I say, I can't use the iterative model.
My question is: based on the values passed in to the func_for_add_image() callback (using any additional system calls necessary) how could I determine the image name?