feat(libkernel_sys): implement the POSIX aio calls #9355
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9355"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-21T19:10:40Z.
What
Implements the POSIX asynchronous I/O calls in a new
libkernel_sys/Aio.cpp, following FreeBSD 11sys/kern/vfs_aio.c. They replace eight discovery stubs that threw.How the calls run:
pread,pwriteandfsync.(count, 0)or(-1, errno), asaio_process_rwandaio_process_syncdo.struct aiocb(160 bytes):_aiocb_privateat 56 andaio_sigeventat 80.The calls:
aio_read,aio_write: these queue asaio_aqueuedoes.status-1 anderror0 first.EFAULTfor a NULL aiocb, andEAGAINpast 256 requests.EINVALforaio_nbytesoverINT_MAX, for asigev_notifythat is not NONE, SIGNAL, THREAD_ID or KEVENT, and for a bad signal number.EBADFfor a descriptor that isn't open for that direction.EINVALfor a negative offset.EOPNOTSUPPfor anything but a regular file or directory, asaio_queue_filedoes withvfs.aio.enable_unsafe0.EBADF,EINVALandEOPNOTSUPPerrors are also stored in the aiocb'serror, as FreeBSD does. A queued request readsEINPROGRESS.aio_fsync:EINVALunless the op isO_SYNC(0x80); FreeBSD 11 rejectsO_DSYNCtoo.EINVALfor a descriptor without a vnode, such as a pipe. It is queued behind the earlier requests.aio_error:EINPROGRESSuntil the request is done, then its error.statusis -1 (FreeBSD's queue-failure case), otherwiseEINVAL.aio_return: returns a finished request's result once and storesstatusanderrorinto the aiocb. A failed request returns -1 with its errno. A second call, or a request still running, givesEINVAL.aio_suspend:EINVALfor a count outside 0..256 or a bad timespec, andEAGAINbefore any aio use.EAGAINon timeout.aio_waitcomplete: stores NULL first. A{0, 0}timeout givesEAGAINat once and a NULL timeout waits forever. It takes the first finished request and consumes it likeaio_return.aio_cancel:EBADFfor a bad descriptor. A request still queued completes with(-1, ECANCELED); a running or finished one can't be cancelled. ReturnsAIO_CANCELED,AIO_NOTCANCELEDorAIO_ALLDONEinsys_aio_cancel's order.What throws: completion by
SIGEV_SIGNAL,SIGEV_THREAD_IDorSIGEV_KEVENT, and aio on a socket (FreeBSD'ssoaiopath). 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*ForTestseams,SetDepthPlaneClearForTestandOverrideCacheBudgetForTest.Aio.cppis added to theadd_libraryline rather than appended, so this PR merges cleanly with the open PRs that appendtarget_sourcestolibkernel_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:aio_error'sstatus == -1case;EOPNOTSUPP, andaio_fsyncon a pipe gettingEINVAL;O_DSYNCand op 0 rejections;aio_returnconsuming once, andaio_suspend's argument errors;EINPROGRESS, theaio_suspendtimeout, cancelling a queued request (AIO_CANCELED, thenECANCELEDfromaio_errorandaio_return), a second cancel givingAIO_ALLDONE, andaio_cancel(fd, NULL);aio_waitcomplete, and its{0,0}, timeout and bad-timespec cases.Results:
guest_kernel_sysstill passes,tools/check_conventions.pypasses, and there are no warnings.aio_returnnot consuming, the test fails at line 152;tools/pr_overlap.pycrashes on this machine's partial clone, so I rangit merge-treeagainst every open PR that touches these files. It merges cleanly with all of them except #9137, which already conflicts withmainin files this PR doesn't touch.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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
aio_cancel_nid_postfixaio_error_nid_postfixaio_return_nid_postfixaio_suspend_nid_postfixaio_waitcomplete_nid_postfixImported 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.cppand the same test nameguest_kernel_sys_aio(the two branches conflict on both files).Head
478947f71fmerged onto maina6dcea927(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. Withlibkernel_sysfrom main (stubs back,Aio.cppremoved) 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):
vfs_aio.caio_suspendwithnent17 and 256, the list holding a finished requestmax_aio_queue_per_proc, 256, L1937)EINVALaio_readwithaio_offset-5 on a regular fileEINVALat submit (L1564)EINVALaio_error22,aio_return-1EINVALlateraio_readwithaio_nbytesINT_MAX+1 (8-byte file)IOSIZE_MAXisiosize_max(),SSIZE_MAXon LP64 withdebug.iosize_max_clamp0 (L1491, sys_generic.c L93/L174)EINVALaio_return8 on Linux, -1EIOon Windows (hostpread)aio_error(NULL)after a requestfetch_statusof NULL, L2067)aio_suspend(NULL, 1, NULL)while a finished request is not yet returnedEFAULT(copyin, L1949)0xc0000005, Linux SIGSEGV)EFAULTResults are the same on Windows and Linux except where noted.
Two of these are in this branch:
Aio.cpp:55limitsaio_nbytestoINT_MAX, and the test asserts it (GuestKernelSysAio.cpp:123). FreeBSD 11 amd64 accepts up toSSIZE_MAXthere. #9391 uses the 64-bit limit.aio_suspend_nid_postfixreadslist[index](Aio.cpp:288) without a null check, so a NULL list withnent> 0 crashes the host once any request is onall. FreeBSD returnsEFAULT.aio_error(NULL)returnsEINVAL(Aio.cpp:255); FreeBSD returns -1.Where this branch is closer to FreeBSD than #9391: the
aio_suspendlimit (256), the synchronousEINVALfor any negative offset, and real cancellation (ECANCELED,AIO_CANCELED) with requests that stayEINPROGRESSuntil the worker runs them. #9391 completes each request insideaio_read, soaio_cancelnever cancels; it does deliverSIGEV_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 eightaio_*NIDs only), so nothing is missing there.AI-assisted: yes (Claude Code); results above were run on this machine.
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
478947f71fmerged ontomain8c26eac3c.guest_kernel_sys_aiopasses 3/3, andguest_kernel_syspasses 3/3.queued.back()andpop_back()), it fails at line 211, as listed.aio_returnnot consuming (thedone.eraseremoved), 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.
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T13:33:19Z.
Review: COMMENTED
Checked against main
b786b907c8and FreeBSD 11.4sys/kern/vfs_aio.c(release/11.4.0):_aiocb_privateat 56,aio_sigeventat 80) and the checks inaio_aqueueline up with FreeBSD.aio_return,aio_waitcomplete,aio_suspendandaio_cancelfollowkern_aio_*andsys_aio_cancel, and nosigev_notifymode is reported as a fake success. Thanks for the careful work.aio_read(NULL)returnsEFAULTbeforeaio.usedis set (Aio.cpp:183-186), while FreeBSD createsp_aioinfofirst (aio_aqueueL1466). So after onlyaio_read(NULL),aio_error(&cb)on an aiocb withstatus == -1anderror == 5returns 22 here but 5 on FreeBSD, andaio_suspendwith a{0,0}timeout on a never-submitted aiocb returnsEAGAINhere but 0 on FreeBSD. Settingusedbefore the NULL check would fix both.aio_suspendcrash wachi35676 found:sys_aio_suspendcopies the list in (L1949) beforekern_aio_suspendchecksp_aioinfo, soaio_suspend(NULL, 1, NULL)isEFAULTeven before any aio use. The new check needs to go before the!aio.used→EAGAINreturn atAio.cpp:282.NotImplemented_nid_no_patchatAio.cpp:209runs before two checks that FreeBSD settles without socket aio:aio_fsyncon a socket isEINVAL(nof_vnode, L1558), and a negative offset isEINVAL(L1564). Moving the throw afterAio.cpp:211-212would cover them.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.