feat(libkernel): implement kqueue, kevent and file events #3764
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3764"
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 YossiYad on 2026-10-11T16:33:17Z.
What
Carries David's two
screamm/AnyPS5:feat/libkernel-kqueuecommits from #3461 onto currentmain, preserving their author, and adds two follow-up test commits:kqueueandkeventover the event queue: change list,EV_ERROR/EV_RECEIPT, errno codes and timeout rules after FreeBSD 11.0.1kern_event.c, with read/write on guest sockets, timers and user events. Cloudberry Kingdom (PPSA23827, #3177) callskeventright after start-up.EVFILT_VNODEandsceKernelAddFileEvent/sceKernelDeleteFileEvent(cG3t15OK4Ow,UmXngHKB6is), which Palworld's Discord module imports (#2648). Host file and directory changes become FreeBSD vnode hints (Linux: inotify; Windows: change notifications plus a 50 ms snapshot poll).Equeue.cppand leaves a duplicatedCollectTriggereddeclaration inEqueue.hppthat does not compile; both are resolved inside the first commit. The resulting tree is identical to blawesom's verified rebase (blawesom:verify/3461).kqueue, which reaches the inotifyIN_MOVE_SELFand link-count paths that were never run on Linux. The case is skipped on Windows, where a descriptor from guestopenis opened without delete sharing and the host refuses to rename or remove it.IN_MOVED_FROM/IN_MOVED_TOasNOTE_WRITEand a removed subdirectory asNOTE_WRITE|NOTE_LINK.The library progress moves from 2903/3383 (85.81%) to 2906/3385 (85.85%):
kqueue,sceKernelAddFileEventandsceKernelDeleteFileEvent. The total rises by two because the file-event calls were not exported before.keventstays counted as todo because unmodelled cases still throw. Those cases, and the deviations listed in #3461, are recorded in TechnicalDebt.Closes #3461.
Tested
Linux (Bazzite 44, GCC 16.2.1, Ninja, Release,
-DBUILD_TESTING=ON), based onmaina11c8f7f:libs, and fullctest: 825 pass, 8 skip, no failures (833 registered tests). The GPUagc_driver_pixel_interlocktest failed on an earlier run and passed on the final full run; the changed library does not participate in that test.guest_kqueuepasses 20 consecutive runs, and 5 rounds of four copies running at the same time. The targeted run ofguest_kqueue,guest_equeue_events,guest_socket_events,guest_dup,guest_ppsa01530_exports,patched_libraries,progress_reportandprogress_encodingpasses (8/8).NOTE_DELETE, directory rename reported asNOTE_WRITE|NOTE_EXTEND).tools/check_conventions.py --base upstream/mainandgit diff --checkpass.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T16:33:43Z.
Progress report (
03895fc→b7c67a3)📈 System libraries: 87.3% (+0.04%, +3 implemented functions)
✅ 3 implemented
kqueue_nid_postfixsceKernelAddFileEventsceKernelDeleteFileEventImported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T16:47:38Z.
Windows data point for this PR (the description says the two new cases were not run on Windows): Windows 10, MinGW/Ninja Release build of the PR head on top of
maina11c8f7f7(git fetch upstream pull/3764/head).guest_kqueuepasses in 6 consecutive runs (1.3 to 1.5 s each, run one after the other, not in parallel), andguest_equeue_events,guest_dup,guest_socket_eventsandguest_ppsa01530_exportspass. No title was run, and I did not check which cases the test skips on Windows.I also had a much smaller branch for the same imports (
kqueuereturns a placeholder descriptor,keventaccepts onlyEVFILT_VNODEregistrations and never fires). This PR covers all of it, so I am not opening mine.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-11T21:13:25Z.
Title evidence for this PR: on #2648, queeeef's ordered Palworld (PPSA23126,
maina11c8f7f7) stop list has this as stop 1 —FAIL: unresolved ELF import cG3t15OK4Ow from libkernel.prx(sceKernelAddFileEvent, withkeventandsceKernelDeleteFileEventalso absent). Their table passes it withblawesom:verify/3461, which this PR carries (identical tree), and reports every import then binds, the title reaching character creation with the other listed PRs.Thanks @xXPBSXx for the Windows run above.
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T02:10:26Z.
Test of this PR on titles, Windows 10, MinGW GCC, RTX 4080 SUPER, each run under a 150 s limit, on current
mainwith this PR merged locally (merge was clean):sceKernelAddFileEventimports bind (0 unresolved imports) and the title runs for a while (shader cache activity), then aborts withwhat(): EVFILT_VNODE: NOTE_EXTEND on a directory not implemented(SIGABRT). That is the throw inFileEvent.cppOpenHostWatch, so the title registers aEVFILT_VNODEevent withNOTE_EXTENDon a directory descriptor, which this PR deliberately does not implement.unhandled exception 0xc0000005 on thread 'RtcNetworkThread',eossdk-ps5-shipping.prx.guest.prx+0xdea2be, write fault,rcx/r12=0x10000005(the libkernel socket,FD_SET, #1794). Needed the game directory (pal,sce_sys) linked intoapp0as queeeef describes.So the PR removes the first stop for both titles; for Cloudberry the directory
NOTE_EXTENDcase is what decides next. No game data shared.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T02:13:06Z.
Follow-up on the Cloudberry stop above (
EVFILT_VNODE: NOTE_EXTEND on a directory not implemented): what FreeBSD does withNOTE_EXTENDon a directory. Source: freebsd-srcrelease/13.2.0(the PS5 kernel is FreeBSD-derived, but I have not checked that the console matches this version),sys/kern/vfs_subr.c,lib/libc/sys/kqueue.2.vfs_kqfilteronly switches on the filter (EVFILT_READ/EVFILT_WRITE/EVFILT_VNODE, elseEINVAL); it checks neither the vnode type norfflags.filt_vfsvnodejust masks the posted hint against the registered flags:if (kn->kn_sfflags & hint) kn->kn_fflags |= hint;. So a directory withNOTE_EXTENDregisters without error and simply may never fire.kqueue(2): "For directory, reports that a directory entry was added or removed, as the result of rename operation. The NOTE_EXTEND event is not reported when a name is changed inside the directory." In code the only place isvop_rename_post:hint = NOTE_WRITE; if (a->a_fdvp == a->a_tdvp) {...} else { hint |= NOTE_EXTEND; ...}, delivered to the source and the target directory, i.e. only when an entry moves between two different directories.vop_create_post,vop_remove_post,vop_mknod_post,vop_symlink_post,vop_link_postpostNOTE_WRITEon the directory;vop_mkdir_post/vop_rmdir_postpostNOTE_WRITE | NOTE_LINK.Suggestion to the author: since the Linux path in this PR already posts
NOTE_WRITE | NOTE_EXTENDfor a move between directories (themoves[...]handling), the Windows directory path could accept theNOTE_EXTENDregistration the same way instead of throwing, and postNOTE_WRITEfor added or removed entries as it does now. Whether Windows can tell a cross-directory move from a remove plus an add is for the author to judge; if it cannot, registering without ever deliveringNOTE_EXTENDon directories would be the documented gap (a TechnicalDebt line), which matches how the other vnode cases are handled in this PR. Cloudberry only needs the registration to succeed to get past this point; I cannot tell from the stop whether it waits for the event.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T19:08:42Z.
Review: COMMENTED
Linux build and run, and the one arm the Cloudberry stop turns on
I built this head on Linux and ran its own suite, a control against the parent implementation, and a probe for the registration the title stops at. Nothing below asks you to change something I have not measured on Linux — the one Windows-side suggestion is labelled as the part only you can judge. I have no PR against this path.
Refs in my checkout: the branch's own base (merge-base with
upstream/main) is33067ca0c, the head I built is58c940edc, andupstream/mainwas1acfa7f78while I worked.Control, meaning the parent implementation with this PR's own test kept:
Equeue.cpp,Equeue.hpp,File/src/Open.cppandFile/src/Stdio.cpptaken from33067ca0c,Equeue/src/FileEvent.cppandEqueue/src/Kqueue.cppremoved. The test cannot run there, and it fails at link, not at run:7 undefined references in all (4
sceKernelAddFileEvent, 3sceKernelDeleteFileEvent).kqueue_nid_postfixandkevent_nid_postfixare not among them:33067ca0calready exports both as throwing stubs (core/libs/prx/libkernel/Equeue/Equeue.cpp:318,:323), so on the parent those two halves are runtime throws while the file-event pair does not exist to link against at all.The Windows refusal, and the Linux arm that does not have it
Reading the registration as valid, and the recommendation that follows, were first put by @xXPBSXx earlier in this thread; what I can add is the Linux measurement behind them and the line-level check against the source the debt entry pins.
core/libs/prx/libkernel/Equeue/src/FileEvent.cpp:289-293, inside the#ifdef _WIN32block that opens at:120and closes at:479:The Linux
OpenHostWatchat the same file's:447takes that argument unnamed (int OpenHostWatch(int descriptor, std::uint32_t, HostWatch& host)), so the notes are never consulted on that path. I put Cloudberry's registration through the guest API on Linux:So the registration is not refused on Linux, and that arm already delivers
NOTE_EXTENDfor an entry moved across the directory boundary (FileEvent.cpp:426-428). The console's own system software is FreeBSD-derived, so FreeBSD's kernel source is the reference for these semantics rather than an analogy, and it agrees the registration is legal: insys/kern/vfs_subr.cat the commit the debt entry pins (34bd34750187),vfs_kqfilter(:4937) switches only on the filter and answersEINVALfor an unknown one, checking neither the vnode type norfflags, andfilt_vfsvnode(:5032) only masks the posted hint (:5038-5039,if (kn->kn_sfflags & hint)thenkn->kn_fflags |= hint;) — a directory registered withNOTE_EXTENDregisters fine and simply may never fire.That makes the Windows throw a portability gap rather than a modelled refusal: the same registration is a working configuration on the Linux half of this same file. Accepting it on the Windows side, posting the
NOTE_WRITEthe directory handles already report for an added or removed entry and recording the undeliveredNOTE_EXTENDin the debt entry as the file already does for its other cases, should clear the throw that is this title's current stop without inventing semantics — whether Cloudberry then waits for the event is not something the stop shows. Whether Windows can tell a cross-directory move from a remove plus an add is the part only you can judge. I cannot test any of the Windows half: I have no Windows machine here.The arm the test does not cover
core/libs/tests/GuestKqueue.cpp:343registers a directory withNoteWrite | NoteLink | NoteDelete | NoteRename—NOTE_EXTENDis not in that set — and its only rename case (:350-352) is within the directory, which is themoves[cookie] > 1half ofFileEvent.cpp:427. TheNOTE_EXTENDhalf, an entry moved into or out of the watched directory, is exercised by no test on either host, and it is the arm that decides what this title needs. A case inDirectoryWatch()would cover it.One caveat on that arm, measured at the host level with the library's own 16384-byte read buffer and directory mask (
inotify_batch_probe.c): the "within" vs "across" classification is a property of a singleread()chunk, so a pair split across two reads reports both halves as cross-directory.16 of 4000 is 0.4%, which is consistent with the split pairs needing more than one read chunk (about 512 events) of backlog to occur at all; the guest then sees a spurious
NOTE_EXTENDrather than a missing event. Worth a debt sentence beside the Linux hint mapping, not a change.Rebase state
git merge-tree --write-tree pr-3764 upstream/mainexits 1 with four conflicting files:core/libs/prx/libkernel/CMakeLists.txt(main addsFile/src/DescriptorControl.cppwhere this adds the two new sources),File/src/Open.cppandFile/src/Stdio.cpp(main added the socket forwardingif (d >= GuestSockets::FirstDescriptor) return GuestSockets::Close(d) ...andKernelCloseSocket_nid_no_patch(d, &socketError)where this addsEqueueDescriptorClosed(d);), anddocs/dev/TechnicalDebt.md(both sides append entries to the same list). All four are additive; the only judgement is whereEqueueDescriptorClosed(d)belongs relative to main's new socket line.Things that check out, so nobody has to re-derive them
vfs_subr.c:5032isfilt_vfsvnode,vfs_kqfilteris at:4937, and the rename rule is at:4671-4691—hint = NOTE_WRITEwhen both parents are the same directory (plusNOTE_LINKwhen a directory is replaced),hint |= NOTE_EXTENDwhen they differ (plusNOTE_LINKwhen the moved vnode is itself a directory).vop_create_post(:4608) andvop_remove_post(:4664-4665) postNOTE_WRITEon the directory,vop_mkdir_post(:4637) andvop_rmdir_post(:4713-4714) postNOTE_WRITE | NOTE_LINK, which is what the Linux mapping andDirectoryWatch()expect.fflags" is measurable and right. Re-registering a directory withNOTE_WRITEonly and then moving an entry in across the boundary still reports0x00000006, becauseTriggerVnode(FileEvent.cpp:486-488) tests the intersection and then ORs the whole hint —filt_vfsvnode's shape. I read it as stale registration notes first; the source says otherwise and the debt entry already states it.David <[email protected]>on both, matchingscreamm/AnyPS5 feat/libkernel-kqueue'scd21c720eanda289fb403), and the change's own library sources are byte-identical toblawesom:verify/3461's head (FileEvent.cpp02bfd335,Kqueue.cppa60b3dbb;Equeue.cppandEqueue.hppdo not differ at all). The body's "the resulting tree is identical" is literally not so — the branch is rebased onto newer main and adds two test commits, so the trees differ by 341 files — but the carried change itself is the same, which is the part that matters.sceKernelAddFileEvent,sceKernelDeleteFileEventorEVFILT_VNODE(the search API returns this PR only), so the checklist's no-duplicate line holds.linuxandwindowsjobs are gated(push || workflow_dispatch) && full == 'true'(.github/workflows/build.yml:191-193,:238-240), which is whygh pr checks 3764reports both as skipping. The Windows evidence is @xXPBSXx's manual runs; the Linux run is what I have added here.What I could not check: anything on Windows (the throw itself, and whether the directory handles can distinguish a cross-directory move); a title run, since the stop is on the platform I cannot run and no game data is staged here; and whether the console's kernel matches the FreeBSD 11 source the debt cites.
AI-assisted review; every number above comes from a command run here.
Hermes Agent 🤖 at your service
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:48:28Z.
Rebased onto current
main(conflicts inlibkernel/CMakeLists.txt,File/src/Open.cpp,File/src/Stdio.cpp, and the TechnicalDebt entries, which now live indocs/dev/debt/libkernel.mdandlibSceNet.md). The four commits are kept; I added one on top:FileEvent.cpp: a directory registered withNOTE_EXTENDis no longer refused on Windows. FreeBSD'svfs_kqfilterchecks neither the vnode type norfflags, and this is the throw Cloudberry Kingdom (PPSA23827) stops at in @xXPBSXx's run. Windows never delivers it (the directory handle cannot tell a move between directories from a removal plus an addition); the debt entry says so. Suggested in this thread by @xXPBSXx and @Dextroid17.Checked on Linux: build and ctest of
libkernel+core/libson the rebased head are green (guest_kqueue,guest_equeue_events,guest_dup,guest_socket_events,guest_ppsa01530_exports10/10 repeated;guest_kernel_fcntlaborted once in the parallel full run and passes repeated).guest_kqueuedoes not link without the change. Not checked here: Windows and any title run; theNOTE_EXTENDarm for a move between directories has no test.Merging once CI is green.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T20:51:54Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libkernel.mdL93core/libs/prx/libkernel/CMakeLists.txtL1023core/libs/prx/libkernel/File/src/Open.cppL223core/libs/prx/libkernel/File/src/Stdio.cppL498, L546-547, L572-574, L579, L595core/libs/prx/libkernel/File/src/Stdio.cppL579Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T21:04:07Z.
The overlap bot flagged my #4640 because it also updates the Windows
dup2block inStdio.cpp. I rebased #4640 onto current main and preserved the existingEqueueDescriptorClosed(to)plus the directory-descriptor bookkeeping while adding the standard-handle save/restore. There is no API dependency between the PRs, but the shared hunk may need a rebase after either lands.