72 Commits
Author SHA1 Message Date
Dean d2409cef70 Merge pull request #10645 from rocklouis055/feat/equeue-pipe-write-lowat-on9099
feat(libkernel): add pipe write events and socket low watermarks to sceKernelAdd*Event
2026-11-27 02:10:22 +13:00
Dean 5c69358784 Merge pull request #24491 from brajankw/fix/libkernel-ksem-fstat-fchmod
fix(libkernel): answer fstat and fchmod on a ksem id as FreeBSD 11.4's ksem_stat and ksem_chmod do
2026-11-22 14:18:21 +13:00
brajankwandClaude Opus 5.5 f9c7ef4e59 fix(libkernel): answer fstat and fchmod on a ksem id as FreeBSD 11.4's ksem_stat and ksem_chmod do
A ksem id is a host null device descriptor here, so fstat reported the
host's /dev/null and fchmod called the host's fchmod on it, which as
root changes the mode of the host's /dev/null. FreeBSD 11.4 answers
both from the semaphore: ksem_init creates it with S_IRWXU | S_IRWXG
under the umask, owned by the caller; ksem_stat reports a zeroed stat
with S_IFREG, that mode, the owner and the four times; ksem_chmod keeps
the mode's ACCESSPERMS bits. The times are taken to the microsecond, as
vfs_timestamp does by default: all four at creation, the change time on
ksem_post and the access time on every wait and on ksem_getvalue, also
when its copy-out then fails.

