Function mz_proc::linux::collect_shared_objects

source ·
pub unsafe fn collect_shared_objects() -> Result<Vec<SharedObject>, Error>
Expand description

Collects information about all shared objects loaded into the current process, including the main program binary as well as all dynamically loaded libraries. Intended to be useful for profilers, who can use this information to symbolize stack traces offline.

Uses dl_iterate_phdr to walk all shared objects and extract the wanted information from their program headers.

SAFETY: This function is written in a hilariously unsafe way: it involves following pointers to random parts of memory, and then assuming that particular structures can be found there. However, it was written by carefully reading man dl_iterate_phdr and man elf, and is thus intended to be relatively safe for callers to use. Assuming I haven’t written any bugs (and that the documentation is correct), the only known safety requirements are:

(1) It must not be called multiple times concurrently, as dl_iterate_phdr is not documented as being thread-safe. (2) The running binary must be in ELF format and running on Linux.