Skip to content

fix(libSceNet): answer a zero-length stream receive on Linux without waiting for data - #2276

Open
Thimo188 wants to merge 2 commits into
mainfrom
upstream-pr/28541
Open

Thimo188 wants to merge 2 commits into
mainfrom
upstream-pr/28541

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#28541, originally opened by Dr-Coconut.

Source commit: 5af425306c2c3e679b00d9ed146ad52e91364d75. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

On Linux a zero-length sceNetRecv, sceNetRecvfrom or sceNetRecvmsg on a connected TCP socket went to the host, and Linux's tcp_recvmsg waits for data even when nothing was asked for, so the call blocked until the peer sent something (or the receive timeout ran out). FreeBSD 11.4's soreceive_generic returns 0 at once. Windows already answers this case without the host (boykopovar#8686's check in wait_for_local_address); libkernel's recv does too (ReceiveAnsweredHere).

That check moves into empty_stream_receive, which Windows and Linux share: a connected socket with no pending error or hang-up gets 0 without waiting or consuming data, and a socket on which sceNetConnect was never called and that was not accepted gets ENOTCONN; the other states still go to the host. On Linux wait_for_local_address is just that check for stream sockets, so the three receive functions call it on every host; macOS is not changed.

NetEmptyStream.cpp (net_empty_stream_*, 24 cases: empty, MSG_DONTWAIT, MSG_PEEK, non-blocking, queued data, null buffer, error states and a queued datagram, for each of the three calls) was registered on Windows only; it now runs on Linux too. The debt entry for the states that still use the host now names the hosts.

Tested

Commit 8ed57e1 on main 4a7fd1c, Release, in a workflow on my fork: https://github.com/Dr-Coconut/AnyPS5/actions/runs/46693583719

  • Linux (GitHub-hosted ubuntu-latest, image ubuntu-26.04, GCC 15.2.0), with the change: all 24 net_empty_stream_* tests pass, and so does guest_sce_net.
  • Linux with libSceNet's Export.cpp restored to main and the test registration kept: 15 of the 24 fail, every empty, dontwait, peek, nonblocking and nullbuf case of the three calls ("zero-length receive waited for peer data" or "did not return zero"); queued, errors and datagram pass, as the host already answers those.
  • Windows (GitHub-hosted windows-latest, image windows-2025-vs2026, WinLibs GCC 15.2.0 15.2.0posix-14.0.0-ucrt-r7), with the change: all 24 and guest_sce_net pass (the Windows path only moved into the shared function).

Not run on macOS. No title tested. tools/check_conventions.py passes. tools/pr_overlap.py --branch reported no overlap among the open pull requests it could merge; it could not compare eight that conflict with main. Compared by hand: boykopovar#12682, boykopovar#12688, boykopovar#12700 and boykopovar#12965 rework blocking transfers and connects on Windows; boykopovar#5836 adds peer-socket types; boykopovar#16826 keeps close-on-exec in fcntl; boykopovar#18108 changes socket options; boykopovar#23975 adds a DNS override. None of them changes the zero-length receive path.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of zero-length TCP receives on Linux and other non-Apple platforms, including disconnected sockets and sockets with pending errors. These receives now report appropriate connection errors or return without data when applicable.
  • Tests
    • Enabled the empty-stream receive tests on Linux.
  • Documentation
    • Added a note describing platform behavior and compatibility limitations.

Dr-Coconut and others added 2 commits December 1, 2026 21:42
…waiting for data

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… macOS, so the portability build has the check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 3, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Empty stream receive handling

Layer / File(s) Summary
Implement and validate cross-platform receive handling
core/libs/prx/libSceNet/Export.cpp, core/libs/prx/libSceNet/CMakeLists.txt, docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
The receive functions now use local-address waits on every platform. Empty stream receives use the platform-specific check, and Linux now configures the related test block. A change note records the described platform cases and FreeBSD reference.

Possibly related PRs

  • Thimo188/AnyPS5#2277: Adds zero-length receive handling for empty bound datagram sockets in the same receive APIs and on the same hosts.

Change: Bug fix

Merge Risk: Minimal · up to 5af42

This change makes zero-length TCP receives behave consistently on Linux and Windows and enables the related tests on Linux. No merge-blocking risk was identified.

Security architecture risk: Minimal · up to 5af42

On Linux, libSceNet can now complete an eligible zero-length stream receive without waiting for the peer or consuming queued data. The change uses the same guest socket lookup and output validation, and leaves datagram and nonempty receives on their existing paths.

Security review details

Security Blast Radius

  • inferred — The changed decision is scoped to the socket resolved for a guest zero-length stream receive. It adds no listener or destination and does not let the caller select a host handle independently of the guest descriptor lookup.

Trust Boundaries and Controls

  • observed — Guest-supplied flags, descriptor, and applicable buffer arguments are checked before the local result. On the early-success path, recvfrom uses checked guest copies for the length output, and recvmsg validates the message header for writing before updating it.

Rollout and rollback

  • inferred — The behavior is selected by the build platform, not an operator setting. No operator action or state migration is indicated; reverting the code restores the prior Linux behavior in which the native receive determined when the call completed.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 3
  • Waived: $0.75 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 051de494-82bd-4d0f-a6d7-a7b3bc319caf
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and 5af4253.

Files selected for processing: 3

  • core/libs/prx/libSceNet/CMakeLists.txt
  • core/libs/prx/libSceNet/Export.cpp
  • docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md

@github-actions github-actions Bot added prx Other PRX libraries build CMake, submodules, 3rdparty docs Documentation labels Dec 5, 2026
@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 1 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 4 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 5 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 6 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 7 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 8 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 9 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 10 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 11 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 12 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 13 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 14 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 15 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 16 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 17 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 18 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 19 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md
PR 20 docs/dev/debt/changes/fix-libscenet-empty-stream-receive-linux.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build CMake, submodules, 3rdparty docs Documentation prx Other PRX libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants