unsafe extern "C" fn patch_phdr_cb(
info: *mut dl_phdr_info,
_size: size_t,
_data: *mut c_void,
) -> c_intExpand description
dl_iterate_phdr callback: for each loaded object matching a targeted NVIDIA library,
find its PT_DYNAMIC segment and repoint its ioctl slots. Returns 0 to keep iterating.
- Panic firewall: the whole body runs under
catch_unwindbecause a panic must not unwind across thisextern "C"boundary into the Cdl_iterate_phdr— that would abort the process; a caught panic just ends this object’s processing and iteration continues. - Tight library match: only
libnvcuvid,libnvidia-encode, andlibcuda.soare patched — the libraries that issue the enumeration ioctl (libnvidia-encodecalls throughlibnvcuvid). Unrelated modules (libcudart,libnvidia-ml,libnvidia-glcore, …) and objects with no name are skipped so theirioctlbindings are left untouched. - Patch each
PT_DYNAMIC: for a matched object, walk its program headers and hand everyioctlslot of each dynamic segment topatch_ioctl_slot, using the object’s load address as the base.