Commit Graph
78 Commits
Author SHA1 Message Date
Henrik RydgårdandClaude Opus 5.5 bd56e07bb0 sceNetInet: Fix the blocking socket waits on Windows
Headless only started Winsock (net::Init) for the debugger, so on Windows
every socket call failed with WSANOTINITIALISED. Start it always.

Winsock's select() fails on empty sets, where POSIX waits out the timeout, so
a select() used as a sleep (the VSH's Skype) returned an error at once. With
no host sockets to check, select and poll now just report nothing ready.

Look up host sockets without GetHostSocketFromInetSocket, which asserts on a
socket closed while a call waits for it, and whose -1 can't be caught with
< 0 on Windows, where SOCKET is unsigned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:04:09 +01:00
Henrik RydgårdandClaude Opus 5.5 be9383c08f sceNetInetPoll: The timeout is in milliseconds
Like POSIX poll(), as pspautotests net/inet/blocking shows. We took it as
microseconds, so every poll timeout was a thousand times too short.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:03:59 +01:00
Henrik RydgårdandClaude Opus 5.5 22e0a1a536 sceNetInet: Wait for blocking socket calls in emulated time
Host sockets are always non-blocking, so a game's blocking recv(), accept()
and so on came back with EAGAIN at once, and connect() and poll() blocked the
whole emulator in the host call instead. Now recv, recvfrom, send, sendto,
accept, connect, poll and select try once, and if the call would block on a
blocking socket (no SO_NBIO or MSG_DONTWAIT), the thread waits and a
CoreTiming event retries it every millisecond. It ends when the call completes
or fails, or when SO_RCVTIMEO/SO_SNDTIMEO runs out in emulated time.

Sockets accepted on Linux are made non-blocking too: unlike BSD and Windows,
Linux doesn't pass that on from the listening socket. select() rejects a
tv_usec of a second or more with EINVAL.

Hardware behaviour from pspautotests net/inet/blocking.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:03:59 +01:00
Henrik RydgårdandClaude Opus 5.5 72a0cd1879 sceNetInetSelect: Wait in emulated time instead of blocking the host
select() ran on the CPU thread with the guest's timeout (5.5 seconds when it
gave none), so the whole emulator stopped for as long as it waited. The VSH's
Skype uses select() with no sockets as a sleep, 0.65-0.95 s at a time, and ran
at a crawl: almost no emulated time passed, and the UI barely moved.

Now the sockets are checked without blocking. If none is ready, the thread
waits and a CoreTiming event polls again every millisecond until one is, or
the timeout runs out in emulated time. A null timeout now waits for as long as
it takes. Pending waits are saved in savestates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:02:03 +01:00
Henrik RydgårdandClaude Opus 5.5 455209b43e Net: Fix use-after-pop, the resolver after loads, inet sockaddr/poll
- The apctl, NpAuth and NpMatching2 event loops kept references to the
  front of their deque after popping it, so callbacks could get the
  next event's arguments. NpMatching2 also dereferenced its optional
  opt param when it was null.
- The resolver was left stopped after any savestate load or reboot,
  which broke Outrun 2006 (it relies on it starting out running).
- Getpeername/Getsockname with a namelen under 2 copied a negative size.
  They now write the PSP's 16-byte sockaddr truncated to namelen, with
  sa_len 16, as pspautotests net/inet/poll shows on hardware.
- Poll handed an fd that isn't open (-1) to FD_SET. It now reports
  POLLNVAL for it and counts it, as on hardware (net/inet/poll).
  Setsockopt read past a local u32 for larger options, and passed a
  negative optlen to the host. A zero cmsg_len looped forever.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 08:43:28 +01:00
Henrik RydgårdandClaude Opus 5.5 7dd1475ed7 HLE: Pass the MIPSState to syscalls and their implementations
HLEFunc and ReplaceFunc now take the MIPSState they run on. The dispatch
paths (both interpreters and every JIT backend) pass in the state they
belong to, and CallSyscall*, hleFinishSyscall and the HLE mips call
machinery use it instead of currentMIPS.

