fix(libkernel): accept MSG_NOSIGNAL in send and sendto #1279

Merged
TheAggie merged 2 commits from upstream-pr/1279 into main 2026-10-08 10:58:28 +00:00
TheAggie commented 2026-10-07 21:42:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-07T21:42:05Z.


What

send, sendto and sendmsg (which forwards to sendto) failed every call with a nonzero flags with EOPNOTSUPP. FreeBSD code commonly passes MSG_NOSIGNAL (0x20000) to avoid SIGPIPE on a closed connection, so such callers could not send at all.

  • MSG_NOSIGNAL is accepted. Windows sockets never raise SIGPIPE, so nothing is passed there; on Linux it maps to the native MSG_NOSIGNAL.
  • Any other flag still fails with EOPNOTSUPP, as before.
  • guest_tcp: send with MSG_OOB (0x1) still fails with EOPNOTSUPP; send with MSG_NOSIGNAL succeeds and the data arrives. guest_udp: sendto with MSG_NOSIGNAL succeeds. Both tests fail without the change.

Tested

Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti.

  • guest_tcp, guest_udp, guest_sce_net, guest_addresses pass; all 403 registered tests pass on current main with this, poll and #1265 applied (run from the generated CTestTestfile.cmake commands, as antivirus blocks ctest.exe here).
  • DOOM homebrew PPSA99666 v1.1.1 (lowbit/ps5-doom, GPL-2.0) sends its upload server replies with MSG_NOSIGNAL. Without this, every connection was closed without an answer (curl: empty reply). With it, plus poll and the same change as #1088, the server answered GET / (HTTP 200) and received a 28.8 MB WAD through PUT /upload/...; the saved file matches the source's SHA-256.

Not tested on Linux.

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
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4778834926 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1279). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-07T21:42:05Z. --- ### What `send`, `sendto` and `sendmsg` (which forwards to `sendto`) failed every call with a nonzero `flags` with `EOPNOTSUPP`. FreeBSD code commonly passes `MSG_NOSIGNAL` (0x20000) to avoid `SIGPIPE` on a closed connection, so such callers could not send at all. - `MSG_NOSIGNAL` is accepted. Windows sockets never raise `SIGPIPE`, so nothing is passed there; on Linux it maps to the native `MSG_NOSIGNAL`. - Any other flag still fails with `EOPNOTSUPP`, as before. - `guest_tcp`: `send` with `MSG_OOB` (0x1) still fails with `EOPNOTSUPP`; `send` with `MSG_NOSIGNAL` succeeds and the data arrives. `guest_udp`: `sendto` with `MSG_NOSIGNAL` succeeds. Both tests fail without the change. ### Tested Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti. - `guest_tcp`, `guest_udp`, `guest_sce_net`, `guest_addresses` pass; all 403 registered tests pass on current `main` with this, `poll` and #1265 applied (run from the generated `CTestTestfile.cmake` commands, as antivirus blocks `ctest.exe` here). - DOOM homebrew PPSA99666 v1.1.1 ([lowbit/ps5-doom](https://github.com/lowbit/ps5-doom), GPL-2.0) sends its upload server replies with `MSG_NOSIGNAL`. Without this, every connection was closed without an answer (`curl`: empty reply). With it, plus `poll` and the same change as #1088, the server answered `GET /` (HTTP 200) and received a 28.8 MB WAD through `PUT /upload/...`; the saved file matches the source's SHA-256. Not tested on Linux. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
hikazey commented 2026-10-08 07:28:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hikazey on 2026-10-08T07:28:18Z.


Linux run, since the description says it wasn't tested there (Ubuntu 24.04, GCC 14.2, this commit applied to current main 6b573862, which it applies to cleanly).

The PR's own tests: guest_tcp and guest_udp pass with the change and fail with Udp.cpp from main.

The Linux-specific part is what MSG_NOSIGNAL is for: sending on a connection the peer has closed. Nothing in the tree ignores SIGPIPE, so on Linux the native flag is what keeps the process alive. I added that case to guest_tcp: close accepted, then send from client with 0x20000 until it fails. That turned up one gap. The Linux branch of NativeError has no EPIPE case, so the failure is reported as 5 (EIO) instead of FreeBSD's EPIPE (32), which is what callers that pass MSG_NOSIGNAL usually check for.

