feat(libSceRudp): bind, listen and accept as a firmware 13.42 run shows #13799

Merged
zaryabzip merged 4 commits from upstream-pr/13799 into main 2026-11-01 01:22:11 +00:00
zaryabzip commented 2026-10-31 07:14:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-31T07:14:48Z.


What

sceRudpBind, sceRudpSetEventHandler, sceRudpListen and sceRudpAccept follow @BunnyFl's firmware 13.42 runs of the real exports (first, socket records), done under an emulator with imports stubbed, not on a console. This is the Bind follow-up that #13718 mentions; #13718 has merged, so every commit here is new.

Export Checks, in order Answer here
sceRudpBind(int ctxId, int socketId, uint16_t vport, uint8_t muxMode) not initialized 0x80770001; negative id or socket 0x80770004; mux mode other than 1 or 2 0x80770006; unknown or terminated id 0x80770003; listening 0x80770011; second bind 0x8077001D; a mux mode other than that of the contexts on the socket 0x80770006; mux mode 1 with vport 0 0x80770015; with mux mode 2, a vport in use on the socket 0x80770017 0; with mux mode 2, vport 0 takes the next free vport above the last one handed out on the socket, from 0x2711
sceRudpSetEventHandler(handler, arg) not initialized; null handler 0x80770022 0; sceRudpEnd clears it
sceRudpListen(int ctxId, int backlog) not initialized; negative id or backlog of 0 or less 0x80770004; no handler 0x80770022; unknown id; not bound with mux mode 2 0x80770011; second listen 0x80770021 0, keeping a backlog of at most 0x80
sceRudpAccept(ctxId, handler, arg, int* newCtxId, addr, addrLen, vport) not initialized; negative id or null newCtxId 0x80770004; unknown id; not listening 0x80770011 no peer ever connects here: 0x80770016 (WOULDBLOCK) while option 7 is set, as by default; otherwise it waits until sceRudpTerminate ends the context and returns 0x80770014, as the run did

main declared Bind as (ctxId, vport, transport, port), which the run shows is wrong, and Listen and Accept without parameters. The second run settled the socket records:

  • Records: a socket's record exists while contexts are bound to it. It keeps no mux mode of its own: a bind is compared with its contexts'. Only mux mode 2 tracks vports, so two mux mode 1 contexts can share one. A failed bind leaves the context unbound and creates no record.
  • Counter: it holds the last vport handed out. Vport 0 skips vports bound by hand, and an explicit vport doesn't move it. It goes with the record, so a socket whose last context left starts at 0x2711 again; while another context stays, a freed 0x2711 can be bound by hand but isn't handed out again.
  • sceRudpTerminate: a bound context that isn't listening frees its vport, and the record if it was the last, before returning. A listening context's id is gone at once, but its vport and the record are held until the next sceRudpProcessEvents, which now releases them.

Two cases still throw std::runtime_error, as the library does for its other narrow unmeasured cases:

  • an automatic vport past 0xFFFF: the disassembly gives 0x2710 next and 0x80770018 when none is free, but that wasn't run;
  • a waiting accept ended by sceRudpEnd.

The test pins neither. When a socket's record goes, the module's next sceRudpProcessEvents calls the sceRudpSetEventHandler handler with (2, socketId, 0, 0, 0, 0, arg). That handler is typed here as the four-argument context handler, so the call isn't made; the new sceRudpTerminate debt entry records it with the rest of what isn't modelled. sceRudpGetLocalInfo stays throwing: on a bound context the console copies the address from sceNetGetsockname, which this library doesn't reach. libSceRudp goes from 31 to 33 of 35.

The new GuestRudpListen.cpp covers each measured check in order before sceRudpInit, on bound, listening, unbound and mux mode 1 contexts, after sceRudpTerminate and after sceRudpEnd. That includes the rows the second run gave for the order: a bound context answers 0x8077001D to arguments that fail a socket check, a listening one 0x80770011, and mux mode 1 with vport 0 on a mux mode 2 socket 0x80770006. It also covers:

  • the counter: 0x2711, 0x2712, then 0x2713 after 0x2711 is freed and bound again by hand, skipping a vport bound by hand, and 0x2711 again after the last context leaves;
  • mux mode changing both ways once a socket's last context leaves, and two mux mode 1 contexts on one vport;
  • a listening context's vport and socket held until sceRudpProcessEvents(0) and free after it;
  • a blocking accept cancelled by sceRudpTerminate from another thread.

It resolves Listen and Accept at runtime through function types that match the new declarations, so it builds on main and aborts there at its first check. GuestRudpContextLifecycle.cpp changes three lines: SetEventHandler before init now returns NOT_INITIALIZED, and its two binds after initialization use mux mode 2, because mux mode 0 is rejected.