The equeue read and write events and AIO decided from fstat whether a
descriptor is a regular file, which a ksem id would now pass. They ask
an exported IsKsemDescriptor_nid_no_patch instead: the equeue calls keep
their throw, and AIO keeps EOPNOTSUPP for a read and gives
aio_fsync EINVAL, as aio_aqueue does for a file without a vnode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 18:24:35 +01:00
brajankwandClaude Opus 5.5 0c7dd7b9cb fix(libkernel): fail EVFILT_READ and EVFILT_WRITE on the random device with ENODEV, as FreeBSD 11.4 does
kevent, sceKernelAddReadEvent and sceKernelAddWriteEvent threw for read
and write events on /dev/random and /dev/urandom. FreeBSD 11.4 attaches
these filters through the file's fo_kqfilter; devfs passes it to the
device's d_kqfilter, which random_cdevsw leaves unset and prep_cdevsw
fills with enodev. kqueue_register clears fflags before the attach, so
the error event has fflags 0 and ENODEV in data. The check now comes
before the standard input shortcut, so a random device duplicated onto
descriptor 0 answers the same, and the two equeue calls check a bad
queue first, as kern_kevent fetches the kqueue before the attach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 18:20:15 +01:00
pushkarreddyy bbd069c09d fix(libkernel): clamp host wait buffer in sceKernelWaitEqueue 2026-11-16 14:01:55 +05:30
pushkarreddyy 32bb61b95e fix(libkernel): safely probe output and timeout pointers in sceKernelWaitEqueue 2026-11-16 12:23:49 +05:30
PetreandClaude Sonnet 5.5 6ccaecd4be fix(libkernel): report user events in the order they were triggered
On a PS5 (firmware 13.590.001), user events 1, 2 and 3 added in that order
and triggered as 2, 1, 3 were reported as 2, 1, 3, again as 2, 1, 3 on the
next wait, and unchanged by a second trigger of an event already
triggered. They were reported here in registration order. A user event
that goes from idle to triggered now moves behind the other events, as
FreeBSD's knote_enqueue queues it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 21:28:27 +01:00
BunnyFl 43fe07b7f9 fix(libkernel): zero sceKernelWaitEqueue's count on every failure as firmware 13.42 does (#15123)
* fix(libkernel): zero sceKernelWaitEqueue's count on every failure as firmware 13.42 does
* docs(libkernel): describe sceKernelWaitEqueue's null event list without naming kevent
2026-11-16 08:15:53 +13:00
tablefrogpillowandClaude Opus 4.8 dcdccac8f8 fix(libkernel): record and log equeue pending-event drops instead of dropping them silently
Triggers and AddEvent past the 64-event pending cap dropped the oldest queued
events with no record. Each dropped-oldest batch is now counted per queue
(DroppedPendingEvents()) and logged, gated on APS5_TRACE_EQUEUE and
rate-limited to the first drop and each power-of-two of the cumulative total,
so a long burst reports in log2 lines rather than one per drop. The cap value
and the drop-oldest (keep-newest) semantics are unchanged, pending the console
queue-depth / keep-newest-vs-oldest question on #7509.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-14 20:59:01 +00:00
Lindamea1 daad982457 fix(libkernel): wake every thread waiting on an equeue or kqueue when an event fires (#7492) 2026-11-13 23:08:30 +13:00
Dean fcfb95cabe Merge pull request #18817 from THEMANnt/fix/libkernel-equeue-hrtimer-input
fix(libkernel): check high-resolution timer input buffers
2026-11-13 15:01:25 +13:00
THEMANnt 1cdf90c51b fix(libkernel): check event queue creation buffers 2026-11-12 14:23:33 +03:00
THEMANnt 0e968442bd fix(libkernel): check high-resolution timer input buffers 2026-11-12 14:17:19 +03:00
xXPBSXxandClaude Sonnet 5.5 594b03d74e fix(libkernel): sceKernelCreateEqueue returns ENAMETOOLONG for a name of 32 characters or more
The name was accepted at any length.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-08 00:55:17 +01:00
Dean 9e47f0c3ac Merge pull request #15884 from zaryabzip/fix/kernel-ampr-event-bad-queue
fix(libkernel): return EBADF from sceKernelAddAmprEvent for an equeue that is not live
2026-11-08 12:04:03 +13:00
BunnyFlandClaude Opus 5.5 63dbad84c0 Merge upstream/main into feat/libkernel-equeue-kqueue-descriptor
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 00:27:10 +01:00
zaryabzip cbdff138ef Merge branch 'main' of https://github.com/boykopovar/AnyPS5 into fix/kernel-ampr-event-bad-queue
# Conflicts:
#	docs/dev/debt/libkernel.md
2026-11-07 02:39:52 +05:00
kenny soloandClaude Opus 5.5 d8afe4c68b feat(libkernel): always fire a socket read knote with NOTE_LOWAT below 1
A socket EVFILT_READ knote whose NOTE_LOWAT mark is below 1 is now always ready and reports the bytes in the receive buffer, 0 when it is empty, because FreeBSD 11.4 filt_soread returns kn_data >= kn_sdata and the bytes available are never negative. This holds for level-triggered and EV_CLEAR knotes and when EV_ADD changes the mark of an existing knote. A listening socket ignores the mark, as filt_solisten does. An EVFILT_WRITE mark below 1 still throws.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-06 21:48:24 +01:00
zaryabzip eed90324cb fix(libkernel): return EBADF from sceKernelAddAmprEvent for an equeue that is not live
obSCEne's PS5 run (system software 12.40) returned 0x80020009 for a null
equeue and for one that is not live; the host returned 0 for both,
dropping the EBADF its own add already reported.
2026-11-05 03:06:22 +05:00
BunnyFlandClaude Opus 5.5 c029cd11fc feat(libkernel): make an equeue a kqueue descriptor as firmware 13.42 does
Firmware 13.42's libkernel_sys.sprx creates a kqueue for every equeue,
returns (named object id << 32) | descriptor, waits with kevent on the
descriptor and closes it on delete. sceKernelGetKqueueFromEqueue
stores the descriptor. Equeue handles were counters in their own table,
so the descriptor could not be used with kevent or close and the export
threw.

Equeues now reserve a descriptor and live in the kqueue table.
sceKernelDeleteEqueue checks the whole handle and closes the
descriptor, and sceKernelGetKqueueFromEqueue returns its low 32 bits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 19:57:26 +01:00
Dean Galvin efd499f60d Merge commit 'f1a7b02028ae50adaf6c5aaaef892a51841b25bf' into HEAD
# Conflicts:
#	core/libs/prx/libkernel/Equeue/Equeue.cpp
#	core/libs/tests/GuestEqueueEvents.cpp
#	docs/dev/debt/libkernel.md
2026-11-02 03:00:24 +13:00
louise-patraandClaude Opus 5.5 69cf176682 fix(libkernel): peek Windows datagram sizes and replace re-added socket marks
- GuestSockets::Ready on Windows reads a datagram socket's next datagram size
  with an overlapped MSG_PEEK receive, cancelled if it would wait, since
  Winsock's FIONREAD reports 1 for a zero-length datagram.
- Adding an existing socket event again replaces its low watermark.
- A socket low watermark above INT64_MAX throws instead of being capped.
- A write event re-added on a pipe whose read end closed succeeds and replaces
  its udata; EPIPE is kept for a new event.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 16:04:35 +05:30
louise-patraandClaude Opus 5.5 cc1e3c285a fix(libkernel): keep the default socket watermark for sizes 0 and 1
A size of 1 set a watermark of 1, so a readiness with no data, such as
a zero-length datagram, no longer fired.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 16:04:35 +05:30
louise-patraandClaude Opus 5.5 9efc5cd539 fix(libkernel): cap socket low watermarks at INT64_MAX
A size that does not fit in int64_t became negative and let every
readable or writable event through; it now caps at INT64_MAX, which
only end of file reaches. The tests drop the throw assertions for
unimplemented cases and run the pipe write path only where the host
reports pipe write readiness.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 16:04:34 +05:30
louise-patraandClaude Opus 5.5 3f8fc2e72b feat(libkernel): add pipe write events and socket low watermarks to sceKernelAdd*Event
sceKernelAddWriteEvent takes the write end of a pipe, with EPIPE once
the read end is closed, and a size above 1 sets the low watermark of a
stream socket, as kevent already does for both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 16:04:25 +05:30
Florent Combet a6fd9994f7 fix(libkernel): keep close observer registry alive through exit 2026-10-31 02:26:40 +01:00
Florent Combet 1caa5a7cab fix(libkernel): initialize close observer registry on first use 2026-10-30 23:18:28 +01:00
Adrià 0e5dad41c2 Merge pull request #9575 from DavidSamir/feat/libkernel-kqueue-evclear
feat(libkernel): support EV_CLEAR on a kqueue watched by another kqueue
2026-10-29 11:23:08 +01:00
David ec708dbde2 fix(libkernel): take the watched kqueue's count and activations in one snapshot
A cleared kqueue watch read the watched queue's triggered count and its
activation counter under two separate locks, so an activation between the
reads was marked seen without making the watch active, and the wakeup was
lost. SnapshotTriggered now returns both under one lock. Every poll of an
active watch also rechecks the count, as kqueue_scan reruns filt_kqueue:
it drops when the watched queue empties and reports the current count.
EV_ADD and EV_ENABLE of an existing watch re-arm it. A separate
guest_kqueue_cleared_race test triggers the watched queue from another
thread while the watching queue waits.
2026-10-28 13:45:03 +01:00
David 4c77b6ab65 feat(libkernel): support EV_CLEAR on a kqueue watched by another kqueue
FreeBSD re-evaluates a kqueue's EVFILT_READ note from kqueue_wakeup,
which runs whenever the watched kqueue queues a note, so an EV_CLEAR
note fires again only after such an activation. The equeue now counts
activations, and the EV_CLEAR note fires when the count moves while
notes are queued.
2026-10-28 13:44:50 +01:00
David 0742c4f6b4 feat(libkernel): let other libraries observe closed guest descriptors 2026-10-28 12:56:30 +01:00
Adrià 62b3ba2522 Merge pull request #11125 from MarcZX10/marc/fix-equeue-close-during-measure
fix(libkernel): wait for an in-flight file measurement before closing a watched descriptor
2026-10-27 13:30:54 +01:00
MarcZX10 9b9f9b4af8 fix(libkernel): retire an in-flight file measurement on every exit with a guard
MeasureFiles registered the descriptors it measures in m_measuring and removed them only on the normal path, so an exception between unlocking and relocking left them there and every later RemoveDescriptorEvents for one of them waited forever. Both vectors are reserved before anything is registered, and a guard owns the registration: on every exit it relocks if needed, removes the entries and notifies.
2026-10-27 04:46:00 +00:00
MarcZX10 de2b96d8bd fix(libkernel): wait for an in-flight file measurement before closing a watched descriptor 2026-10-27 04:46:00 +00:00
Evrim Cicek 3f67bbcd4e Merge branch 'main' of https://github.com/boykopovar/AnyPS5 into fix/recvmsg-after-shut-rd
# Conflicts:
#	core/libs/prx/libkernel/Socket/src/Udp.cpp
#	docs/dev/debt/libkernel.md
2026-10-27 01:04:45 +03:00
Dean f92497d1e5 Merge pull request #9780 from Retr0G28/fix/kevent-rotate-reported-knotes
fix(libkernel): move every knote kevent reports behind the waiting ones
2026-10-26 14:12:10 +13:00
Evrim Cicek 1c5e876164 fix(libkernel): report EV_EOF and wake read waiters when a socket is shut for reading 2026-10-26 01:09:17 +03:00
Adrià c2e087b2a6 Merge pull request #7049 from blawesom/followup/6510
fix(libkernel): retire an EV_ONESHOT note through its delete callback and follow Windows $Deleted paths
2026-10-25 12:38:21 +01:00
boykopovar 53a65ec210 fix(sdk): sync declarations with latest main 2026-10-24 23:17:48 +03:00
boykopovar f38d29fd08 refactor(sdk): add canonical headers for remaining libraries 2026-10-24 23:17:42 +03:00
Dean d003e64fcf Merge pull request #9099 from aarushkha/feat/libkernel-equeue-regular-file-events-v2
feat(libkernel): answer sceKernelAddReadEvent and sceKernelAddWriteEvent on regular files
2026-10-25 06:33:30 +13:00
Dean ce16645691 Merge pull request #9127 from Retr0G28/fix/equeue-rotate-level-events
fix(libkernel): move events reported by sceKernelWaitEqueue behind the waiting ones
2026-10-25 04:17:49 +13:00
Nawasfadili 29a6fc7169 fix(libkernel): retire an EV_ONESHOT note through its delete callback and follow Windows $Deleted paths
Carries the additive pieces of #6510 onto main after its feature was
superseded by #5847: the deleteEventFunc invocation when an EV_ONESHOT
note retires in CollectTriggered, the Windows $Deleted path detection
in FileEvent (IsDeleted transitions), the relaxed timer-modify and
SetVnodeNotes guards, and the compatible kevent tests.
2026-10-24 11:13:43 +02:00
ionut27001 27e37024a8 fix(libkernel): handle kevent timer re-adds and the AIO, LIO, SENDFILE and PROCDESC filters as measured on a PS5
In payload processes on a PS5 (firmware 12.70), re-adding an existing
periodic EVFILT_TIMER with EV_ADD, fflags 0 and a positive period kept
the armed expiry and the expirations already counted, and applied the
new period after that expiry, as FreeBSD 11.0 does. EV_ONESHOT in the
re-add left the timer periodic. Here such a re-add threw; it now does
the same. Re-adding a one-shot or disabled timer, a re-add with nonzero
fflags, a period of 0 or less, a period that overflows the armed expiry
or flags other than EV_ONESHOT, and the other changes to an existing
timer except EV_DELETE still throw.

There, EV_ADD failed with EPERM for EVFILT_AIO, EVFILT_LIO and
EVFILT_SENDFILE at every ident and flag set tried, and EV_DELETE and
EV_ENABLE of them without EV_ADD failed with ENOENT. EVFILT_PROCDESC
failed with EBADF on a descriptor that is not open and with EINVAL on
every kind of open descriptor tried, and EV_DELETE of it on a socket
failed with ENOENT. These filters threw here; they now answer the same
way. EV_ADD of EVFILT_PROCDESC fails with EINVAL on the kinds of
descriptor tried and on shared memory, and throws on other kinds and on
descriptors 0 to 2 that are not sockets or kqueues; a change without
EV_ADD fails with ENOENT, after the descriptor check for
EVFILT_PROCDESC.

A new kevent measurements debt entry, which the kqueue and kevent entry
points to, records these measurements and the answers for NOTE_LOWAT
marks and EVFILT_READ on another kqueue, which still throw here. The
kqueue and kevent entry also stops listing a NOTE_NSECONDS period above
one second with a fraction among the cases that throw, since d71a1c577
made it work.
2026-10-24 10:08:01 +02:00
Retr0 3383d303a7 fix(libkernel): move every knote kevent reports behind the waiting ones
FreeBSD 11.4 kqueue_scan (sys/kern/kern_event.c) puts a reported level
knote back at the tail of the queue and takes an EV_CLEAR or EV_DISPATCH
knote off it, and knote_enqueue queues that one at the tail when it fires
again. kevent moved a reported knote to the tail only while it stayed
triggered, so a level socket or pipe knote and a re-fired EV_CLEAR or
EV_DISPATCH knote kept their place and could starve later knotes when
nevents is smaller than the number of ready ones. Now every reported
knote that is not deleted moves to the tail.
2026-10-22 20:01:03 +03:00
aarushkha def751a787 fix(libkernel): reapply regular-file read events on top of watched equeues
Merge the file repoll into GatherInterests through WaitSet, so a wait on a
queue that watches another queue still polls regular-file events every
millisecond.
2026-10-21 23:46:39 +05:30
Retr0 41709ae50e fix(libkernel): move events reported by sceKernelWaitEqueue behind the waiting ones
FreeBSD 11 kqueue_scan (sys/kern/kern_event.c) re-inserts a reported
knote without EV_CLEAR or EV_DISPATCH at the tail of kq_head, and
knote_enqueue puts a knote that fires again at the tail as well, so the
next scan starts with the events that were not reported yet.
sceKernelWaitEqueue scanned the event list in place, so with num smaller
than the number of ready events the first ones were reported on every
call and the later ones starved. Each reported event that stays
registered now moves to the end of the list, in the order reported.
2026-10-21 15:41:06 +03:00
Federico Marras 6ead14f9e8 feat(libkernel): watch a kqueue with EVFILT_READ 2026-10-20 16:56:06 +02:00
Claude 5c6f6da7dc feat(libkernel): accept pipe read ends in sceKernelAddReadEvent
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-19 18:30:55 +00:00
Alexej Szpevák 5cbc46029b refactor(libkernel): let an equeue filter name the descriptor its waits block on
WaitForDescriptors always handed the knote's own descriptor to the host wait. A filter that tracks readiness through a descriptor of its own, such as an edge watch, needs the wait to block on that descriptor instead, or a descriptor that stays ready keeps waking the wait. KernelFilter gets a waitDescriptor, and the filter's owner is held for the length of the wait so the descriptor cannot be closed under it.
2026-10-19 15:05:10 +02:00