The wrappers in FunctionWrappers.h take the function as `auto` and call it
through HLECall, which also accepts an implementation with an extra leading
MIPSState * parameter and passes the state to it. Any other signature still
fails to compile, as before. PARAM/RETURN now refer to a local `mips`.

The HLE functions (and replacement functions) that used currentMIPS now take
the state that way. Callers outside a syscall's own frame - CoreTiming
events, the adhoc matching thread, dialogs, PPGe, the debugger UIs - pass
currentMIPS or &mipsr4k explicitly. The kernel's thread internals still use
currentMIPS.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-20 15:45:14 +02:00
Henrik RydgårdandClaude Opus 5.5 5080cb23b6 sceNetInet: Only let the ad hoc settings change bind addresses during ad hoc
- Fixes #22647

sceNetInetBind rewrote the address whenever the ad hoc server was set to
localhost (to 127.0.0.x, even an explicit address) or the built-in ad hoc
server was enabled (INADDR_ANY to the address facing the ad hoc server),
breaking infrastructure sockets. Both rewrites now only apply while
adhocctl is initialized, which keeps ad hoc as it was.

sceNetApctlGetInfo reported its IP from the same ad hoc-relative
getLocalIp(), so a localhost ad hoc server told infrastructure games their
IP was 127.0.0.x. It now uses the host interface's IP (getHostLocalIp(),
split out of getLocalIp()).

