feat(libkernel_sys): implement the POSIX aio calls #9355

Merged
DavidSamir merged 2 commits from upstream-pr/9355 into main 2026-10-23 08:28:49 +00:00
DavidSamir commented 2026-10-21 19:10:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-21T19:10:40Z.


What

Implements the POSIX asynchronous I/O calls in a new libkernel_sys/Aio.cpp, following FreeBSD 11 sys/kern/vfs_aio.c. They replace eight discovery stubs that threw.

How the calls run:

  • The worker: requests run on one worker thread for the process, in submission order, through libkernel pread, pwrite and fsync.
  • Completion: a request completes with (count, 0) or (-1, errno), as aio_process_rw and aio_process_sync do.
  • The aiocb layout: it is the amd64 struct aiocb (160 bytes): _aiocb_private at 56 and aio_sigevent at 80.

The calls:

  • aio_read, aio_write: these queue as aio_aqueue does.
    • The aiocb gets status -1 and error 0 first.
    • EFAULT for a NULL aiocb, and EAGAIN past 256 requests.
    • EINVAL for aio_nbytes over INT_MAX, for a sigev_notify that is not NONE, SIGNAL, THREAD_ID or KEVENT, and for a bad signal number.
    • EBADF for a descriptor that isn't open for that direction.
    • EINVAL for a negative offset.
    • EOPNOTSUPP for anything but a regular file or directory, as aio_queue_file does with vfs.aio.enable_unsafe 0.
    • The EBADF, EINVAL and EOPNOTSUPP errors are also stored in the aiocb's error, as FreeBSD does. A queued request reads EINPROGRESS.
  • aio_fsync: EINVAL unless the op is O_SYNC (0x80); FreeBSD 11 rejects O_DSYNC too. EINVAL for a descriptor without a vnode, such as a pipe. It is queued behind the earlier requests.
  • aio_error:
    • EINPROGRESS until the request is done, then its error.
    • For an aiocb it doesn't know, the stored error while status is -1 (FreeBSD's queue-failure case), otherwise EINVAL.
  • aio_return: returns a finished request's result once and stores status and error into the aiocb. A failed request returns -1 with its errno. A second call, or a request still running, gives EINVAL.
  • aio_suspend:
    • EINVAL for a count outside 0..256 or a bad timespec, and EAGAIN before any aio use.
    • Returns 0 when a listed request is done or none of them is known any more.
    • EAGAIN on timeout.
  • aio_waitcomplete: stores NULL first. A {0, 0} timeout gives EAGAIN at once and a NULL timeout waits forever. It takes the first finished request and consumes it like aio_return.
  • aio_cancel: EBADF for a bad descriptor. A request still queued completes with (-1, ECANCELED); a running or finished one can't be cancelled. Returns AIO_CANCELED, AIO_NOTCANCELED or AIO_ALLDONE in sys_aio_cancel's order.

What throws: completion by SIGEV_SIGNAL, SIGEV_THREAD_ID or SIGEV_KEVENT, and aio on a socket (FreeBSD's soaio path). A debt line records these, the single worker thread, the use of the descriptor number, and pipes failing as on FreeBSD 11 (the console's sysctl is unverified).

The test hook: AioHoldWorkerForTest_nid_no_patch(bool) stops the worker from taking new requests. It exists only to make the queued-request tests (EINPROGRESS, cancelling) deterministic. It follows the existing *ForTest seams, SetDepthPlaneClearForTest and OverrideCacheBudgetForTest.

Aio.cpp is added to the add_library line rather than appended, so this PR merges cleanly with the open PRs that append target_sources to libkernel_sys/CMakeLists.txt.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. This is a CPU-side export, so no GPU is involved.

New test guest_kernel_sys_aio, which covers:

  • the errors before any use;
  • each queueing error, including the stored aiocb error and aio_error's status == -1 case;
  • a pipe getting EOPNOTSUPP, and aio_fsync on a pipe getting EINVAL;
  • the O_DSYNC and op 0 rejections;
  • a write and read round trip at offsets, and a 0-byte read;
  • aio_return consuming once, and aio_suspend's argument errors;
  • with the worker held: EINPROGRESS, the aio_suspend timeout, cancelling a queued request (AIO_CANCELED, then ECANCELED from aio_error and aio_return), a second cancel giving AIO_ALLDONE, and aio_cancel(fd, NULL);
  • the write-then-fsync order as seen by aio_waitcomplete, and its {0,0}, timeout and bad-timespec cases.

