Skip to content

fix(libkernel): fail socket() with EPROTOTYPE for an unknown type like FreeBSD - #4993

Closed
xXPBSXx wants to merge 1 commit into
boykopovar:mainfrom
xXPBSXx:fix/socket-create-errors-v2
Closed

xXPBSXx wants to merge 1 commit into
boykopovar:mainfrom
xXPBSXx:fix/socket-create-errors-v2

Conversation

@xXPBSXx

@xXPBSXx xXPBSXx commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What

libkernel socket answered EPROTONOSUPPORT (43) for every socket type it does not provide. FreeBSD 11.4's socreate tells the cases apart when no protocol matches:

  • a nonzero type with protocol 0 (the type is unknown): EPROTOTYPE (41);
  • a protocol was given, or the type is 0: EPROTONOSUPPORT (43);
  • an unknown family is EAFNOSUPPORT (47), unchanged.

socket(AF_INET, 99, 0) and socket(AF_INET6, 99, 0) now fail with 41, socket(AF_INET, 99, 6) and socket(AF_INET, 0, 0) stay 43. Every other type that is not 1, 2 or 3 with protocol 0 (4 and 5 as well) now answers 41; the test covers 99 only, and which of these types the console provides is not known. SOCK_RAW stays 43 because libkernel does not provide raw sockets (FreeBSD would create one or answer EPERM; listed as a new entry in the TechnicalDebt file for libkernel); a stream socket with the UDP protocol and a datagram socket with the TCP protocol stay 43, as pffindproto finds no match and a protocol was given.

No title evidence: found by writing failure-path tests for socket from the FreeBSD source; no title I ran passes an unknown type. This is FreeBSD conformance. The same change for the sceNetSocket of libSceNet is part of #4989.

Overlap (checked with git merge-tree against the heads of #4796, #4920, #4922, #4929, #4968 and #4989): no conflict. The new test is registered next to guest_poll so it does not collide with the other test registrations in that file. #4933 (poll libSceNet sockets with the host wait) conflicts with this PR in docs/dev/debt/libkernel.md (git merge-tree of the two heads, re-checked); whichever lands second rebases the debt entry. #5510 (simonbronk, EPIPE for a stream send after the peer closed) conflicts with this PR in docs/dev/debt/libkernel.md (git merge-tree of the two heads, re-checked against main ce5c83953; both heads are clean against main); whichever lands second rebases the debt entry.

Tested

Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, on main c2565f014; the code is unchanged since, the branch is one commit on main 0f2683cb7 and adds a TechnicalDebt entry for SOCK_RAW; git merge-tree of the head f53fea6ef against main bf8dc610e is clean (checked, not rebuilt):

  • guest_socket_create_errors (new) passes: unknown type with protocol 0 (41, on AF_INET and AF_INET6), unknown type with a protocol (43), type 0 (43), stream with the UDP protocol (43), datagram with the TCP protocol (43), unknown family (47), and valid sockets still created.
  • It fails without the change to Udp.cpp (an unknown type with protocol 0 must fail with EPROTOTYPE (41) (errno 43)).
  • The socket tests (guest_socket*, guest_udp, guest_tcp, guest_sce_net, guest_poll, guest_dup, guest_select) pass. python tools/check_conventions.py --base upstream/main passes.
  • Measured on a combined build of the twelve open branches of this series (this PR and the others) merged onto main 0f2683cb7: guest_socket_create_errors takes 0.26 s (ctest, serial, Windows). The full guest_* / libc / libkernel group passes (391 of 391, 0 failed; the build also contains the other branches of this series).
  • Not tested: Linux (one source for both hosts, only Windows was built), a console, a title run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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 .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
#4933 docs/dev/debt/libkernel.md L153

…rotocol 0

socket reported EPROTONOSUPPORT for every unknown type. FreeBSD 11.4's socreate returns EPROTOTYPE when no protocol matches a nonzero type and the protocol is 0, and EPROTONOSUPPORT when a protocol was given or the type is 0. SOCK_RAW stays EPROTONOSUPPORT, as raw sockets are not provided.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants