Commit Graph
39 Commits
Author SHA1 Message Date
Evrim Cicek 3f67bbcd4e Merge branch 'main' of https://github.com/boykopovar/AnyPS5 into fix/recvmsg-after-shut-rd
# Conflicts:
#	core/libs/prx/libkernel/Socket/src/Udp.cpp
#	docs/dev/debt/libkernel.md
2026-10-27 01:04:45 +03:00
orezraeyandClaude Opus 5.5 19566dbee8 fix(libkernel): set MSG_CTRUNC for an empty recvmsg control buffer as FreeBSD 11.4 does
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 21:05:10 -03:00
Evrim Cicek cf57327015 fix(libkernel): drop the data a socket held before shutdown(SHUT_RD) in every receive path 2026-10-26 01:08:17 +03:00
orezraeyandClaude Opus 5.5 49bcd7549e fix(libkernel): report SCM_BINTIME and SCM_TIMESTAMP from recvmsg as measured on a PS5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 16:30:34 -03:00
Adrià f55190f7e3 Merge pull request #9477 from EagleBearerYS/fix/libkernel-udp-unreachable-port
fix(libkernel): stop Winsock failing an unconnected datagram receive after an unreachable port
2026-10-25 18:04:34 +01:00
boykopovar f38d29fd08 refactor(sdk): add canonical headers for remaining libraries 2026-10-24 23:17:42 +03:00
orezraeyandClaude Opus 5.5 9afaeff204 fix(libkernel): answer a zero-length recvmsg on an empty datagram socket
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 15:14:09 -03:00
orezraeyandClaude Opus 5.5 a537c33096 fix(libkernel): answer zero-length datagram receives and recvmsg flags as measured on a PS5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 14:09:47 -03:00
Yunus Shaikh 6b75fb99f6 Merge main into fix/libkernel-udp-unreachable-port
# Conflicts:
#	docs/dev/debt/libkernel.md
2026-10-22 20:53:20 -07:00
Adrià 8499ea52e5 Merge pull request #8499 from xXPBSXx/fix/sendto-port-zero
fix(libkernel): fail sendto to port 0 from an unbound IPv4 datagram socket with EADDRNOTAVAIL
2026-10-22 17:54:00 +02:00
Yunus Shaikh cfda40433c Merge main into fix/libkernel-udp-unreachable-port 2026-10-21 15:15:13 -07:00
Adrià de4ef842b5 Merge pull request #7850 from mugurc/feat/libkernel-sockets-macos
feat(libkernel): UDP sockets and name resolution on macOS hosts
2026-10-21 13:36:21 +02:00
xXPBSXxandClaude Sonnet 5.5 0bb7b02e9f fix(libkernel): answer a bound IPv4 datagram send to port 0 without the host
Linux's udp_sendmsg refuses port 0 with EINVAL, so a send that FreeBSD
accepts (the socket is bound to a specific address and port and the
destination is not INADDR_ANY or INADDR_BROADCAST) failed there. Nothing can
receive on port 0, so the call now returns the length itself on every host.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-20 16:56:47 +02:00
xXPBSXxandClaude Sonnet 5.5 aec1f2c012 fix(libkernel): fail sendto to port 0 from an unbound IPv4 datagram socket with EADDRNOTAVAIL
udp_output hands the destination to in_pcbconnect_setup unless the socket is
bound to a specific address and port and the destination is neither
INADDR_ANY nor INADDR_BROADCAST, and in_pcbconnect_setup fails port 0 with
EADDRNOTAVAIL. The send went to the host, which accepted it. sendto, and
sendmsg through it, now fails the same way for an AF_INET datagram socket
that is not connected. connect to port 0 already did.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-20 16:54:21 +02:00
xXPBSXxandClaude Sonnet 5.5 45940f27cc fix(libkernel): honour MSG_DONTWAIT in the socket send and receive calls on Windows
send, sendto, sendmsg, recv, recvfrom and recvmsg failed with EOPNOTSUPP for
MSG_DONTWAIT on Windows, where FreeBSD 11.4 sosend_generic and
soreceive_generic make the one call non-blocking and fail with EWOULDBLOCK
when it would wait. Winsock has no per-call flag, so the call now asks WSAPoll
with a zero timeout whether the socket is ready and fails with EAGAIN when it
is not. The Windows branches of the socket tests that expected EOPNOTSUPP now
run the same checks as the other hosts.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-20 03:43:59 +02:00
mugurc 7701a9b9da feat(libkernel): UDP sockets and name resolution on macOS hosts
The guest socket layer relies on a few Linux calls:

- The equeue wait uses poll with the timeout rounded up to a millisecond;
  macOS has no ppoll.
- A readable stream socket whose peer closed is reported with POLLHUP by
  peeking one byte; macOS has no POLLRDHUP.
- FIONREAD on a datagram socket, and the byte count that fstat and kevent
  report for it, is SO_NREAD, the size of the next datagram; macOS adds the
  source address to FIONREAD.
- socketpair throws for SOCK_SEQPACKET, which has no AF_UNIX pair on macOS.
- gethostbyname replaces gethostbyname_r, which macOS lacks.

The UDP test sends on its connected socket without an address, as #7475
does, because macOS, like FreeBSD, fails sendto with an address on a
connected socket with EISCONN. The log test uses a datagram pair with
enlarged buffers instead of SOCK_SEQPACKET.
2026-10-19 23:36:56 +03:00
Adrià b60e0bc0a5 Merge pull request #4676 from milescoviello/fix/socket-msg-dontwait
fix(libkernel): accept MSG_DONTWAIT in the socket send and receive calls
2026-10-14 19:13:53 +02:00
Dean 4ddce7993d Merge pull request #4845 from EagleBearerYS/test/guest-udp-readv-compare
test(libkernel): compare the unterminated readv buffer with memcmp
2026-10-14 14:34:41 +13:00
Yunus Shaikh 4d35b48daf fix(libkernel): stop Winsock failing an unconnected datagram receive after an unreachable port
Winsock reports an ICMP port-unreachable reply as WSAECONNRESET on the
next receive of any datagram socket, so on Windows a guest UDP socket
that sent to a port nobody listens on failed its next recvfrom with
ECONNRESET. FreeBSD's udp_common_ctlinput passes the reply on only to
a socket connected to the sender; an unconnected one keeps receiving.
socket now turns SIO_UDP_CONNRESET off on datagram sockets on Windows,
as #5295 does for sceNetSocket.
2026-10-13 12:08:21 -07:00
Dean 3779597778 Merge pull request #4658 from milescoviello/fix/sockopt-option-lengths
fix(libkernel): accept socket option values longer than an int
2026-10-13 16:53:12 +13:00
Yunus Shaikh 584c59e5ac test(libkernel): compare the unterminated readv buffer with memcmp 2026-10-12 16:37:56 -07:00
milescovielloandClaude Opus 5.5 b8d71fc7f2 fix(libkernel): dissolve a UDP association on connect to AF_UNSPEC
connect() on a guest datagram socket checked the address family before
doing anything, so an AF_UNSPEC (null) address failed with EAFNOSUPPORT
and left the socket connected: getpeername() still reported the old
peer, send() without an address still went there, and datagrams from
any other sender were dropped by the host.

FreeBSD 11.4 disconnects a connected datagram socket first and only then
rejects the address. sys/kern/uipc_socket.c, soconnectat():

	 * If protocol is connection-based, can only connect once.
	 * Otherwise, if connected, try to disconnect first.  This allows
	 * user to disconnect by connecting to, e.g., a null address.
	 */
	if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING) &&
	    ((so->so_proto->pr_flags & PR_CONNREQUIRED) ||
	    (error = sodisconnect(so)))) {

udp_disconnect() (sys/netinet/udp_usrreq.c) clears the peer and resets
only the local address, keeping the local port:

	in_pcbdisconnect(inp);
	inp->inp_laddr.s_addr = INADDR_ANY;

after which in_pcbconnect_setup() (sys/netinet/in_pcb.c) returns
EAFNOSUPPORT for the full-size address, as main already does. connect(2)
documents it: "Datagram sockets may dissolve the association by
connecting to an invalid address, such as a null address."

A connected internet datagram socket given an address whose family byte
is 0 is now disconnected on the host first (AF_UNSPEC on Linux, a zeroed
address on Windows) and the call then fails as before. Linux also drops
an ephemeral local port on that disconnect, so the port is bound again
on the wildcard address, which is what FreeBSD leaves. A host
failure during the disconnect is returned as the call's error. Stream
sockets keep the previous path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-12 19:33:20 +00:00
milescovielloandClaude Opus 5.5 7afd88926a fix(libkernel): accept MSG_DONTWAIT in the socket send and receive calls
send, sendto, sendmsg, recv, recvfrom and recvmsg failed with EOPNOTSUPP
for MSG_DONTWAIT (0x80), so code that polls a blocking socket with it
got an error on every call instead of its data or EWOULDBLOCK.

FreeBSD 11.4 defines the flag in sys/sys/socket.h:

	#define	MSG_DONTWAIT	0x80		/* this message should be nonblocking */

and soreceive_generic() (sys/kern/uipc_socket.c) treats it as a
non-blocking socket for that one call:

		if ((so->so_state & SS_NBIO) ||
		    (flags & (MSG_DONTWAIT|MSG_NBIO))) {
			SOCKBUF_UNLOCK(&so->so_rcv);
			error = EWOULDBLOCK;
			goto release;

On Linux and macOS the flag now maps to the host's MSG_DONTWAIT, next to
MSG_PEEK on a receive and MSG_NOSIGNAL on a send. Winsock has no
per-call non-blocking flag, so Windows keeps failing with EOPNOTSUPP
for it; TechnicalDebt records that. Other flags still fail with
EOPNOTSUPP.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-12 18:42:53 +00:00
milescovielloandClaude Opus 5.5 eb9da23e68 fix(libkernel): accept socket option values longer than an int
setsockopt() on a guest socket failed with EINVAL unless the option
length was exactly sizeof(int), so an option passed as a 64-bit value
(for example SO_BROADCAST or SO_RCVBUF from an int64_t or size_t) was
rejected and silently left unchanged.

FreeBSD 11.4 reads these integer options through sooptcopyin() with the
size of an int as both the wanted and the minimum length, and only a
shorter value fails. sys/kern/uipc_socket.c, sooptcopyin():

	 * If the user gives us more than we wanted, we ignore it, but if we
	 * don't get the minimum length the caller wants, we return EINVAL.
	...
	if ((valsize = sopt->sopt_valsize) < minlen)
		return EINVAL;
	if (valsize > len)
		sopt->sopt_valsize = valsize = len;

and sosetopt() uses it for SO_BROADCAST, SO_REUSEADDR, SO_SNDBUF and
SO_RCVBUF:

	error = sooptcopyin(sopt, &optval, sizeof optval,
	    sizeof optval);

A longer value now sets the option from its first int; a shorter one
still fails with EINVAL.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-12 18:04:27 +00:00
Dean 9bc4356990 Merge pull request #4295 from AaravMehta-07/codex/kernel-socket-address-length
fix(libkernel): report copied socket address lengths
2026-10-13 01:57:25 +13:00
Dean 90c7ab3390 Merge pull request #4102 from itsbo5/fix/libkernel-udp-send-edestaddrreq
fix(libkernel): return EDESTADDRREQ for send and sendto on unconnecte…
2026-10-13 01:28:39 +13:00
Aarav 6197edea2b fix(libkernel): report copied socket address lengths 2026-10-12 10:21:17 +05:30
milescovielloandClaude Opus 5.5 cba3b5a8b3 fix(libkernel): accept SOCK_NONBLOCK and SOCK_CLOEXEC in socket
socket only took a type of exactly SOCK_STREAM or SOCK_DGRAM, so a type
with SOCK_NONBLOCK (0x20000000) or SOCK_CLOEXEC (0x10000000) set failed
with EPROTONOSUPPORT, although socketpair already accepted both.

FreeBSD strips both flags before creating the socket (sys/kern/
uipc_syscalls.c, kern_socket: "if ((type & SOCK_CLOEXEC) != 0) { type
&= ~SOCK_CLOEXEC; oflag |= O_CLOEXEC; }" and the same for SOCK_NONBLOCK
with FNONBLOCK), and makes the new socket non-blocking with
"fo_ioctl(fp, FIONBIO, &fflag, ...)".

socket now does the same as socketpair: it creates the socket from the
plain type and, with SOCK_NONBLOCK, switches it to non-blocking.
SOCK_CLOEXEC needs nothing more, since a guest never executes another
program.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-12 01:48:40 +00:00
virp-mta 8b04156bfd fix(libkernel): return EDESTADDRREQ for send and sendto on unconnected UDP sockets 2026-10-12 03:12:34 +04:00
Adrià Franch e8ea9a62bb test(libkernel): check that a socket call returns the mapped guest errno
Sending on an unconnected UDP socket must report the guest EDESTADDRREQ (39)
through NativeError, so a regression to EIO is caught on Linux.
2026-10-11 23:43:47 +02:00
DariusHQ b4a59e34c4 feat(libkernel): export _ioctl
Stremio Plus (PPSA74126) stops at start-up on _ioctl, which its statically
linked tc* functions call. FreeBSD's _ioctl is the same system call as
ioctl, so it forwards to ioctl.
2026-10-11 14:19:02 +03:00
MarcZX100 d78af2c710 fix(libkernel): route vector I/O on guest sockets 2026-10-11 01:16:58 +00:00
Scott SchusterandClaude Opus 5.5 a2f9a50985 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 <[email protected]>
2026-10-08 12:36:58 +02:00
kjhqandClaude Opus 5.5 afb8d8e2d7 fix(libkernel): accept guest socket addresses whatever their sa_len
The FreeBSD kernel ignores sa_len in a socket address passed in and sets
it from the length argument, so titles may leave it 0. Only the family
and the length argument decide the address kind now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-07 10:34:23 +00:00
ChadandClaude Opus 5.5 77550ab731 feat(libkernel): implement sendmsg and recvmsg
Both take the FreeBSD msghdr (48 bytes, iovecs of a pointer and a 64-bit
length) and run on the host sockets: sendmsg gathers the iovecs and sends
through sendto, recvmsg receives into one buffer and scatters it. A
datagram longer than the iovecs is cut and reported with MSG_TRUNC, also
on Windows where recvfrom fails with WSAEMSGSIZE. More than 1024 iovecs
fail with EMSGSIZE. No ancillary data is ever received, so recvmsg
clears msg_controllen; sending control data throws.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-05 20:10:13 -05:00
Praetorian0420 e3eeac4a81 Implement network control and socket functionality improvements
- Enhanced the network control library to check for host addresses and update connection states accordingly.
- Added support for socket operations including connect, listen, accept, send, and recv in the UDP and TCP socket implementations.
- Introduced error handling for various socket operations, ensuring proper feedback for unsupported actions.
- Created comprehensive tests for both TCP and UDP socket functionalities, validating the expected behavior of the network stack.
- Refactored existing code to improve clarity and maintainability, including the removal of unused functions and the addition of necessary error checks.
2026-09-30 23:29:01 -05:00
asimplestray a4e755ccb1 feat(kernel): implement file metadata ops and address conversion 2026-09-30 16:51:37 +00:00
SamG-Coder b8c1097db4 feat(kernel): support socket nonblocking flags through fcntl 2026-09-25 06:34:30 +10:00
SamG-Coder 9cbefb7e04 feat(kernel): implement tracked UDP sockets and ioctl 2026-09-25 06:23:44 +10:00