177 Commits
Author SHA1 Message Date
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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
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 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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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
Adrià f1d13abca4 Merge pull request #7559 from mugurc/fix/libkernel-listening-socket-macos
fix(libkernel): recognize listening sockets on macOS hosts
2026-10-20 12:56:12 +02:00
Dean 1e3efa7ccf Merge pull request #8132 from Retr0G28/fix/socketpair-cloexec
fix(libkernel): mark both socketpair ends close-on-exec for SOCK_CLOEXEC
2026-10-20 18:31:15 +13:00
Dean 564c75b289 Merge pull request #7956 from Lindamea1/fix/libkernel-ioctl-malformed-enotty
fix(libkernel): fail a malformed ioctl request with ENOTTY
2026-10-20 17:49:59 +13:00
Dean 4405703fa6 Merge pull request #8186 from xXPBSXx/fix/socket-dontwait-windows-fb
fix(libkernel): honour MSG_DONTWAIT in the socket send and receive calls on Windows
2026-10-20 16:22:35 +13:00
Dean d19c3d6db8 Merge pull request #8188 from xXPBSXx/fix/listen-connected-socket-fb
fix(libkernel): fail listen on a connected socket with EINVAL
2026-10-20 16:22:22 +13:00
Dean 7020db3098 Merge pull request #8156 from xXPBSXx/fix/socket-call-on-non-socket-v4
fix(libkernel): fail a socket call on an open non-socket descriptor with ENOTSOCK
2026-10-20 15:53:25 +13:00
xXPBSXxandClaude Sonnet 5.5 d672e8d54a fix(libkernel): fail listen on a connected socket with EINVAL
listen on a connected stream socket failed with EISCONN, the Winsock error.
FreeBSD 11.4 solisten_proto_check fails a socket that is connected,
connecting or disconnecting with EINVAL. The guest listen now reports EINVAL
for the host's EISCONN, and the connect-listening test checks it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-20 03:48:18 +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 <noreply@anthropic.com>
2026-10-20 03:43:59 +02:00
xXPBSXxandClaude Sonnet 5.5 d5d17788ae fix(libkernel): fail a socket call on an open non-socket descriptor with ENOTSOCK
bind, listen, accept, connect, shutdown, getsockname, getsockopt, setsockopt, send, recv and the other calls that look up a guest socket answered EBADF for a descriptor that is open but not a socket, for example a pipe end. FreeBSD 11.4's getsock_cap fails these with ENOTSOCK and keeps EBADF for a closed or invalid descriptor.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-20 02:44:17 +02:00
xXPBSXxandClaude Sonnet 5.5 cd09badb2b fix(libkernel): fail a short or long socket address like FreeBSD
bind, connect and sendto answered EFAULT for an address length below 2 and EAFNOSUPPORT for an AF_INET address below 16 or an AF_INET6 address below 28 bytes. FreeBSD 11.4's getsockaddr fails a length below 2 with EINVAL and above SOCK_MAXADDRLEN (255) with ENAMETOOLONG, and the protocols compare the length with sizeof(struct sockaddr_in) or sockaddr_in6 and fail with EINVAL.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-20 02:30:55 +02:00
Retr0 04c16c74f9 fix(libkernel): mark both socketpair ends close-on-exec for SOCK_CLOEXEC
socketpair accepted SOCK_CLOEXEC but left both descriptors out of the
close-on-exec set, so F_GETFD read 0 on them. FreeBSD 11's
kern_socketpair opens both files with O_CLOEXEC when the type carries
SOCK_CLOEXEC, as socket already does here.
2026-10-20 02:26:15 +03:00
Adrià 309ab11eaf Merge pull request #7539 from ionut27001/fix/libkernel-inet-ntop-pad
fix(libkernel): match inet_ntop and inet_pton padding and null pointers as measured on a PS5
2026-10-20 00:51:02 +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
Dean 6b981a212c Merge pull request #7675 from valenciana-nc/fix/recvmsg-guest-validation
fix(libkernel): fail recvmsg with EFAULT on guest memory it cannot read or write
2026-10-20 09:21:54 +13:00
Hussein Kadhim baa6d4aeee fix(libkernel): fail a malformed ioctl request with ENOTTY before the descriptor is looked at
FreeBSD's sys_ioctl rejects a request with no direction bit, an output request with no length, or a void request whose length is not an int before it reads the argument or resolves the descriptor. ioctl threw on such a request for a file, pipe or directory, failed with EBADF for a closed descriptor and with EFAULT for a socket given no argument.

