fix(libSceNet): wake UDP receives on abort and close #24065

Open
Romannachwievor wants to merge 1 commit from upstream-pr/24065 into main
Romannachwievor commented 2026-11-20 03:58:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Romannachwievor on 2026-11-20T03:58:01Z.


What

On macOS, wake blocked UDP receives when an unconnected socket is aborted or closed. The native shutdown fallback connects the datagram socket to loopback before shutting it down.

Tested

  • macOS 26.5, Apple M1: guest_sce_net_tests --unbound-datagram-receive passed three times on the change, covering IPv4/IPv6, bound/unbound sockets, Abort/Close. Without the helper, the bound receive remained blocked. Full guest_sce_net still fails at CheckConnectTimeoutExpiry (errno 61).
  • Linux Offload, Ubuntu 24.04/GCC 13.3: base aborted before tests with userfaultfd failed (Operation not permitted) and recvmsg: process_vm_readv failed with errno 38; the fix was not reached.
  • Base check on the same M1 (build-full, main a4d1053d4b + #17425 + #11049, without this change): full guest_sce_net fails at the same place (line 1241, connect timeout expiry: no connect stayed pending, errno 61). That is the known macOS backlog issue #22443 (PR #22623), not this change. The Linux code path is unchanged: the extra connect and shutdown run only under __APPLE__.

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: #12682
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5407457749 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24065). Originally posted by [Romannachwievor](https://github.com/Romannachwievor) on 2026-11-20T03:58:01Z. --- ### What On macOS, wake blocked UDP receives when an unconnected socket is aborted or closed. The native shutdown fallback connects the datagram socket to loopback before shutting it down. ### Tested - macOS 26.5, Apple M1: `guest_sce_net_tests --unbound-datagram-receive` passed three times on the change, covering IPv4/IPv6, bound/unbound sockets, Abort/Close. Without the helper, the bound receive remained blocked. Full `guest_sce_net` still fails at `CheckConnectTimeoutExpiry` (errno 61). - Linux Offload, Ubuntu 24.04/GCC 13.3: base aborted before tests with `userfaultfd failed (Operation not permitted)` and `recvmsg: process_vm_readv failed with errno 38`; the fix was not reached. - Base check on the same M1 (`build-full`, main `a4d1053d4b` + #17425 + #11049, without this change): full `guest_sce_net` fails at the same place (line 1241, `connect timeout expiry: no connect stayed pending`, errno 61). That is the known macOS backlog issue #22443 (PR #22623), not this change. The Linux code path is unchanged: the extra connect and shutdown run only under `__APPLE__`. ### 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: #12682 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code)
PrivacyOnion commented 2026-11-20 04:00:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-20T04:00:30Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 369900d7ba:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_sce_net_tests built cleanly.
  • CTest (guest_sce_net, guest_net_inet_pton_source_faults):
    1/2 Test #4874: guest_net_inet_pton_source_faults ...   Passed    0.01 sec
    2/2 Test #4873: guest_sce_net .......................   Passed    1.68 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceNet/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/2 Test #4874: guest_net_inet_pton_source_faults ...   Passed    0.01 sec
    2/2 Test #4873: guest_sce_net .......................   Passed    1.67 sec
    100% tests passed, 0 tests failed out of 2
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified ShutdownSocket_nid_no_patch handles null native pointer safely and executes proper shutdown sequences across Windows, Linux, and macOS platforms.
    • Verified macOS ENOTCONN fallback logic correctly inspects sockaddr_storage address family (AF_INET and AF_INET6) and rewrites unspecified/ANY addresses to loopback before connect and shutdown.
    • Verified lock scoping in sceNetSocketClose and sceNetSocketAbort: g_mutex is held during lookup and extraction of native and type, and released prior to calling ShutdownSocket_nid_no_patch and g_cv.NotifyAll() to avoid lock inversion.
    • Verified AGENTS.md compliance: no unauthorized comments added, debt fragment correctly formatted in docs/dev/debt/changes/fix-net-abort-unconnected-udp-macos.md, and Conventional Commits followed.
    • Verified test coverage in GuestSceNet.cpp covering bound and unbound datagram socket abort/close behaviors across IPv4 and IPv6 families without regressing Linux or Windows behavior.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5987298019 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24065#pullrequestreview-5987298019). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-20T04:00:30Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `369900d7ba`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_sce_net_tests` built cleanly. - **CTest** (`guest_sce_net`, `guest_net_inet_pton_source_faults`): ``` 1/2 Test #4874: guest_net_inet_pton_source_faults ... Passed 0.01 sec 2/2 Test #4873: guest_sce_net ....................... Passed 1.68 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libSceNet/Export.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/2 Test #4874: guest_net_inet_pton_source_faults ... Passed 0.01 sec 2/2 Test #4873: guest_sce_net ....................... Passed 1.67 sec 100% tests passed, 0 tests failed out of 2 ``` Restoring the change makes it pass again. - **Code reading**: - Verified ShutdownSocket_nid_no_patch handles null native pointer safely and executes proper shutdown sequences across Windows, Linux, and macOS platforms. - Verified macOS ENOTCONN fallback logic correctly inspects sockaddr_storage address family (AF_INET and AF_INET6) and rewrites unspecified/ANY addresses to loopback before connect and shutdown. - Verified lock scoping in sceNetSocketClose and sceNetSocketAbort: g_mutex is held during lookup and extraction of native and type, and released prior to calling ShutdownSocket_nid_no_patch and g_cv.NotifyAll() to avoid lock inversion. - Verified AGENTS.md compliance: no unauthorized comments added, debt fragment correctly formatted in docs/dev/debt/changes/fix-net-abort-unconnected-udp-macos.md, and Conventional Commits followed. - Verified test coverage in GuestSceNet.cpp covering bound and unbound datagram socket abort/close behaviors across IPv4 and IPv6 families without regressing Linux or Windows behavior. Looks Good To Me
MarcZX10 commented 2026-11-20 05:14:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T05:14:08Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing in the inspected change shows a verified blocking defect; the change remains incompletely verified because no checks were run in this review.

What I ran

Reviewed head 369900d7ba4e9f33184ae2dd4674bdeae32d7523 using the prepared diff and pinned reader. No build or tests were run. Files read: review/description.md, review/commits.md, review/manifest.json, review/diff.patch, core/libs/prx/libSceNet/Export.cpp (lines 260–320, 1388–1440, 1770–1825), core/libs/tests/GuestSceNet.cpp (lines 760–845, 2960–2990), and docs/dev/debt/changes/fix-net-abort-unconnected-udp-macos.md. The change’s complete text was included for all three changed files; no changed files were excluded in manifest.json. review/files.json was not available through the reader.

Results

Check Result Note
Source review passed Targeted changes and callers inspected
Build and tests not run Author-reported runs are not independent verification

Findings

Blocking

None.

Non-blocking

None.

Not verified

The macOS and Windows runtime behavior, Linux behavior, and the author-reported test results were not independently verified. The full source text for each changed file was available, but only the targeted ranges above were read. The excluded-file listing was unavailable.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5987849214 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24065#pullrequestreview-5987849214). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T05:14:08Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing in the inspected change shows a verified blocking defect; the change remains incompletely verified because no checks were run in this review. ## What I ran Reviewed head `369900d7ba4e9f33184ae2dd4674bdeae32d7523` using the prepared diff and pinned reader. No build or tests were run. Files read: `review/description.md`, `review/commits.md`, `review/manifest.json`, `review/diff.patch`, `core/libs/prx/libSceNet/Export.cpp` (lines 260–320, 1388–1440, 1770–1825), `core/libs/tests/GuestSceNet.cpp` (lines 760–845, 2960–2990), and `docs/dev/debt/changes/fix-net-abort-unconnected-udp-macos.md`. The change’s complete text was included for all three changed files; no changed files were excluded in `manifest.json`. `review/files.json` was not available through the reader. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Targeted changes and callers inspected | | Build and tests | not run | Author-reported runs are not independent verification | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The macOS and Windows runtime behavior, Linux behavior, and the author-reported test results were not independently verified. The full source text for each changed file was available, but only the targeted ranges above were read. The excluded-file listing was unavailable. ## To get this to a good state Nothing is required.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/24065:upstream-pr/24065'
git switch 'upstream-pr/24065'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/24065'
git switch 'upstream-pr/24065'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/24065'
git switch 'upstream-pr/24065'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/24065'
git switch 'main'
git merge --squash 'upstream-pr/24065'
git switch 'main'
git merge --ff-only 'upstream-pr/24065'
git switch 'main'
git merge 'upstream-pr/24065'
git push origin 'main'
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!24065
No description provided.