Commit Graph
211 Commits
Author SHA1 Message Date
orezraeyandClaude Opus 5.5 c7b39854eb Merge main into fix/libkernel-socket-flags-measured-ps5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 13:57:57 -03:00
Dean dc9f1ef656 Merge pull request #10327 from orezraey/fix/libkernel-tcp-options-measured-ps5
fix(libkernel): keep TCP_MAXSEG and the TCP keepalive options as measured on a PS5
2026-10-25 05:52:56 +13:00
Dean 2393e2e773 Merge pull request #10320 from orezraey/fix/libkernel-ip-options-measured-ps5
fix(libkernel): keep IP_TTL, IP_TOS and the multicast options as measured on a PS5
2026-10-25 04:18:17 +13:00
orezraeyandClaude Opus 5.5 2f443f3b88 Merge fix/libkernel-tcp-options-measured-ps5 into fix/libkernel-socket-flags-measured-ps5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 09:56:35 -03:00
orezraeyandClaude Opus 5.5 d360078c6a Merge fix/libkernel-ip-options-measured-ps5 into fix/libkernel-tcp-options-measured-ps5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 09:56:27 -03:00
orezraeyandClaude Opus 5.5 55473fb673 fix(libkernel): keep the low byte of an int IP_MULTICAST_LOOP
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-24 09:55:58 -03:00
Adrià 887a9640b4 Merge pull request #7605 from HQasper/fix/poll-kqueues
fix(libkernel): poll kqueues as kqueue_poll answers
2026-10-24 12:32:33 +02:00
Dean efe844c653 Merge pull request #10308 from orezraey/fix/libkernel-socket-receive-measured-ps5
fix(libkernel): answer zero-length datagram receives and recvmsg flags as measured on a PS5
2026-10-24 20:46:44 +13:00
Dean 83a25ceb71 Merge pull request #9105 from Retr0G28/fix/connect-port0-connected-dgram
fix(libkernel): disconnect a connected datagram socket on connect to port 0
2026-10-24 16:54:25 +13:00
Dean 6fc058f5cf Merge pull request #10302 from orezraey/fix/libkernel-socket-buffers-measured-ps5
fix(libkernel): keep socket buffer sizes and SO_NBIO as measured on a PS5
2026-10-24 15:25:05 +13:00
Dean d8b73e3644 Merge pull request #9273 from DavidSamir/feat/libkernel-sys-pselect
feat(libkernel): implement pselect over select
2026-10-24 12:53:12 +13:00
Dean 7956a166c7 Merge pull request #9108 from Retr0G28/fix/socket-address-length-exact
fix(libkernel): reject socket addresses longer than sockaddr_in or sockaddr_in6 with EINVAL
2026-10-24 09:12:39 +13:00
orezraeyandClaude Opus 5.5 802bcc8d61 fix(libkernel): share a port between SO_REUSEPORT sockets on the host
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 15:38:45 -03:00
orezraeyandClaude Opus 5.5 122541c7a8 fix(libkernel): keep the SOL_SOCKET flags a PS5 accepts
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 15:20:17 -03:00
orezraeyandClaude Opus 5.5 29f717c607 fix(libkernel): keep TCP_MAXSEG and the TCP keepalive options as measured on a PS5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 15:20:16 -03:00
orezraeyandClaude Opus 5.5 b776394b4f fix(libkernel): keep IP_TTL, IP_TOS and the multicast options as measured on a PS5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 15:20:03 -03:00
orezraeyandClaude Opus 5.5 d8d03c2839 fix(libkernel): give the host the requested socket buffer and test the inherited sizes
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 15:16:09 -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
orezraeyandClaude Opus 5.5 f334c156e1 fix(libkernel): keep socket buffer sizes and SO_NBIO as measured on a PS5
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-23 13:49:03 -03:00
Dean Galvin 2f741e737f Merge main into feat/libkernel-underscore-socket-signal-entries 2026-10-23 22:00:32 +13:00
Dean c9edaff579 Merge pull request #9104 from Retr0G28/fix/sendfile-enotsock
fix(libkernel): return ENOTSOCK from sendfile on a descriptor that is not a socket
2026-10-23 19:25:35 +13:00
HQasperandClaude Opus 5.5 8fd72f02c5 fix(libkernel): poll kqueues as kqueue_poll answers
A kqueue descriptor is ready for POLLIN and POLLRDNORM while one of its
events is triggered and for no other event, as FreeBSD's kqueue_poll
answers; poll threw for it on both hosts. A kqueue cannot be waited on,
so while one is polled poll checks it every millisecond and waits on the
other descriptors in slices of 1 ms. This is the loop Windows already
used for pipes, which Linux now shares.

