feat(libkernel_sys): notify aio completions by signal or kevent and queue aio on sockets #21463

Merged
frankea merged 15 commits from upstream-pr/21463 into main 2026-11-25 23:13:06 +00:00
frankea commented 2026-11-16 06:50:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-11-16T06:50:58Z.


What

aio_read, aio_write and aio_fsync no longer throw for SIGEV_SIGNAL, SIGEV_THREAD_ID or SIGEV_KEVENT completion, or for a request on a socket. These were the two NotImplemented_nid_no_patch calls left in the shared Queue() helper of core/libs/prx/libkernel_sys/Aio.cpp. The behaviour follows FreeBSD 11.4: sys/kern/vfs_aio.c and sys/kern/sys_socket.c, with the kqueue parts checked against sys/kern/kern_event.c.

#19463 is merged into main (2026-11-21), and this branch has merged main at ef7dc4452df. It reuses the queued-signal entries that #19463 added to Signals.cpp (code, value, si_value at offset 32) instead of adding a second mechanism. The commits of this PR are 613be0a396a, 660296545c1, 4c721b9c105, 4c9710db5a6, ada4cc96312, d300f12e04e, 82fcbf5e84d and 908178b6689, plus merges of main.

SIGEV_KEVENT (vfs_aio.c aio_aqueue L1589-L1605, filt_aioattach/filt_aio L2492-L2539, aio_free_entry L532, aqueue_fail L1645-L1650):

  • sigev_notify_kevent_flags (the low 16 bits of the sigevent union) other than EV_CLEAR, EV_DISPATCH and EV_ONESHOT fail with EINVAL, after kernelinfo is stored, as aio_aqueue checks them there.
  • sigev_notify_kqueue (sigev_signo) that is not a kqueue fails with EBADF, as kqueue_acquire (L1496) answers, and the error is stored in the aiocb.
  • The knote has ident = the aiocb address, filter EVFILT_AIO, udata = sigev_value, and the requested flags without EV_FLAG1, which filt_aioattach clears.
  • At completion (also by aio_cancel) it fires with EV_EOF and data = the request's error (0, ECANCELED, an errno), as filt_aio sets them. The knote keeps that error, so a re-activated knote (an EV_CLEAR one after a later change) reports it again, as filt_aio sets kn_data on every call. It stays level-triggered until aio_return or aio_waitcomplete frees the request, which deletes the knote as aio_free_entry does through knlist_delete.
  • A request that fails after registration (a pipe, EOPNOTSUPP) deletes its knote, as aqueue_fail does.
  • A new request on an aiocb address that still has an EVFILT_AIO knote in that kqueue (the earlier request finished but was not yet returned) replaces that knote with a fresh one bound to the new request (908178b6689). The earlier request's completion and aio_return then no longer touch it, and the new request's completion and aio_return fire and free it. Before, the old knote kept the old request's token, so it re-reported the old completion at once, the new completion did not fire it, and aio_return of the old request deleted it.
  • Kqueue.cpp: a user EV_ADD of a new EVFILT_AIO knote still fails with EPERM (user EV_FLAG1 is stripped by kqueue_kevent L1087, then filt_aioattach refuses). A change to an existing aio knote now takes the generic path, as kqueue_register (L1234-L1493) does: EV_DELETE, EV_ENABLE/EV_DISABLE, EV_FORCEONESHOT and a new udata. A finished knote is re-activated by such a change, as kqueue_register calls f_event again at done_ev_add.
  • New libkernel helpers KqueueAddAio_nid_no_patch, KqueueAioDone_nid_no_patch and KqueueAioFree_nid_no_patch in Kqueue.cpp, declared in libkernel/include/Api.hpp.

SIGEV_SIGNAL and SIGEV_THREAD_ID (vfs_aio.c aio_sendsig L469-L485, aio_bio_done_notify L874-L940):

  • The completion posts sigev_signo with si_code SI_ASYNCIO (0x10004), si_value = sigev_value and si_pid 0, as ksiginfo_set_sigev and aio_sendsig fill it.
  • SIGEV_THREAD_ID targets sigev_notify_thread_id; an unknown thread sends nothing, as sigev_findtd returns ESRCH and the completion goes on.
  • New SendValueSignal_nid_no_patch in Signals.cpp follows #19463's SendTimerSignal without the overrun accounting: an ignored signal is dropped, a signal the target blocks is queued (each completion queues its own entry, as KSI_INS does), and the mask is checked again after queueing.
  • aio_return and aio_waitcomplete remove the request's own completion signal if it is still queued, as aio_free_entry (L534) calls sigqueue_take(&job->ksi). Each queued entry carries a ticket, so a request removes only its own entry, not one of another request with the same sigev_value.
  • Same gap as #19463: a target thread that does not block the signal throws (NotImplemented_nid_no_patch), because guest handlers do not run on the aio threads. For SIGEV_SIGNAL the target is the submitting thread, where FreeBSD posts to the process; this matches how #19463 picks the arming thread.

Sockets (sys_socket.c soo_aio_queue L774-L808, soaio_process_job L560-L673, soo_aio_cancel L743-L771):

  • aio_fsync and a negative offset on a socket fail with EINVAL, as aio_aqueue does for a file without a vnode. The socket type no longer counts as a vnode for that check.
  • Requests run in submission order per socket and direction on their own thread, which waits until the socket is readable or writable and then calls recv or send with MSG_DONTWAIT (MSG_NBIO), and MSG_NOSIGNAL on sends.
  • A read completes with what was read, 0 at end of file. A write that would block is put back at the head of the queue when nothing was sent or the socket is blocking, and completes with the bytes sent when the socket is non-blocking. EINTR or EWOULDBLOCK after progress completes with the progress.
  • EPIPE on a write without SO_NOSIGPIPE posts SIGPIPE with SI_KERNEL, as soaio_process_job (L620-L624) calls kern_psignal(job->userproc, SIGPIPE), through the same helper. That is process-directed, so like SIGEV_SIGNAL it targets the submitting thread, also when the request uses SIGEV_THREAD_ID for its completion.
  • aio_cancel on a waiting socket request completes it with ECANCELED (AIO_CANCELED), or with the bytes already sent and AIO_NOTCANCELED when part was sent, as soo_aio_cancel and aio_cancel_job (L576-L624) count it.
  • aio_cancel on a socket request in the middle of an attempt gives AIO_NOTCANCELED and marks it, as aio_cancel_job sets KAIOCB_CANCELLED on a job without a cancel function. When that attempt would put the request back, it completes instead: with the bytes already moved, or ECANCELED when none moved, as soaio_process_job (L651-L660) does when aio_set_cancel_function fails.

