fix(libkernel): report SO_ERROR and the other SOL_SOCKET options like FreeBSD #4796
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4796"
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 xXPBSXx on 2026-10-12T22:11:47Z.
What
getsockoptandsetsockopton a libkernel socket knew fourSOL_SOCKEToptions (SO_REUSEADDR,SO_BROADCAST,SO_SNDBUF,SO_RCVBUF) and failed every other one withENOPROTOOPT. The options now follow FreeBSD 11.4'ssosetoptandsogetopt(the same constants libSceNet already uses, for exampleNET_SO_RCVTIMEO = 0x1006):SO_ERROR(0x1007) returns the socket's pending error as a FreeBSD errno and reports it once. On Windows the host does not clear it when read, so the library does.SO_KEEPALIVE,SO_DONTROUTE,SO_OOBINLINEandSO_LINGERare read from and set on the host socket;SO_TYPEandSO_ACCEPTCONNare read only (as isSO_ERROR), andsetsockopton any of the three fails withENOPROTOOPT, as FreeBSD'ssosetopthas no case for them (they reach its default; the test does not cover this). A boolean option reads back as its own bit (FreeBSD returnsso_options & option),SO_LINGERas{SO_LINGER bit, seconds}.SO_DEBUG,SO_USELOOPBACK,SO_REUSEPORT,SO_TIMESTAMPandSO_NOSIGPIPEare left out and still fail withENOPROTOOPT, as onmain, until a title needs one (review of this PR).Lengths follow
sooptcopyin/sooptcopyout: a value is read from its firstintand fails withEINVALwhen shorter; agetsockoptbuffer gets as many bytes as it holds and its own length back.SO_SNDBUF/SO_RCVBUFbelow 1 fail withEINVAL,SO_LINGERoutside 0 to 65535 seconds withEDOM.A
connecton a non-blocking socket on Windows fails withEINPROGRESS(36) now; it returnedEWOULDBLOCK(35), which a program waiting for the connection does not expect. This is the other half of whatSO_ERRORis for, so it is in the same change.Title: The Mound (PPSA26223, EOS SDK). With a temporary trace in
socketandgetsockopt(not part of this PR), a Windows run (it ended after a few seconds at an unrelated GPU error, #1409) showed 6 callssocket(2, 1, 0)(AF_INET,SOCK_STREAM) and 2 callsgetsockopt(fd, 0xffff, 0x1007),SO_ERROR, on two different sockets; nosetsockoptand no other option was requested. Those two calls failed withENOPROTOOPTbefore. Stray and Harmony's Odyssey made no libkernel socket call in the same kind of run. Palworld (also EOS SDK) was not measured. A separate Linux run by coltken95 with Nuvio Max'd (PPSA99288), reported in the comments below, shows the sameSO_ERRORfailure of curl's connect check and its fix by this PR. The options other thanSO_ERRORare not requested by any title I ran; they follow FreeBSD for completeness.Overlap: #4903 also changes
Udp.cppand conflicts with this branch there (reported by the overlap bot), so whichever lands second needs a small rebase. #5403 contains #4903's commit and conflicts here for that reason: both add fields tostruct Socketat the same place (optionshere,receiveShutandsendShutthere). Keeping all three fields resolves it, in either order. #4658 (accepting option values longer than anint) and #4391 (descriptor numbering) are merged; the routing inSocketOptions.cppcovers every option (theGuestUdptest still passes). The test registration and the TechnicalDebt entry sit at their own places inCMakeLists.txtandlibkernel.md(next toguest_udpand the socket error numbers entry), away from the other socket PRs. Receive and send timeouts, the low-water marks and theIPPROTO_TCP,IPPROTO_IPandIPPROTO_IPV6levels are not part of this PR (they still fail withENOPROTOOPT). #5510 (simonbronk, EPIPE for a stream send after the peer closed) conflicts with this PR indocs/dev/debt/libkernel.md(git merge-treeof the two heads, re-checked againstmaince5c83953; both heads are clean againstmain); whichever lands second rebases the debt entry. #5565 (Dripl1x,TCP_NODELAY,SO_NOSIGPIPEandSO_NBIO) conflicts with this PR incore/libs/prx/libkernel/Socket/src/Udp.cpp, in the lines ofsetsockoptandgetsockoptthis PR rewrites (git merge-treeof the two heads, re-checked againstmaince5c83953; both heads are clean againstmain); its text already says it goes after this PR, and its three options move intoSocketOptions.cppon the rebase.Title evidence from screamm's Windows validation on this PR (comment of 13 October, 07:46Z; head
e6740bc6): traced onmainin ProsperoRadio (PPSA99001, bundled libcurl 8.18.0 and OpenSSL 3.5.2 over libkernel sockets),connect(12, 91.98.4.78:443)returns errno 35,pollthen reportsPOLLOUT, andgetsockopt(12, SOL_SOCKET, SO_ERROR)fails with errno 42, which curl'sverifyconnect()takes as the connect error (Could not connect to server, curl 7); ProsperoRadio is the title that was traced, PSXS5, SwanStation and ProsperoTV bundle the same libcurl. With this PR the same trace shows errno 36 andSO_ERROR0, and the TCP connection succeeds; the next failure there is OpenSSL's CA file path (a separate gap, issue #5001). The trace is screamm's, not run by me.More title evidence, from p3n1cillin's comment on this PR (13 October, 14:48Z): PS5MC (PPSA99420, Kodi 22) on
main3faa9cb40merged with other open PRs it needs to start. Without this PR Kodi's connectivity check fails about 10 ms after eachconnect(sceNetResolverStartNtoaforwww.msftconnecttest.comandwww.w3.org, then libkernelconnectto port 80; Kodi logsCCurlFile::Exists ... Failed: Could not connect to server(7)); with this PR merged too, noCCurlFileerrors appear in the same 60 s run. This is their measurement, not mine.Tested
Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, built and run on
mainc2565f014after #4391 (the branch is one commit on it); the branch has since been moved to a newermain(git merge-treeof the head79e162110againstmainbf8dc610eis clean; not rebuilt there) with its test registration and debt entry at new places and merges with the other branches of this series without conflicts:guest_socket_options(new) passes: types,SO_ACCEPTCONNbefore and afterlisten,SO_ERRORafter a successful and a refused non-blocking connect (the second read is 0), the boolean bits,SO_LINGERvalues and errors, the length rules, unknown options and a bad descriptor.It fails without the change to
Udp.cpp(getsockopt of an integer option failed (errno 42)).guest_udp,guest_tcp,guest_sce_net,guest_poll,guest_dupand the other socket tests: pass.guest_socket_optionstakes about 2 seconds on Windows (4 runs, 2.07 to 2.16 s; most of it is the refused loopback connect), the other new test about 0.2 s; its wait for the connect is at most 6 s, well below the 30 s limit.python tools/check_conventions.py --base upstream/mainpasses.Measured on a combined build of the twelve open branches of this series (this PR and the others) merged onto
main0f2683cb7:guest_socket_optionstakes 2.58 s (ctest, serial, Windows). The fullguest_*/ libc / libkernel group passes (391 of 391, 0 failed; the build also contains the other branches of this series).Not tested: Linux (the code compiles the Winsock and POSIX forms from one source, only the Windows one was built), a console, a title run with this change.
On Windows
SO_ERRORis emulated for the connect error only: the library reports it once and clears it on the nextconnect; a later asynchronous error of the same socket without a newconnectis not modelled. A nulloptvalwith a length returnsEINVAL(FreeBSD:EFAULT).Checklist
Merges onto
mainbf8dc610ewithout a conflict (git merge-tree, not rebuilt); no other open PR implements the same functions (overlap with #4903 described above)One topic per PR; follow-ups go in a new PR
No comments in code except technical debt
Unimplemented paths throw (
NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt (docs/dev/debt/libkernel.md)No notes, investigation
.mdfiles or images added to the repositoryNew third-party code is a submodule built from source (none added)
Generic behaviour, not specific to one title
Depends on: none
Unblocks: PPSA99288 Nuvio Max'd, sign-in fails without it (confirmed on Linux by coltken95 in the comments; no Game bring-up discussion exists); also PPSA99420 (PS5MC, p3n1cillin's trace) and PPSA99001 ProsperoRadio with its group (screamm's trace), see above
AI-assisted: yes
AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T00:15:44Z.
Tested on Linux (CachyOS, RTX 2070, NVIDIA 615.71.09) with Nuvio Max'd (PPSA99288):
mainate6ecece94with this PR and #3644 merged on top.Without this PR, every HTTPS request fails: curl's
getsockopt(SOL_SOCKET, SO_ERROR)after a nonblockingconnectgetsENOPROTOOPT, so the sign-in screen shows "Failed to connect to api.nuvio.tv port 443 after 45 ms".straceshows the hostconnectreturningEINPROGRESSand no hostgetsockoptfollowing it. With this PR, the connection completes and the sign-in screen receives its link code from api.nuvio.tv.guest_socket_optionspasses.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T02:37:13Z.
Thanks for testing this, that is a useful confirmation.
One question, only if it is easy for you: could you share which
setsockoptcalls the Nuvio run makes on the host (for examplestrace -f -e trace=setsockoptduring sign-in, levels and option names only)? curl normally setsTCP_NODELAYand the TCP keep-alive options and ignores a failure; a follow-up PR for theIPPROTO_TCPlevel (not part of this one) only makes sense if a title actually asks for them.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T02:45:25Z.
SO_DEBUG,SO_USELOOPBACK,SO_REUSEPORT,SO_TIMESTAMPandSO_NOSIGPIPEare accepted and only kept by the library (SocketOptions.cpp:66-77). The description says no title sets them, and a title that setsSO_REUSEPORTorSO_TIMESTAMPwould get success without the behaviour. Please leave those five out (ENOPROTOOPT, as on main) until a title needs one.The
SO_ERRORandEINPROGRESSpart, with The Mound and PPSA99288, is fine as it is.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T03:02:43Z.
Updated as requested:
SO_DEBUG,SO_USELOOPBACK,SO_REUSEPORT,SO_TIMESTAMPandSO_NOSIGPIPEare left out again (ENOPROTOOPT, as onmain), the test checks that, and the stored-only state is gone. The branch is one commit onmainc13dc7e6b;guest_socket_options(still fails without theUdp.cppchange) and the other socket tests pass on Windows (22 of 22).AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-13T07:46:47Z.
Windows validation with title evidence (Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Release,
BUILD_TESTING=ON; heade6740bc6onmainc2565f01, with #4525 applied as well because curl pollsPOLLOUT|POLLPRI): the 17 socket/poll/net tests including the newguest_socket_optionspass 3/3; the non-GPU suite passes apart from the GPU-onlyagc_*targets I did not build; conventions clean.This PR is what makes HTTPS work from inside the guest. Traced on
mainin ProsperoRadio (PPSA99001, bundled libcurl 8.18.0 + OpenSSL 3.5.2 over libkernel sockets):connect(12, 91.98.4.78:443) = -1 errno 35,pollthen reportsPOLLOUT, andgetsockopt(12, SOL_SOCKET, SO_ERROR) = -1 errno 42(ENOPROTOOPT), which curl'sverifyconnect()takes as the connect error, henceFailed to connect to all.api.radio-browser.info port 443 after 51 ms: Could not connect to server(curl 7) in every title of this group (PSXS5, SwanStation, ProsperoTV, ProsperoRadio). With this PR:connect = -1 errno 36,getsockopt(SO_ERROR) = 0 value 0, the TCP connection succeeds, and the next failure is OpenSSL's CA path/<sandbox word>/common/cert/CA_LIST.cer(curl 77, a separate gap I'm filing). With a PEM bundle placed at that path for the test, ProsperoRadio downloads its catalog (11838693 bytes in 845 ms,accepted=9556, six pages) and SwanStation (PPSA98510) goes fromgamedb.yaml -> curl 7, http 0togamedb: index written. Smaller mismatches curl tolerates, for later:fcntl(F_SETFD)on a socket returnsEINVAL, andsetsockoptTCP_NODELAY,SO_NOSIGPIPEand option 0x1200 returnENOPROTOOPT.Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-13T14:48:34Z.
Title evidence for this PR: PS5MC (PPSA99420, Kodi 22, catalog release) on Windows 11, MinGW GCC 15.2.0, Release, on
main3faa9cb40merged with the open PRs it needs to start (#4379, #4374, #4383, #5183, #5184, #5185, #5186).connect: gdb showssceNetResolverStartNtoaresolvingwww.msftconnecttest.comandwww.w3.org(2.21.64.155 and 104.18.23.19), then libkernelconnectto port 80, and Kodi logsCCurlFile::Exists - <http://www.w3.org/> Failed: Could not connect to server(7)(the same formsftconnecttest.com). That is curl reading the non-blocking connect's result throughgetsockopt(SO_ERROR).CCurlFileerrors in the same 60 s run.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T15:50:13Z.
Still needed on main
842766d39: without this PR Nuvio Max'd (PPSA99288) shows "Failed to connect to v3-cinemeta.strem.io port 443" (tested on main0f2683cb7, CachyOS, RTX 2070). With d748c659e (this PR cherry-picked onto842766d39) the addons and all 8 home catalogs load. The cherry-pick applies cleanly.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T21:18:23Z.
Thank you for the validations and title traces, @screamm, @p3n1cillin and @coltken95. They are quoted in the description (ProsperoRadio and its group, PS5MC, Nuvio Max'd).
On the mismatches mentioned in the comments:
fcntl(F_SETFD)on a socket is #5020.TCP_NODELAY,SO_NOSIGPIPEand option 0x1200 are not part of this PR; the maintainer's comment above asks to leave options out until a title needs them, and screamm's ProsperoRadio trace is the evidence for those three, so they would be a separate change if wanted.@coltken95, my earlier question about which
setsockoptcalls the Nuvio run makes still stands; screamm's list is from ProsperoRadio, not from Nuvio. It is not needed for this PR.AI-assisted (Claude Code).