fix(libkernel): answer zero-length datagram receives and recvmsg flags as measured on a PS5 #10308
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10308"
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 orezraey on 2026-10-23T17:13:35Z.
What
Socket receives measured on a retail PS5 (firmware 13.60) through
libkernel_sys.sprxfrom a payload process. The sources and console logs are in this gist (precv,precv2).The console:
recvfromwithMSG_DONTWAITon a datagram socket with nothing queued, and a zero-length receive dequeues the next datagram when one is queued;recvmsginmsg_flags, withMSG_TRUNCadded for a truncated datagram (0x12 withMSG_PEEK, 0x90 withMSG_DONTWAIT);MSG_PEEKand reports the sender, as AnyPS5 already does, so the libkernel half of that debt entry is removed;recvon a stream socket with 0, orENOTCONNwhen unconnected, areadof 0 bytes with 0 even when unconnected,preadandlseekwithESPIPE, and discards data buffered beforeshutdown(SHUT_RD), all as AnyPS5 already does on Windows.AnyPS5 asked the host for a zero-length datagram receive, which blocks on an empty queue, and reported only
MSG_TRUNCinmsg_flags. A zero-length receive on a socket that is not a stream now polls the host and returns 0 when nothing is queued; otherwise the host receive dequeues the datagram as before.recvmsgnow keeps the caller's flags, and a zero-lengthrecvmsgon an empty datagram socket also returns 0 at once. Three cases follow FreeBSD 11.4 rather than a console measurement: the blocking zero-lengthrecvon an empty datagram socket (soreceive_dgramreturns 0 foruio_resid == 0before itsSS_NBIOandsbwaitchecks; the blocking zero-length call in the logs isread, whichdofilereadfinishes before the socket layer), a zero-lengthMSG_PEEKkeeping the datagram (soreceive_generic), and the emptyrecvmsg, sincerecvmsgwas measured only with a datagram queued. The debt entry says so, and the libSceNetsceNetRecv/sceNetRecvfromhalf of the removed entry stays, since only libkernel_sys was measured.Tested
Windows 11, MinGW (winlibs).
guest_datagram_recvandguest_datagram_recvfromcheck the zero-length receives (the blocking one hangs until the test times out without this change), andguest_udpchecks therecvmsgflags. The socket tests pass three runs in a row.-E "^agc_|^select_tests$") passes apart fromguest_kqueue, which fails only under-j 14, as onmain.tools/check_conventions.pypasses.tools/pr_overlap.py: #7090 touch nearby lines; whichever lands second keeps both.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 harisibrar1 on 2026-10-24T05:19:30Z.
Review: COMMENTED
Checked against main
7966e590ef, FreeBSD 11.4sys/kern/uipc_socket.c/uipc_syscalls.c/sys_generic.c(release/11.4.0) and the precv/precv2 logs in the gist:msg_flagschange matches both the logs (0x10, 0x12, 0x90) and FreeBSD:sys_recvmsgseedsmsg_flagswith the call flags (L1325), andsoreceive_dgramORsMSG_TRUNCback in (L2321, L2325).MSG_PEEKcall in precv.c or precv2.c, so "a zero-lengthMSG_PEEKkeeps it" looks FreeBSD-derived (soreceive_generic,uio_resid == 0at L1575) rather than measured.recvfromon an empty queue was measured only withMSG_DONTWAIT. The blocking zero-length case in the logs isread, which FreeBSD finishes indofilereadbefore the socket layer (sys_generic.c L367-371), which is also whyudp_read0_with_datadoesn't dequeue. The blockingrecvbehaviour does follow FreeBSD, sincesoreceive_dgramreturns 0 foruio_resid == 0before its SS_NBIO and sbwait checks (L2199-2202). It might be worth saying so in the debt entry.sceNetRecv/sceNetRecvfromin libSceNet, but the gist only measures libkernel_sys. Could you keep the libSceNet half, or note why the measurement carries over?Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.