Results:

  • It passes, 4 of 4 runs. guest_kernel_sys still passes, tools/check_conventions.py passes, and there are no warnings.
  • Negative controls:
    • with aio_return not consuming, the test fails at line 152;
    • with cancelling of queued requests disabled, it fails at line 186;
    • with a worker that takes the newest request first, it fails at line 211.
  • Overlap: tools/pr_overlap.py crashes on this machine's partial clone, so I ran git merge-tree against every open PR that touches these files. It merges cleanly with all of them except #9137, which already conflicts with main in files this PR doesn't touch.

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
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4956954059 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9355). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-21T19:10:40Z. --- ### What Implements the POSIX asynchronous I/O calls in a new `libkernel_sys/Aio.cpp`, following FreeBSD 11 `sys/kern/vfs_aio.c`. They replace eight discovery stubs that threw. How the calls run: - **The worker:** requests run on one worker thread for the process, in submission order, through libkernel `pread`, `pwrite` and `fsync`. - **Completion:** a request completes with `(count, 0)` or `(-1, errno)`, as `aio_process_rw` and `aio_process_sync` do. - **The aiocb layout:** it is the amd64 `struct aiocb` (160 bytes): `_aiocb_private` at 56 and `aio_sigevent` at 80. The calls: - **`aio_read`, `aio_write`:** these queue as `aio_aqueue` does. - The aiocb gets `status` -1 and `error` 0 first. - `EFAULT` for a NULL aiocb, and `EAGAIN` past 256 requests. - `EINVAL` for `aio_nbytes` over `INT_MAX`, for a `sigev_notify` that is not NONE, SIGNAL, THREAD_ID or KEVENT, and for a bad signal number. - `EBADF` for a descriptor that isn't open for that direction. - `EINVAL` for a negative offset. - `EOPNOTSUPP` for anything but a regular file or directory, as `aio_queue_file` does with `vfs.aio.enable_unsafe` 0. - The `EBADF`, `EINVAL` and `EOPNOTSUPP` errors are also stored in the aiocb's `error`, as FreeBSD does. A queued request reads `EINPROGRESS`. - **`aio_fsync`:** `EINVAL` unless the op is `O_SYNC` (0x80); FreeBSD 11 rejects `O_DSYNC` too. `EINVAL` for a descriptor without a vnode, such as a pipe. It is queued behind the earlier requests. - **`aio_error`:** - `EINPROGRESS` until the request is done, then its error. - For an aiocb it doesn't know, the stored error while `status` is -1 (FreeBSD's queue-failure case), otherwise `EINVAL`. - **`aio_return`:** returns a finished request's result once and stores `status` and `error` into the aiocb. A failed request returns -1 with its errno. A second call, or a request still running, gives `EINVAL`. - **`aio_suspend`:** - `EINVAL` for a count outside 0..256 or a bad timespec, and `EAGAIN` before any aio use. - Returns 0 when a listed request is done or none of them is known any more. - `EAGAIN` on timeout. - **`aio_waitcomplete`:** stores NULL first. A `{0, 0}` timeout gives `EAGAIN` at once and a NULL timeout waits forever. It takes the first finished request and consumes it like `aio_return`. - **`aio_cancel`:** `EBADF` for a bad descriptor. A request still queued completes with `(-1, ECANCELED)`; a running or finished one can't be cancelled. Returns `AIO_CANCELED`, `AIO_NOTCANCELED` or `AIO_ALLDONE` in `sys_aio_cancel`'s order. **What throws:** completion by `SIGEV_SIGNAL`, `SIGEV_THREAD_ID` or `SIGEV_KEVENT`, and aio on a socket (FreeBSD's `soaio` path). A debt line records these, the single worker thread, the use of the descriptor number, and pipes failing as on FreeBSD 11 (the console's sysctl is unverified). **The test hook:** `AioHoldWorkerForTest_nid_no_patch(bool)` stops the worker from taking new requests. It exists only to make the queued-request tests (`EINPROGRESS`, cancelling) deterministic. It follows the existing `*ForTest` seams, `SetDepthPlaneClearForTest` and `OverrideCacheBudgetForTest`. `Aio.cpp` is added to the `add_library` line rather than appended, so this PR merges cleanly with the open PRs that append `target_sources` to `libkernel_sys/CMakeLists.txt`. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. This is a CPU-side export, so no GPU is involved. New test `guest_kernel_sys_aio`, which covers: - the errors before any use; - each queueing error, including the stored aiocb error and `aio_error`'s `status == -1` case; - a pipe getting `EOPNOTSUPP`, and `aio_fsync` on a pipe getting `EINVAL`; - the `O_DSYNC` and op 0 rejections; - a write and read round trip at offsets, and a 0-byte read; - `aio_return` consuming once, and `aio_suspend`'s argument errors; - with the worker held: `EINPROGRESS`, the `aio_suspend` timeout, cancelling a queued request (`AIO_CANCELED`, then `ECANCELED` from `aio_error` and `aio_return`), a second cancel giving `AIO_ALLDONE`, and `aio_cancel(fd, NULL)`; - the write-then-fsync order as seen by `aio_waitcomplete`, and its `{0,0}`, timeout and bad-timespec cases. Results: - It passes, 4 of 4 runs. `guest_kernel_sys` still passes, `tools/check_conventions.py` passes, and there are no warnings. - Negative controls: - with `aio_return` not consuming, the test fails at line 152; - with cancelling of queued requests disabled, it fails at line 186; - with a worker that takes the newest request first, it fails at line 211. - Overlap: `tools/pr_overlap.py` crashes on this machine's partial clone, so I ran `git merge-tree` against every open PR that touches these files. It merges cleanly with all of them except #9137, which already conflicts with `main` in files this PR doesn't touch. ### 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) - [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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-21 19:11:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T19:11:37Z.


