fix(libkernel): answer a zero-length recvmsg on a stream socket as recv does #24944

Merged
Dr-Coconut merged 1 commit from upstream-pr/24944 into main 2026-11-27 15:34:30 +00:00
Dr-Coconut commented 2026-11-21 12:02:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dr-Coconut on 2026-11-21T12:02:55Z.


What

recv and recvfrom answer a zero-length receive on a stream socket without the host: 0 when it is connected, ENOTCONN when it is not, as FreeBSD 11.4's soreceive_generic does when nothing is queued. recvmsg asked the host instead, after WaitForTransfer, so on an empty connected socket it failed with EAGAIN under MSG_DONTWAIT or on a non-blocking socket and blocked otherwise, and an unconnected socket did not get ENOTCONN; the libkernel debt file records this ("asks the host in the stream cases").

  • recvmsg takes the same ReceiveAnsweredHere answer before waiting when a stream socket's iovecs total zero bytes.
  • A Unix stream socket with a control buffer for passed descriptors still asks the host: with data queued, soreceive_generic goes on to deliver the queued control messages even for a zero-length request.

GuestTcp.cpp's ReceiveAnsweredWithoutTheHost gets the recvmsg cases beside the recv and recvfrom ones: ENOTCONN on an unconnected socket with and without MSG_DONTWAIT, 0 on an empty connected socket with and without it, and 0 with data queued, the data still there afterwards. The debt fragment rewrites the entry to cover recvmsg and records the control-buffer case and the pending socket error these answers do not return.

Tested

Commit 14bebd06fc on main b1ef52c45e, Release, in a workflow on my fork: https://github.com/Dr-Coconut/AnyPS5/actions/runs/45036318072 (the run on the first version, 7db64acc9a on 26194f0fcf, gave the same results: https://github.com/Dr-Coconut/AnyPS5/actions/runs/44901177525)

  • Windows (GitHub-hosted windows-latest, image windows-2025-vs2026, WinLibs GCC 15.2.0 15.2.0posix-14.0.0-ucrt-r7) and Linux (GitHub-hosted ubuntu-latest, image ubuntu-26.04, GCC 15.2.0), with the change: guest_tcp, guest_udp, guest_socket_pair and guest_kernel_socket_dontwait pass on both.
  • With Udp.cpp restored to main and the new cases kept, on both: guest_tcp aborts (Windows 0xc0000409, Linux Subprocess aborted); the other three pass.

