UNW_SE...UNCTION(3libunwind)

✨ UNW_SET_ITERATE_PHDR_FUNCTION ✨

okay so bestie, you found a page from libunwind (the Programming Library, no less πŸ’…) and it's literally all about telling libunwind how to go walk the program headers. it's giving very niche, very powerful, and i'm obsessed πŸŽ€


🌸 NAME 🌸

unw_set_iterate_phdr_function β€” set the dl_iterate_phdr implementation, periodt πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <libunwind.h>

typedef int (*unw_iterate_phdr_callback_t)(struct dl_phdr_info *,
size_t, void *);
typedef int (*unw_iterate_phdr_func_t)(unw_iterate_phdr_callback_t, void
*);

void unw_set_iterate_phdr_function(unw_addr_space_t as,
unw_iterate_phdr_func_t function);

like, copy that exactly bestie, character for character, no notes 🫢


πŸ’œ DESCRIPTION πŸ’œ

so unw_set_iterate_phdr_function() is the routine that sets the dl_iterate_phdr implementation of the address space as to the function you pass in as the argument function. yep, that's the whole vibe: you hand it your function, and libunwind is like "say less, this is my phdr iterator now" 😌✨

that function of yours gets called whenever libunwind needs to iterate over the program headers of the application. normally that job is done by calling dl_iterate_phdr, but β€” and this is the part where we gasp 😭 β€” that function is not signal safe. not even a little.

so with the help of a custom implementation, caching and iterating over the program headers is also possible in a signal-safe manner 🌈. but here's the tea: the burden lies on the user of libunwind. that's you. you're the main character now πŸ‘‘. no cap.


πŸ’… THREAD AND SIGNAL SAFETY πŸ’…

unw_set_iterate_phdr_function() is thread safe 🧚 β€” iconic behaviour, honestly.

and if the local address space is passed in argument as, this routine is also safe to use from a signal handler πŸ”₯. slay.


⭐ SEE ALSO ⭐

(yes the comma's there, i don't make the rules πŸ’€)


πŸŽ€ AUTHOR πŸŽ€

Bert Wesarg Email: bert.wesarg@googlemail.com WWW: http://www.nongnu.org/libunwind/.


and that's the whole page bestie!! it came from the Programming Library side of things, dated 29 August 2023 β€” big libunwind energy, iykyk πŸ’–βœ¨πŸ¦‹ go forth and iterate those program headers safely, you absolute legend πŸŒˆπŸ‘‘πŸ’œ