fix(libkernel): report SCM_BINTIME and SCM_TIMESTAMP from recvmsg as measured on a PS5 #11141
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11141"
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-25T19:30:00Z.
What
recvmsgon a UDP socket now returns theSCM_BINTIMEandSCM_TIMESTAMPcontrol messages whileSO_BINTIMEorSO_TIMESTAMPis set, as a retail PS5 (firmware 13.60) does. Until nowcontrolLengthwas always 0, and the options were only kept as bits. Measured with a homebrew probe from a payload process; the source and console log are in this gist (ptstamp).On the console, over loopback:
msg_controllenis 0.SO_TIMESTAMPon IPv4 gives one 32-byte record:cmsg_len32, level0xffff(SOL_SOCKET), type 2 (SCM_TIMESTAMP), then a 16-bytetimevalholding the real time of arrival.SO_BINTIMEgives{32, 0xffff, 4}(SCM_BINTIME) and a 16-bytebintime: seconds, then a 64-bit fraction.SCM_BINTIMEcomes first, thenSCM_TIMESTAMP, andmsg_controllenis 64.msg_controllen16 or 8, andMSG_CTRUNC(0x20). The data is intact.SCM_TIMESTAMPis produced;SO_BINTIMEadds nothing, as in FreeBSD 11'sip6_savecontrol.The records are built in a new
ArrivalTimestampshelper. The fraction is computed from nanoseconds as FreeBSD'stimespec2bintimedoes.recvmsgcopies as many bytes as the guest buffer holds and setsMSG_CTRUNCwhen some are cut off, as the console did; FreeBSD 11.4'skern_recvitcopies whole messages only, so this partial copy is a measured difference from it. Four cases were not measured and follow 11.4: an empty control buffer with a stamp pending (nothing copied,msg_controllen0,MSG_CTRUNC), a nullmsg_control(nothing, no flag), and TCP and Unix sockets (no message).The time is guest
CLOCK_REALTIME, read when the host hands the datagram over. That is later than the moment it reached the socket, and the debt entry says so. Sockets created through libSceNet have their own receive path and are unchanged.Before and after
recvmsgon a UDP socketmsg_controllen0SO_TIMESTAMPSCM_TIMESTAMPrecordmsg_controllen0SCM_TIMESTAMPrecordSO_BINTIME(IPv4)SCM_BINTIMErecordmsg_controllen0SCM_BINTIMErecordSCM_BINTIMEthenSCM_TIMESTAMP, 64 bytesmsg_controllen0SCM_BINTIMEthenSCM_TIMESTAMP, 64 bytesMSG_CTRUNCmsg_controllen0MSG_CTRUNCSO_BINTIMEon IPv6msg_controllen0Tested
Windows 11, WinLibs GCC 15.2, full build.
guest_udppasses 3 times out of 3. On IPv4 and IPv6 it covers no option, each option and both, with control buffers of 0, 8, 16, 40, 64 and 80 bytes. It checks the record layout and order,msg_controllen,MSG_CTRUNC, that bytes past the copied length stay untouched, and that the seconds fall betweenCLOCK_REALTIMEreadings taken before and after the call.socket|udp|tcp|net_|recv|send|underscorepass.tools/check_conventions.pypasses.Head
49bcd7549eonmainaeff26bd97.Head
19566dbee8setsMSG_CTRUNCfor an empty control buffer with a stamp pending, as 11.4 does (wachi35676's review), andguest_udpnow expects it and checks that a nullmsg_controlgets no flag.guest_udpandguest_socket_optionspass 3 times out of 3 on Windows 11 (WinLibs GCC 15.2) and on Linux (WSL, GCC 13.3); with the oldUdp.cpplineguest_udpfails.tools/check_conventions.pypasses.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)recvmsg's receive check), #7090 (UnixSCM_RIGHTS) and #10767 (SHUT_RD), which edit the end ofrecvmsg, and #11116 (mine), which edits the debt entry next to theSO_TIMESTAMPone; merge order only, and the control messages are disjoint (this PR only adds them on IP datagram sockets)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T19:35:49Z.
Review: APPROVED
Reviewed exact head
49bcd7549e8a4baba5bb6cfdb7ca203013c2ca94. The IPv4-onlySCM_BINTIMEand IPv4/IPv6SCM_TIMESTAMPrecords use the expected 32-byte control-message layout, order, arrival seconds/fraction encoding, and capacity-based truncation behavior. The helper is restricted to UDP IP sockets, and the debt entry records that the timestamp is sampled after host receive rather than at kernel packet arrival.Local checks:
Udp.cppandGuestUdp.cpp: passed.python3 tools/check_conventions.py --base upstream/main --head HEADandgit diff --check upstream/main...HEAD: passed.The author reports PS5 observations for both message types/order/truncation and Windows
guest_udpcoverage across IPv4/IPv6, option combinations and control-buffer sizes. Hosted eligibility, conventions, intake, labels and report pass; product build/test jobs are skipped. I did not independently run the PS5 probe or Windows runtime tests. Declared merge-order dependencies remain as documented. No blocking issue found.