feat(libkernel): accept EVFILT_PROC with NOTE_EXIT on the calling process #14854
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14854"
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-01T20:23:41Z.
What
keventthrewNotImplemented_nid_no_patchfor everyEVFILT_PROCchange. It now acceptsEVFILT_PROCon the calling process withNOTE_EXITor no notes, as FreeBSD 11.4 does. Inkern_event.c,filt_procattachfinds the process withpfind(kn->kn_id), checksp_cansee, addsEV_CLEARto the knote and activates it at attach only for a process that is already exiting or for aNOTE_TRACKchild knote.filt_procreports a knote only for a hint carrying a subscribed note (NOTE_EXITwhen the process exits,NOTE_FORKandNOTE_EXECwhen it forks or execs), so aNOTE_EXITknote on the calling process is never reported while that process runs:EV_ADDstores the knote withEV_CLEARadded andfflagsanddata0, askqueue_registermoveskev->fflagsandkev->dataintokn_sfflagsandkn_sdataand clears them in the stored kevent. An add withEV_RECEIPTreturnsEV_ERRORwithdata0 andfflags0.EV_ADDon the existing knote,EV_DISABLEandEV_ENABLEreport nothing:proc_filtopshas nof_touch, andfilt_procwith hint 0 returnskn_fflags != 0, which is false.EV_FORCEONESHOTreports the knote once, with its stored flags plusEV_ONESHOT,fflags0,data0 and theudataof that change, and then it is gone:kqueue_registersetsEV_ONESHOTand activates the knote, andkqueue_scancopies a one-shot knote's kevent without callingf_event.EV_DELETEremoves the knote;EV_DELETEorEV_ENABLEwith no knote fails withENOENT.NOTE_EXIT(NOTE_FORK,NOTE_EXEC,NOTE_TRACKand the rest), still throw: this PR does not look up other processes or report forks and execs.The kevent measurements entry in
docs/dev/debt/libkernel.md(payload processes on a PS5, firmware 12.70) recorded thatEVFILT_PROCon the process itself withNOTE_EXITwas accepted there and still threw here. This PR accepts it and rewrites that clause (line 172) to say so and that another process and notes other thanNOTE_EXITstill throw. The kqueue and kevent entry (line 167) now listsEVFILT_PROCon the process itself withNOTE_EXITor no notes among the filters that do not throw. Only the acceptance was measured on a PS5; the behaviour after it follows FreeBSD 11.4.Code:
RegisterinEqueue/src/Kqueue.cppchecks everyEVFILT_PROCchange with the newDefinedProcessChangeand throws when it returns false. A change to an existing knote is defined when it deletes the knote or carries no note other thanNOTE_EXIT; a change withoutEV_ADDand with no knote goes on to the existingENOENTpath; an add is defined whenidentisgetpid()and the notes areNOTE_EXITor none. The newAddProcessKnotestores the knote withEV_CLEARadded andfflagsanddatacleared in both the stored event and the change.Tests:
ProcessExitOnSelfincore/libs/tests/GuestKqueue.cpp:EV_DELETEwith no knote (ENOENT); anEV_ADD | EV_RECEIPTadd withNOTE_EXIT(receipt withEV_ERROR,data0 andfflags0, then no event); re-adds withNOTE_EXITand with no notes, thenEV_DISABLEandEV_ENABLE(no event);EV_FORCEONESHOT(one event withEV_RECEIPT | EV_CLEAR | EV_ONESHOT,fflags0,data0 and the newudata, then none, andEV_DELETEthen fails withENOENT); anEV_ADD | EV_ONESHOTadd withNOTE_EXITand itsEV_DELETE(both 0), thenEV_ENABLE(ENOENT).Overlap: no open PR implements
EVFILT_PROC.gh pr list --repo boykopovar/AnyPS5 --state open --searchforEVFILT_PROC,NOTE_EXIT,EVFILT_SIGNAL,EVFILT_FS,filt_proc,filt_signalandkevent procreturned no PRs. On this branch's base, the searches forEVFILT_PROC,NOTE_EXITandfilt_procattachagain returned none, andkevent process exitreturned #14832, #10645 and #7532: #14832 is my NOTE_LOWAT PR (below), and by title #10645 (pipe write events and socket low watermarks insceKernelAdd*Event) and #7532 (guest entry stack on Linux) are unrelated.tools/pr_overlap.pyreports three PRs. #7492 (wake every waiter on an equeue or kqueue) addsUserEventWakesEveryWaiter();afterUserEvents();inmaininGuestKqueue.cpp(line 1636 onmain), where this PR addsProcessExitOnSelf();; it adds and removes no process-filter code or text. #12741 (macOS edge watches) rewrites debt line 167 and adds or removes noEVFILT_PROCtext. My #14832 (NOTE_LOWAT below 1) rewrites debt lines 167 and 172, the same two lines, and keeps theEVFILT_PROCclause as it is onmain.git merge-treeonmainatb6e3f68173merges this PR and each of the three cleanly on its own, but this PR then has one content conflict with each: inGuestKqueue.cppafter #7492, and in the debt file after #12741 or #14832. All three were opened first, so the proposed order is all three before this PR (Depends on: #7492, #12741, #14832, proposed to the authors of #7492 and #12741 in a comment here). After each merges, this branch is rebased ontomainand keeps both edits to those lines.main. I searched each of their diffs for changed code lines that this PR also changes and for added or removed lines namingEVFILT_PROC,NOTE_EXIT,NOTE_FORK,NOTE_EXEC,NOTE_TRACK,filt_procor the process itself; for #5021, wheregh pr difffailed, I searched its per-file patches from the GitHub API. None match. #7088, #7121 and #9843 shareKqueue.cpp,GuestKqueue.cppand the debt file; #7088 and #9843 also rewrite the kqueue and kevent entry (line 167) without namingEVFILT_PROC, so the second to merge will need a rebase there.Tested
Windows 11 Home 10.0.26300.9711, Git Bash, WinLibs gcc/g++, Ninja, Release. No title or homebrew; only the guest kqueue test was run.
e450145140, before the branch was cut:git submodule update --init --recursive --jobs 8,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,cmake --build build --parallel 4: exit 0.e0caf13600), after the last edit and before the commit:cmake --build build --target guest_kqueue_tests --parallel 4rebuilt 10 libkernel objects, among themKqueue.cpp, andGuestKqueue.cpp, and relinkedlibkernel.prxandguest_kqueue_tests.exe: exit 0.ctest --test-dir build -R '^guest_kqueue$' --no-tests=error --output-on-failure --timeout 120: 1/1 passed (5.48 s). The commitf5e1921254has the same 3 files, 64 insertions and 3 deletions as the tested working tree.f5e1921254:python tools/check_conventions.py --base origin/main: exit 0, 0 errors and 2debt-lengthwarnings fordocs/dev/debt/libkernel.md. Line 167 is 3603 characters (3537 onmain) and line 172 is 4635 characters (4336 onmain); both were already over 1000 characters onmain.575c14f9b4, which drops the twoThrowsassertions forNOTE_FORKadds fromProcessExitOnSelfand the unusedNoteForkconstant (NOTE_FORKstill throws inKqueue.cpp, and no test pins it), in a new worktree of this branch with the submodule and configure commands above:cmake --build build --target guest_kqueue_tests --parallel 4: exit 0.ctest --test-dir build -R '^guest_kqueue' --output-on-failure: 2/2 passed (guest_kqueue,guest_kqueue_cleared_race). The commit has the same 1 file and 3 deletions as the tested working tree. On575c14f9b4,python tools/check_conventions.py --base origin/main: exit 0, 0 errors and the same 2debt-lengthwarnings.python tools/pr_overlap.py --branch feat/libkernel-kevent-proc-exit-self: exit 2. It probed 1851 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