sceNet translated only 21 host socket errors and reported every other one
as EIO. libkernel already owns the complete FreeBSD table in
GuestSockets::GuestErrorFromHost, so use it for net_error. The new check
makes a stream socket with the UDP protocol fail with EPROTONOSUPPORT (43)
instead of EIO (5).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Report the host IPv4 DNS servers of the interface sceNetCtlGetInfo
uses, through a helper libSceNetCtl exports, and return their count.
The signature and layout follow the OpenOrbis musl resolver and Net.h.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sceNetGetSockInfo returned 0 for a known socket and wrote nothing, so
callers read uninitialised bytes as the socket's endpoints. Monster
Hunter Wilds (PPSA24191) calls it after bind, connect and accept and
stores the local and remote address and port it reads back.
It now writes one 0xA0-byte record in the layout SharpProspero and
shadPS4 give: the socket id, the socket type, the local and remote
IPv4 address and port of the host socket in network byte order, the
SELF and NONBLOCK status flags, and the receive and send buffer sizes
sceNetGetsockopt reports for the socket. The other fields are 0. It
returns 1, the number of records written, and EINVAL for a null record
or an n below 1, as shadPS4 does.
An s below 0 lists the sockets as shadPS4 does: with a null record it
returns their number, otherwise it writes up to n records in socket
order and returns how many it wrote. Unlike shadPS4, which lists IPv6
sockets with zero addresses and ignores flags, an IPv6 socket fails
with EAFNOSUPPORT and is left out of the count and the list, and a
flags bit other than 0x40 fails with EINVAL. SharpProspero names 0x40
SockInfoTimeWait; closed sockets leave the table at once, so it lists
the same sockets. docs/dev/debt/libSceNet.md lists the fields left 0
and these differences.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implement sceNetShowRoute as a silent stub returning 0, matching the (void) signature in shadPS4 and the behavior of sceNetShowIfconfig and sceNetShowNetstat. Adds guest unit tests in GuestSceNet.cpp and updates technical debt documentation.
sceNetRecv, sceNetRecvfrom and sceNetRecvmsg on a datagram socket without a
local address waited in wait_for_local_address until the socket was bound,
connected or written to, because only a non-blocking socket made that wait
fail. FreeBSD 11.4 soreceive_dgram fails a MSG_DONTWAIT receive without data
with EWOULDBLOCK. The flags now reach wait_for_local_address and the test
covers an unbound socket.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
sceNetSend, sceNetSendto, sceNetSendmsg, sceNetRecv, sceNetRecvfrom and
sceNetRecvmsg 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 branch of
the test that expected EOPNOTSUPP now runs the checks of the other hosts.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The overlap audit against origin/main and the open pull requests found 39 of
the 193 declared exports that must not be declared here:
- 14 that origin/main already exports. The nid_patcher computes the NID of a
symbol from its name, and a name ending in _nid_postfix exports the NID of
the base name, so scePadOpen, sceNetInit and the rest are already there.
- 23 that an open pull request provides: #6832, #6847, #6852, #7846, #7881,
#7889, #7890, #6977 and #7690.
- 2 whose technical-debt file an open pull request creates: #7463 and #8094.
The scope is now 30 libraries and 154 exports.
AnyPS5 resolves a title's imports by NID, so a title that imports a system
function no library provides fails to load with an unresolved import. The
PS5 3.20 export inventory lists 193 such exports across 37 PS5 system
libraries AnyPS5 implements but does not provide.
Declare them as throwing stubs so those titles load and reach their next
blocker. Each declaration calls NotImplemented_nid_no_patch and returns 0;
none of them implements the function. Declarations with a credible
prototype use it and cite the source with a pinned commit, and the rest
are declared without parameters, which resolves the import without making
an ABI claim. The technical-debt files record the limitation per library.
libSceMbus and libSceSystemService are left out because pull request #7821
declares them. libSceAgc is left out because its exports are versioned, so
the 3.20 NID names a different symbol from the one AnyPS5 ships.
libSceAvPlayer.native is left out because it compiles libSceAvPlayer's
Export.cpp.
Names and NIDs come from the PS5 3.20 export inventory at
https://github.com/DNNDHH/PS5-3.20_Libs/tree/b2a77c09cd71c01f34c790cfbe98c751a13262ad
On PS4 firmware 10.71 sceNetInetPtonEx reads IPv4 text the way
inet_aton does, not the way sceNetInetPton does: "1.2.3" is 1.2.0.3,
"127.1" is 127.0.0.1, hex and octal parts are accepted, a part value
wraps at 32 bits ("1.4294967296" is 1.0.0.0) and the text ends at the
first whitespace. Two differences from BSD inet_aton were measured: a
part starting with "09" is decimal ("0989" is 989), and an octal part
containing 8 or 9 fails.
The flags argument changed nothing for 0, every single bit up to
0x100, 0x10000, 0x80000000 and -1, so it is ignored instead of
throwing. IPv6 still converts as sceNetInetPton does, which matches
the console.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Implement sceNetGetIfName, sceNetGetRandom, sceNetMemoryAllocate and
sceNetMemoryFree with the signatures shadPS4 uses, and cover them in
guest_sce_net_tests.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
sceNetSetsockopt and sceNetGetsockopt failed with EOPNOTSUPP
(0x8041012d) for every level other than SOL_SOCKET, so TCP_NODELAY
could not be set on a libSceNet stream socket; libkernel setsockopt on
such a socket failed the same way. FreeBSD 11.4's sosetopt and sogetopt
(uipc_socket.c) pass any other level to the protocol: tcp_ctloutput
sets TF_NODELAY and returns 0, a get returns t_flags & TF_NODELAY (4),
an option it does not know fails with ENOPROTOOPT, and on a UDP or raw
socket ip_ctloutput and rip_ctloutput fail the IPPROTO_TCP level with
EINVAL. Set TCP_NODELAY on the host socket of a stream socket, read it
back as TF_NODELAY, fail other IPPROTO_TCP options on a stream socket
with ENOPROTOOPT (0x8041012a), and fail the IPPROTO_TCP level with
EINVAL on other socket types, as libkernel already does for its own
sockets.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PS4 firmware 10.71 converts "1.2.3.4" followed by a space, tab, LF,
VT, FF or CR, and anything after it ("1.2.3.4 x"), to 1.2.3.4 and
returns 1, where host inet_pton returns 0. Leading whitespace, other
trailing bytes (0x01, 0xa0), "1.2.3 " and IPv6 text with whitespace
still fail there.
A failed conversion leaves the destination and sceNetErrnoLoc
unchanged on the console; Winsock inet_pton writes the parsed prefix
before failing, so the conversion now goes through a local buffer.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sceNetUsleep fails with EINVAL for a negative count and otherwise sleeps
through libkernel's sceKernelUsleep, a cancellation point. sceNetInetPtonEx
converts as sceNetInetPton does when its flags are 0 and throws for any
other flags, whose meaning is unknown. The signatures follow shadPS4 and
are recorded as unverified in the libSceNet technical debt.
MXGP 26 (PPSA30839) opens TCP sockets with libkernel's socket() and
later closes them with sceNetSocketClose. libSceNet only looked in its
own socket table, so every one of those closes failed with
SCE_NET_ERROR_EBADF and the host socket stayed open. On the console both
calls work on the same kernel sockets.
A descriptor libSceNet does not own but libkernel has open as a socket
is now closed through libkernel's close(). Anything else still fails
with EBADF. The fallback runs after g_mutex is released, because
libkernel's close() first asks libSceNet's socket closer, which takes it.
guest_sce_net closes a libkernel TCP socket with sceNetSocketClose,
checks that libkernel no longer has it open, and checks that a second
close fails with EBADF.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MXGP 26 (PPSA30839) opens TCP sockets with libkernel's socket() and
turns on TCP_NODELAY with sceNetSetsockopt. libSceNet only looked in its
own socket table, so the call failed with SCE_NET_ERROR_EBADF. On the
console both calls work on the same kernel sockets.
A descriptor libSceNet does not own but libkernel has open as a socket
now goes to libkernel's setsockopt(), which answers the options it
models. Anything else still fails with EBADF. The fallback runs after
g_mutex is released.
guest_sce_net sets SO_SNDBUF on a libkernel TCP socket through
sceNetSetsockopt, and checks that the call fails with EBADF once the
socket is closed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Windows answers a SYN to a closed port with a RST and then retransmits
the SYN, so connect to a closed loopback port takes about 2 s before
ECONNREFUSED; FreeBSD fails at once. PS5VR (PPSA99177) makes about 33
such connects to 127.0.0.1:17600 and reaches its home screen 45 s late.
When no socket listens on the destination port (GetExtendedTcpTable),
a loopback connect now sets SIO_TCP_INITIAL_RTO with no SYN
retransmissions and fails at once. A port with a listener keeps the
retransmissions: Windows also answers a SYN to a full accept backlog
with a RST, and the retransmission connects once the server accepts,
as the console's does after FreeBSD drops the SYN.
guest_refused_connect requires ECONNREFUSED in under a second for a
closed port through libkernel connect and sceNetConnect, and a second
connect to a listener with backlog 1 to succeed once the server accepts
the first, through both.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
When the address came during the wait, the host receive that followed
waited its whole SO_RCVTIMEO again, so a receive could take up to twice
the timeout. FreeBSD's soreceive_dgram sleeps once per timeout. Now the
receive waits for a datagram with WSAPoll only for what is left of the
timeout, and fails with EAGAIN when it runs out, as before. Nothing
changes when the socket already had an address or has no timeout.
A receive on an unbound datagram socket checked the host socket every
10 ms, so it went on waiting up to 10 ms after another thread's bind,
connect or send had named the socket. sceNetBind now wakes the waiting
receives. On Windows a datagram connect or a send marks the socket bound
and wakes them once the host socket has its local address; a raw socket
that a send leaves without one stays unmarked and keeps waiting.
On Windows a receive on a datagram socket with no local address waits
for one. A sceNetShutdown of the receive side now ends that wait, and
later receives return 0 at once; a zero-length receive returns 0 without
waiting. FreeBSD's soreceive_dgram returns 0 in both cases. Before, a
thread blocked in such a receive kept waiting after the socket was shut
down.
With libSceNet sockets on ordinary descriptor numbers (#4391), poll on a
libSceNet socket threw "neither a socket nor a pipe": poll only knew
libkernel sockets and pipes, while select already asks libSceNet through
its poller. libSceNet now lends libkernel the host socket behind a
descriptor, together with an owner that keeps it open, so poll puts it in
the same WSAPoll or poll call as libkernel sockets. ProsperoLight
(PPSA99002) stopped here on Linux and now reaches its PC list.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EvDbpwUPTa78oCAJqe7m9K