fix(libkernel): recognize listening sockets on macOS hosts #7559
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7559"
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-18T14:00:00Z.
What
On macOS,
getsockoptwithSO_ACCEPTCONNfails withENOPROTOOPT. libkernel asks it whether a socket is listening in three places, so on macOS onmain:getsockoptofSO_ACCEPTCONNfails (guest_socket_options:getsockopt of an integer option failed (errno 42));connect, which since #6950 refuses a listening stream socket withEOPNOTSUPP, fails withEAFNOSUPPORTfor an address of another family (guest_socket_connect_listening);FIONREADinstead and reports 0 whereguest_socket_eventsexpects 1;On macOS the listening state is now read from the
SO_ACCEPTCONNflag of the socket options thatproc_pidfdinforeports (PROC_PIDFDSOCKETINFO). The three places go through oneNativeListeningfunction; other hosts keep thegetsockoptcall.#7332, which brings the open macOS pull requests together, reads the flag the same way among its other fixes; this pull request is that change on its own.
Tested
main385ed71f2with the macOS series and the open macOS fixes #6928, #6667, #6668, #6969, #6853, #6836, #6620 and #7524 (the libraries do not link on macOS without the series):guest_socket_options,guest_socket_connect_listeningandguest_socket_eventsfail without this change and pass with it;guest_tcpandguest_udppass.bind, afterlistenwith a backlog of 0, and for a UDP socket: it is set only afterlisten.NativeListeningmakes the samegetsockoptcall as before.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-18T14:13:40Z.
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.
core/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/prx/libkernel/Socket/src/SocketOptions.cppcore/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/prx/libkernel/Socket/src/Udp.cppcore/libs/prx/libkernel/Socket/src/Udp.cppImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T14:24:04Z.
Review: APPROVED
Reviewed the shared
NativeListeningpath and its three call sites. On Apple hosts it readsSO_ACCEPTCONNfromproc_pidfdinfo; on other hosts it retains the existinggetsockoptbehavior. I found no correctness issue in the diff.The PR reports focused macOS fail/pass results for the affected socket-option, connect, and event cases. I did not run the macOS reproduction locally.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T14:44:04Z.
Checked the host side of this on a newer macOS and on native arm64, head
6f2a61ade.Machine: Apple M2 Max, macOS 27.2 (26B5091g), Xcode 27 clang. A standalone C program that does exactly what
NativeListeningdoes on Apple hosts (proc_pidfdinfo(getpid(), fd, PROC_PIDFDSOCKETINFO, ...), thensoi_options & SO_ACCEPTCONN), built for arm64 and for x86_64 (run under Rosetta 2). Both builds print the same table:getsockopt(SO_ACCEPTCONN)proc_pidfdinfoflagENOPROTOOPT)bindlisten(0)acceptlisten(5)listenSO_ACCEPTCONNingetsockopt, so the change is still needed there.acceptreturns does not inherit it, so theEOPNOTSUPPcheck inconnect(#6950) and the read-event path only take the listener branch for the listener.proc_pidfdinforeturns 0 with the same errnogetsockoptgives:EBADFfor a closed descriptor,ENOTSOCKfor a pipe. SoHostError()after a failedNativeListeningreports the same guest error as before.proc_pidfdinfocall against 0.4 µs for agetsockopt(200,000 calls, arm64 and Rosetta alike). TheEqueuecaller only reaches it when the data is below the low watermark.Not run: the
guest_socket_*tests.maindoes not link the libraries on macOS without the macOS series, and your run already covers them under Rosetta.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T14:46:09Z.
Thanks for checking both native arm64 and x86-64 under Rosetta on macOS 27.2. The accepted-listener-only flag, matching EBADF/ENOTSOCK behavior, and the roughly 1.4 µs call cost support the implementation’s scope; I have not run this newer host-side probe locally.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T15:45:20Z.
I also ran the library tests in a full x86-64 build under Rosetta:
maine5f18ea99withci/macos-series-2(fa6d8ae0b) and the open macOS fixes it uses.guest_socket_options,guest_socket_connect_listeningandguest_socket_eventspass. With this PR's three files reverted on the same tree, all three fail:getsockopt of an integer option failed (errno 42), andconnect on a listening socket with an address of another family must fail with EOPNOTSUPP (45) (errno 47).Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T16:44:30Z.
Windows run, since the description lists Linux and Windows as not run. Windows 11 26300, Ryzen AI 7 350, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON. Build:main6efb7261bwith #6648, #7559, #7496, #7497 and #7498 merged together (each merge clean, built once).The build is clean.
guest_socket_connect_listening,guest_socket_events,guest_socket_options,guest_tcpandguest_udppass 3 runs of 3 on Winsock. TheSocketOptions.cppchange is under#ifdef __APPLE__, so this confirms the shared path is unchanged here.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T10:57:56Z.
Checked the diff against current main:
NativeListeningis the only reader of the listening state, every call site inUdp.cppandSocketOptions.cppgoes through it, and non-Apple hosts keep the samegetsockoptcall. The recent socket changes on main don't touch it. Confirmed on macOS by @jotitadev and on Windows by @LeandroLP23; merged.