Overlap, rechecked with git merge-tree against main 73f4f7e06e and every open pull request that merges with it:

  • #11042 deletes the sceRudpActivate block in GuestRudpContextLifecycle.cpp right above the sceRudpBind(ctx, 0, 0, 0) line that this changes, so whichever merges second needs a one-line rebase.
  • My #13814 adds a helper and changes sceRudpEnd next to the lines this adds there, and both add a debt entry at the same place. I'll rebase whichever of the two merges second.
  • @ntamas94's docs-only #13844 adds a debt entry at the same place as this one.
  • Everything else merges cleanly, #13871 included.

Tested

Windows 11 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) and Ubuntu 24.04 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1).

  • The head 651808a48b merged into main 73f4f7e06e:
    • No warnings. Every file that includes libSceRudp/include/Api.hpp rebuilds with no warnings, and so does each header compiled on its own.
    • ctest -R "guest_rudp|rudp_poll": 8 of 8 pass on WSL2 and 9 of 9 on Windows (plus rudp_poll_wait_exception). guest_offline_imports passes, and guest_rudp_listen passes 3 of 3 on --repeat until-fail:3.
    • Baseline: the previous head 9c423e59bd with only the new GuestRudpListen.cpp aborts on both hosts with sceRudpBind: a bind failing more than one socket check, the throw this replaces (Windows exit 0xc0000409, Linux SIGABRT).
    • Mutants, each alone, each failing on both hosts with its own message:
      • sceRudpTerminate freeing a listening context at once: a listening context's vport was freed before sceRudpProcessEvents.
      • no skipping of vports bound by hand: vport 0 did not skip a vport bound by hand.
      • the listening check after the bound check: a listening context did not answer NOT_ACCEPTABLE to a bind.
      • a record kept after its last context leaves: a bind expected to succeed failed.
  • Earlier heads, on earlier main commits: on that main with only the new test file and its CMakeLists.txt block, the test builds and then aborts at its first check, a handler was set before sceRudpInit, on both hosts.
  • tools/check_conventions.py passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5095490305 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13799). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-31T07:14:48Z. --- ### What `sceRudpBind`, `sceRudpSetEventHandler`, `sceRudpListen` and `sceRudpAccept` follow @BunnyFl's firmware 13.42 runs of the real exports ([first](https://github.com/boykopovar/AnyPS5/issues/13682#issuecomment-6537745577), [socket records](https://github.com/boykopovar/AnyPS5/issues/13682#issuecomment-6543610064)), done under an emulator with imports stubbed, not on a console. This is the `Bind` follow-up that #13718 mentions; #13718 has merged, so every commit here is new. | Export | Checks, in order | Answer here | |---|---|---| | `sceRudpBind(int ctxId, int socketId, uint16_t vport, uint8_t muxMode)` | not initialized `0x80770001`; negative id or socket `0x80770004`; mux mode other than 1 or 2 `0x80770006`; unknown or terminated id `0x80770003`; listening `0x80770011`; second bind `0x8077001D`; a mux mode other than that of the contexts on the socket `0x80770006`; mux mode 1 with vport 0 `0x80770015`; with mux mode 2, a vport in use on the socket `0x80770017` | 0; with mux mode 2, vport 0 takes the next free vport above the last one handed out on the socket, from 0x2711 | | `sceRudpSetEventHandler(handler, arg)` | not initialized; null handler `0x80770022` | 0; `sceRudpEnd` clears it | | `sceRudpListen(int ctxId, int backlog)` | not initialized; negative id or backlog of 0 or less `0x80770004`; no handler `0x80770022`; unknown id; not bound with mux mode 2 `0x80770011`; second listen `0x80770021` | 0, keeping a backlog of at most 0x80 | | `sceRudpAccept(ctxId, handler, arg, int* newCtxId, addr, addrLen, vport)` | not initialized; negative id or null `newCtxId` `0x80770004`; unknown id; not listening `0x80770011` | no peer ever connects here: `0x80770016` (`WOULDBLOCK`) while option 7 is set, as by default; otherwise it waits until `sceRudpTerminate` ends the context and returns `0x80770014`, as the run did | `main` declared `Bind` as `(ctxId, vport, transport, port)`, which the run shows is wrong, and `Listen` and `Accept` without parameters. The second run settled the socket records: - **Records:** a socket's record exists while contexts are bound to it. It keeps no mux mode of its own: a bind is compared with its contexts'. Only mux mode 2 tracks vports, so two mux mode 1 contexts can share one. A failed bind leaves the context unbound and creates no record. - **Counter:** it holds the last vport handed out. Vport 0 skips vports bound by hand, and an explicit vport doesn't move it. It goes with the record, so a socket whose last context left starts at 0x2711 again; while another context stays, a freed 0x2711 can be bound by hand but isn't handed out again. - **`sceRudpTerminate`:** a bound context that isn't listening frees its vport, and the record if it was the last, before returning. A listening context's id is gone at once, but its vport and the record are held until the next `sceRudpProcessEvents`, which now releases them. Two cases still throw `std::runtime_error`, as the library does for its other narrow unmeasured cases: - an automatic vport past 0xFFFF: the disassembly gives 0x2710 next and `0x80770018` when none is free, but that wasn't run; - a waiting accept ended by `sceRudpEnd`. The test pins neither. When a socket's record goes, the module's next `sceRudpProcessEvents` calls the `sceRudpSetEventHandler` handler with `(2, socketId, 0, 0, 0, 0, arg)`. That handler is typed here as the four-argument context handler, so the call isn't made; the new `sceRudpTerminate` debt entry records it with the rest of what isn't modelled. `sceRudpGetLocalInfo` stays throwing: on a bound context the console copies the address from `sceNetGetsockname`, which this library doesn't reach. libSceRudp goes from 31 to 33 of 35. The new `GuestRudpListen.cpp` covers each measured check in order before `sceRudpInit`, on bound, listening, unbound and mux mode 1 contexts, after `sceRudpTerminate` and after `sceRudpEnd`. That includes the rows the second run gave for the order: a bound context answers `0x8077001D` to arguments that fail a socket check, a listening one `0x80770011`, and mux mode 1 with vport 0 on a mux mode 2 socket `0x80770006`. It also covers: - the counter: 0x2711, 0x2712, then 0x2713 after 0x2711 is freed and bound again by hand, skipping a vport bound by hand, and 0x2711 again after the last context leaves; - mux mode changing both ways once a socket's last context leaves, and two mux mode 1 contexts on one vport; - a listening context's vport and socket held until `sceRudpProcessEvents(0)` and free after it; - a blocking accept cancelled by `sceRudpTerminate` from another thread. It resolves `Listen` and `Accept` at runtime through function types that match the new declarations, so it builds on `main` and aborts there at its first check. `GuestRudpContextLifecycle.cpp` changes three lines: `SetEventHandler` before init now returns `NOT_INITIALIZED`, and its two binds after initialization use mux mode 2, because mux mode 0 is rejected. Overlap, rechecked with `git merge-tree` against `main` 73f4f7e06e and every open pull request that merges with it: - #11042 deletes the `sceRudpActivate` block in `GuestRudpContextLifecycle.cpp` right above the `sceRudpBind(ctx, 0, 0, 0)` line that this changes, so whichever merges second needs a one-line rebase. - My #13814 adds a helper and changes `sceRudpEnd` next to the lines this adds there, and both add a debt entry at the same place. I'll rebase whichever of the two merges second. - @ntamas94's docs-only #13844 adds a debt entry at the same place as this one. - Everything else merges cleanly, #13871 included. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 (WinLibs MinGW-w64 GCC 15.2.0 UCRT r7, CMake 4.3.1, Ninja 1.13.2) and Ubuntu 24.04 on WSL2 (GCC 13.3.0, CMake 3.28.3, Ninja 1.11.1). - The head 651808a48b merged into `main` 73f4f7e06e: - No warnings. Every file that includes `libSceRudp/include/Api.hpp` rebuilds with no warnings, and so does each header compiled on its own. - `ctest -R "guest_rudp|rudp_poll"`: 8 of 8 pass on WSL2 and 9 of 9 on Windows (plus `rudp_poll_wait_exception`). `guest_offline_imports` passes, and `guest_rudp_listen` passes 3 of 3 on `--repeat until-fail:3`. - Baseline: the previous head 9c423e59bd with only the new `GuestRudpListen.cpp` aborts on both hosts with `sceRudpBind: a bind failing more than one socket check`, the throw this replaces (Windows exit 0xc0000409, Linux SIGABRT). - Mutants, each alone, each failing on both hosts with its own message: - `sceRudpTerminate` freeing a listening context at once: `a listening context's vport was freed before sceRudpProcessEvents`. - no skipping of vports bound by hand: `vport 0 did not skip a vport bound by hand`. - the listening check after the bound check: `a listening context did not answer NOT_ACCEPTABLE to a bind`. - a record kept after its last context leaves: `a bind expected to succeed failed`. - Earlier heads, on earlier `main` commits: on that `main` with only the new test file and its `CMakeLists.txt` block, the test builds and then aborts at its first check, `a handler was set before sceRudpInit`, on both hosts. - `tools/check_conventions.py` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13799
No description provided.