feat(libkernel): UDP sockets and name resolution on macOS hosts #7850
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7850"
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 mugurc on 2026-10-19T10:57:55Z.
What
UDP sockets and name resolution on macOS hosts. The socket layer calls
ppolland asks forPOLLRDHUP, and the resolver callsgethostbyname_r; macOS has none of them, solibkernelandlibScePosixForWebKitdo not compile on macOS without this. Part of the macOS series announced on #1 (https://github.com/boykopovar/AnyPS5/issues/1#issuecomment-6124344298).pollwith the timeout rounded up to a millisecond.POLLHUPby peeking one byte.FIONREADon a datagram socket, and the byte count thatfstatandkeventreport for it, come fromSO_NREAD, the size of the next datagram. macOS'sFIONREADcounts every queued datagram together with its source address. One helper,QueuedBytes, serves the three; on Linux it makes the sameioctl(FIONREAD)call as before.socketpairthrows forSOCK_SEQPACKET, which has noAF_UNIXpair on macOS, andguest_socket_pairexpects that throw there.gethostbynamereplacesgethostbyname_r; macOS keeps its result in thread-specific storage.guest_udpsends on its connected socket without an address. macOS, like FreeBSD, failssendtowith an address on a connected socket withEISCONN, where Linux accepts it. The two changed lines are the same as in #7475, which makes the guest returnEISCONNthere on every host and checks it, so the two pull requests merge in either order.log_macroscaptures its writes through a datagram pair with 1 MiB buffers instead ofSOCK_SEQPACKET.The whole-port PRs #7201 and #7332 contain these functions too. #7332 carries the first version of this commit from the series and also reads
SO_NREADforfstatandkevent.Tested
macOS 26.5.1, Apple M5 Max, Apple clang 21, x86-64 build under Rosetta 2.
main9127ea36dwith the rest of the macOS series (ci/macos-series-2on my fork), the open macOS fix #7524, the JIT shared memory change of the closed #6928 (#7937 carries it now) and three changes from #7332. The libraries do not link on macOS without the series.Without this PR,
libkernelandlibScePosixForWebKitdo not compile on macOS (ppoll,POLLRDHUP,gethostbyname_r). With it,guest_udp,guest_tcp,guest_kqueue,guest_equeue_events,guest_resolver,log_macrosandlog_macros_timestampspass.With
SO_NREADinioctlonly (the first version of this commit),guest_kqueueaborts where it expects a kevent byte count of 1 for a 1-byte datagram on anAF_UNIXpair. A probe, run under Rosetta and natively, shows why.FIONREADreads 17 for that datagram, 35 after a second 2-byte datagram and 21 for a 5-byte UDP datagram on loopback.SO_NREADreads 1, 1 and 5.guest_socket_pair,guest_pollandguest_sce_netstill fail on macOS, at checks this PR does not touch:shutdown(SHUT_RD)fails withENOTCONNon a stream end whose peer shut its writing side.polldoes not report urgent data withPOLLPRI.sceNetShutdowndoes not wake arecvfromblocked on an unbound UDP socket.#7332 handles all three. With the failing
shutdowncheck reported instead of required, the rest ofguest_socket_pairpasses, including theSOCK_SEQPACKETcheck this PR adds.guest_udpandguest_kqueuepass 5 runs of 5. With #7475 merged on top,guest_udppasses 5 runs of 5 as well.ninja,ninja libsandctest -j4: 1624 tests, 991 passed, 23 failed, the rest skipped (no Vulkan loader in the environment). 17 failures are the same as in the run before this update, all among the failures #7631 lists. Five come from tests thatmainadded or changed today, in #6985, #6916, #6851 and #7872. The last isguest_socket_read_write, which fails only some runs; it passed when run alone afterwards.Linux and Windows: not run. On Linux,
QueuedBytesmakes the sameioctlcall as before andgethostbyname_rruns as before. The twoguest_udplines send on a connected socket without an address, which every host accepts; #7475 ran the same lines on Windows. Every other change is in an__APPLE__branch.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-19T11:09:47Z.
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.
main)docs/dev/debt/libkernel.mdL186docs/dev/debt/libkernel.mdL186core/libs/prx/libkernel/Socket/src/Udp.cppL439, L764-765, L801-802, L844, L867-868, L1304core/libs/tests/LogMacros.cppL40-41docs/dev/debt/libkernel.mdL186Some 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.
core/libs/prx/libScePosixForWebKit/Resolver.cppcore/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/tests/GuestSocketPair.cppdocs/dev/debt/libkernel.mdcore/libs/tests/GuestSocketPair.cppcore/libs/tests/GuestUdp.cppcore/libs/tests/LogMacros.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/Socket/src/Udp.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libScePosixForWebKit/Resolver.cppcore/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/tests/LogMacros.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-19T12:08:23Z.
Review: COMMENTED
Tested and reviewed the diff:
The macOS host socket adaptations (
SO_NREADfor datagram size onFIONREAD/fstat/kevent, millisecond rounding forpolltimeouts in absence ofppoll, andgethostbynamefallback) are well isolated under#ifdef __APPLE__.One overlap coordination note:
The modifications in
core/libs/tests/GuestUdp.cpp(lines 154, 202, 222-223) overlap with open PR #7475 (fix(libkernel): return EISCONN from sendto with an address on a connected datagram socket).PR #7475 adds explicit
EISCONN(56) validation inUdp.cppforsendtocalls with an address on connected sockets to match FreeBSD kernel behavior, and updatesGuestUdp.cppaccordingly. Your separation ofsender(connected) andaddressed(unconnected) inGuestUdp.cppaligns cleanly with that change.To help maintainers sequence them without merge conflicts, consider adding
Depends on: #7475(or noting how the two interact in the PR description).AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by mugurc on 2026-10-19T20:55:55Z.
Thanks @fogydes. The two lines of
guest_udpthat #7475 changes are now changed the same way here: the connected sender sends without an address, and thesendmsgheader has no name. With identical lines the two pull requests merge in either order without a conflict, so this one needs no Depends on.git merge-treeagrees for both orders onmain9127ea36d.This drops the second, unconnected socket and the macOS-only
EISCONNcheck from this pull request. #7475 adds that check for every host, and on macOS the host already returnsEISCONNthere. On macOSguest_udppasses with this head alone and with #7475 merged on top. The description is updated.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T11:37:29Z.
Checked the diff: every macOS change sits behind
__APPLE__,QueuedByteskeeps theioctl(FIONREAD)call on Linux,POLLRDHUPstays in the non-Apple branch, theguest_udplines match #7475, and the debt entries match the code; merged.