(cherry picked from commit 501518f321ac5d0b45ce1090af39c680927edf49)
(cherry picked from commit 3eb7edd9cf)
2026-10-19 16:25:42 +01:00
Alexej Szpevák cb9a4c7417 feat(libkernel): support EV_CLEAR on sockets and pipes in kevent on Linux
kevent threw for EV_CLEAR on a socket or the read end of a pipe; Boost.Asio's kqueue reactor, among others, registers every socket that way. On Linux such a knote now watches its host descriptor through an edge watch. It is armed when added, on every later EV_ADD or EV_ENABLE while enabled, and by each host wakeup; when armed it is checked with the level-triggered readiness test and reported with the current data and EV_EOF, or disarmed if no longer ready, as kqueue_scan re-runs the filter; reporting it disarms it until the next edge. Waits block on the watch's epoll descriptor, so a socket that stays readable does not wake them. Windows and macOS still throw. GuestSockets::NativeDescriptor exposes the host socket behind a guest one for the watch.
2026-10-19 15:05:28 +02:00
valenciana-nc f7fd9dbf9f fix(libkernel): check recvmsg guest copies on macOS 2026-10-19 06:33:13 -06:00
valenciana-nc 7ef31e91cf fix(libkernel): check only the guest bytes recvmsg reads and writes 2026-10-19 06:33:13 -06:00
valenciana-nc 370f48be82 fix(libkernel): validate recvmsg guest pointer ranges are committed
Address review: check the msghdr, iovec array, iovec bases and name
are mapped before MessageLength or the receive loop touches them,
pairing the HostWrite guard with committed-range validation. Add
regression tests for forged iovec-array and output pointers.
2026-10-19 06:33:13 -06:00
valenciana-nc fe8782adc3 fix(libkernel): validate recvmsg guest output buffers in the guest arena
recvmsg_nid_postfix wrote the msghdr, every iovec base and the sender
address with only null checks, unlike recv_nid_postfix and the
sceNetRecvfrom sender outputs which all gate on GuestArena::HostWrite.
Validate the message, each iovec base and the name buffer the same way
so a forged pointer fails with EFAULT instead of writing received bytes
to an arbitrary host address.
2026-10-19 06:33:13 -06:00
Adrià 48f436406b Merge pull request #6663 from karimibrahim07/feat/libkernel-ipv6-v6only
feat(libkernel): set and read IPV6_V6ONLY on a guest socket
2026-10-19 10:44:37 +02:00
MarcZX100 00ca965c57 fix(libkernel): reject connects on listening sockets first 2026-10-18 18:25:48 +00:00
MarcZX100 0751dffcb1 fix(libkernel): match FreeBSD port-zero stream connects 2026-10-18 18:23:39 +00:00
Hussein Kadhim f571b37f5a fix(libkernel): limit the port 0 check to connect on an unconnected datagram socket 2026-10-18 18:23:39 +00:00
Hussein Kadhim b10f1310df fix(libkernel): fail connect and sendto to port 0 with EADDRNOTAVAIL 2026-10-18 18:23:38 +00:00
Adrià bb86ca38b8 Merge pull request #5992 from Get-fix/ps4/libkernel-underscore-io
fix(libkernel): export _readv, _writev, _fcntl, _fstat, __sys_socketex
2026-10-18 16:45:19 +02:00
ionut27001andClaude Opus 5.5 213a741eb2 fix(libkernel): match inet_ntop and inet_pton padding and null pointers as measured on a PS5
Measured from a payload process on a PS5 (firmware 12.70), where
__inet_ntop/__inet_pton and the plain inet_ntop/inet_pton exports
resolve to the same functions:
- inet_ntop follows an AF_INET6 result with zero bytes up to size (sizes
  4 to 65536 sampled) and never writes past size; AF_INET writes only the
  text and its NUL.
