feat(libkernel): accept EVFILT_SIGNAL in kevent #14886
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14886"
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 kallmek3nny on 2026-11-01T22:37:53Z.
What
keventthrewNotImplemented_nid_no_patchfor everyEVFILT_SIGNALchange. It now acceptsEVFILT_SIGNAL, as FreeBSD 11.4 does. Inkern_sig.c,filt_sigattachattaches the knote to the calling process and addsEV_CLEARto it.filt_signaladds 1 tokn_datafor eachNOTE_SIGNALhint whose signal is the knote's ident, and reports the knote whilekn_datais not 0.tdsendsignalsends that hint withKNOTE_LOCKED(p->p_klist, NOTE_SIGNAL | sig)before it checks whether the signal is ignored or masked, so ignored and blocked signals are counted too:EV_ADDstores the knote withEV_CLEARadded andfflagsanddata0, askqueue_registermoveskev->fflagsandkev->dataintokn_sfflagsandkn_sdata.raise,kill,killpgorpthread_killsends, and eachITIMER_REALexpiry, adds 1 todataof theEVFILT_SIGNALknote for that signal in every kqueue and triggers it. Ignored and blocked signals are counted too, as intdsendsignal.killwith signal 0 counts nothing.EV_CLEAR,fflags0, the signals counted since it was last reported indataand itsudata, and then its count starts again from 0.EV_ENABLEreports what it counted.EV_DELETEremoves the knote;EV_DELETEorEV_ENABLEwith no knote fails withENOENT.The kevent measurements entry in
docs/dev/debt/libkernel.md(payload processes on a PS5, firmware 12.70) recorded thatEVFILT_SIGNALforSIGUSR1was accepted there and still threw here. This PR rewrites that clause (line 172) to say it is accepted here, thatdatacounts only the signals those four functions and theITIMER_REALexpiry send, and that the counts the PS5 reports were not measured. The kqueue and kevent entry (line 167) now lists the signal filter among the filters that do not throw. Only the acceptance was measured on a PS5; the counting follows FreeBSD 11.4.Code:
RegisterinEqueue/src/Kqueue.cppacceptsEVFILT_SIGNALand adds it with the newAddSignalKnote, which stores the knote withEV_CLEARadded andfflagsanddatacleared in both the stored event and the change. The newKqueueSignalSent, declared inEqueue/Equeue.hpp, adds 1 todataof theEVFILT_SIGNALknote with that ident in every open kqueue and triggers it.System/src/Signals.cppcalls it in three places. Each call comes after the signal's disposition has been read, because a thread that the knote wakes can change that disposition. Inraise(whichkillandkillpgon the calling process andpthread_killon the calling thread go through), it runs before the ignore check. Inpthread_killon another live thread, it runs after the disposition check that marks the signal pending. InExpireAlarm, it runs withSIGALRMbefore the ignore and mask checks.Tests:
SignalEventsincore/libs/tests/GuestKqueue.cppruns withSIGUSR1andSIGALRMignored:EV_DELETEandEV_ENABLEwith no knote fail withENOENT.SIGUSR1(withfflags7,data9 and audata),SIGUSR2andSIGALRMreport no event, and neither doeskillwith signal 0.raise,killandpthread_killon the calling thread withSIGUSR1give one event withEV_CLEAR,fflags0,data3 and theudata, then none.EV_DISABLE, araisereports no event;EV_ENABLEthen reports one withdata1.ITIMER_REALgives oneSIGALRMevent withdata1.EV_DELETEreturns 0 and a second one fails withENOENT. Araiseafter the delete reports no event, and araiseafterclosestill succeeds.Overlap: no open PR implements
EVFILT_SIGNAL.gh pr list --repo boykopovar/AnyPS5 --state open --searchforfilt_sigattachandNOTE_SIGNALreturned no PRs.EVFILT_SIGNALreturned only my #14854 (below), whose debt rewrite keeps theEVFILT_SIGNALclause as it is onmain.kevent signaladded #9491 (semaphore tokens for queued waiters), andkqueue signaladded #9557 (SIGIOowner of a pipe) and #12682 (cancel blocked POSIX reads). By title #9491 is unrelated; the diff search below found no signal-filter code or text in #9557 or #12682.tools/pr_overlap.pyreports five PRs. The first four add or remove no signal-filter code or text:UserEventWakesEveryWaiterright afterUserEventsinGuestKqueue.cpp(line 357 onmain), where this PR addsSignalEvents.si_codeofsigwaitinfoandsigtimedwait) changes theMarkPendingcall inpthread_kill(lines 699-700 onmain), next to the line this PR adds there.EVFILT_PROCwithNOTE_EXITon the calling process) changes the same filter check inRegisterand adds its own constant, add function andRegisterbranch next to this PR's.git merge-treeof this branch with its head575c14f9b4conflicts in four blocks inKqueue.cppand on debt lines 167 and 172. Each conflict puts two additions side by side, and keeping both sides resolves it. Whichever PR merges second needs a rebase of those lines.main. I searched each of their diffs for removed code lines this PR also removes, for the same debt lines or entries, and for added or removed signal-filter text. None shares a removed code line or adds or removes signal-filter text. #7088 and #9843 also rewrite the kqueue and kevent entry (line 167), so the second to merge will need a rebase there. #3986, #7121, #9389, #12682, #12688, #12700 and #12965 shareSignals.cppor the kqueue files and change other lines.Tested
Windows 11 Home 10.0.26300.9711, Git Bash, WinLibs gcc/g++, Ninja, Release, in the build tree configured with
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DBUILD_TESTING=ON -DPython3_EXECUTABLE=C:/Python314/python.exe. No title or homebrew; only the guest tests below were run.5bae1a4bc2), after the code and test edits:cmake --build build --target guest_kqueue_tests guest_kill_tests guest_itimer_tests: exit 0.ctest --test-dir build -R '^(guest_kqueue|guest_kill|guest_itimer|guest_itimer_pending_default)$' --no-tests=error --output-on-failure --timeout 120: 4/4 passed.ctest --test-dir build -R 'public_headers' --no-tests=error --output-on-failure --timeout 120: 65/65 passed, becauseEqueue.hppchanged.cmake --build build: exit 0.ctest --test-dir build -R '^guest_(kqueue|kqueue_cleared_race|kill|itimer|itimer_pending_default|getitimer|signals|signal_interrupt|signal_handler_mask|sigtimedwait|signal_sets|sigaltstack|raise_.*|mutex_raise_exception)$' --no-tests=error --output-on-failure --timeout 120: 30/30 passed, among themguest_kqueue,guest_kqueue_cleared_race,guest_kill,guest_itimer,guest_signalsand theguest_raise_*tests. The commit7014b28abbhas the same 5 files, 87 insertions and 3 deletions as the tested working tree.0211640a74amends7014b28abband changes only debt line 172 (1 insertion, 1 deletion), to shorten theEVFILT_SIGNALclause. On it,python tools/check_conventions.py --base origin/mainexited 0 with 0 errors and 2debt-lengthwarnings fordocs/dev/debt/libkernel.md. Line 167 is 3545 characters (3537 onmain) and line 172 is 4546 characters (4336 onmain); both were already over 1000 characters onmain. None of the 5 files changed onorigin/main(0580e5c951) since the merge base.0211640a74failed inguest_kqueuebecauseSIGALRMexpired with the default disposition.ExpireAlarmcountedSIGALRMin the kqueues before it read the disposition, soSignalEvents, woken by the knote, could restoreSIG_DFLfirst.pthread_killon another live thread had the same order. The head49dc637ee2reads the disposition first in both places (Signals.cpp, 2 insertions, 2 deletions). These checks ran on0211640a74with that diff uncommitted. A fullcmake --build buildexited 0.ctest --test-dir build -R '^(guest_kqueue|guest_kill|guest_itimer)' --output-on-failure: 5/5 passed.ctest --test-dir build -R '^guest_kqueue$' --repeat until-fail:25 --output-on-failure: all 25 runs passed. On49dc637ee2,python tools/check_conventions.py --base origin/mainexited 0 with 0 errors and the same 2debt-lengthwarnings.python tools/pr_overlap.py --branch feat/libkernel-kevent-signal: exit 2. It found 1858 open PRs and fails closed when it cannot compare every one. The manual comparison is under What.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T00:17:45Z.
Review: APPROVED
Reviewed at
49dc637ee2, merged locally intomain66e1f7f993(clean merge; GitHub reports it mergeable). Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0, Release, Ninja.Checked against FreeBSD 11.4's source (
release/11.4.0, source read, not run, not measured on a console):sys/kern/kern_sig.c:3784-3794:filt_sigattachattaches tocurprocand setsEV_CLEAR.3811-3821:filt_signaladds 1 tokn_datafor aNOTE_SIGNALhint matching the ident and reports whilekn_datais not 0.kern_sig.c:2163:tdsendsignalrunsKNOTE_LOCKED(p->p_klist, NOTE_SIGNAL | sig)before theps_sigignorecheck, so ignored and blocked signals are counted, as this PR does.sys/kern/kern_event.c:knote()callsf_eventon a disabled knote too (it skips only a knote in flux, line 2131), andKNOTE_ACTIVATE(lines 202-212) only skips the queue whileKN_DISABLEDis set, so a disabled knote keeps counting.EV_ENABLEre-checks withf_event(kn, 0)inkqueue_registerand reports the count, which matches theEV_DISABLE/EV_ENABLEcase inSignalEvents.In
Signals.cppwith this PR,raise(whichkillon the calling process goes through) counts before its ignore check, andpthread_killon another live thread counts after marking the signal pending, whatever its disposition. So both paths count ignored signals, astdsendsignaldoes.What I ran
ctest -R '^(guest_kqueue|guest_kqueue_cleared_race|guest_signals|guest_signal_list|guest_signal_sets|guest_signal_handler_mask|guest_signal_interrupt|guest_sigtimedwait|guest_sigaltstack|guest_itimer|guest_itimer_pending_default)$' --repeat until-fail:3: 11 of 11 pass, 3 of 3 runs.main'sEqueue/src/Kqueue.cpp,Equeue/Equeue.hppandSystem/src/Signals.cppwith this PR's test:guest_kqueueaborts withkevent: filter -6 not implemented.python tools/check_conventions.py --base upstream/main: no errors; twodebt-lengthwarnings on thekqueue and keventandkevent measurementsentries, which are already over the limit onmain.Looks good.
AI-assisted: yes (Claude Code)