The libkernel_sys debt entry is rewritten gap first (951 characters): the signal throw, the submitting-thread target, the 10 ms socket poll and the host send that can block (below). It drops the claim that a bad aio_suspend pointer crashes the host, which is no longer true on main (aio_suspend copies its list and timeout in with GuestCopyIn and returns EFAULT).

Progress (python3 tools/progress.py --module libkernel_sys, main at fb233c99c4): main 193/820, this branch 195/820. aio_read, aio_write and aio_fsync become implemented. aio_cancel becomes pending in the count: a cancelled request with SIGEV_SIGNAL now reaches the unblocked-signal throw through its completion, so the scanner sees that throw from aio_cancel. Before this PR such a request could not be created, since aio_read threw. libkernel goes from 716 to 717 through #19463 only.

Tested

macOS 27.0.1 on Apple silicon (arm64), Release build with Ninja and AppleClang.

  • 2026-11-21, head 19980cb26f4 (merge of main ef7dc4452df), x86_64 build: guest_kernel_sys_aio passed 10 of 10; guest_kernel_sys_ktimer, guest_kernel_sys_ktimer_exit_armed, guest_kernel_sys_ktimer_exit_deleted, guest_legacy_signal_mask and guest_kqueue passed. guest_kqueue_cleared_race passed when run directly, in 57 s on a host at load average about 180, which is over its 30 s ctest limit; it does not involve aio. With the 908178b6689 change to Kqueue.cpp reverted, guest_kernel_sys_aio fails at the first check after the second request on the reused aiocb.
  • 2026-11-18, head 82fcbf5e84d: guest_kernel_sys_aio passed 10 of 10 on Windows 11 (RTX 4090 box, MinGW build) and 3 of 3 on macOS.

Earlier runs:

  • guest_kernel_sys_aio passed 10 of 10 consecutive runs, about 0.54 s each, after merging main fb233c99c4.
  • ctest -R over guest_kernel_sys_aio, guest_kernel_sys_ktimer, guest_kernel_sys_ktimer_exit_armed, guest_kernel_sys_ktimer_exit_deleted, guest_signals, guest_signal_interrupt, guest_signal_handler_mask, guest_sigtimedwait, guest_kernel_sig_pending, guest_signal_context, guest_equeue_events, guest_kqueue and guest_kqueue_cleared_race: 13 of 13 passed. public_headers and its compile tests: 65 of 65 passed.
  • With the main Aio.cpp and the new test, the test stops with aio completion delivering a signal or a kevent not implemented.

New test cases in core/libs/tests/GuestKernelSysAio.cpp:

  • Kevent: the event's ident, filter, flags (EV_EOF), data and udata; level-triggered until aio_return, then gone (EV_DELETE gives ENOENT); a second request on the same aiocb before the first is returned reports nothing while pending, nothing after aio_return of the first, then fires once with its own udata and is gone after its own aio_return; EV_ONESHOT and EV_CLEAR report once; a later EV_ADD change re-reports a finished EV_CLEAR knote with the new udata; a cancelled request fires with data ECANCELED, and a cancelled EV_CLEAR request re-reported by a later change still has data ECANCELED; a user EV_DELETE before completion means no event; a forged EV_ADD of EVFILT_AIO still gives EPERM; EBADF for a descriptor that is not a kqueue and EINVAL for a bad flag, both stored in the aiocb; a pipe request leaves no knote.
  • Signals: SIGUSR1 blocked, sigtimedwait returns SI_ASYNCIO, si_pid 0 and the value; two completions queue two entries in order; SIGEV_THREAD_ID to the calling thread; an unknown thread id sends nothing; an ignored SIGURG is dropped; a cancelled request still signals; aio_return and aio_waitcomplete leave no SIGUSR1 pending (sigpending, sigtimedwait gives EAGAIN); two requests with the same sigev_value: after sigtimedwait takes the first one's signal, aio_return of the first leaves the second one's signal queued.
  • Sockets (AF_UNIX stream pair): aio_fsync and a negative offset give EINVAL; a waiting read is cancelled; two queued reads complete in order from one write; a short read completes with 2 bytes; a write with SIGEV_KEVENT; end of file reads 0; EPIPE with SIGPIPE ignored; a 1 MiB write on a blocking socket gives AIO_NOTCANCELED and completes once drained; on a non-blocking socket it completes with part of the bytes; a read cancelled in the middle of an attempt (held there by a test hook, AioHoldSocketForTest_nid_no_patch) gives AIO_NOTCANCELED twice, and after the test drains the data first the request completes with ECANCELED instead of waiting again; SIGPIPE from a write with SIGEV_THREAD_ID to another thread (which blocks the completion signal but not SIGPIPE) is queued for the submitting thread, which blocks it.