Not run on macOS. No title tested. tools/check_conventions.py passes, and tools/debt_fold.py --check accepts the fragment. Rebased onto main after #23341 changed ReceiveShut to ReceiveEnded on the line before this change; the branch keeps ReceiveEnded. tools/pr_overlap.py --branch merged 26 open pull requests that share files with this branch and reported #18197, which adds the arrival-time setup between stamps and the condition changed here, so they overlap textually. It could not compare seven that conflict with main; compared by hand, #8605 changes GuestSockets::Stat, #11896 replaces the host call inside the block this skips, #22048 adds a check inside that block, and #12682, #12688, #12700 and #12965 rework blocking connects and waits on Windows without touching these lines.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5427599222 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24944). Originally posted by [Dr-Coconut](https://github.com/Dr-Coconut) on 2026-11-21T12:02:55Z. --- ### What `recv` and `recvfrom` answer a zero-length receive on a stream socket without the host: 0 when it is connected, `ENOTCONN` when it is not, as FreeBSD 11.4's [`soreceive_generic`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/uipc_socket.c#L1566-L1578) does when nothing is queued. `recvmsg` asked the host instead, after `WaitForTransfer`, so on an empty connected socket it failed with `EAGAIN` under `MSG_DONTWAIT` or on a non-blocking socket and blocked otherwise, and an unconnected socket did not get `ENOTCONN`; the libkernel debt file records this ("asks the host in the stream cases"). - `recvmsg` takes the same `ReceiveAnsweredHere` answer before waiting when a stream socket's iovecs total zero bytes. - A Unix stream socket with a control buffer for passed descriptors still asks the host: with data queued, `soreceive_generic` goes on to deliver the queued control messages even for a zero-length request. `GuestTcp.cpp`'s `ReceiveAnsweredWithoutTheHost` gets the `recvmsg` cases beside the `recv` and `recvfrom` ones: `ENOTCONN` on an unconnected socket with and without `MSG_DONTWAIT`, 0 on an empty connected socket with and without it, and 0 with data queued, the data still there afterwards. The debt fragment rewrites the entry to cover `recvmsg` and records the control-buffer case and the pending socket error these answers do not return. ### 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. --> Commit 14bebd06fc on `main` b1ef52c45e, Release, in a workflow on my fork: https://github.com/Dr-Coconut/AnyPS5/actions/runs/45036318072 (the run on the first version, 7db64acc9a on 26194f0fcf, gave the same results: https://github.com/Dr-Coconut/AnyPS5/actions/runs/44901177525) - Windows (GitHub-hosted `windows-latest`, image windows-2025-vs2026, WinLibs GCC 15.2.0 `15.2.0posix-14.0.0-ucrt-r7`) and Linux (GitHub-hosted `ubuntu-latest`, image ubuntu-26.04, GCC 15.2.0), with the change: `guest_tcp`, `guest_udp`, `guest_socket_pair` and `guest_kernel_socket_dontwait` pass on both. - With `Udp.cpp` restored to `main` and the new cases kept, on both: `guest_tcp` aborts (Windows `0xc0000409`, Linux `Subprocess aborted`); the other three pass. Not run on macOS. No title tested. `tools/check_conventions.py` passes, and `tools/debt_fold.py --check` accepts the fragment. Rebased onto `main` after #23341 changed `ReceiveShut` to `ReceiveEnded` on the line before this change; the branch keeps `ReceiveEnded`. `tools/pr_overlap.py --branch` merged 26 open pull requests that share files with this branch and reported #18197, which adds the arrival-time setup between `stamps` and the condition changed here, so they overlap textually. It could not compare seven that conflict with `main`; compared by hand, #8605 changes `GuestSockets::Stat`, #11896 replaces the host call inside the block this skips, #22048 adds a check inside that block, and #12682, #12688, #12700 and #12965 rework blocking connects and waits on Windows without touching these lines. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-21 12:11:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T12:11:59Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the review supports merging based on the inspected implementation and tests.

What I ran

Reviewed head 7db64acc9a13096674e23d64bc18c3e19fa49877. No commands or tests were run during this review; author-reported CI results are not treated as review runs.

Results

