feat(libkernel): list the calling process's threads for kern.proc.pid_td #16401
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16401"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by NevesHenry on 2026-11-06T16:11:32Z.
What
ProsperoWeb (PRWB00001) 0.2.1 lists its own threads every 30 s with
sysctl{CTL_KERN,KERN_PROC,KERN_PROC_PID | KERN_PROC_INC_THREAD, pid} (ps5_cpu_monitor.cpp#L65-L100). Onmain, with #16270 so that the title gets past the loader, the first call throws about 6 s in:kern.proc.pidwithout threads (1.14.1) already answers for the calling process. This adds itspid_tdsibling, 1.14.17, as FreeBSD 11.4'skern_proc_outanswers it withoutKERN_PROC_NOTHREADS: one 1,088-bytekinfo_procper thread.SystemConfiguration.cpp: each record is thekern.proc.pidrecord (ki_structsize,ki_pid,ki_ppid,ki_comm) plus, for one live guest thread,ki_tid(offset 600, thepthread_getthreadid_npvalue),ki_numthreads(596, the number of records) and the thread name split asfill_kinfo_threadsplits it: up to 16 bytes inki_tdname(394), the next 3 inki_moretdname(502). The offsets are those of FreeBSD 11.4 amd64sys/user.h, checked withstatic_assert. A null buffer reports the size of all records, a short buffer getsENOMEM, a writeEPERM, any other pid (including -1)ESRCHand a name that is not four elements longEINVAL, the same checks as 1.14.1.Pthread:LiveGuestThreadNames()copies the tid and name of every registered guest thread that has not finished, under the registry lock, afterscePthreadSelf()so the calling thread is always listed.pthread_create. I have no console measurement either way, so this follows FreeBSD, as 1.14.1 and 1.14.8 do, and the debt entry says so. If a measurement showsENOENT, the node becomes anENOENTanswer like the other measured-absent MIBs, and the title takes its fallback.guest_system_configurationgetsCheckProcessThreadsSysctl: it creates a thread namedkproc_thread_name, reads the records, checks the common fields andki_numthreadsin each, distinctki_tids, that both the calling thread and the new one are listed, the name split (kproc_thread_nam+e), the error cases, and that the joined thread is no longer listed.Tested
Linux: Ubuntu 24.04 container on WSL2, Ryzen 9 7900, GCC 13.3, Release, llvmpipe (the only Vulkan device here).
Title: ProsperoWeb 0.2.1,
PRWB00001.zipfrom kvaps/ProsperoWeb, SHA-256687652cbc05c01db60410c357bc4322f05170de4829ace174d1d5628ba63b0b0, the same as in the homebrew catalog. I ran it withtools/title_run.py(relinker default flags) for 40 s under Xvfb in a container with no network, without input, 3 runs each. The title also needs #16270, so both columns have it merged onmain492ed5c5fe; the only difference is this branch'slibkernel.prx.main+ #16270main+ #16270 + this PRwhat(): sysctl_nid_postfix: unsupported MIB 1.14.17.<pid>, SIGABRT 6 to 7 s in (3/3)main: starting the UI, then the abortcpu: affinity 0-12 ... threads 2 (kern.proc; ...)at start andthreads 11 (kern.proc; ...)30 s later,splash: drawn and flipped,WebKit: context and data store created, thenstartup: showing the startup-error messageThe title now waits for its broker process, which it starts through an ELF loader (
elfldron 127.0.0.1:9021 or etaHEN'swebsrvon 127.0.0.1:8080) that only a jailbroken console runs, so its WebContent and Networking processes fail to launch. That is outside this PR.ctest -R "^guest_system_configuration$": passes. Withcore/libs/prx/libkernelfrommainand the test kept, it fails:what(): sysctl_nid_postfix: unsupported MIB 1.14.17.9(Subprocess aborted).ctest -R "kernel|pthread|sched|cpuset|system_configuration|thread|sysctl" -E "^agc_": 162/162 pass.tools/check_conventions.py --base origin/mainpasses.main3e089775b9(no conflicts).mainnow checksGuestThreadEndedinstead of_finishedeverywhere it walks the thread registry (on Windows it also counts an adopted thread whose host thread has ended), soLiveGuestThreadNames()uses it too:b0b07fc8f0, one line, no change on Linux. On the merged head,guest_system_configurationpasses and still fails withmain'sSystemConfiguration.cpp(unsupported MIB 1.14.17.<pid>), the same ctest set passes 184/184 (it has grown since), andcheck_conventions.py --base origin/mainpasses.KERN_PROC_INC_THREAD,kinfo_proc,pid_tdor 1.14.17 except #16270's description, which names this stop.tools/pr_overlap.pyneeds git 2.38 and this host has 2.34, so I merged the heads of the 124 open PRs that change these files into this branch and intomain: all merge or conflict the same way with both, except #15040, which adds#include <utility>on the line where this branch adds#include <vector>inPthread.hpp.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)AI disclosure: this change and description were written with Claude Code.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-09T07:53:19Z.
Review: APPROVED
Read
bff6aa8315againstmainb66ca0e85a(the merge preview is clean).Layout. I checked the new
GuestKinfoProcfields against FreeBSD'ssys/sys/user.hatrelease/11.4.0, and every offset matches.ki_tdname[TDNAMLEN+1]sits right beforeki_wmesg,ki_loginandki_lockname, which puts it at 394, below the existingki_commat 447.ki_comm,ki_emul[17]andki_loginclass[18]putki_moretdname[4]at 502.ki_sparestrings[46], thenki_spareints[KI_NSPARE_INT]withKI_NSPARE_INT4 in 11.4, then seven ints (ki_oncputoki_jid) putki_numthreadsat 596 andki_tidat 600.static_asserts and the 1088-byte total agree with that.Name split. Up to
TDNAMLEN(16) characters go intoki_tdname, and the rest, up to 3 more, intoki_moretdname. Both stay NUL-terminated because the record starts zeroed. That is the split FreeBSD'sfill_kinfo_threadmakes for names longer thanTDNAMLEN, and the test pins it with a 17-character name ("kproc_thread_nam"+"e").Locks.
LiveGuestThreadNamestakes the registry lock, then each thread'snameLock.scePthreadRenameandscePthreadGetnametake them in the same order, and nothing inThread.cpptakesnameLockfirst, so there is no inversion.Errors. EPERM for a write, EINVAL for a MIB that isn't 4 long, ESRCH for another PID, and ENOMEM with a partial copy for a short buffer (through the shared
CopyOut). These match the existing 1.14.1 handler and FreeBSD'ssysctl_kern_proc.One behaviour note, not a request. As in FreeBSD, a caller that sizes its buffer from the
oldValue == nullptrquery can get ENOMEM if a thread starts before the second call. ProsperoWeb would need slack or a retry for that; FreeBSD's ownpsadds slack for the same reason.AI-assisted: yes (Claude Code)