A kqueue closed during the wait reports POLLNVAL, and one whose number
was reused is polled again with the rest of the timeout, as FreeBSD's
pollrescan looks the descriptor up again.

Depends on #7248.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-22 18:13:27 +00:00
xXPBSXxandClaude Sonnet 5.5 ff2b4ba4cc fix(libkernel): report EPIPE for a stream send on a connection the peer closed on Windows
sosend_generic fails a send on a socket that can send no more with EPIPE
before it looks at so_error. Winsock reports the same send as WSAECONNABORTED
or WSAECONNRESET, which reached the guest as ECONNABORTED or ECONNRESET.
A stream send now maps both to EPIPE. The send-after-close checks of
guest_tcp, guest_socket_read_write and guest_socket_pair run on Windows too.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-22 19:09:29 +02:00
Retr0 be4fd86249 fix(libkernel): disconnect a connected datagram socket on connect to port 0
FreeBSD 11.4's soconnectat() (sys/kern/uipc_socket.c) disconnects a
connected socket of a protocol without PR_CONNREQUIRED before it calls
pru_connect. udp_disconnect() and udp6_disconnect() drop the peer and
reset the local address, then in_pcbconnect_setup() and in6_pcbladdr()
fail port 0 with EADDRNOTAVAIL, so the socket is left unconnected.
connect to port 0 on a connected datagram socket now dissolves the
association through the AF_UNSPEC disconnect path before failing with 49,
where it kept the old peer. Stream sockets keep EISCONN.
2026-10-22 20:00:13 +03: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
Adrià 093149c5bd Merge pull request #8483 from xXPBSXx/fix/poll-peer-close-pollin
fix(libkernel): report a stream whose peer closed as readable in poll on Windows
2026-10-22 17:44:27 +02:00
David 375b53d918 refactor(libkernel): move pselect into libkernel
The PS5 3.20 export lists have pselect in libkernel as well as
libkernel_sys, and on Windows a libkernel import never reaches
libkernel_sys. The implementation moves unchanged to
libkernel/Socket/src/Pselect.cpp, beside select.
2026-10-21 22:30:43 +01:00
Adrià eaff87674c Merge pull request #8492 from xXPBSXx/fix/recv-after-shutdown-and-empty
fix(libkernel): answer a receive after SHUT_RD or with no buffer without the host
2026-10-21 20:39:37 +02:00
Adrià 0b117a8bfc Merge pull request #8392 from xXPBSXx/fix/socket-argument-order-fb
fix(libkernel): check socket address arguments before the descriptor
2026-10-21 20:05:37 +02:00
xXPBSXxandClaude Sonnet 5.5 c02a5d8034 fix(libkernel): keep the receive-after-SHUT_RD answer on Windows only
On Linux the host keeps data that was buffered before shutdown(SHUT_RD) and
guest_socket_pair expects to read it, so the shortcut that answers 0 for any
receive after SHUT_RD broke that test there. Limit the shortcut to Windows,
where the host cannot answer it, and run the post-shutdown receives of
guest_tcp on Windows only.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-21 20:01:18 +02:00
xXPBSXxandClaude Sonnet 5.5 ba8b881fa6 fix(libkernel): answer a receive after SHUT_RD or with no buffer without the host
soreceive_generic returns 0 for a socket whose receive side is shut and for a
zero-length receive on a connected stream socket (ENOTCONN when it is not
connected), without waiting. Winsock fails the first with WSAESHUTDOWN, which
reached the guest as EPIPE, and blocks the second until data arrives. recv and
recvfrom now answer both themselves.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-21 20:01:18 +02:00
Adrià 606297f34f Merge pull request #8474 from xXPBSXx/fix/recv-msg-waitall
feat(libkernel): accept MSG_WAITALL in recv, recvfrom and recvmsg on a stream socket
2026-10-21 20:00:45 +02:00
NikoandClaude Opus 5.5 0ac2b0bc6f feat(libkernel): export the underscore entry points of the socket, directory and signal calls
The PS5 libkernel exports _accept, _bind, _connect, _getdirentries,
_getpeername, _getsockname, _getsockopt, _listen, _recvfrom, _recvmsg,
_sendmsg, _sendto, _setsockopt, _sigaction and _sigsuspend (PS5 3.20
export list, DNNDHH/PS5-3.20_Libs b2a77c0 libkernel.c), and main
exports none of them, so a title importing one fails at startup. Each
now forwards to the export without the underscore, as _close, _ioctl
and _nanosleep already do.

