Skip to main content

visit_import_slots

Function visit_import_slots 

Source
unsafe fn visit_import_slots(
    base: usize,
    dynp: *const Elf64Dyn,
    symbol: &[u8],
    visit: &mut dyn FnMut(*mut *mut c_void),
)
Expand description

Hand every GOT slot through which one loaded library calls symbol to visit, by walking its PT_DYNAMIC array — the only way to interpose without an LD_PRELOAD object, or to read where the dynamic linker bound an import — covering both the lazy-PLT and -fno-plt relocation forms because NVIDIA ships the latter.

  1. Parse .dynamic: iterate the Elf64Dyn entries until DT_NULL, recording the dynamic symbol table, string table, PLT relocation table (DT_JMPREL/DT_PLTRELSZ), and general relocation table (DT_RELA/DT_RELASZ). Table addresses are resolved through dyn_addr to handle the glibc-absolute vs musl-relative pointer conventions.
  2. Sanity-gate the tables: bail if the symbol or string table is missing, and — via the readable closure over page_prot — bail if a table’s mapping is known but lacks read permission (an address whose mapping cannot be determined is presumed readable), so a wrong relative/absolute guess from dyn_addr cannot fault on first dereference.
  3. Visit both relocation tables: hand each present, adequately-sized, readable table to visit_reloc_table. The PLT table (.rela.plt) carries the classic lazily-bound JUMP_SLOT entries; the general table (.rela.dyn) carries the GLOB_DAT slot that -fno-plt NVIDIA builds use to bind ioctl.