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

Closed
xXPBSXx wants to merge 1 commit from upstream-pr/4993 into main
xXPBSXx commented 2026-10-13 07:30:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T07:30:31Z.


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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4839899575 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4993). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T07:30:31Z. --- ### What libkernel `socket` answered `EPROTONOSUPPORT` (43) for every socket type it does not provide. FreeBSD 11.4's [`socreate`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_socket.c) 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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt (`docs/dev/debt/libkernel.md`) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-13 13:13:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T13:13:15Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6146359928 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4993#issuecomment-6146359928). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T13:13:15Z. --- <!-- pr-overlap --> 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](https://github.com/boykopovar/AnyPS5/blob/0df6e295c52e7cd6afa394ed35513bd252045c74/docs/dev/debt/libkernel.md#L153) | | |
oneandonlydean commented 2026-10-14 02:34:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:34:45Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159608874 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4993#issuecomment-6159608874). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:34:45Z. --- 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.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4993
No description provided.