feat(libkernel_sys): implement POSIX AIO #9391

Closed
GitamarT045T3R wants to merge 2 commits from upstream-pr/9391 into main
GitamarT045T3R commented 2026-10-21 20:18:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-21T20:18:29Z.


What

The eight POSIX AIO calls of libkernel_sys were NotImplemented stubs. They now follow FreeBSD 11's vfs_aio.c on the LP64 struct aiocb (160 bytes, _aiocb_private at 56, aio_sigevent at 80):

Call FreeBSD 11 Now
aio_read, aio_write, aio_fsync aio_aqueue stores status -1, error 0 and kernelinfo -1 first; EAGAIN (stored) past 256 requests per process; EFAULT for a null aiocb; EINVAL (not stored) for aio_nbytes over SSIZE_MAX or a signal number outside 1-128; EINVAL (stored) for a sigev_notify other than NONE, SIGNAL, KEVENT or THREAD_ID; EBADF (stored) for a closed descriptor or the wrong access mode; EINVAL for aio_offset -1 (read, write) or a descriptor without a vnode (fsync); then a job id in kernelinfo and EINPROGRESS in error; aio_lio_opcode is ignored
unsafe descriptors aio_queue_file with vfs.aio.enable_unsafe 0 pipes, devices and other non-file descriptors fail with EOPNOTSUPP (stored)
transfer aio_process_rw, aio_process_sync sceKernelPread, sceKernelPwrite or sceKernelFsync at aio_offset; a zero-byte read does no I/O
aio_fsync kern_aio_fsync EINVAL unless op is O_SYNC (0x80)
aio_error kern_aio_error EINVAL before any request; the job's error or EINPROGRESS; for an unknown aiocb, its stored error when status is -1, else EINVAL (returned, not through errno)
aio_return kern_aio_return collects a finished job once, writing error and status back; -1 with the job's error as errno; EINVAL otherwise
aio_suspend sys_aio_suspend, kern_aio_suspend EINVAL for nent outside 0-16 or a bad timespec; EAGAIN before any request; returns once a listed job is finished or none is known; EAGAIN on timeout
aio_cancel sys_aio_cancel EBADF for a closed descriptor; AIO_NOTCANCELED while a matching job is still running, else AIO_ALLDONE
aio_waitcomplete kern_aio_waitcomplete stores NULL first; NULL waits, {0, 0} polls, others are validated; takes finished jobs in completion order, waking when another thread completes one

A request runs to completion on the calling thread before aio_read, aio_write or aio_fsync returns. FreeBSD handles the same case, a queue callback that completes synchronously, in aio_aqueue. libkernel's sceKernelAio* also completes on submission. SIGEV_SIGNAL, and SIGEV_THREAD_ID naming the caller, raise the signal after completion through libkernel's raise. SIGEV_KEVENT (libkernel has no EVFILT_AIO), requests on a socket, and SIGEV_THREAD_ID naming another thread throw after the argument checks.

The implementation is in a new libkernel_sys/Aio.cpp, with the eight stubs removed from Export.Discovery.cpp. The gaps are in a new libkernel_sys debt entry.

Tested

Windows 10 Pro 22H2 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release, BUILD_TESTING=ON, on main cecb540a6:

  • New guest_kernel_sys_aio covers:
    • every call before the first request;
    • read, write, read past the end, and a failing read collected by aio_return and by aio_waitcomplete, with the stored fields checked after each;
    • each rejection above, including pipes (EOPNOTSUPP, and EINVAL from aio_fsync);
    • the SIGEV_KEVENT flag check;
    • read-only and write-only descriptors, and aio_fsync on a read-only file and a directory;
    • aio_suspend and aio_waitcomplete timeouts and validation, and aio_waitcomplete woken by a request from another thread;
    • the 256-request limit;
    • SIGEV_SIGNAL and SIGEV_THREAD_ID delivery to a guest handler.
  • It passes 30 of 30 repeated runs. On main the first call throws aio_error_nid_postfix not implemented.
  • guest_kernel_sys still passes.
  • python tools/check_conventions.py --base origin/main passes.
  • Not built or run on Linux or macOS. The code has no host-specific paths: it goes through libkernel's fcntl, sceKernelFstat, sceKernelPread, sceKernelPwrite and sceKernelFsync.

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:4957791954 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9391). Originally posted by [GitamarT045T3R](https://github.com/GitamarT045T3R) on 2026-10-21T20:18:29Z. --- ### What The eight POSIX AIO calls of libkernel_sys were `NotImplemented` stubs. They now follow FreeBSD 11's [`vfs_aio.c`](https://github.com/freebsd/freebsd-src/blob/34bd34750187bae02a0086402c78c031c59dd8b3/sys/kern/vfs_aio.c) on the LP64 `struct aiocb` (160 bytes, `_aiocb_private` at 56, `aio_sigevent` at 80): | Call | FreeBSD 11 | Now | | --- | --- | --- | | `aio_read`, `aio_write`, `aio_fsync` | `aio_aqueue` | stores `status` -1, `error` 0 and `kernelinfo` -1 first; `EAGAIN` (stored) past 256 requests per process; `EFAULT` for a null `aiocb`; `EINVAL` (not stored) for `aio_nbytes` over `SSIZE_MAX` or a signal number outside 1-128; `EINVAL` (stored) for a `sigev_notify` other than `NONE`, `SIGNAL`, `KEVENT` or `THREAD_ID`; `EBADF` (stored) for a closed descriptor or the wrong access mode; `EINVAL` for `aio_offset` -1 (read, write) or a descriptor without a vnode (fsync); then a job id in `kernelinfo` and `EINPROGRESS` in `error`; `aio_lio_opcode` is ignored | | unsafe descriptors | `aio_queue_file` with `vfs.aio.enable_unsafe` 0 | pipes, devices and other non-file descriptors fail with `EOPNOTSUPP` (stored) | | transfer | `aio_process_rw`, `aio_process_sync` | `sceKernelPread`, `sceKernelPwrite` or `sceKernelFsync` at `aio_offset`; a zero-byte read does no I/O | | `aio_fsync` | `kern_aio_fsync` | `EINVAL` unless `op` is `O_SYNC` (0x80) | | `aio_error` | `kern_aio_error` | `EINVAL` before any request; the job's error or `EINPROGRESS`; for an unknown `aiocb`, its stored `error` when `status` is -1, else `EINVAL` (returned, not through `errno`) | | `aio_return` | `kern_aio_return` | collects a finished job once, writing `error` and `status` back; `-1` with the job's error as `errno`; `EINVAL` otherwise | | `aio_suspend` | `sys_aio_suspend`, `kern_aio_suspend` | `EINVAL` for `nent` outside 0-16 or a bad `timespec`; `EAGAIN` before any request; returns once a listed job is finished or none is known; `EAGAIN` on timeout | | `aio_cancel` | `sys_aio_cancel` | `EBADF` for a closed descriptor; `AIO_NOTCANCELED` while a matching job is still running, else `AIO_ALLDONE` | | `aio_waitcomplete` | `kern_aio_waitcomplete` | stores NULL first; NULL waits, `{0, 0}` polls, others are validated; takes finished jobs in completion order, waking when another thread completes one | A request runs to completion on the calling thread before `aio_read`, `aio_write` or `aio_fsync` returns. FreeBSD handles the same case, a queue callback that completes synchronously, in `aio_aqueue`. libkernel's `sceKernelAio*` also completes on submission. `SIGEV_SIGNAL`, and `SIGEV_THREAD_ID` naming the caller, raise the signal after completion through libkernel's `raise`. `SIGEV_KEVENT` (libkernel has no `EVFILT_AIO`), requests on a socket, and `SIGEV_THREAD_ID` naming another thread throw after the argument checks. The implementation is in a new `libkernel_sys/Aio.cpp`, with the eight stubs removed from `Export.Discovery.cpp`. The gaps are in a new libkernel_sys debt entry. ### Tested Windows 10 Pro 22H2 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release, `BUILD_TESTING=ON`, on `main` `cecb540a6`: - New `guest_kernel_sys_aio` covers: - every call before the first request; - read, write, read past the end, and a failing read collected by `aio_return` and by `aio_waitcomplete`, with the stored fields checked after each; - each rejection above, including pipes (`EOPNOTSUPP`, and `EINVAL` from `aio_fsync`); - the `SIGEV_KEVENT` flag check; - read-only and write-only descriptors, and `aio_fsync` on a read-only file and a directory; - `aio_suspend` and `aio_waitcomplete` timeouts and validation, and `aio_waitcomplete` woken by a request from another thread; - the 256-request limit; - `SIGEV_SIGNAL` and `SIGEV_THREAD_ID` delivery to a guest handler. - It passes 30 of 30 repeated runs. On `main` the first call throws `aio_error_nid_postfix not implemented`. - `guest_kernel_sys` still passes. - `python tools/check_conventions.py --base origin/main` passes. - Not built or run on Linux or macOS. The code has no host-specific paths: it goes through libkernel's `fcntl`, `sceKernelFstat`, `sceKernelPread`, `sceKernelPwrite` and `sceKernelFsync`. ### Checklist - [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 20:19:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T20:19:24Z.


Progress report (0c6a5bd → f1f90b2)

📈 System libraries: 42.18% (+0.08%, +8 implemented functions)

✅ 8 implemented
Library Name
libkernel_sys aio_cancel_nid_postfix
libkernel_sys aio_error_nid_postfix
libkernel_sys aio_fsync_nid_postfix
libkernel_sys aio_read_nid_postfix
libkernel_sys aio_return_nid_postfix
libkernel_sys aio_suspend_nid_postfix
libkernel_sys aio_waitcomplete_nid_postfix
libkernel_sys aio_write_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6325656516 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9391#issuecomment-6325656516). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T20:19:24Z. --- <!-- progress-report --> ### Progress report (0c6a5bd → f1f90b2) 📈 **System libraries**: 42.18% (+0.08%, +8 implemented functions) <details> <summary>✅ 8 implemented</summary> | Library | Name | | - | - | | libkernel_sys | `aio_cancel_nid_postfix` | | libkernel_sys | `aio_error_nid_postfix` | | libkernel_sys | `aio_fsync_nid_postfix` | | libkernel_sys | `aio_read_nid_postfix` | | libkernel_sys | `aio_return_nid_postfix` | | libkernel_sys | `aio_suspend_nid_postfix` | | libkernel_sys | `aio_waitcomplete_nid_postfix` | | libkernel_sys | `aio_write_nid_postfix` | </details>
github-actions[bot] commented 2026-10-21 20:39:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T20:39:17Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 9297 core/libs/prx/libkernel_sys/CMakeLists.txt L2
PR 9302 core/libs/prx/libkernel_sys/CMakeLists.txt L2
PR 9355 core/libs/prx/libkernel_sys/Aio.cpp
core/libs/tests/GuestKernelSysAio.cpp
aio_cancel
aio_error
aio_fsync
aio_read
aio_return
aio_suspend
aio_waitcomplete
aio_write
core/libs/prx/libkernel_sys/Aio.cpp
core/libs/tests/GuestKernelSysAio.cpp

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
PR 6469 core/libs/prx/libkernel/CMakeLists.txt
PR 6525 docs/dev/debt/libkernel_sys.md
PR 6830 core/libs/prx/libkernel/CMakeLists.txt
PR 6936 core/libs/prx/libkernel/CMakeLists.txt
PR 7201 core/libs/prx/libkernel/CMakeLists.txt
PR 8726 core/libs/prx/libkernel/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6326046122 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9391#issuecomment-6326046122). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T20:39:17Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 9297](https://www.github.com/boykopovar/AnyPS5/pull/9297) | `core/libs/prx/libkernel_sys/CMakeLists.txt` [L2](https://github.com/boykopovar/AnyPS5/blob/a6dcea9279b53b3a39c13695eac66f7c8b5b503c/core/libs/prx/libkernel_sys/CMakeLists.txt#L2) | | | | [PR 9302](https://www.github.com/boykopovar/AnyPS5/pull/9302) | `core/libs/prx/libkernel_sys/CMakeLists.txt` [L2](https://github.com/boykopovar/AnyPS5/blob/a6dcea9279b53b3a39c13695eac66f7c8b5b503c/core/libs/prx/libkernel_sys/CMakeLists.txt#L2) | | | | [PR 9355](https://www.github.com/boykopovar/AnyPS5/pull/9355) | `core/libs/prx/libkernel_sys/Aio.cpp` <br>`core/libs/tests/GuestKernelSysAio.cpp` | `aio_cancel`<br>`aio_error`<br>`aio_fsync`<br>`aio_read`<br>`aio_return`<br>`aio_suspend`<br>`aio_waitcomplete`<br>`aio_write` | `core/libs/prx/libkernel_sys/Aio.cpp`<br>`core/libs/tests/GuestKernelSysAio.cpp` | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6525](https://www.github.com/boykopovar/AnyPS5/pull/6525) | `docs/dev/debt/libkernel_sys.md` | | [PR 6830](https://www.github.com/boykopovar/AnyPS5/pull/6830) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6936](https://www.github.com/boykopovar/AnyPS5/pull/6936) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 8726](https://www.github.com/boykopovar/AnyPS5/pull/8726) | `core/libs/prx/libkernel/CMakeLists.txt` |

Pull request closed

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!9391
No description provided.