Skip to main content

patch_phdr_cb

Function patch_phdr_cb 

Source
unsafe extern "C" fn patch_phdr_cb(
    info: *mut dl_phdr_info,
    _size: size_t,
    _data: *mut c_void,
) -> c_int
Expand 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.

  1. Panic firewall: the whole body runs under catch_unwind because a panic must not unwind across this extern "C" boundary into the C dl_iterate_phdr — that would abort the process; a caught panic just ends this object’s processing and iteration continues.
  2. Tight library match: only libnvcuvid, libnvidia-encode, and libcuda.so are patched — the libraries that issue the enumeration ioctl (libnvidia-encode calls through libnvcuvid). Unrelated modules (libcudart, libnvidia-ml, libnvidia-glcore, …) and objects with no name are skipped so their ioctl bindings are left untouched.
  3. Patch each PT_DYNAMIC: for a matched object, walk its program headers and hand every ioctl slot of each dynamic segment to patch_ioctl_slot, using the object’s load address as the base.