unsafe extern "C" fn filtered_ioctl(
fd: c_int,
req: c_ulong,
arg: *mut c_void,
) -> c_intExpand description
The seam where a hidden GPU gets scrubbed out: the ioctl wrapper installed into the
NVIDIA libraries’ GOT slots, which forwards to the real libc::ioctl and then post-processes the
response. The three steps below exist only to make interposing on ioctl safe:
- Call through: invoke the genuine
libc::ioctl. Only this crate’s own GOT is left unpatched, so this inner call resolves to libc rather than back into this wrapper (no recursion). - Filter the result under
catch_unwind:rewrite_attached_idsmay drop hidden GPUs from the response. A panic must never unwind across thisextern "C"boundary — the compiler guard would abort the whole process — so any panic is caught and the unmodified real result is returned instead. - Preserve
errno: the real syscall’serrnois saved before the/proc+/devlookups inside the filter and restored afterward, so a caller readingerrnosees the syscall’s value.