- An unsupported family returns EAFNOSUPPORT first, even with null
  pointers.
- A null source or text raises SIGSEGV during the call, before the size
  is checked; here it throws instead of returning EFAULT.
- A null destination is reached only after the size check and the text
  parse: ENOSPC for a size that is too small, 0 for text that does not
  parse, and SIGSEGV (a throw here) otherwise.
The test pins the measured inet_pton and inet_ntop rows, including all
inputs the existing assertions use. The text-form debt entry is replaced
by one that records what a payload process measured (the text forms, the
order of the checks and the padding) and what is still assumed: the
sizes that were not sampled, sizes above 65536, and a title process.
inet_ntoa_r calls __inet_ntop, so a null inet_ntoa_r buffer with room
for the text now throws, and a null buffer that is too small sets ENOSPC
instead of EFAULT; the libSceLibcInternal debt entry says so.

AI-assisted: yes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 17:02:40 +03:00
mugurc 6f2a61ade0 fix(libkernel): recognize listening sockets on macOS hosts
macOS does not support getsockopt with SO_ACCEPTCONN; it fails with
ENOPROTOOPT. So on macOS the guest's getsockopt of SO_ACCEPTCONN failed,
connect did not see that a stream socket was listening (an address of
another family failed with EAFNOSUPPORT instead of EOPNOTSUPP), and the
read event of a listening socket reported FIONREAD's 0 instead of the
waiting connection and did not ignore its low watermark.

On macOS the listening state is read from the SO_ACCEPTCONN flag of the
socket options that proc_pidfdinfo reports, and the three places that ask
go through NativeListening. Other hosts keep getsockopt.
2026-10-18 16:13:50 +03:00
Alexej Szpevák b40e0bfb80 fix(libkernel): report the accept queue length for a listening socket's read event
A read event on a listening socket took its data from FIONREAD, which a listening socket refuses on Linux, so kevent and sceKernelAddReadEvent reported 0 connections while saying one was ready. FreeBSD 11.4 gives a listening socket filt_solisten, which reports so_qlen, the completed connections waiting for accept. Ready now checks SO_ACCEPTCONN and on Linux reads a TCP listener's accept backlog from TCP_INFO, where tcp_get_info puts it in tcpi_unacked; with no host call for the count (Windows, macOS, a listener that is not TCP) it reports 1, the lower bound the readiness already implies.
2026-10-18 13:35:15 +02:00
Dean d704b808e3 Merge pull request #6828 from loyalburrito/claude/brave-ride-lz92qi
feat(ssl): run TLS 1.2 client connections over Mbed TLS
2026-10-18 18:58:26 +13:00
Dean Galvin 2edaf44a64 Merge main into claude/brave-ride-lz92qi 2026-10-18 17:20:58 +13:00
Dean Galvin 67e7043332 Merge main into feat/poll-files 2026-10-18 16:04:36 +13:00
HQasperandClaude Opus 5.5 6d4c7c3150 fix(libkernel): select on kqueues as kqueue_poll answers
A kqueue descriptor is readable while one of its events is triggered and
is never writable or exceptional, as FreeBSD's kqueue_poll answers, on
both hosts. On Windows select threw for it, and on Linux its /dev/null
placeholder was reported readable and writable.

A descriptor that stops being a socket, a kqueue or a pipe during the
wait now fails the call with EBADF when it was closed and is selected
again with the rest of the timeout when its number was reused, as
FreeBSD's kern_select looks every descriptor up again in each pass,
instead of throwing. On Windows a host descriptor that is not a pipe
throws when select starts, before waiting.

Depends on #7139.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-18 00:45:57 +02:00
Alexej Szpevák 74629458d3 feat(libkernel): poll descriptors 0 to 2 with the console model select uses
select takes descriptors 0 to 2 as a console title's terminal with no input: 0 is never readable and 1 and 2 are always writable. poll threw for them unless the host happened to attach a pipe, so the same title could select on its standard streams but not poll them. poll now gives the same answer, with POLLOUT, the one bit ttydev_poll reports for a writable terminal, for 1 and 2 and nothing for 0.
2026-10-18 00:45:56 +02:00