fix(libSceNet): report the FreeBSD errno of every host socket error #4989

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

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


What

native_error() in libSceNet translated 21 host socket errors to FreeBSD error numbers and returned EIO (5) for every other one. A title that calls a sceNet socket function sees the translated number in sceNetErrnoLoc() and in the 0x80410000 | errno result, so the missing ones came out as a generic I/O error: for example WSAEPROTONOSUPPORT / WSAEPROTOTYPE (sceNetSocket(…, SOCK_STREAM, IPPROTO_UDP) returned EIO), WSAEDESTADDRREQ, WSAENOPROTOOPT, WSAEFAULT, WSAENETDOWN, WSAEHOSTDOWN and WSAEMFILE.

libkernel already keeps the complete table for these errors in GuestSockets::GuestErrorFromHost (SocketError.hpp, the FreeBSD 11 errno.h numbers). native_error() now uses it on Windows and Linux; every error it translated before keeps its number (compared entry by entry: all 21 Windows and all 21 Linux entries of the old native_error() give the same number in GuestErrorFromHost), the others get their FreeBSD number instead of EIO.

Two more differences from FreeBSD, in the same area:

  • sceNetSend and sceNetSendto without an address on an unconnected datagram socket failed with ENOTCONN (57) on Windows (sceNetSendmsg ends in a call to sceNetSendto, so it gets the same answer; not tested). FreeBSD's sosend_dgram answers EDESTADDRREQ (39) for a socket that does not require a connection, and libkernel's send / sendto already map this case. Linux reports EDESTADDRREQ itself.
  • sceNetSocket with an unknown socket type and protocol 0 failed with EPROTONOSUPPORT (43). FreeBSD's socreate returns EPROTOTYPE (41) when no protocol matches a type and the protocol is 0, and EPROTONOSUPPORT when a protocol was given.

No title evidence: found by calling the sceNet socket functions with invalid arguments on loopback (25 cases) and comparing the errno with the FreeBSD source. The cases that already matched are not touched. sceNetGetsockopt / sceNetSetsockopt answer EOPNOTSUPP for an option they do not implement (FreeBSD: ENOPROTOOPT) and are left as they are (a deliberate subset, not a mapping problem); this is a new entry in docs/dev/debt/libSceNet.md.

Overlap (checked with git merge-tree against the open sceNet PRs): #4988 (SO_ERROR for sceNetGetsockopt) changes neighbouring lines in the libSceNet Export.cpp; textual conflicts also with #4673 (MSG_DONTWAIT: it changes the flags on the line of sceNetSend where this PR changes the error function), which resolves by keeping both changes. #4988 conflicts with this PR in docs/dev/debt/libSceNet.md as well as in Export.cpp. #5349 (auto-bind an unbound stream socket in sceNetListen) also conflicts with this PR in the libSceNet Export.cpp; whichever lands second rebases that hunk. (git merge-tree of the heads of this PR and #4988, #4673 and #5349, re-checked; each conflicts only in the files named; #4610 is merged and no longer in the list.)

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:

  • guest_sce_net_errors (new; the other host errors listed above are covered by the table change, not by a case each): sceNetSocket with an unknown type (protocol 0: 41, protocol 6: 43), a stream socket with the UDP protocol (43), sceNetSend and sceNetSendto without an address on an unconnected datagram socket (39), and bind of a non-local address (49, already correct before) through sceNetErrnoLoc.
  • It fails without the change to Export.cpp (a socket of an unknown type and protocol 0 must fail with EPROTOTYPE (41) (errno 43); the first failing case, the later ones were checked by hand).
  • guest_sce_net passes. 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_sce_net_errors takes 0.19 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 (the table is the same one libkernel uses there), a console, a title run.