Progress report (17f5335 → 05b7d20)

📈 System libraries: 42.39% (+0.04%, +5 implemented functions)

✅ 5 implemented
Library Name
libkernel_sys aio_cancel_nid_postfix
libkernel_sys aio_error_nid_postfix
libkernel_sys aio_return_nid_postfix
libkernel_sys aio_suspend_nid_postfix
libkernel_sys aio_waitcomplete_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6324330072 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9355#issuecomment-6324330072). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T19:11:37Z. --- <!-- progress-report --> ### Progress report (17f5335 → 05b7d20) 📈 **System libraries**: 42.39% (+0.04%, +5 implemented functions) <details> <summary>✅ 5 implemented</summary> | Library | Name | | - | - | | libkernel_sys | `aio_cancel_nid_postfix` | | libkernel_sys | `aio_error_nid_postfix` | | libkernel_sys | `aio_return_nid_postfix` | | libkernel_sys | `aio_suspend_nid_postfix` | | libkernel_sys | `aio_waitcomplete_nid_postfix` | </details>
wachi35676 commented 2026-10-21 23:39:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-21T23:39:47Z.


Windows and Linux run, plus a comparison with #9391, which implements the same eight exports in the same new libkernel_sys/Aio.cpp and the same test name guest_kernel_sys_aio (the two branches conflict on both files).

Head 478947f71f merged onto main a6dcea927 (clean). Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON; WSL2 Ubuntu 24.04, GCC 13.3.0, Release.

  • guest_kernel_sys_aio: 3/3 on Windows, 3/3 on Linux. With libkernel_sys from main (stubs back, Aio.cpp removed) the test does not link (AioHoldWorkerForTest_nid_no_patch).
  • check_conventions.py --base a6dcea927: passes.

I ran one probe against both branches (same file, same results on both hosts unless noted):

Case FreeBSD 11.4 vfs_aio.c #9355 #9391
aio_suspend with nent 17 and 256, the list holding a finished request 0 (limit is max_aio_queue_per_proc, 256, L1937) 0 -1 EINVAL
aio_read with aio_offset -5 on a regular file -1 EINVAL at submit (L1564) -1 EINVAL 0; aio_error 22, aio_return -1 EINVAL later
aio_read with aio_nbytes INT_MAX+1 (8-byte file) queued: IOSIZE_MAX is iosize_max(), SSIZE_MAX on LP64 with debug.iosize_max_clamp 0 (L1491, sys_generic.c L93/L174) -1 EINVAL queued; aio_return 8 on Linux, -1 EIO on Windows (host pread)
aio_error(NULL) after a request -1 (fetch_status of NULL, L2067) 22 -1
aio_suspend(NULL, 1, NULL) while a finished request is not yet returned -1 EFAULT (copyin, L1949) access violation (Windows 0xc0000005, Linux SIGSEGV) -1 EFAULT

Results are the same on Windows and Linux except where noted.

Two of these are in this branch:

  • Aio.cpp:55 limits aio_nbytes to INT_MAX, and the test asserts it (GuestKernelSysAio.cpp:123). FreeBSD 11 amd64 accepts up to SSIZE_MAX there. #9391 uses the 64-bit limit.
  • aio_suspend_nid_postfix reads list[index] (Aio.cpp:288) without a null check, so a NULL list with nent > 0 crashes the host once any request is on all. FreeBSD returns EFAULT.
  • Minor: aio_error(NULL) returns EINVAL (Aio.cpp:255); FreeBSD returns -1.