In FreeBSD 11.4 (8c639945a4) these are libc's plain system call
entries: lib/libc/amd64/SYS.h makes bind, getdirentries, getpeername,
getsockname, getsockopt, listen and setsockopt one stub under both
names, and lib/libc/sys/Makefile.inc gives accept, connect, recvfrom,
recvmsg, sendmsg, sendto, sigaction and sigsuspend a separate public
name that goes through libthr's interposing table, which adds the
cancellation points and the sigaction wrapper. The exports without the
underscore have no libthr layer here, so forwarding gives the system
call. docs/dev/debt/libkernel.md records what stays unverified: the
console is not measured, _sigaction shares the handler table of
sigaction, and a null set throws in _sigsuspend as in sigsuspend,
where FreeBSD's system call returns EFAULT.

guest_underscore_entries calls every new export: a loopback TCP
connection, UDP datagrams with scatter, truncation and sender
addresses, a directory listing compared with getdirentries, a SIGTERM
handler set by _sigaction, and a pending SIGUSR1 that _sigsuspend
delivers before returning EINTR with the mask restored. It checks the
errors they pass on (EBADF, EINVAL, EFAULT, ENOPROTOOPT, EOPNOTSUPP)
and that outputs stay untouched on failure.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-21 17:02:54 +02:00
Retr0 f2bc1195f8 fix(libkernel): reject socket addresses longer than sockaddr_in or sockaddr_in6 with EINVAL
FreeBSD 11.4 getsockaddr sets sa_len to the length argument, and
tcp_usr_bind, tcp_usr_connect, in_pcbbind_setup, in_pcbconnect_setup,
in6_pcbbind and in6_pcbladdr answer EINVAL when it is not the size of
the socket family's address. udp6_bind and udp6_connect pass an
IPv4-mapped address to the IPv4 code without that check when
IPV6_V6ONLY is clear, and udp6_send always checks it. bind and connect
on AF_INET and AF_INET6 sockets, and sendto on AF_INET6 datagram
sockets, now fail a longer address with EINVAL.
2026-10-21 15:31:15 +03:00
xXPBSXxandClaude Sonnet 5.5 f1c8ae0ccb fix(libkernel): report a stream whose peer closed as readable in poll on Windows
WSAPoll reports POLLHUP alone for a stream socket whose peer has closed, so
poll never returned POLLIN for it and a caller waiting for POLLIN did not see
the end of the stream. sopoll_generic reports a socket that can receive no
more as readable and adds POLLHUP only once it can send no more either.
poll now adds the requested read bit and keeps POLLHUP only after the socket
shut its own sending side. A reset or refused connection keeps WSAPoll's flags.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-21 14:28:15 +02:00
Retr0 9bd2bb06cc fix(libkernel): return ENOTSOCK from sendfile on a descriptor that is not a socket
FreeBSD 11 sendfile checks the file descriptor first, then looks up the
socket with getsock_cap, which answers ENOTSOCK for an open descriptor
that is not a socket and EBADF for one that is not open
(sys/kern/kern_sendfile.c, sys/kern/uipc_syscalls.c).