Mutation check, 10 hand mutations: 8 failed the test (SIGEV_THREAD_ID treated as process-directed, the knote not freed by aio_return, the knote not freed after EOPNOTSUPP, no signal removal in aio_return, removal of any aio entry instead of the request's own, no cancelled check at the requeue (the request never completes), a re-activated knote without its error, SIGPIPE to the SIGEV_THREAD_ID thread). 2 survived on macOS: completing a blocking socket write early, and cancelling a partly sent write as ECANCELED. The macOS host blocks in send(..., MSG_DONTWAIT) on a blocking AF_UNIX stream socket when the data does not fit (a standalone C program confirmed it), so a partly sent blocking write never happens there. Linux honours MSG_DONTWAIT, so these paths need a Linux run. On Windows MSG_DONTWAIT is a poll followed by a blocking send in WaitForTransfer; the debt entry records both hosts.

$ python3 tools/check_conventions.py --base origin/main
All conventions checks passed.

Overlap. python3 tools/pr_overlap.py --names aio_read aio_write aio_fsync and gh pr list --search for each name, SIGEV_KEVENT, EVFILT_AIO and sigevent find no open PR that implements aio notification or socket aio. #16191 changes the same Queue() function; git merge-tree merges it with this branch without conflicts. #20808 changes the same libkernel_sys debt entry in its own fragment (docs-kernel-sys-aio-suspend-debt.md) to replace the stale aio_suspend crash sentence with the EFAULT behaviour. The two texts agree: this one drops the sentence. The files merge without conflicts, but tools/debt_fold.py --check refuses two fragments that change the same entry, so whichever lands second folds the other's fragment into its own; this fragment applies cleanly on top of #20808's folded entry (checked with debt_fold.py locally). #9389 (sigqueue) also changes Signals.cpp and is not needed here.

Not verified:

  • the console
  • a Linux run of the partial-write socket paths on the current head (a reviewer ran the suite on Linux at 22ee655388)
  • delivery to a thread that does not block the signal, which still throws

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none (#19463 is merged)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5332488831 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21463). Originally posted by [frankea](https://github.com/frankea) on 2026-11-16T06:50:58Z. --- ### What `aio_read`, `aio_write` and `aio_fsync` no longer throw for `SIGEV_SIGNAL`, `SIGEV_THREAD_ID` or `SIGEV_KEVENT` completion, or for a request on a socket. These were the two `NotImplemented_nid_no_patch` calls left in the shared `Queue()` helper of `core/libs/prx/libkernel_sys/Aio.cpp`. The behaviour follows FreeBSD 11.4: [`sys/kern/vfs_aio.c`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_aio.c) and [`sys/kern/sys_socket.c`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/sys_socket.c), with the kqueue parts checked against [`sys/kern/kern_event.c`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_event.c). #19463 is merged into `main` (2026-11-21), and this branch has merged `main` at `ef7dc4452df`. It reuses the queued-signal entries that #19463 added to `Signals.cpp` (code, value, `si_value` at offset 32) instead of adding a second mechanism. The commits of this PR are `613be0a396a`, `660296545c1`, `4c721b9c105`, `4c9710db5a6`, `ada4cc96312`, `d300f12e04e`, `82fcbf5e84d` and `908178b6689`, plus merges of `main`. **`SIGEV_KEVENT`** (`vfs_aio.c` `aio_aqueue` L1589-L1605, `filt_aioattach`/`filt_aio` L2492-L2539, `aio_free_entry` L532, `aqueue_fail` L1645-L1650): - `sigev_notify_kevent_flags` (the low 16 bits of the `sigevent` union) other than `EV_CLEAR`, `EV_DISPATCH` and `EV_ONESHOT` fail with `EINVAL`, after `kernelinfo` is stored, as `aio_aqueue` checks them there. - `sigev_notify_kqueue` (`sigev_signo`) that is not a kqueue fails with `EBADF`, as `kqueue_acquire` (L1496) answers, and the error is stored in the aiocb. - The knote has ident = the aiocb address, filter `EVFILT_AIO`, `udata` = `sigev_value`, and the requested flags without `EV_FLAG1`, which `filt_aioattach` clears. - At completion (also by `aio_cancel`) it fires with `EV_EOF` and `data` = the request's error (0, `ECANCELED`, an errno), as `filt_aio` sets them. The knote keeps that error, so a re-activated knote (an `EV_CLEAR` one after a later change) reports it again, as `filt_aio` sets `kn_data` on every call. It stays level-triggered until `aio_return` or `aio_waitcomplete` frees the request, which deletes the knote as `aio_free_entry` does through `knlist_delete`. - A request that fails after registration (a pipe, `EOPNOTSUPP`) deletes its knote, as `aqueue_fail` does. - A new request on an aiocb address that still has an `EVFILT_AIO` knote in that kqueue (the earlier request finished but was not yet returned) replaces that knote with a fresh one bound to the new request (`908178b6689`). The earlier request's completion and `aio_return` then no longer touch it, and the new request's completion and `aio_return` fire and free it. Before, the old knote kept the old request's token, so it re-reported the old completion at once, the new completion did not fire it, and `aio_return` of the old request deleted it. - `Kqueue.cpp`: a user `EV_ADD` of a new `EVFILT_AIO` knote still fails with `EPERM` (user `EV_FLAG1` is stripped by `kqueue_kevent` L1087, then `filt_aioattach` refuses). A change to an existing aio knote now takes the generic path, as `kqueue_register` (L1234-L1493) does: `EV_DELETE`, `EV_ENABLE`/`EV_DISABLE`, `EV_FORCEONESHOT` and a new `udata`. A finished knote is re-activated by such a change, as `kqueue_register` calls `f_event` again at `done_ev_add`. - New libkernel helpers `KqueueAddAio_nid_no_patch`, `KqueueAioDone_nid_no_patch` and `KqueueAioFree_nid_no_patch` in `Kqueue.cpp`, declared in `libkernel/include/Api.hpp`. **`SIGEV_SIGNAL` and `SIGEV_THREAD_ID`** (`vfs_aio.c` `aio_sendsig` L469-L485, `aio_bio_done_notify` L874-L940): - The completion posts `sigev_signo` with `si_code` `SI_ASYNCIO` (0x10004), `si_value` = `sigev_value` and `si_pid` 0, as `ksiginfo_set_sigev` and `aio_sendsig` fill it. - `SIGEV_THREAD_ID` targets `sigev_notify_thread_id`; an unknown thread sends nothing, as `sigev_findtd` returns `ESRCH` and the completion goes on. - New `SendValueSignal_nid_no_patch` in `Signals.cpp` follows #19463's `SendTimerSignal` without the overrun accounting: an ignored signal is dropped, a signal the target blocks is queued (each completion queues its own entry, as `KSI_INS` does), and the mask is checked again after queueing. - `aio_return` and `aio_waitcomplete` remove the request's own completion signal if it is still queued, as `aio_free_entry` (L534) calls `sigqueue_take(&job->ksi)`. Each queued entry carries a ticket, so a request removes only its own entry, not one of another request with the same `sigev_value`. - Same gap as #19463: a target thread that does not block the signal throws (`NotImplemented_nid_no_patch`), because guest handlers do not run on the aio threads. For `SIGEV_SIGNAL` the target is the submitting thread, where FreeBSD posts to the process; this matches how #19463 picks the arming thread. **Sockets** (`sys_socket.c` `soo_aio_queue` L774-L808, `soaio_process_job` L560-L673, `soo_aio_cancel` L743-L771): - `aio_fsync` and a negative offset on a socket fail with `EINVAL`, as `aio_aqueue` does for a file without a vnode. The socket type no longer counts as a vnode for that check. - Requests run in submission order per socket and direction on their own thread, which waits until the socket is readable or writable and then calls `recv` or `send` with `MSG_DONTWAIT` (`MSG_NBIO`), and `MSG_NOSIGNAL` on sends. - A read completes with what was read, 0 at end of file. A write that would block is put back at the head of the queue when nothing was sent or the socket is blocking, and completes with the bytes sent when the socket is non-blocking. `EINTR` or `EWOULDBLOCK` after progress completes with the progress. - `EPIPE` on a write without `SO_NOSIGPIPE` posts `SIGPIPE` with `SI_KERNEL`, as `soaio_process_job` (L620-L624) calls `kern_psignal(job->userproc, SIGPIPE)`, through the same helper. That is process-directed, so like `SIGEV_SIGNAL` it targets the submitting thread, also when the request uses `SIGEV_THREAD_ID` for its completion. - `aio_cancel` on a waiting socket request completes it with `ECANCELED` (`AIO_CANCELED`), or with the bytes already sent and `AIO_NOTCANCELED` when part was sent, as `soo_aio_cancel` and `aio_cancel_job` (L576-L624) count it. - `aio_cancel` on a socket request in the middle of an attempt gives `AIO_NOTCANCELED` and marks it, as `aio_cancel_job` sets `KAIOCB_CANCELLED` on a job without a cancel function. When that attempt would put the request back, it completes instead: with the bytes already moved, or `ECANCELED` when none moved, as `soaio_process_job` (L651-L660) does when `aio_set_cancel_function` fails. The libkernel_sys debt entry is rewritten gap first (951 characters): the signal throw, the submitting-thread target, the 10 ms socket poll and the host send that can block (below). It drops the claim that a bad `aio_suspend` pointer crashes the host, which is no longer true on `main` (`aio_suspend` copies its list and timeout in with `GuestCopyIn` and returns `EFAULT`). **Progress** (`python3 tools/progress.py --module libkernel_sys`, `main` at fb233c99c4c): `main` 193/820, this branch 195/820. `aio_read`, `aio_write` and `aio_fsync` become implemented. `aio_cancel` becomes pending in the count: a cancelled request with `SIGEV_SIGNAL` now reaches the unblocked-signal throw through its completion, so the scanner sees that throw from `aio_cancel`. Before this PR such a request could not be created, since `aio_read` threw. libkernel goes from 716 to 717 through #19463 only. ### Tested macOS 27.0.1 on Apple silicon (arm64), Release build with Ninja and AppleClang. - 2026-11-21, head `19980cb26f4` (merge of `main` `ef7dc4452df`), x86_64 build: `guest_kernel_sys_aio` passed 10 of 10; `guest_kernel_sys_ktimer`, `guest_kernel_sys_ktimer_exit_armed`, `guest_kernel_sys_ktimer_exit_deleted`, `guest_legacy_signal_mask` and `guest_kqueue` passed. `guest_kqueue_cleared_race` passed when run directly, in 57 s on a host at load average about 180, which is over its 30 s ctest limit; it does not involve aio. With the `908178b6689` change to `Kqueue.cpp` reverted, `guest_kernel_sys_aio` fails at the first check after the second request on the reused aiocb. - 2026-11-18, head `82fcbf5e84d`: `guest_kernel_sys_aio` passed 10 of 10 on Windows 11 (RTX 4090 box, MinGW build) and 3 of 3 on macOS. Earlier runs: - `guest_kernel_sys_aio` passed 10 of 10 consecutive runs, about 0.54 s each, after merging `main` fb233c99c4c. - `ctest -R` over `guest_kernel_sys_aio`, `guest_kernel_sys_ktimer`, `guest_kernel_sys_ktimer_exit_armed`, `guest_kernel_sys_ktimer_exit_deleted`, `guest_signals`, `guest_signal_interrupt`, `guest_signal_handler_mask`, `guest_sigtimedwait`, `guest_kernel_sig_pending`, `guest_signal_context`, `guest_equeue_events`, `guest_kqueue` and `guest_kqueue_cleared_race`: 13 of 13 passed. `public_headers` and its compile tests: 65 of 65 passed. - With the `main` `Aio.cpp` and the new test, the test stops with `aio completion delivering a signal or a kevent not implemented`. New test cases in `core/libs/tests/GuestKernelSysAio.cpp`: - Kevent: the event's ident, filter, flags (`EV_EOF`), `data` and `udata`; level-triggered until `aio_return`, then gone (`EV_DELETE` gives `ENOENT`); a second request on the same aiocb before the first is returned reports nothing while pending, nothing after `aio_return` of the first, then fires once with its own `udata` and is gone after its own `aio_return`; `EV_ONESHOT` and `EV_CLEAR` report once; a later `EV_ADD` change re-reports a finished `EV_CLEAR` knote with the new `udata`; a cancelled request fires with `data` `ECANCELED`, and a cancelled `EV_CLEAR` request re-reported by a later change still has `data` `ECANCELED`; a user `EV_DELETE` before completion means no event; a forged `EV_ADD` of `EVFILT_AIO` still gives `EPERM`; `EBADF` for a descriptor that is not a kqueue and `EINVAL` for a bad flag, both stored in the aiocb; a pipe request leaves no knote. - Signals: `SIGUSR1` blocked, `sigtimedwait` returns `SI_ASYNCIO`, `si_pid` 0 and the value; two completions queue two entries in order; `SIGEV_THREAD_ID` to the calling thread; an unknown thread id sends nothing; an ignored `SIGURG` is dropped; a cancelled request still signals; `aio_return` and `aio_waitcomplete` leave no `SIGUSR1` pending (`sigpending`, `sigtimedwait` gives `EAGAIN`); two requests with the same `sigev_value`: after `sigtimedwait` takes the first one's signal, `aio_return` of the first leaves the second one's signal queued. - Sockets (`AF_UNIX` stream pair): `aio_fsync` and a negative offset give `EINVAL`; a waiting read is cancelled; two queued reads complete in order from one write; a short read completes with 2 bytes; a write with `SIGEV_KEVENT`; end of file reads 0; `EPIPE` with `SIGPIPE` ignored; a 1 MiB write on a blocking socket gives `AIO_NOTCANCELED` and completes once drained; on a non-blocking socket it completes with part of the bytes; a read cancelled in the middle of an attempt (held there by a test hook, `AioHoldSocketForTest_nid_no_patch`) gives `AIO_NOTCANCELED` twice, and after the test drains the data first the request completes with `ECANCELED` instead of waiting again; `SIGPIPE` from a write with `SIGEV_THREAD_ID` to another thread (which blocks the completion signal but not `SIGPIPE`) is queued for the submitting thread, which blocks it. Mutation check, 10 hand mutations: 8 failed the test (`SIGEV_THREAD_ID` treated as process-directed, the knote not freed by `aio_return`, the knote not freed after `EOPNOTSUPP`, no signal removal in `aio_return`, removal of any aio entry instead of the request's own, no cancelled check at the requeue (the request never completes), a re-activated knote without its error, `SIGPIPE` to the `SIGEV_THREAD_ID` thread). 2 survived on macOS: completing a blocking socket write early, and cancelling a partly sent write as `ECANCELED`. The macOS host blocks in `send(..., MSG_DONTWAIT)` on a blocking `AF_UNIX` stream socket when the data does not fit (a standalone C program confirmed it), so a partly sent blocking write never happens there. Linux honours `MSG_DONTWAIT`, so these paths need a Linux run. On Windows `MSG_DONTWAIT` is a poll followed by a blocking send in `WaitForTransfer`; the debt entry records both hosts. ```text $ python3 tools/check_conventions.py --base origin/main All conventions checks passed. ``` **Overlap.** `python3 tools/pr_overlap.py --names aio_read aio_write aio_fsync` and `gh pr list --search` for each name, `SIGEV_KEVENT`, `EVFILT_AIO` and `sigevent` find no open PR that implements aio notification or socket aio. #16191 changes the same `Queue()` function; `git merge-tree` merges it with this branch without conflicts. #20808 changes the same libkernel_sys debt entry in its own fragment (`docs-kernel-sys-aio-suspend-debt.md`) to replace the stale `aio_suspend` crash sentence with the `EFAULT` behaviour. The two texts agree: this one drops the sentence. The files merge without conflicts, but `tools/debt_fold.py --check` refuses two fragments that change the same entry, so whichever lands second folds the other's fragment into its own; this fragment applies cleanly on top of #20808's folded entry (checked with `debt_fold.py` locally). #9389 (`sigqueue`) also changes `Signals.cpp` and is not needed here. **Not verified:** - the console - a Linux run of the partial-write socket paths on the current head (a reviewer ran the suite on Linux at `22ee655388`) - delivery to a thread that does not block the signal, which still throws ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> none (#19463 is merged) - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
PrivacyOnion commented 2026-11-16 07:03:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-16T07:03:13Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 22ee655388:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_kernel_sys_aio_tests, guest_kernel_sys_ktimer_exit_tests, guest_kernel_sys_ktimer_tests built cleanly.
  • CTest (guest_kernel_sys_ktimer, guest_kernel_sys_ktimer_exit_armed, guest_kernel_sys_ktimer_exit_deleted, guest_kernel_sys_aio):
    1/4 Test #929: guest_kernel_sys_ktimer_exit_armed .....   Passed    0.03 sec
    2/4 Test #930: guest_kernel_sys_ktimer_exit_deleted ...   Passed    0.08 sec
    3/4 Test #933: guest_kernel_sys_aio ...................   Passed    0.30 sec
    4/4 Test #928: guest_kernel_sys_ktimer ................   Passed    0.63 sec
    100% tests passed, 0 tests failed out of 4
    
  • Negative control: with core/libs/prx/libkernel/Equeue/src/Kqueue.cpp, core/libs/prx/libkernel/System/src/Signals.cpp, core/libs/prx/libkernel/Time/Ktimer.cpp, core/libs/prx/libkernel/include/Api.hpp, core/libs/prx/libkernel_sys/Aio.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified EVFILT_AIO knote registration, modification, retriggering, completion (EV_EOF and error propagation), and cleanup in core/libs/prx/libkernel/Equeue/src/Kqueue.cpp against FreeBSD 11.4 vfs_aio.c and kern_event.c.
    • Verified GuestSiginfo layout static assertions (sizeof == 80, value at offset 32, timerid at offset 40, overrun at offset 44) and queued signal handling in core/libs/prx/libkernel/System/src/Signals.cpp.
    • Verified thread-directed signal registration (RegisterSignalThread) and lookup (SignalThread) synchronization and safety across sigwait/sigtimedwait/sigsuspend paths.
    • Verified ktimer_getoverrun_nid_postfix locking and overrun retrieval via TimerSignalOverrun in core/libs/prx/libkernel/Time/Ktimer.cpp.
    • Verified CMake test target definitions and Windows/Linux portability in core/libs/CMakeLists.txt.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5916157974 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21463#pullrequestreview-5916157974). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-16T07:03:13Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `22ee655388`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_kernel_sys_aio_tests`, `guest_kernel_sys_ktimer_exit_tests`, `guest_kernel_sys_ktimer_tests` built cleanly. - **CTest** (`guest_kernel_sys_ktimer`, `guest_kernel_sys_ktimer_exit_armed`, `guest_kernel_sys_ktimer_exit_deleted`, `guest_kernel_sys_aio`): ``` 1/4 Test #929: guest_kernel_sys_ktimer_exit_armed ..... Passed 0.03 sec 2/4 Test #930: guest_kernel_sys_ktimer_exit_deleted ... Passed 0.08 sec 3/4 Test #933: guest_kernel_sys_aio ................... Passed 0.30 sec 4/4 Test #928: guest_kernel_sys_ktimer ................ Passed 0.63 sec 100% tests passed, 0 tests failed out of 4 ``` - **Negative control**: with `core/libs/prx/libkernel/Equeue/src/Kqueue.cpp`, `core/libs/prx/libkernel/System/src/Signals.cpp`, `core/libs/prx/libkernel/Time/Ktimer.cpp`, `core/libs/prx/libkernel/include/Api.hpp`, `core/libs/prx/libkernel_sys/Aio.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified EVFILT_AIO knote registration, modification, retriggering, completion (EV_EOF and error propagation), and cleanup in core/libs/prx/libkernel/Equeue/src/Kqueue.cpp against FreeBSD 11.4 vfs_aio.c and kern_event.c. - Verified GuestSiginfo layout static assertions (sizeof == 80, value at offset 32, timerid at offset 40, overrun at offset 44) and queued signal handling in core/libs/prx/libkernel/System/src/Signals.cpp. - Verified thread-directed signal registration (RegisterSignalThread) and lookup (SignalThread) synchronization and safety across sigwait/sigtimedwait/sigsuspend paths. - Verified ktimer_getoverrun_nid_postfix locking and overrun retrieval via TimerSignalOverrun in core/libs/prx/libkernel/Time/Ktimer.cpp. - Verified CMake test target definitions and Windows/Linux portability in core/libs/CMakeLists.txt. Looks Good To Me
MarcZX10 commented 2026-11-16 07:37:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T07:37:30Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: remove the dangling thread registry entries and make the socket worker lifetime safe when its queue is removed.

What I ran

Reviewed head 22ee65538880b0d881102b7857b503b2a8f0d8fc; no merged preview or programmatic checks were run. Inspected the prepared diff and repository context with repo_read.py.

Results

Check Result Note
Diff review passed Prepared change inspected
Build and tests not run No local execution available
Thread and socket lifetime failed Two concrete lifetime defects found

Findings

Blocking

  • core/libs/prx/libkernel/System/src/Signals.cpp:150: RegisterSignalThread stores a raw ThreadSignals* in the global map, and no corresponding unregister or erase path exists. After a guest thread exits, a later timer or AIO completion can find that stale pointer and call SignalBlocked through it. This is a use-after-lifetime risk on thread exit. Remove registry entries as threads exit, or use storage whose lifetime safely outlives all senders.
  • core/libs/prx/libkernel_sys/Aio.cpp:257: SocketWorker erases its SocketQueue node once the job deque becomes empty. The worker drops aio.lock while polling at lines 251–254; meanwhile, another thread can enqueue on that same queue or cancel its last job, allowing the worker to erase the node after it was reused. The worker then holds an invalid list iterator/reference, causing undefined behavior. Keep queue nodes alive until the worker has reacquired the lock and confirmed they remain empty, coordinating enqueue/cancel with that lifecycle.

Non-blocking

None.

Sources

  • Changed code: core/libs/prx/libkernel/System/src/Signals.cpp and core/libs/prx/libkernel_sys/Aio.cpp.
  • Prepared diff and manifest; repository context read at the pinned head.

Not verified

  • Build, tests, console behavior, Linux behavior, and Windows behavior were not run in this review. The author reports macOS tests in the PR description; those were not independently run.
  • Read full changed text for core/libs/prx/libkernel/Equeue/src/Kqueue.cpp, core/libs/prx/libkernel/System/src/Signals.cpp, and core/libs/prx/libkernel_sys/Aio.cpp. Inspected changed hunks for the remaining files; did not read their full text. The manifest marks all listed changed files as included; files.json was not available through the reader.

To get this to a good state

Fix the thread registry and socket queue lifetimes, then rerun the relevant build and tests on the new head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5916470810 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21463#pullrequestreview-5916470810). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T07:37:30Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: remove the dangling thread registry entries and make the socket worker lifetime safe when its queue is removed. ## What I ran Reviewed head `22ee65538880b0d881102b7857b503b2a8f0d8fc`; no merged preview or programmatic checks were run. Inspected the prepared diff and repository context with `repo_read.py`. ## Results | Check | Result | Note | |---|---|---| | Diff review | passed | Prepared change inspected | | Build and tests | not run | No local execution available | | Thread and socket lifetime | failed | Two concrete lifetime defects found | ## Findings ### Blocking - `core/libs/prx/libkernel/System/src/Signals.cpp:150`: `RegisterSignalThread` stores a raw `ThreadSignals*` in the global map, and no corresponding unregister or erase path exists. After a guest thread exits, a later timer or AIO completion can find that stale pointer and call `SignalBlocked` through it. This is a use-after-lifetime risk on thread exit. Remove registry entries as threads exit, or use storage whose lifetime safely outlives all senders. - `core/libs/prx/libkernel_sys/Aio.cpp:257`: `SocketWorker` erases its `SocketQueue` node once the job deque becomes empty. The worker drops `aio.lock` while polling at lines 251–254; meanwhile, another thread can enqueue on that same queue or cancel its last job, allowing the worker to erase the node after it was reused. The worker then holds an invalid list iterator/reference, causing undefined behavior. Keep queue nodes alive until the worker has reacquired the lock and confirmed they remain empty, coordinating enqueue/cancel with that lifecycle. ### Non-blocking None. ## Sources - Changed code: `core/libs/prx/libkernel/System/src/Signals.cpp` and `core/libs/prx/libkernel_sys/Aio.cpp`. - Prepared diff and manifest; repository context read at the pinned head. ## Not verified - Build, tests, console behavior, Linux behavior, and Windows behavior were not run in this review. The author reports macOS tests in the PR description; those were not independently run. - Read full changed text for `core/libs/prx/libkernel/Equeue/src/Kqueue.cpp`, `core/libs/prx/libkernel/System/src/Signals.cpp`, and `core/libs/prx/libkernel_sys/Aio.cpp`. Inspected changed hunks for the remaining files; did not read their full text. The manifest marks all listed changed files as included; `files.json` was not available through the reader. ## To get this to a good state Fix the thread registry and socket queue lifetimes, then rerun the relevant build and tests on the new head.
MarcZX10 commented 2026-11-18 07:35:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T07:35:19Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change based on the source and test coverage reviewed; the reported test runs were supplied by the author and were not run here.

What I ran

Reviewed head d300f12e04e452d404f46a9ee7eb1751ef649861. No commands or tests were run; the prepared diff and repository reader were the available review inputs.

Results

Check Result Note
Runtime code review passed AIO, signal, timer, and kqueue paths inspected
Test execution not run Test results are author-reported
Excluded changed file not applicable Deleted debt fragment adds no text

Findings

Blocking

None.

Non-blocking

None.

Not verified

The full changed-file texts were included for 10 of 11 changed files. The deleted docs/dev/debt/changes/docs-kernel-sys-aio-suspend-debt.md was excluded because it has no added lines. I read targeted runtime ranges and test sections; I did not read every line of every included changed file. Linux, Windows, and console behavior were not run or confirmed here. The test outcomes in the PR description are author-reported.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5952419868 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21463#pullrequestreview-5952419868). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T07:35:19Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change based on the source and test coverage reviewed; the reported test runs were supplied by the author and were not run here. ## What I ran Reviewed head `d300f12e04e452d404f46a9ee7eb1751ef649861`. No commands or tests were run; the prepared diff and repository reader were the available review inputs. ## Results | Check | Result | Note | |---|---|---| | Runtime code review | passed | AIO, signal, timer, and kqueue paths inspected | | Test execution | not run | Test results are author-reported | | Excluded changed file | not applicable | Deleted debt fragment adds no text | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The full changed-file texts were included for 10 of 11 changed files. The deleted `docs/dev/debt/changes/docs-kernel-sys-aio-suspend-debt.md` was excluded because it has no added lines. I read targeted runtime ranges and test sections; I did not read every line of every included changed file. Linux, Windows, and console behavior were not run or confirmed here. The test outcomes in the PR description are author-reported. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-18 18:54:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T18:54:32Z.

Review: COMMENTED


Reviewed — comments

The review is incomplete because the full changed-line inventory and targeted source audit were not completed, so approval or a formal change request is not justified.

What I ran

Read the prepared description, commits, manifest, diff excerpt, and changed source excerpts through the pinned-head reader. No build or tests were run; author-reported results were not independently verified.

Results

Check Result Note
Source review not run Full changed-file inventory not read
Tests not run No commands executed

Findings

Blocking

None verified from the inspected excerpts.

Non-blocking

None.

Not verified

The full diff and remaining changed-file lines were not read, including most of Aio.cpp, the remaining signal helpers, tests, and build/debt changes. Thus correctness, test coverage, and the claims in the PR description remain unverified. Files listed as changed and included in the review folder: core/libs/CMakeLists.txt, core/libs/prx/libkernel/Equeue/src/Kqueue.cpp, core/libs/prx/libkernel/System/include/TimerSignals.hpp, core/libs/prx/libkernel/System/src/Signals.cpp, core/libs/prx/libkernel/Time/Ktimer.cpp, core/libs/prx/libkernel/include/Api.hpp, core/libs/prx/libkernel_sys/Aio.cpp, core/libs/tests/GuestKernelSysAio.cpp, core/libs/tests/GuestKernelSysKtimer.cpp, core/libs/tests/GuestKernelSysKtimerExit.cpp, docs/dev/debt/changes/feat-aio-sigevent-completion.md, and docs/dev/debt/changes/feat-libkernel-ktimer-signal.md. docs/dev/debt/changes/docs-kernel-sys-aio-suspend-debt.md is deleted and has no new text to inspect.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5963065175 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21463#pullrequestreview-5963065175). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T18:54:32Z. **Review:** COMMENTED --- # Reviewed — comments The review is incomplete because the full changed-line inventory and targeted source audit were not completed, so approval or a formal change request is not justified. ## What I ran Read the prepared description, commits, manifest, diff excerpt, and changed source excerpts through the pinned-head reader. No build or tests were run; author-reported results were not independently verified. ## Results | Check | Result | Note | |---|---|---| | Source review | not run | Full changed-file inventory not read | | Tests | not run | No commands executed | ## Findings ### Blocking None verified from the inspected excerpts. ### Non-blocking None. ## Not verified The full diff and remaining changed-file lines were not read, including most of `Aio.cpp`, the remaining signal helpers, tests, and build/debt changes. Thus correctness, test coverage, and the claims in the PR description remain unverified. Files listed as changed and included in the review folder: `core/libs/CMakeLists.txt`, `core/libs/prx/libkernel/Equeue/src/Kqueue.cpp`, `core/libs/prx/libkernel/System/include/TimerSignals.hpp`, `core/libs/prx/libkernel/System/src/Signals.cpp`, `core/libs/prx/libkernel/Time/Ktimer.cpp`, `core/libs/prx/libkernel/include/Api.hpp`, `core/libs/prx/libkernel_sys/Aio.cpp`, `core/libs/tests/GuestKernelSysAio.cpp`, `core/libs/tests/GuestKernelSysKtimer.cpp`, `core/libs/tests/GuestKernelSysKtimerExit.cpp`, `docs/dev/debt/changes/feat-aio-sigevent-completion.md`, and `docs/dev/debt/changes/feat-libkernel-ktimer-signal.md`. `docs/dev/debt/changes/docs-kernel-sys-aio-suspend-debt.md` is deleted and has no new text to inspect. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-20 18:57:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T18:57:10Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: prevent an existing AIO knote from being rebound to a different request.

What I ran

Reviewed head 6822e196629f93825dfdfe93e63659a5cbae7dde using the prepared review artifacts and repo_read.py; no tests or build commands were run.

Results

Check Result Note
Diff and description passed Prepared artifacts reviewed
Targeted code review failed Found a knote reuse defect
Tests not run Author-reported results were not rerun

Findings

Blocking

  • core/libs/prx/libkernel/Equeue/src/Kqueue.cpp:735: When a new AIO request uses an ident that already has an EVFILT_AIO knote, this path updates the existing knote but leaves its AioNote::token unchanged. AIO completion and cleanup only act when that token matches the request (Kqueue.cpp:755-763, 767-773). Reusing an aiocb address can therefore leave the new request without its completion event and leave the old knote behind after aio_return. Reject the duplicate registration or safely replace/rebind the note so completion and cleanup match the new request.

Non-blocking

None.

Not verified

No tests or build were run. Full changed-file texts read: core/libs/prx/libkernel/Equeue/src/Kqueue.cpp and core/libs/prx/libkernel_sys/Aio.cpp. The prepared description, commits, manifest, and diff were read; other changed-file texts were not read. docs/dev/debt/changes/docs-kernel-sys-aio-suspend-debt.md is deleted and has no new text. Author-reported test results were not independently verified.

To get this to a good state

Fix duplicate AIO knote registration so a request cannot inherit a knote with another request's token, then rerun the AIO tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5997867167 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21463#pullrequestreview-5997867167). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T18:57:10Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: prevent an existing AIO knote from being rebound to a different request. ## What I ran Reviewed head `6822e196629f93825dfdfe93e63659a5cbae7dde` using the prepared review artifacts and `repo_read.py`; no tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Diff and description | passed | Prepared artifacts reviewed | | Targeted code review | failed | Found a knote reuse defect | | Tests | not run | Author-reported results were not rerun | ## Findings ### Blocking - `core/libs/prx/libkernel/Equeue/src/Kqueue.cpp:735`: When a new AIO request uses an `ident` that already has an `EVFILT_AIO` knote, this path updates the existing knote but leaves its `AioNote::token` unchanged. AIO completion and cleanup only act when that token matches the request (`Kqueue.cpp:755-763`, `767-773`). Reusing an aiocb address can therefore leave the new request without its completion event and leave the old knote behind after `aio_return`. Reject the duplicate registration or safely replace/rebind the note so completion and cleanup match the new request. ### Non-blocking None. ## Not verified No tests or build were run. Full changed-file texts read: `core/libs/prx/libkernel/Equeue/src/Kqueue.cpp` and `core/libs/prx/libkernel_sys/Aio.cpp`. The prepared description, commits, manifest, and diff were read; other changed-file texts were not read. `docs/dev/debt/changes/docs-kernel-sys-aio-suspend-debt.md` is deleted and has no new text. Author-reported test results were not independently verified. ## To get this to a good state Fix duplicate AIO knote registration so a request cannot inherit a knote with another request's token, then rerun the AIO tests.
MarcZX10 commented 2026-11-22 04:34:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T04:34:29Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: prevent zero-byte socket requests from waiting indefinitely and preserve the pending-signal queue limit for AIO completions.

What I ran

Reviewed head 19980cb26f4fc7395f870a5cb9199ca84c446114 against main. Read the prepared description, commits, diff, manifest, all included changed files, and targeted socket, signal, and kqueue context through repo_read.py. No build or tests were run.

Results

Check Result Note
Changed-code review failed Two concrete edge cases found
Build and tests not run No commands run

Findings

Blocking

  • core/libs/prx/libkernel_sys/Aio.cpp:223: For a zero-byte socket read, recv returns 0 only when data is available or the peer has closed; while a live socket has no data, SocketWorker waits for POLLIN before it calls RunSocketJob. The queued request therefore never completes even though a zero-byte read should complete immediately. The write path has the same readiness gating. Complete zero-byte socket requests without waiting for socket readiness, and add a regression test.
  • core/libs/prx/libkernel/System/src/Signals.cpp:789: QueueValueSignal appends every AIO completion signal without enforcing MaxQueuedPerSignal (1024), unlike the existing MarkPending path. Repeated completions to a blocked signal can grow the queue without bound and bypass the established per-signal cap. Enforce the cap and define the completion behavior when it is reached; add a capacity test.

Non-blocking

None.

Not verified

No build, tests, Linux run, or console run was performed. The deleted debt fragment was excluded because it has no added lines. The code review covered the included changed files: Kqueue.cpp, Signals.cpp, Api.hpp, Aio.cpp, GuestKernelSysAio.cpp, and feat-aio-sigevent-completion.md.

To get this to a good state

Handle zero-byte socket requests without readiness polling and enforce the signal queue limit. Add regression coverage for both cases, then rerun the AIO test suite on the new head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6010349934 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21463#pullrequestreview-6010349934). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T04:34:29Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: prevent zero-byte socket requests from waiting indefinitely and preserve the pending-signal queue limit for AIO completions. ## What I ran Reviewed head `19980cb26f4fc7395f870a5cb9199ca84c446114` against `main`. Read the prepared description, commits, diff, manifest, all included changed files, and targeted socket, signal, and kqueue context through `repo_read.py`. No build or tests were run. ## Results | Check | Result | Note | |---|---|---| | Changed-code review | failed | Two concrete edge cases found | | Build and tests | not run | No commands run | ## Findings ### Blocking - `core/libs/prx/libkernel_sys/Aio.cpp:223`: For a zero-byte socket read, `recv` returns 0 only when data is available or the peer has closed; while a live socket has no data, `SocketWorker` waits for `POLLIN` before it calls `RunSocketJob`. The queued request therefore never completes even though a zero-byte read should complete immediately. The write path has the same readiness gating. Complete zero-byte socket requests without waiting for socket readiness, and add a regression test. - `core/libs/prx/libkernel/System/src/Signals.cpp:789`: `QueueValueSignal` appends every AIO completion signal without enforcing `MaxQueuedPerSignal` (1024), unlike the existing `MarkPending` path. Repeated completions to a blocked signal can grow the queue without bound and bypass the established per-signal cap. Enforce the cap and define the completion behavior when it is reached; add a capacity test. ### Non-blocking None. ## Not verified No build, tests, Linux run, or console run was performed. The deleted debt fragment was excluded because it has no added lines. The code review covered the included changed files: `Kqueue.cpp`, `Signals.cpp`, `Api.hpp`, `Aio.cpp`, `GuestKernelSysAio.cpp`, and `feat-aio-sigevent-completion.md`. ## To get this to a good state Handle zero-byte socket requests without readiness polling and enforce the signal queue limit. Add regression coverage for both cases, then rerun the AIO test suite on the new head.
MarcZX10 commented 2026-11-22 14:15:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T14:15:07Z.

Review: APPROVED


Reviewed — looks good

The reviewed changes implement AIO signal and kqueue completion notifications and socket requests; no verified blocking defect was found in the code read.

What I ran

Reviewed head 7ddbf60a2efb22c67bd96cfce1cd97703ffa6b86 against main. No commands or tests were run; the test results below are author-reported.

Results

Check Result Note
Code review passed Inspected the main AIO, signal, and kqueue paths
Tests not run Test runs are reported by the author
Console and Linux behavior not run Not verified on this head

Findings

Blocking

None.

Non-blocking

None.

Not verified

The console, Linux behavior for partial socket writes on this head, unblocked signal delivery, and the deleted debt fragment were not verified. The author reports macOS and Windows test runs and identifies the unblocked-signal path as still throwing. Files read: description.md, commits.md, manifest.json, diff.patch, Kqueue.cpp, Signals.cpp, Api.hpp (diff only), Aio.cpp, GuestKernelSysAio.cpp, and feat-aio-sigevent-completion.md. Excluded: deleted docs/dev/debt/changes/docs-kernel-sys-aio-suspend-debt.md; files.json was unavailable in the review folder.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6012665192 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21463#pullrequestreview-6012665192). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T14:15:07Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed changes implement AIO signal and kqueue completion notifications and socket requests; no verified blocking defect was found in the code read. ## What I ran Reviewed head `7ddbf60a2efb22c67bd96cfce1cd97703ffa6b86` against `main`. No commands or tests were run; the test results below are author-reported. ## Results | Check | Result | Note | |---|---|---| | Code review | passed | Inspected the main AIO, signal, and kqueue paths | | Tests | not run | Test runs are reported by the author | | Console and Linux behavior | not run | Not verified on this head | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The console, Linux behavior for partial socket writes on this head, unblocked signal delivery, and the deleted debt fragment were not verified. The author reports macOS and Windows test runs and identifies the unblocked-signal path as still throwing. Files read: `description.md`, `commits.md`, `manifest.json`, `diff.patch`, `Kqueue.cpp`, `Signals.cpp`, `Api.hpp` (diff only), `Aio.cpp`, `GuestKernelSysAio.cpp`, and `feat-aio-sigevent-completion.md`. Excluded: deleted `docs/dev/debt/changes/docs-kernel-sys-aio-suspend-debt.md`; `files.json` was unavailable in the review folder. ## To get this to a good state Nothing is required.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!21463
No description provided.