Checklist

  • Based on current main; no other open PR implements the same functions (overlaps 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/libSceNet.md, new entry for the EOPNOTSUPP answer of sceNetGetsockopt / sceNetSetsockopt)
  • 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:4839834070 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4989). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T07:23:59Z. --- ### What `native_error()` in libSceNet translated 21 host socket errors to FreeBSD error numbers and returned `EIO` (5) for every other one. A title that calls a sceNet socket function sees the translated number in `sceNetErrnoLoc()` and in the `0x80410000 | errno` result, so the missing ones came out as a generic I/O error: for example `WSAEPROTONOSUPPORT` / `WSAEPROTOTYPE` (`sceNetSocket(…, SOCK_STREAM, IPPROTO_UDP)` returned `EIO`), `WSAEDESTADDRREQ`, `WSAENOPROTOOPT`, `WSAEFAULT`, `WSAENETDOWN`, `WSAEHOSTDOWN` and `WSAEMFILE`. libkernel already keeps the complete table for these errors in `GuestSockets::GuestErrorFromHost` (`SocketError.hpp`, the FreeBSD 11 `errno.h` numbers). `native_error()` now uses it on Windows and Linux; every error it translated before keeps its number (compared entry by entry: all 21 Windows and all 21 Linux entries of the old `native_error()` give the same number in `GuestErrorFromHost`), the others get their FreeBSD number instead of `EIO`. Two more differences from FreeBSD, in the same area: - `sceNetSend` and `sceNetSendto` without an address on an unconnected datagram socket failed with `ENOTCONN` (57) on Windows (`sceNetSendmsg` ends in a call to `sceNetSendto`, so it gets the same answer; not tested). FreeBSD's `sosend_dgram` answers `EDESTADDRREQ` (39) for a socket that does not require a connection, and libkernel's `send` / `sendto` already map this case. Linux reports `EDESTADDRREQ` itself. - `sceNetSocket` with an unknown socket type and protocol 0 failed with `EPROTONOSUPPORT` (43). FreeBSD's [`socreate`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_socket.c) returns `EPROTOTYPE` (41) when no protocol matches a type and the protocol is 0, and `EPROTONOSUPPORT` when a protocol was given. No title evidence: found by calling the sceNet socket functions with invalid arguments on loopback (25 cases) and comparing the errno with the FreeBSD source. The cases that already matched are not touched. `sceNetGetsockopt` / `sceNetSetsockopt` answer `EOPNOTSUPP` for an option they do not implement (FreeBSD: `ENOPROTOOPT`) and are left as they are (a deliberate subset, not a mapping problem); this is a new entry in `docs/dev/debt/libSceNet.md`. Overlap (checked with `git merge-tree` against the open sceNet PRs): #4988 (`SO_ERROR` for `sceNetGetsockopt`) changes neighbouring lines in the libSceNet `Export.cpp`; textual conflicts also with #4673 (`MSG_DONTWAIT`: it changes the flags on the line of `sceNetSend` where this PR changes the error function), which resolves by keeping both changes. #4988 conflicts with this PR in `docs/dev/debt/libSceNet.md` as well as in `Export.cpp`. #5349 (auto-bind an unbound stream socket in `sceNetListen`) also conflicts with this PR in the libSceNet `Export.cpp`; whichever lands second rebases that hunk. (`git merge-tree` of the heads of this PR and #4988, #4673 and #5349, re-checked; each conflicts only in the files named; #4610 is merged and no longer in the list.) ### 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: - `guest_sce_net_errors` (new; the other host errors listed above are covered by the table change, not by a case each): `sceNetSocket` with an unknown type (protocol 0: 41, protocol 6: 43), a stream socket with the UDP protocol (43), `sceNetSend` and `sceNetSendto` without an address on an unconnected datagram socket (39), and `bind` of a non-local address (49, already correct before) through `sceNetErrnoLoc`. - It fails without the change to `Export.cpp` (`a socket of an unknown type and protocol 0 must fail with EPROTOTYPE (41) (errno 43)`; the first failing case, the later ones were checked by hand). - `guest_sce_net` passes. `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_sce_net_errors` takes 0.19 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 (the table is the same one libkernel uses there), a console, a title run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (overlaps described above) - [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/libSceNet.md`, new entry for the `EOPNOTSUPP` answer of `sceNetGetsockopt` / `sceNetSetsockopt`) - [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 07:31:21 +00:00 (Migrated from github.com)

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


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
#4673 core/libs/prx/libSceNet/Export.cpp L840-841
#4758 docs/dev/debt/libSceNet.md L11
#4988 core/libs/prx/libSceNet/Export.cpp L110-135, L143-171
docs/dev/debt/libSceNet.md L11
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140608884 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4989#issuecomment-6140608884). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T07:31:21Z. --- <!-- 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 | |---|---|---|---| | #4673 | `core/libs/prx/libSceNet/Export.cpp` [L840-841](https://github.com/boykopovar/AnyPS5/blob/0df6e295c52e7cd6afa394ed35513bd252045c74/core/libs/prx/libSceNet/Export.cpp#L840-L841) | | | | #4758 | `docs/dev/debt/libSceNet.md` [L11](https://github.com/boykopovar/AnyPS5/blob/0df6e295c52e7cd6afa394ed35513bd252045c74/docs/dev/debt/libSceNet.md#L11) | | | | #4988 | `core/libs/prx/libSceNet/Export.cpp` [L110-135](https://github.com/boykopovar/AnyPS5/blob/0df6e295c52e7cd6afa394ed35513bd252045c74/core/libs/prx/libSceNet/Export.cpp#L110-L135), [L143-171](https://github.com/boykopovar/AnyPS5/blob/0df6e295c52e7cd6afa394ed35513bd252045c74/core/libs/prx/libSceNet/Export.cpp#L143-L171)<br>`docs/dev/debt/libSceNet.md` [L11](https://github.com/boykopovar/AnyPS5/blob/0df6e295c52e7cd6afa394ed35513bd252045c74/docs/dev/debt/libSceNet.md#L11) | | |
oneandonlydean commented 2026-10-14 02:34:51 +00:00 (Migrated from github.com)

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


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:6159610084 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4989#issuecomment-6159610084). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:34:51Z. --- 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!4989
No description provided.