fix(libSceNet): preserve successful stream recvfrom results #4394

Merged
AaravMehta-07 merged 2 commits from upstream-pr/4394 into main 2026-10-12 18:23:14 +00:00
AaravMehta-07 commented 2026-10-12 09:07:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AaravMehta-07 on 2026-10-12T09:07:28Z.


What

Recognize AF_UNSPEC as an absent native address in the existing address converter: set the output length to zero without touching the address buffer. This keeps a successful sceNetRecvfrom result when a TCP receive returns no sender, matching the no-sender result sceNetRecvmsg already produces. Other unsupported native families still fail conversion. Previously a TCP read with a sender buffer consumed the bytes, then returned NET_EAFNOSUPPORT instead of the received byte count.

A guest-export loopback probe on unpatched code received X but returned -2143223505 with errno 47 and address length 16. With this change it returns 1, preserves errno 123, reports address length 0 and leaves the address canary unchanged.

This is the SceNet counterpart of libkernel's already-merged #3957. FreeBSD 11.4 kern_recvit reports zero name length when no sender is returned. Console hardware behavior has not been measured. No fake peer address or silent stub is introduced.

The guest regression covers IPv4/IPv6 TCP in both directions, zero/short/full/oversized address capacities, zero-byte and ordinary peeks, consuming reads, EOF, unchanged address buffers and preserved errno. It also checks that an invalid null length is rejected before consuming data and that a null address leaves an unrelated length unchanged. Existing datagram tests protect UDP behavior.

The conversion-helper change is independent of #4092 (receive timeouts), #4112 (errno propagation) and #4272 (receive write guards); it leaves their receive-call edits alone.

Tested

  • Windows 11, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON: full CMake configuration and default build passed. All 14 networking/address CTest cases passed; guest_sce_net passed ten repeated runs.
  • Ubuntu under WSL2, GCC 15.2.0, Release, BUILD_TESTING=ON: full CMake configuration and default build passed. All 15 networking/address CTest cases passed (the Windows selection plus guest_select); guest_sce_net passed ten repeated runs.
  • Red/green: the augmented guest_sce_net aborts on unpatched code on Windows and Ubuntu under WSL2, and passes with this fix on both.
  • check_conventions.py passed with this title/body; pr_overlap.py reported no overlap with open pull requests. Three-way merges with #4092, #4112 and #4272 were also clean.
  • Guest-export loopback tests only; no commercial title or console hardware tested.

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; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4827234972 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4394). Originally posted by [AaravMehta-07](https://github.com/AaravMehta-07) on 2026-10-12T09:07:28Z. --- ### What Recognize `AF_UNSPEC` as an absent native address in the existing address converter: set the output length to zero without touching the address buffer. This keeps a successful `sceNetRecvfrom` result when a TCP receive returns no sender, matching the no-sender result `sceNetRecvmsg` already produces. Other unsupported native families still fail conversion. Previously a TCP read with a sender buffer consumed the bytes, then returned `NET_EAFNOSUPPORT` instead of the received byte count. A guest-export loopback probe on unpatched code received `X` but returned `-2143223505` with errno 47 and address length 16. With this change it returns 1, preserves errno 123, reports address length 0 and leaves the address canary unchanged. This is the SceNet counterpart of libkernel's already-merged #3957. FreeBSD 11.4 [`kern_recvit`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/sys/kern/uipc_syscalls.c#L1049-L1069) reports zero name length when no sender is returned. Console hardware behavior has not been measured. No fake peer address or silent stub is introduced. The guest regression covers IPv4/IPv6 TCP in both directions, zero/short/full/oversized address capacities, zero-byte and ordinary peeks, consuming reads, EOF, unchanged address buffers and preserved errno. It also checks that an invalid null length is rejected before consuming data and that a null address leaves an unrelated length unchanged. Existing datagram tests protect UDP behavior. The conversion-helper change is independent of #4092 (receive timeouts), #4112 (errno propagation) and #4272 (receive write guards); it leaves their receive-call edits alone. ### Tested - Windows 11, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`: full CMake configuration and default build passed. All 14 networking/address CTest cases passed; `guest_sce_net` passed ten repeated runs. - Ubuntu under WSL2, GCC 15.2.0, Release, `BUILD_TESTING=ON`: full CMake configuration and default build passed. All 15 networking/address CTest cases passed (the Windows selection plus `guest_select`); `guest_sce_net` passed ten repeated runs. - Red/green: the augmented `guest_sce_net` aborts on unpatched code on Windows and Ubuntu under WSL2, and passes with this fix on both. - `check_conventions.py` passed with this title/body; `pr_overlap.py` reported no overlap with open pull requests. Three-way merges with #4092, #4112 and #4272 were also clean. - Guest-export loopback tests only; no commercial title or console hardware tested. ### Checklist - [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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
xXPBSXx commented 2026-10-12 09:55:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T09:55:34Z.


Windows test: head 74defef67 merged onto current main 9aa5fd290 (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j4: the full build finished with 0 errors; ctest -R guest_sce_net: 1/1 passed (guest_sce_net, 0.39 s, includes the new test code in core/libs/tests/GuestSceNet.cpp); python tools/check_conventions.py --base upstream/main: passed. I did not run the new test against main without the change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6121911287 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4394#issuecomment-6121911287). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T09:55:34Z. --- Windows test: head `74defef67` merged onto current `main` `9aa5fd290` (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, `-j4`: the full build finished with 0 errors; `ctest -R guest_sce_net`: 1/1 passed (`guest_sce_net`, 0.39 s, includes the new test code in `core/libs/tests/GuestSceNet.cpp`); `python tools/check_conventions.py --base upstream/main`: passed. I did not run the new test against `main` without the change. AI-assisted (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!4394
No description provided.