From a2f9a50985b5a58a4a15a497a5078f8c6565631d Mon Sep 17 00:00:00 2001 From: Scott Schuster Date: Wed, 7 Oct 2026 15:28:54 -0500 Subject: [PATCH 1/2] fix(libkernel): accept MSG_NOSIGNAL in send and sendto send, sendto and sendmsg rejected every flag with EOPNOTSUPP, so callers that pass FreeBSD's MSG_NOSIGNAL (0x20000) could not send at all. Accept it: Windows sockets never raise SIGPIPE, and on Linux it maps to the native MSG_NOSIGNAL. Other flags still fail with EOPNOTSUPP. DOOM (PPSA99666) sends its upload server replies with MSG_NOSIGNAL and closed every connection without an answer. Co-Authored-By: Claude Opus 5.5 --- core/libs/prx/libkernel/Socket/src/Udp.cpp | 19 ++++++++++++++----- core/libs/tests/GuestTcp.cpp | 3 ++- core/libs/tests/GuestUdp.cpp | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/libs/prx/libkernel/Socket/src/Udp.cpp b/core/libs/prx/libkernel/Socket/src/Udp.cpp index 820aa4507..4602f9549 100644 --- a/core/libs/prx/libkernel/Socket/src/Udp.cpp +++ b/core/libs/prx/libkernel/Socket/src/Udp.cpp @@ -34,6 +34,15 @@ using NativeSocket = int; constexpr auto Invalid = -1; #endif int Fail(int error) { *__error_nid_postfix() = error; return -1; } +constexpr int GuestNoSignal = 0x20000; +int NativeSendFlags(int flags) { +#ifdef _WIN32 + static_cast(flags); + return 0; +#else + return flags & GuestNoSignal ? MSG_NOSIGNAL : 0; +#endif +} int NativeError() { #ifdef _WIN32 switch (WSAGetLastError()) { @@ -285,10 +294,10 @@ int APS5_VABI accept_nid_postfix(int descriptor, void* address, std::uint32_t* l std::int64_t APS5_VABI send_nid_postfix(int descriptor, const void* buffer, std::uint64_t length, int flags) { const auto socket = Lookup(descriptor); if (!socket) return -1; - if (flags != 0) return Fail(45); + if ((flags & ~GuestNoSignal) != 0) return Fail(45); if (length > INT_MAX) return Fail(40); if (!buffer && length) return Fail(14); - const auto result = ::send(socket->value, static_cast(buffer), static_cast(length), 0); + const auto result = ::send(socket->value, static_cast(buffer), static_cast(length), NativeSendFlags(flags)); return result < 0 ? Fail(NativeError()) : result; } std::int64_t APS5_VABI recv_nid_postfix(int descriptor, void* buffer, std::uint64_t length, int flags) { @@ -359,19 +368,19 @@ std::int64_t APS5_VABI sendto_nid_postfix(int descriptor, const void* buffer, st int flags, const void* address, std::uint32_t addressLength) { const auto socket = Lookup(descriptor); if (!socket) return -1; - if (flags != 0) return Fail(45); + if ((flags & ~GuestNoSignal) != 0) return Fail(45); if (length > INT_MAX) return Fail(40); if (!buffer && length) return Fail(14); int result; if (!address) { if (addressLength != 0) return Fail(22); - result = ::send(socket->value, static_cast(buffer), static_cast(length), 0); + result = ::send(socket->value, static_cast(buffer), static_cast(length), NativeSendFlags(flags)); } else { sockaddr_storage native{}; socklen_t size; if (!Address(address, addressLength, native, size)) return -1; if (native.ss_family != (socket->family == 2 ? AF_INET : AF_INET6)) return Fail(47); - result = static_cast(::sendto(socket->value, static_cast(buffer), static_cast(length), 0, + result = static_cast(::sendto(socket->value, static_cast(buffer), static_cast(length), NativeSendFlags(flags), reinterpret_cast(&native), size)); } return result < 0 ? Fail(NativeError()) : result; diff --git a/core/libs/tests/GuestTcp.cpp b/core/libs/tests/GuestTcp.cpp index 0b9b42f2a..f0874538e 100644 --- a/core/libs/tests/GuestTcp.cpp +++ b/core/libs/tests/GuestTcp.cpp @@ -49,7 +49,8 @@ int main() { const char request[] = "guest TCP loopback"; char received[sizeof(request)]{}; - Require(send_nid_postfix(client, request, sizeof(request), 0) == sizeof(request)); + Require(send_nid_postfix(client, request, sizeof(request), 0x1) == -1 && *__error_nid_postfix() == 45); + Require(send_nid_postfix(client, request, sizeof(request), 0x20000) == sizeof(request)); Require(recv_nid_postfix(accepted, received, sizeof(received), 0) == sizeof(received)); Require(std::strcmp(request, received) == 0); diff --git a/core/libs/tests/GuestUdp.cpp b/core/libs/tests/GuestUdp.cpp index bdcbcd146..ac9b76ea1 100644 --- a/core/libs/tests/GuestUdp.cpp +++ b/core/libs/tests/GuestUdp.cpp @@ -72,7 +72,7 @@ int main() { Require(recvfrom_nid_postfix(receiver, buffer, sizeof(buffer), 0, nullptr, nullptr) == -1); Require(*__error_nid_postfix() == 35); const char message[] = "guest UDP loopback"; - Require(sendto_nid_postfix(sender, message, sizeof(message), 0, destination.data(), destination.size()) == sizeof(message)); + Require(sendto_nid_postfix(sender, message, sizeof(message), 0x20000, destination.data(), destination.size()) == sizeof(message)); int queued = 0; for (int i = 0; i < 100 && queued == 0; ++i) { Require(ioctl_nid_postfix(receiver, 0x4004667f, &queued) == 0); From 065280d58d6c8d627a28a8ce2da38e9148dedf97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Franch?= Date: Thu, 8 Oct 2026 12:36:58 +0200 Subject: [PATCH 2/2] fix(libkernel): map EPIPE on Linux and test send with MSG_NOSIGNAL on a closed peer Case and test by hikazey in the PR thread. Co-authored-by: hikazey Co-Authored-By: Claude --- core/libs/prx/libkernel/Socket/src/Udp.cpp | 1 + core/libs/tests/GuestTcp.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/core/libs/prx/libkernel/Socket/src/Udp.cpp b/core/libs/prx/libkernel/Socket/src/Udp.cpp index 4602f9549..31f21a373 100644 --- a/core/libs/prx/libkernel/Socket/src/Udp.cpp +++ b/core/libs/prx/libkernel/Socket/src/Udp.cpp @@ -82,6 +82,7 @@ int NativeError() { case ETIMEDOUT: return 60; case EINTR: return 4; case EINVAL: return 22; + case EPIPE: return 32; default: return 5; } #endif diff --git a/core/libs/tests/GuestTcp.cpp b/core/libs/tests/GuestTcp.cpp index f0874538e..f82ec5ab4 100644 --- a/core/libs/tests/GuestTcp.cpp +++ b/core/libs/tests/GuestTcp.cpp @@ -55,6 +55,11 @@ int main() { Require(std::strcmp(request, received) == 0); 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); Require(close_nid_postfix(listener) == 0); Require(close_nid_postfix(listener) == -1 && *__error_nid_postfix() == 9);