libkernel: host socket errors outside a 17-entry table all become EIO (WSAEALREADY, WSAENOPROTOOPT, WSAEBADF, WSAEMFILE and more); fix branch ready #3573

Closed
opened 2026-10-11 13:35:14 +00:00 by husseinkad · 2 comments
husseinkad commented 2026-10-11 13:35:14 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-11T13:35:14Z.


NativeError() in Socket/src/Udp.cpp maps only 17 host socket errors to FreeBSD numbers and returns EIO (5) for the rest, so a guest that tests errno gets the wrong value for many real failures.

Examples on Windows (before -> FreeBSD 11 number): WSAEALREADY 5 -> 37, WSAENOPROTOOPT 5 -> 42, WSAEBADF 5 -> 9, WSAEFAULT 5 -> 14, WSAEMFILE 5 -> 24, WSAEINPROGRESS 5 -> 36, WSAENOTSOCK 5 -> 38, WSAEDESTADDRREQ 5 -> 39, WSAEOPNOTSUPP 5 -> 45, WSAEAFNOSUPPORT 5 -> 47, WSAENETDOWN 5 -> 50. Linux has the same gaps (EPERM, ENOMEM, ENFILE, EPROTO, ESHUTDOWN, EALREADY, EINPROGRESS and others all become EIO).

Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/kernel-socket-errno-table

  • New GuestSockets::GuestErrorFromHost in Socket/include/SocketError.hpp: a by-name table of 70 host errors to the FreeBSD 11.4 errno.h numbers; a host error with no FreeBSD socket counterpart stays EIO. WSAESHUTDOWN stays EPIPE, as before.
  • Udp.cpp uses it; PairError() goes away because its one special case (WSAEMFILE) is now in the table.
  • tests/GuestSocketError.cpp checks every entry by name; deleting or renumbering any single case fails it (70 of 70 mutants caught on Windows).

Checked against: FreeBSD 11.4 sys/sys/errno.h, the MinGW winsock2.h/winerror.h names, and Linux 6.6 errno-base.h/errno.h. Old vs new on 13,001 Windows values and 4,201 Linux values: 18 (Windows) and 23 (Linux) inputs change, all EIO becoming the correct number, nothing else moves. 95 loopback scenarios through the guest exports on old and new builds differ in two lines only (below). guest_(socket|udp|tcp|poll|dup) pass; check_conventions.py and pr_overlap.py are clean.

Behaviour changes worth knowing:

  • A repeated nonblocking connect to a refused port now reports EALREADY where it used to report EIO. FreeBSD reports ECONNREFUSED; Windows never surfaces the refusal here (SO_ERROR is unsupported). A guest looping on EALREADY keeps looping. Recorded in TechnicalDebt.
  • setsockopt(SOL_SOCKET, SO_BROADCAST) on a TCP socket goes from EIO to ENOPROTOOPT (FreeBSD succeeds).