Where this branch is closer to FreeBSD than #9391: the aio_suspend limit (256), the synchronous EINVAL for any negative offset, and real cancellation (ECANCELED, AIO_CANCELED) with requests that stay EINPROGRESS until the worker runs them. #9391 completes each request inside aio_read, so aio_cancel never cancels; it does deliver SIGEV_SIGNAL, which this branch throws for.

Neither branch has lio_listio; it is not in the PS5 3.20 libkernel or libkernel_sys export lists (libkernel_sys.c has the eight aio_* NIDs only), so nothing is missing there.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329013437 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9355#issuecomment-6329013437). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-21T23:39:47Z. --- Windows and Linux run, plus a comparison with #9391, which implements the same eight exports in the same new `libkernel_sys/Aio.cpp` and the same test name `guest_kernel_sys_aio` (the two branches conflict on both files). Head `478947f71f` merged onto main `a6dcea927` (clean). Windows 11 Home 10.0.26300, Ryzen 5 9600X, WinLibs GCC 15.2.0 (MinGW-w64 UCRT), Release, `BUILD_TESTING=ON`; WSL2 Ubuntu 24.04, GCC 13.3.0, Release. - `guest_kernel_sys_aio`: 3/3 on Windows, 3/3 on Linux. With `libkernel_sys` from main (stubs back, `Aio.cpp` removed) the test does not link (`AioHoldWorkerForTest_nid_no_patch`). - `check_conventions.py --base a6dcea927`: passes. I ran one probe against both branches (same file, same results on both hosts unless noted): | Case | FreeBSD 11.4 `vfs_aio.c` | #9355 | #9391 | |---|---|---|---| | `aio_suspend` with `nent` 17 and 256, the list holding a finished request | 0 (limit is `max_aio_queue_per_proc`, 256, [L1937](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_aio.c#L1937)) | 0 | -1 `EINVAL` | | `aio_read` with `aio_offset` -5 on a regular file | -1 `EINVAL` at submit ([L1564](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_aio.c#L1564)) | -1 `EINVAL` | 0; `aio_error` 22, `aio_return` -1 `EINVAL` later | | `aio_read` with `aio_nbytes` `INT_MAX`+1 (8-byte file) | queued: `IOSIZE_MAX` is `iosize_max()`, `SSIZE_MAX` on LP64 with `debug.iosize_max_clamp` 0 ([L1491](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_aio.c#L1491), [sys_generic.c L93/L174](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/sys_generic.c#L93)) | -1 `EINVAL` | queued; `aio_return` 8 on Linux, -1 `EIO` on Windows (host `pread`) | | `aio_error(NULL)` after a request | -1 (`fetch_status` of NULL, [L2067](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_aio.c#L2067)) | 22 | -1 | | `aio_suspend(NULL, 1, NULL)` while a finished request is not yet returned | -1 `EFAULT` (`copyin`, [L1949](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_aio.c#L1949)) | access violation (Windows `0xc0000005`, Linux SIGSEGV) | -1 `EFAULT` | Results are the same on Windows and Linux except where noted. Two of these are in this branch: - `Aio.cpp:55` limits `aio_nbytes` to `INT_MAX`, and the test asserts it (`GuestKernelSysAio.cpp:123`). FreeBSD 11 amd64 accepts up to `SSIZE_MAX` there. #9391 uses the 64-bit limit. - `aio_suspend_nid_postfix` reads `list[index]` (`Aio.cpp:288`) without a null check, so a NULL list with `nent` > 0 crashes the host once any request is on `all`. FreeBSD returns `EFAULT`. - Minor: `aio_error(NULL)` returns `EINVAL` (`Aio.cpp:255`); FreeBSD returns -1. Where this branch is closer to FreeBSD than #9391: the `aio_suspend` limit (256), the synchronous `EINVAL` for any negative offset, and real cancellation (`ECANCELED`, `AIO_CANCELED`) with requests that stay `EINPROGRESS` until the worker runs them. #9391 completes each request inside `aio_read`, so `aio_cancel` never cancels; it does deliver `SIGEV_SIGNAL`, which this branch throws for. Neither branch has `lio_listio`; it is not in the PS5 3.20 libkernel or libkernel_sys export lists ([libkernel_sys.c](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libkernel_sys.c) has the eight `aio_*` NIDs only), so nothing is missing there. AI-assisted: yes (Claude Code); results above were run on this machine.
DavidSamir commented 2026-10-22 01:57:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T01:57:58Z.


Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head 478947f71f merged onto main 8c26eac3c.

  • guest_kernel_sys_aio passes 3/3, and guest_kernel_sys passes 3/3.
  • Negative control: with a worker that takes the newest request first (queued.back() and pop_back()), it fails at line 211, as listed.
  • Negative control: with aio_return not consuming (the done.erase removed), it fails at line 152, as listed. I did not repeat the cancel control.

Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6330835939 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9355#issuecomment-6330835939). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T01:57:58Z. --- Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head `478947f71f` merged onto `main` `8c26eac3c`. - `guest_kernel_sys_aio` passes 3/3, and `guest_kernel_sys` passes 3/3. - Negative control: with a worker that takes the newest request first (`queued.back()` and `pop_back()`), it fails at line 211, as listed. - Negative control: with `aio_return` not consuming (the `done.erase` removed), it fails at line 152, as listed. I did not repeat the cancel control. Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine.
harisibrar1 commented 2026-10-22 13:33:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T13:33:19Z.