Check Result Note
Changed-line review passed All added lines inspected
Test execution not run No local test run
Author-reported CI not run Windows and Linux results in the description

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run; macOS and physical-console behavior were not independently verified. All three changed files listed in the manifest were read, and none were excluded. Targeted context in Udp.cpp and GuestTcp.cpp was also read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6005095118 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24944#pullrequestreview-6005095118). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T12:11:59Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the review supports merging based on the inspected implementation and tests. ## What I ran Reviewed head `7db64acc9a13096674e23d64bc18c3e19fa49877`. No commands or tests were run during this review; author-reported CI results are not treated as review runs. ## Results | Check | Result | Note | |---|---|---| | Changed-line review | passed | All added lines inspected | | Test execution | not run | No local test run | | Author-reported CI | not run | Windows and Linux results in the description | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests were run; macOS and physical-console behavior were not independently verified. All three changed files listed in the manifest were read, and none were excluded. Targeted context in `Udp.cpp` and `GuestTcp.cpp` was also read. ## To get this to a good state Nothing is required.
PrivacyOnion commented 2026-11-21 12:17:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T12:17:52Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 7db64acc9a:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_tcp_tests built cleanly.
  • CTest (guest_tcp):
    1/1 Test #5962: guest_tcp ........................   Passed    0.61 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/Socket/src/Udp.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5962: guest_tcp ........................Subprocess aborted***Exception:   0.56 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified core/libs/prx/libkernel/Socket/src/Udp.cpp recvmsg_nid_postfix handles empty stream sockets (type == 1 && total == 0 && !passing) via ReceiveAnsweredHere, returning ENOTCONN (57) when unconnected and 0 when connected.
    • Verified that when control messages are passed (passing is true) on Unix stream sockets, emptyStream is false and control delivery proceeds via the host.
    • Verified that shut sockets (!shut check) bypass ReceiveAnsweredHere and proceed through existing shutdown handling returning 0.
    • Verified core/libs/tests/GuestTcp.cpp exercises recvmsg with zero-length iovec on unconnected and connected stream sockets with and without MSG_DONTWAIT, and after queueing data with MSG_PEEK.
    • Verified docs/dev/debt/changes/fix-libkernel-recvmsg-zero-length-stream.md technical debt fragment format, documentation of FreeBSD 11.4 soreceive_generic semantics, and strict AGENTS.md compliance.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6005126288 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24944#pullrequestreview-6005126288). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T12:17:52Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `7db64acc9a`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_tcp_tests` built cleanly. - **CTest** (`guest_tcp`): ``` 1/1 Test #5962: guest_tcp ........................ Passed 0.61 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/Socket/src/Udp.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5962: guest_tcp ........................Subprocess aborted***Exception: 0.56 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified core/libs/prx/libkernel/Socket/src/Udp.cpp recvmsg_nid_postfix handles empty stream sockets (type == 1 && total == 0 && !passing) via ReceiveAnsweredHere, returning ENOTCONN (57) when unconnected and 0 when connected. - Verified that when control messages are passed (passing is true) on Unix stream sockets, emptyStream is false and control delivery proceeds via the host. - Verified that shut sockets (!shut check) bypass ReceiveAnsweredHere and proceed through existing shutdown handling returning 0. - Verified core/libs/tests/GuestTcp.cpp exercises recvmsg with zero-length iovec on unconnected and connected stream sockets with and without MSG_DONTWAIT, and after queueing data with MSG_PEEK. - Verified docs/dev/debt/changes/fix-libkernel-recvmsg-zero-length-stream.md technical debt fragment format, documentation of FreeBSD 11.4 soreceive_generic semantics, and strict AGENTS.md compliance. Looks Good To Me
MarcZX10 commented 2026-11-22 17:26:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T17:26:22Z.

Review: APPROVED


Reviewed — looks good

The reviewed change at head 14bebd06fc136c93c5943daf514f11c9ab9c5b84 skips the host receive for zero-length stream recvmsg cases that can be answered locally, while preserving the host path when Unix control messages may be delivered; the inspected code and added cases support that behavior.

What I ran

No commands or tests were run. I read the prepared description, commits, manifest and diff, and inspected the changed code, its helper, test cases and debt fragment through repo_read.py.

Results

Check Result Note
Source review passed Three changed files read
Tests not run Author reported Windows and Linux runs

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not run tests, verify the author-reported workflow, or test macOS or console behavior. All three files marked reviewed in the manifest were read; no files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6013498100 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24944#pullrequestreview-6013498100). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T17:26:22Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change at head `14bebd06fc136c93c5943daf514f11c9ab9c5b84` skips the host receive for zero-length stream `recvmsg` cases that can be answered locally, while preserving the host path when Unix control messages may be delivered; the inspected code and added cases support that behavior. ## What I ran No commands or tests were run. I read the prepared description, commits, manifest and diff, and inspected the changed code, its helper, test cases and debt fragment through `repo_read.py`. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Three changed files read | | Tests | not run | Author reported Windows and Linux runs | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not run tests, verify the author-reported workflow, or test macOS or console behavior. All three files marked reviewed in the manifest were read; no files were excluded. ## To get this to a good state Nothing is required.
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!24944
No description provided.