Not fixed here: #3113 stays half open. On Windows send/write on an unconnected UDP socket still returns ENOTCONN because Winsock reports WSAENOTCONN, so the new WSAEDESTADDRREQ entry is never reached. A receive after shutdown(SHUT_RD) returns EPIPE on Windows where FreeBSD returns 0. libSceNet/Export.cpp has its own native_error() table that this does not touch. The numbers are not checked on a console.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5801547123 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3573). Originally posted by [husseinkad](https://github.com/husseinkad) on 2026-10-11T13:35:14Z. --- `NativeError()` in `Socket/src/Udp.cpp` maps only 17 host socket errors to FreeBSD numbers and returns `EIO` (5) for the rest, so a guest that tests `errno` gets the wrong value for many real failures. Examples on Windows (before -> FreeBSD 11 number): `WSAEALREADY` 5 -> 37, `WSAENOPROTOOPT` 5 -> 42, `WSAEBADF` 5 -> 9, `WSAEFAULT` 5 -> 14, `WSAEMFILE` 5 -> 24, `WSAEINPROGRESS` 5 -> 36, `WSAENOTSOCK` 5 -> 38, `WSAEDESTADDRREQ` 5 -> 39, `WSAEOPNOTSUPP` 5 -> 45, `WSAEAFNOSUPPORT` 5 -> 47, `WSAENETDOWN` 5 -> 50. Linux has the same gaps (`EPERM`, `ENOMEM`, `ENFILE`, `EPROTO`, `ESHUTDOWN`, `EALREADY`, `EINPROGRESS` and others all become `EIO`). Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/kernel-socket-errno-table - New `GuestSockets::GuestErrorFromHost` in `Socket/include/SocketError.hpp`: a by-name table of 70 host errors to the FreeBSD 11.4 `errno.h` numbers; a host error with no FreeBSD socket counterpart stays `EIO`. `WSAESHUTDOWN` stays `EPIPE`, as before. - `Udp.cpp` uses it; `PairError()` goes away because its one special case (`WSAEMFILE`) is now in the table. - `tests/GuestSocketError.cpp` checks every entry by name; deleting or renumbering any single `case` fails it (70 of 70 mutants caught on Windows). Checked against: FreeBSD 11.4 `sys/sys/errno.h`, the MinGW `winsock2.h`/`winerror.h` names, and Linux 6.6 `errno-base.h`/`errno.h`. Old vs new on 13,001 Windows values and 4,201 Linux values: 18 (Windows) and 23 (Linux) inputs change, all `EIO` becoming the correct number, nothing else moves. 95 loopback scenarios through the guest exports on old and new builds differ in two lines only (below). `guest_(socket|udp|tcp|poll|dup)` pass; `check_conventions.py` and `pr_overlap.py` are clean. Behaviour changes worth knowing: - A repeated nonblocking `connect` to a refused port now reports `EALREADY` where it used to report `EIO`. FreeBSD reports `ECONNREFUSED`; Windows never surfaces the refusal here (`SO_ERROR` is unsupported). A guest looping on `EALREADY` keeps looping. Recorded in TechnicalDebt. - `setsockopt(SOL_SOCKET, SO_BROADCAST)` on a TCP socket goes from `EIO` to `ENOPROTOOPT` (FreeBSD succeeds). Not fixed here: #3113 stays half open. On Windows `send`/`write` on an unconnected UDP socket still returns `ENOTCONN` because Winsock reports `WSAENOTCONN`, so the new `WSAEDESTADDRREQ` entry is never reached. A receive after `shutdown(SHUT_RD)` returns `EPIPE` on Windows where FreeBSD returns 0. `libSceNet/Export.cpp` has its own `native_error()` table that this does not touch. The numbers are not checked on a console. AI-assisted: yes
MarcZX10 commented 2026-10-11 13:55:40 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T13:55:40Z.


I carried Hussein Kadhim's two commits into PR #3592, preserving the original commit authorship. The PR adds the host-to-FreeBSD socket errno mapping and its cross-platform table test. The Linux libkernel build and eight focused socket CTests pass locally; hosted checks are now running. The documented host-versus-console differences remain recorded in TechnicalDebt.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109764132 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3573#issuecomment-6109764132). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T13:55:40Z. --- I carried Hussein Kadhim's two commits into [PR #3592](https://github.com/boykopovar/AnyPS5/pull/3592), preserving the original commit authorship. The PR adds the host-to-FreeBSD socket errno mapping and its cross-platform table test. The Linux `libkernel` build and eight focused socket CTests pass locally; hosted checks are now running. The documented host-versus-console differences remain recorded in TechnicalDebt.
husseinkad commented 2026-10-11 18:39:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-11T18:39:19Z.


Thank you @MarcZX100 for carrying this into #3592 with the authorship kept. Nothing to add to the caveats already listed in the issue.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6112356175 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3573#issuecomment-6112356175). Originally posted by [husseinkad](https://github.com/husseinkad) on 2026-10-11T18:39:19Z. --- Thank you @MarcZX100 for carrying this into #3592 with the authorship kept. Nothing to add to the caveats already listed in the issue. AI-assisted: yes
Sign in to join this conversation.
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#3573
No description provided.