Review: COMMENTED


Checked against main b786b907c8 and FreeBSD 11.4 sys/kern/vfs_aio.c (release/11.4.0):

  • The aiocb layout (160 bytes, _aiocb_private at 56, aio_sigevent at 80) and the checks in aio_aqueue line up with FreeBSD. aio_return, aio_waitcomplete, aio_suspend and aio_cancel follow kern_aio_* and sys_aio_cancel, and no sigev_notify mode is reported as a fake success. Thanks for the careful work.
  • Small one: aio_read(NULL) returns EFAULT before aio.used is set (Aio.cpp:183-186), while FreeBSD creates p_aioinfo first (aio_aqueue L1466). So after only aio_read(NULL), aio_error(&cb) on an aiocb with status == -1 and error == 5 returns 22 here but 5 on FreeBSD, and aio_suspend with a {0,0} timeout on a never-submitted aiocb returns EAGAIN here but 0 on FreeBSD. Setting used before the NULL check would fix both.
  • On the NULL-list aio_suspend crash wachi35676 found: sys_aio_suspend copies the list in (L1949) before kern_aio_suspend checks p_aioinfo, so aio_suspend(NULL, 1, NULL) is EFAULT even before any aio use. The new check needs to go before the !aio.used → EAGAIN return at Aio.cpp:282.
  • Optional: the socket NotImplemented_nid_no_patch at Aio.cpp:209 runs before two checks that FreeBSD settles without socket aio: aio_fsync on a socket is EINVAL (no f_vnode, L1558), and a negative offset is EINVAL (L1564). Moving the throw after Aio.cpp:211-212 would cover them.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5615043708 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9355#pullrequestreview-5615043708). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-22T13:33:19Z. **Review:** COMMENTED --- Checked against main b786b907c8 and FreeBSD 11.4 `sys/kern/vfs_aio.c` (release/11.4.0): - The aiocb layout (160 bytes, `_aiocb_private` at 56, `aio_sigevent` at 80) and the checks in `aio_aqueue` line up with FreeBSD. `aio_return`, `aio_waitcomplete`, `aio_suspend` and `aio_cancel` follow `kern_aio_*` and `sys_aio_cancel`, and no `sigev_notify` mode is reported as a fake success. Thanks for the careful work. - Small one: `aio_read(NULL)` returns `EFAULT` before `aio.used` is set (`Aio.cpp:183-186`), while FreeBSD creates `p_aioinfo` first (`aio_aqueue` L1466). So after only `aio_read(NULL)`, `aio_error(&cb)` on an aiocb with `status == -1` and `error == 5` returns 22 here but 5 on FreeBSD, and `aio_suspend` with a `{0,0}` timeout on a never-submitted aiocb returns `EAGAIN` here but 0 on FreeBSD. Setting `used` before the NULL check would fix both. - On the NULL-list `aio_suspend` crash wachi35676 found: `sys_aio_suspend` copies the list in (L1949) before `kern_aio_suspend` checks `p_aioinfo`, so `aio_suspend(NULL, 1, NULL)` is `EFAULT` even before any aio use. The new check needs to go before the `!aio.used` → `EAGAIN` return at `Aio.cpp:282`. - Optional: the socket `NotImplemented_nid_no_patch` at `Aio.cpp:209` runs before two checks that FreeBSD settles without socket aio: `aio_fsync` on a socket is `EINVAL` (no `f_vnode`, L1558), and a negative offset is `EINVAL` (L1564). Moving the throw after `Aio.cpp:211-212` would cover them. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!9355
No description provided.