sendfile replaced the errno that Lookup had already set with EBADF. It
now reports the errno Lookup chose, so an open non-socket gives ENOTSOCK
and a closed descriptor still gives EBADF. The sentence about this gap
is cut from the sendfile debt entry and guest_sendfile covers both cases.
2026-10-21 15:16:35 +03: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
Ondra97 c415375041 fix(net): finish blocking stream sends after short writes 2026-10-21 01:53:43 +02:00
Dean b753508271 Merge pull request #8454 from hypermoist/feat/libkernel-byte-order
feat(libkernel): export htonl, ntohl, htons and ntohs
2026-10-21 12:40:32 +13:00
Ondra97 1b182e7fb2 fix(net): keep MSG_DONTWAIT transfers nonblocking on Windows 2026-10-20 21:47:08 +02:00
MarcZX10 2299284a69 fix(libkernel): keep socket descriptors within FD_SETSIZE 2026-10-20 17:41:40 +00:00
Adrià 4036fab1b2 Merge pull request #7437 from lucaslima430/fix/libkernel-socket-fcntl-duplication
fix(libkernel): support socket fcntl duplication
2026-10-20 17:40:06 +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 26f861dd27 feat(libkernel): accept MSG_WAITALL in recv, recvfrom and recvmsg on a stream socket
soreceive_generic keeps a MSG_WAITALL receive on a stream socket waiting until
the buffer is full, the peer closes or an error occurs. The three calls failed
every flag but MSG_PEEK and MSG_DONTWAIT with EOPNOTSUPP. A stream socket now
passes the flag to the host receive; a datagram socket ignores it, as a record
is delivered whole.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-20 15:12:33 +02:00
hypermistandClaude Opus 5.5 14dbed4ed1 feat(libkernel): export htonl, ntohl, htons and ntohs
libkernel exports the byte order conversions; they swap the bytes of
their 32- or 16-bit argument.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
2026-10-21 01:48:48 +13:00
xXPBSXxandClaude Sonnet 5.5 ce8f7803ea fix(libkernel): check socket address arguments before the descriptor
bind, connect and sendto looked the descriptor up before they looked at the
address length, so a descriptor that is not open hid an argument error.
FreeBSD 11.4 sys_bind, sys_connect and sendit run getsockaddr first
(ENAMETOOLONG, EINVAL, EFAULT) and only then look the descriptor up, so
these arguments are now answered first and EBADF only follows for a valid
address.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-20 14:43:54 +02:00
Queuze bbcce1736e fix(libkernel): support socket fcntl duplication 2026-10-20 13:40:22 +02:00
Alexej Szpevák 92e136a129 feat(libkernel): report the write end of a pipe to equeue descriptor polls
GuestSockets::Ready only knew the read end of a pipe, and WaitAny asked the host for POLLIN on every descriptor that is not a socket, so a write interest on a pipe could never be reported or wake a wait. PipeWriteState gives the free space of the host buffer (F_GETPIPE_SZ less FIONREAD on Linux, the write quota on Windows), EOF once the read end is closed, and whether the host takes a write now; Ready reports the write end when it is writable or at EOF, and WaitAny asks for POLLOUT on it. macOS has no call for the capacity of a pipe and throws.
2026-10-20 13:34:50 +02:00