Adds the net/inet/bind test, which failed every bind under headless (whose
ad hoc server is localhost).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-20 08:59:03 +02:00
Henrik Rydgård 86fcfdc60a Add some new function names that were cracked from NIDs by zecoxao
He used Claude, never thought of this use case, but it's logical - it
can go reverse engineer the functions to come up with likely names,
making it easier to match the SHA1 hash. (NIDs are truncated SHA1 hashes
of names, except in firmwares later than around 3.50).
2026-09-10 15:52:53 -06:00
Henrik Rydgård c5e4d0d90d Rename the get-memory-pointer functions to make it clear where CPU exceptions can happen. 2026-08-12 14:06:16 +02:00
Henrik Rydgård 3c81d6b121 More manual Read_U32 cleanup
Buildfix
2026-08-11 10:28:36 +02:00
Henrik Rydgård cf8afb9490 Safety check in sceNetInetSelect 2026-03-13 10:36:59 +01:00
Henrik Rydgård a08b6c1340 More error code cleanup 2025-08-06 17:44:54 +02:00
Adam.N 0aa8e39b50 Reduce the number of lines a little bit. 2025-05-06 23:08:14 +07:00
Adam.N 4e2d5ca6de Only enforce blocking-mode on games that use blocking-mode. 2025-05-06 00:49:06 +07:00
Henrik Rydgård da7c99a585 sceNetInet: Implement per-thread errno. Reduce some log levels 2025-04-08 08:31:09 +02:00
Henrik Rydgård ebcf6be42c When (successfully) using dyn_dns, remove fixed lookups.
Additionally some various cleanup.
2025-04-08 00:32:40 +02:00
Henrik Rydgård 4e25f44eef Rename some module-related functions to include HLE where appropriate 2025-03-31 11:17:50 +02:00
Henrik Rydgård 28b2c7f540 HLE log rename part 1: Remove duplicate log functions. Return type should be determined by metadata. 2025-01-29 09:45:39 +01:00
Henrik Rydgård 57b6850ea0 Pause screen improvements 2025-01-22 11:50:01 +01:00
Henrik Rydgård e4de9dbfb5 Add some socket data in the debugger 2025-01-22 10:12:56 +01:00
Henrik Rydgård 2523690584 Flip around so sceDelayResult is always outermost. Start using HLECall. 2025-01-20 12:20:18 +01:00
Henrik Rydgård 86b3eadc16 Warning fixes, maybe test fix 2025-01-19 16:33:40 +01:00
Henrik Rydgård 9165711cef Convert more HLE logging to the hleLog system 2025-01-19 15:53:20 +01:00
Henrik Rydgård 5316ec7ef7 Fix more misuse of the hleLog* functions 2025-01-19 13:09:30 +01:00
Henrik Rydgård 7a0ec74c32 Merge pull request #19855 from oltolm/cmake
make compile with Clang/GCC on Windows
2025-01-17 15:13:52 +01:00
Henrik Rydgård 6c6ea2a355 Sockopt: Ignore case we can't support (SO_ONESBCAST) 2025-01-17 12:28:09 +01:00
Henrik Rydgård bfcef44c48 setsockopt refactor part #2 2025-01-17 09:31:38 +01:00
Henrik Rydgård 852c41d124 sockopt refactor part #1 2025-01-17 09:31:09 +01:00
Henrik Rydgård 1013be090c sceNetInet: Refactor errno handling and logging, so we always see how it changes 2025-01-12 14:57:51 +01:00
Henrik Rydgård c901486791 Removes another hacky behavior in sceNetInetGetErrno 2025-01-12 12:50:32 +01:00
Henrik Rydgård 016d66f866 sceNetInet: Stop resetting inetLastErrno to 0 in sceNetInetGetErrno()
This fixes MOHH on Windows.
2025-01-12 12:38:47 +01:00
Henrik Rydgård 364fc2ed6a More sceNetInet logging cleanup 2025-01-11 10:22:23 +01:00
Henrik Rydgård 54581441ea Start cleaning up logging in sceNetInet 2025-01-11 10:22:21 +01:00
AdamN c5e1ea71e0 oops 2025-01-11 09:24:39 +07:00
oltolm 9566065455 make compile on mingw-w64 2025-01-11 01:25:27 +01:00
AdamN ec99cb47bd Fix potential buffer size issue on sceNetInetGetsockname 2025-01-10 22:38:30 +07:00
AdamN cbe8c922a4 Fix potential buffer size issue on sceNetInetGetpeername 2025-01-10 22:25:25 +07:00
Henrik Rydgård 885724db83 Add comments (checked that no other host socket numbers leak to the game) 2025-01-10 14:54:45 +01:00
Henrik Rydgård e79fdaca57 Fix bug in sceNetInetPoll, similar to the previous select bug 2025-01-10 11:24:12 +01:00
AdamN e8bf2effc6 Changed Address Replacement log channel to WARN, because apparently Debug channel being disabled on non-Windows 2025-01-10 07:10:27 +07:00
AdamN 6335144392 Only do address replacement when built-in Adhoc Server is enabled. 2025-01-09 16:39:45 +07:00
Henrik Rydgård 0cec39d11f Add socket mapping for accept(). Don't know if games use it... 2025-01-08 19:36:01 +01:00
Henrik Rydgård 440fa80c5f Use the correct count parameter for select 2025-01-08 18:47:16 +01:00
Henrik Rydgård cddd3d439d Crashfix with asan, minor 2025-01-08 18:03:45 +01:00
Henrik Rydgård 77fcb181a5 Just some code formatting 2025-01-08 17:01:27 +01:00
Henrik Rydgård 728268bb3f Better CreateSocket errro handling 2025-01-08 16:35:09 +01:00
Henrik Rydgård c9c594462f Track non-blocking state 2025-01-08 16:25:44 +01:00
Henrik Rydgård b97b0e4cf6 Add Close method to socket manager 2025-01-08 16:25:15 +01:00
Henrik Rydgård a1744a6989 Add SocketManager::CreateSocket for convenience 2025-01-08 15:27:54 +01:00
Henrik Rydgård 155a9f9dbc Turn the socket manager into a class 2025-01-08 14:59:40 +01:00