fix(libkernel): send and receive on libSceNet sockets #18811

Merged
THEMANnt merged 1 commit from upstream-pr/18811 into main 2026-11-12 16:40:00 +00:00
THEMANnt commented 2026-11-12 11:07:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-11-12T11:07:03Z.


What

Route POSIX send and recv on libSceNet-owned descriptors through the same checked transfer hooks used by sendto and recvfrom. Stream and datagram callers can transfer data without supplying a peer address. The forwarded receive path reuses the existing MSG_WAITALL handling.

Tested

Windows x64, WinLibs GCC 15.2, Release. The focused guest_sce_net_kernel_forwards test passed three consecutive runs on the final diff, including native and libSceNet loopback streams and datagrams, null buffers, and an empty nonblocking receive. With the implementation reverted, the fixture aborts at the forwarded send assertion. Source and test inputs are identical on the published patch and the locally built verification patch.

Conventions passed against upstream main. The overlap review found adjacent native transport work in #12682, #12688, #12700 and #12965. This change adds the libSceNet forwarding path. Merge previews with #18167 and #18474 were clean after moving the datagram check into its own fixture.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5276226875 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18811). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-11-12T11:07:03Z. --- ### What Route POSIX send and recv on libSceNet-owned descriptors through the same checked transfer hooks used by sendto and recvfrom. Stream and datagram callers can transfer data without supplying a peer address. The forwarded receive path reuses the existing MSG_WAITALL handling. ### Tested Windows x64, WinLibs GCC 15.2, Release. The focused guest_sce_net_kernel_forwards test passed three consecutive runs on the final diff, including native and libSceNet loopback streams and datagrams, null buffers, and an empty nonblocking receive. With the implementation reverted, the fixture aborts at the forwarded send assertion. Source and test inputs are identical on the published patch and the locally built verification patch. Conventions passed against upstream main. The overlap review found adjacent native transport work in #12682, #12688, #12700 and #12965. This change adds the libSceNet forwarding path. Merge previews with #18167 and #18474 were clean after moving the datagram check into its own fixture. <!-- 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. --> ### 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: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
PrivacyOnion commented 2026-11-12 11:50:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T11:50:28Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 1c30f2410c:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_net_kernel_forwards_tests built cleanly.
  • CTest (guest_sce_net_kernel_forwards):
    1/1 Test #3839: guest_sce_net_kernel_forwards ....   Passed    0.21 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 #3839: guest_sce_net_kernel_forwards ....Subprocess aborted***Exception:   0.34 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libkernel/Socket/src/Udp.cpp:send_nid_postfix: Verified flag validation (flags & ~GuestSendFlags returns 45 EOPNOTSUPP), length check (length > INT_MAX returns 40 EMSGSIZE), null pointer check (!buffer && length returns 14 EFAULT), and proper forwarding to forwards->sendto with nullptr destination and 0 length.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp:recv_nid_postfix: Verified flag validation (flags & ~GuestReceiveFlags returns 45 EOPNOTSUPP), length check (length > INT_MAX returns 40 EMSGSIZE), null pointer check (!buffer && length returns 14 EFAULT), and proper forwarding to forwards->recvfrom with nullptr address and length pointers.
    • core/libs/prx/libkernel/Socket/src/Udp.cpp:ForwardsFor: Confirmed descriptor routing correctly distinguishes native libkernel sockets from libSceNet descriptors and safely falls back to Lookup with EBADF (9) for invalid descriptor numbers.
    • core/libs/tests/GuestNetKernelForwards.cpp:CheckConnectedDatagramTransfer: Verified datagram send and receive loopback coverage over both native and forwarded libSceNet sockets, confirming bidirectional data integrity with std::memcmp and socket cleanup.
    • core/libs/tests/GuestNetKernelForwards.cpp:CheckStreamTransfer: Verified stream send and receive coverage on native and libSceNet sockets, including null buffer EFAULT (14) checking, nonblocking empty receive returning EWOULDBLOCK (35), and MSG_WAITALL (0x40) receive functionality.
    • docs/dev/debt/libkernel.md: Confirmed technical debt documentation was updated to reflect that send and recv now reach libSceNet sockets via the registered transfer hooks alongside sendto and recvfrom.
    • AGENTS.md rules: Confirmed zero comments were introduced in modified code regions in Udp.cpp and GuestNetKernelForwards.cpp, commit title adheres to Conventional Commits, and no unauthorized files were added.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5873938048 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18811#pullrequestreview-5873938048). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-12T11:50:28Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `1c30f2410c`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_net_kernel_forwards_tests` built cleanly. - **CTest** (`guest_sce_net_kernel_forwards`): ``` 1/1 Test #3839: guest_sce_net_kernel_forwards .... Passed 0.21 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 #3839: guest_sce_net_kernel_forwards ....Subprocess aborted***Exception: 0.34 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libkernel/Socket/src/Udp.cpp:send_nid_postfix: Verified flag validation (flags & ~GuestSendFlags returns 45 EOPNOTSUPP), length check (length > INT_MAX returns 40 EMSGSIZE), null pointer check (!buffer && length returns 14 EFAULT), and proper forwarding to forwards->sendto with nullptr destination and 0 length. - core/libs/prx/libkernel/Socket/src/Udp.cpp:recv_nid_postfix: Verified flag validation (flags & ~GuestReceiveFlags returns 45 EOPNOTSUPP), length check (length > INT_MAX returns 40 EMSGSIZE), null pointer check (!buffer && length returns 14 EFAULT), and proper forwarding to forwards->recvfrom with nullptr address and length pointers. - core/libs/prx/libkernel/Socket/src/Udp.cpp:ForwardsFor: Confirmed descriptor routing correctly distinguishes native libkernel sockets from libSceNet descriptors and safely falls back to Lookup with EBADF (9) for invalid descriptor numbers. - core/libs/tests/GuestNetKernelForwards.cpp:CheckConnectedDatagramTransfer: Verified datagram send and receive loopback coverage over both native and forwarded libSceNet sockets, confirming bidirectional data integrity with std::memcmp and socket cleanup. - core/libs/tests/GuestNetKernelForwards.cpp:CheckStreamTransfer: Verified stream send and receive coverage on native and libSceNet sockets, including null buffer EFAULT (14) checking, nonblocking empty receive returning EWOULDBLOCK (35), and MSG_WAITALL (0x40) receive functionality. - docs/dev/debt/libkernel.md: Confirmed technical debt documentation was updated to reflect that send and recv now reach libSceNet sockets via the registered transfer hooks alongside sendto and recvfrom. - AGENTS.md rules: Confirmed zero comments were introduced in modified code regions in Udp.cpp and GuestNetKernelForwards.cpp, commit title adheres to Conventional Commits, and no unauthorized files were added. - Note: the AI-assisted checkbox can stay. Looks Good To Me
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!18811
No description provided.