Files
AnyPS5/docs/dev/debt/changes/fix-libkernel-sysctl-proc-pid-thread-id.md
brajankwandClaude Opus 5.5 94aa6c0be2 fix(libkernel): answer kern.proc.pathname, env and vmmap for a live thread's id, as FreeBSD 11.4's pget does
kern.proc.pathname, kern.proc.env and kern.proc.vmmap answered only the
calling process's pid. FreeBSD 11.4's sysctl_kern_proc_pathname,
sysctl_kern_proc_env and sysctl_kern_proc_vmmap look the id up with
pget without PGET_NOTID, which maps an id above PID_MAX to the process
of that thread, so they now accept the id of one of the calling
process's live threads as kern.proc.pid does. Other pids still fail
with ESRCH.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 02:27:11 +01:00

1.9 KiB

libkernel

change [kern.proc.pid]

  • kern.proc.pid (libkernel) - what the console fills in a process's kinfo_proc is unverified; sysctl {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid} for the calling process returns a 1,088-byte FreeBSD 11 amd64 kinfo_proc (sys/sys/user.h) holding only ki_structsize, ki_pid, ki_ppid and ki_comm (eboot.bin, the base name of the kern.proc.pathname value), with every other field 0, including ki_flag, so P_TRACED (0x800) is clear. Source Port (PPSA20040) asks for its own record with a 0x440-byte buffer and tests only bit 0x800 of ki_flag at offset 0x170, to see whether a debugger is attached. Other processes' pids and -1 fail with ESRCH, a write with EPERM and a short buffer with ENOMEM.

change [kern.proc.pid_td]

  • kern.proc.pid_td (libkernel) - whether the console answers {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD, pid} and what it fills in is unverified; here it returns one kern.proc.pid record per live guest thread, as FreeBSD 11.4's kern_proc_out does without KERN_PROC_NOTHREADS, with ki_tid (the pthread_getthreadid_np value), ki_numthreads, and the thread name split as fill_kinfo_thread splits it: up to 16 bytes in ki_tdname, the next 3 in ki_moretdname. Run time, CPU, state, priority and the other per-thread fields stay 0. As for kern.proc.pid, only the calling process is answered, by its pid or the id of one of its live threads: any other pid, -1 included, fails with ESRCH, where FreeBSD's pget also answers for other visible processes.