--- a/core/libs/prx/libkernel/Socket/src/Udp.cpp
+++ b/core/libs/prx/libkernel/Socket/src/Udp.cpp
@@ int NativeError() {
         case EINVAL: return 22;
+        case EPIPE: return 32;
         default: return 5;
--- a/core/libs/tests/GuestTcp.cpp
+++ b/core/libs/tests/GuestTcp.cpp
@@
     Require(close_nid_postfix(accepted) == 0);
+#ifndef _WIN32
+    std::int64_t sent = 0;
+    for (int i = 0; i < 100 && sent >= 0; ++i) sent = send_nid_postfix(client, request, sizeof(request), 0x20000);
+    Require(sent == -1 && *__error_nid_postfix() == 32);
+#endif
     Require(close_nid_postfix(client) == 0);
build guest_tcp with the case above
this PR aborted (errno 5, not 32)
this PR + EPIPE mapping passed
this PR + EPIPE mapping, NativeSendFlags returning 0 on Linux killed by SIGPIPE

The last row shows the MSG_NOSIGNAL mapping is needed on Linux. With the mapping, the 8 socket-related tests (-R 'tcp|udp|net|socket|address|poll|epoll') pass. I ran the case without the #ifndef. I guarded it because Winsock reports a reset or aborted connection there, not EPIPE; I haven't checked which one on Windows.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6054908206 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1279#issuecomment-6054908206). Originally posted by [hikazey](https://github.com/hikazey) on 2026-10-08T07:28:18Z. --- Linux run, since the description says it wasn't tested there (Ubuntu 24.04, GCC 14.2, this commit applied to current `main` 6b573862, which it applies to cleanly). The PR's own tests: `guest_tcp` and `guest_udp` pass with the change and fail with `Udp.cpp` from `main`. The Linux-specific part is what `MSG_NOSIGNAL` is for: sending on a connection the peer has closed. Nothing in the tree ignores `SIGPIPE`, so on Linux the native flag is what keeps the process alive. I added that case to `guest_tcp`: close `accepted`, then send from `client` with `0x20000` until it fails. That turned up one gap. The Linux branch of `NativeError` has no `EPIPE` case, so the failure is reported as 5 (`EIO`) instead of FreeBSD's `EPIPE` (32), which is what callers that pass `MSG_NOSIGNAL` usually check for. ```diff --- a/core/libs/prx/libkernel/Socket/src/Udp.cpp +++ b/core/libs/prx/libkernel/Socket/src/Udp.cpp @@ int NativeError() { case EINVAL: return 22; + case EPIPE: return 32; default: return 5; --- a/core/libs/tests/GuestTcp.cpp +++ b/core/libs/tests/GuestTcp.cpp @@ Require(close_nid_postfix(accepted) == 0); +#ifndef _WIN32 + std::int64_t sent = 0; + for (int i = 0; i < 100 && sent >= 0; ++i) sent = send_nid_postfix(client, request, sizeof(request), 0x20000); + Require(sent == -1 && *__error_nid_postfix() == 32); +#endif Require(close_nid_postfix(client) == 0); ``` | build | `guest_tcp` with the case above | | --- | --- | | this PR | aborted (errno 5, not 32) | | this PR + `EPIPE` mapping | passed | | this PR + `EPIPE` mapping, `NativeSendFlags` returning 0 on Linux | killed by `SIGPIPE` | The last row shows the `MSG_NOSIGNAL` mapping is needed on Linux. With the mapping, the 8 socket-related tests (`-R 'tcp|udp|net|socket|address|poll|epoll'`) pass. I ran the case without the `#ifndef`. I guarded it because Winsock reports a reset or aborted connection there, not `EPIPE`; I haven't checked which one on Windows. AI-assisted: yes (Claude Code).
adriadam10 commented 2026-10-08 10:48:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T10:48:21Z.


Checked: build + full ctest (439/439) on current main, guest_tcp/guest_udp fail with the Udp.cpp change reverted, Linux and Windows CI green. MSG_NOSIGNAL = 0x20000 matches FreeBSD; mapping to the native flag on Linux is needed (without it the process dies with SIGPIPE, as hikazey showed).

Added as our own commit, taken from hikazey's comment (Co-authored-by):

  • NativeError (Linux): EPIPE → 32. Sending to a closed peer returned 5 (EIO) instead of EPIPE.
  • guest_tcp: send with MSG_NOSIGNAL after the peer closed must fail with 32 (#ifndef _WIN32; not checked what Winsock reports there).

Merging once CI is green on the new head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6058197196 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1279#issuecomment-6058197196). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T10:48:21Z. --- Checked: build + full ctest (439/439) on current main, `guest_tcp`/`guest_udp` fail with the `Udp.cpp` change reverted, Linux and Windows CI green. `MSG_NOSIGNAL` = 0x20000 matches FreeBSD; mapping to the native flag on Linux is needed (without it the process dies with SIGPIPE, as hikazey showed). Added as our own commit, taken from hikazey's comment (Co-authored-by): - `NativeError` (Linux): `EPIPE` → 32. Sending to a closed peer returned 5 (EIO) instead of EPIPE. - `guest_tcp`: send with `MSG_NOSIGNAL` after the peer closed must fail with 32 (`#ifndef _WIN32`; not checked what Winsock reports there). Merging once CI is green on the new head.
hikazey commented 2026-10-09 17:00:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hikazey on 2026-10-09T17:00:28Z.


.hikaze for dev role in Discord

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6085475239 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1279#issuecomment-6085475239). Originally posted by [hikazey](https://github.com/hikazey) on 2026-10-09T17:00:28Z. --- .hikaze for dev role in Discord
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!1279
No description provided.