fix(libSceNet): inherit nonblocking mode on accepted sockets #4898

Closed
Lorkydey wants to merge 2 commits from upstream-pr/4898 into main
Lorkydey commented 2026-10-13 02:50:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Lorkydey on 2026-10-13T02:50:55Z.


What

sceNetAccept now preserves the listener's non-blocking mode in both the accepted host socket and the state returned by sceNetGetsockopt(SO_NBIO).

On the base of this PR, bb9a4d8a244cb4cbe3a8c9f69a21074b696e7684, a connection accepted from a non-blocking listener reports SO_NBIO = 0. On Linux the accepted host socket is also blocking, so an empty receive can wait indefinitely. Windows inherits the host mode but still reports the wrong guest state. The new regression fails on main with sceNetAccept did not inherit listener nonblocking mode.

The implementation explicitly enables the inherited host mode before registering the connection and records it on that connection. A host mode-setting failure closes the new socket through the existing owner and returns the translated error. Changing either socket's mode later does not change the other.

This follows FreeBSD 11.4 kern_accept4 with ACCEPT4_INHERIT. PS5 hardware behavior has not been measured; that limitation is recorded in the library's technical debt.

This addresses the separate sceNetAccept path explicitly left outside #3938. The libkernel accept change in #3958 does not change this implementation. No title run or compatibility-percentage increase is claimed.

Windows readiness follow-up

The test now registers the listener with sceNetEpoll and waits for readable readiness with a one-second timeout before each accept. A completed blocking connect does not itself guarantee that a subsequent nonblocking accept already sees the connection on Windows loopback, as xXPBSXx measured on main. The wait is test synchronization; it introduces no production retry, sleep or fallback. The empty-accept EAGAIN, inherited mode, independent mode changes and data checks remain.

The branch is rebased after #4391, retaining its socket descriptor model. The unverified PS5 hardware behavior is now recorded under Unknown function infos in the debt file.

Tested

Exact source: b2243e14a60af0df15988b3f8dc394ff022bf930, based on main bb9a4d8a244cb4cbe3a8c9f69a21074b696e7684.

  • Windows 11 Pro 26100, WinLibs GCC 15.2.0 r7, Ninja, Release: full libs, relinker and targeted test executables build. Local ANYPS5_ENABLE_SPIRV_TOOLS=OFF.
  • guest_sce_net passes 100 consecutive runs, including IPv4 and IPv6. The exact updated head after #5025 passes all eight focused tests (guest_sce_net, guest_tcp, guest_udp, four guest_datagram_* cases and patched_libraries) five times each. The initial local 100-run stability check was on preceding head 62df1d73f with identical readiness/network code; the new public Windows job repeats and passes all 100 on final head b2243e14a.
  • The extended test against main's libSceNet/Export.cpp still fails at sceNetAccept did not inherit listener nonblocking mode; restoring this PR passes. The readiness wait therefore does not hide the original regression.
  • The earlier Windows patched_libraries failure was the unrelated libkernel_sys/rename import regression. #5025 is now merged into this baseline; the full build and all eight local tests pass without an overlay or exclusion.
  • Public validation: Windows and Linux on the exact updated head passes. Both jobs build runtime/relinker, pass all eight tests five times, verify the inheritance negative control and pass conventions/registration. Windows also passes 100 consecutive runs of the readiness regression. The previous run passed Linux, while Windows reached the known load failure now fixed by #5025.
  • Local conventions, test registration and whitespace pass on the updated head.
  • This is focused validation, not the full suite or a title run. No compatibility-percentage increase is claimed.

Overlap

#4391 is merged and included in the baseline. A pairwise merge with the current #5004 head is clean after placing the hardware uncertainty in the proper debt section; its libc signature cleanup does not implement socket-mode inheritance. #4613 changes address-length reporting, and #3958 handles libkernel accept, not this implementation.

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
  • Unblocks: none
  • AI-assisted: yes (Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4837653071 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4898). Originally posted by [Lorkydey](https://github.com/Lorkydey) on 2026-10-13T02:50:55Z. --- ### What `sceNetAccept` now preserves the listener's non-blocking mode in both the accepted host socket and the state returned by `sceNetGetsockopt(SO_NBIO)`. On the base of this PR, `bb9a4d8a244cb4cbe3a8c9f69a21074b696e7684`, a connection accepted from a non-blocking listener reports `SO_NBIO = 0`. On Linux the accepted host socket is also blocking, so an empty receive can wait indefinitely. Windows inherits the host mode but still reports the wrong guest state. The new regression fails on main with `sceNetAccept did not inherit listener nonblocking mode`. The implementation explicitly enables the inherited host mode before registering the connection and records it on that connection. A host mode-setting failure closes the new socket through the existing owner and returns the translated error. Changing either socket's mode later does not change the other. This follows FreeBSD 11.4 [`kern_accept4` with `ACCEPT4_INHERIT`](https://github.com/freebsd/freebsd-src/blob/d106002967eff712894ab8b5337bbbff106ce5e0/sys/kern/uipc_syscalls.c#L398-L425). PS5 hardware behavior has not been measured; that limitation is recorded in the library's technical debt. This addresses the separate `sceNetAccept` path explicitly left outside #3938. The libkernel `accept` change in #3958 does not change this implementation. No title run or compatibility-percentage increase is claimed. ### Windows readiness follow-up The test now registers the listener with `sceNetEpoll` and waits for readable readiness with a one-second timeout before each accept. A completed blocking connect does not itself guarantee that a subsequent nonblocking accept already sees the connection on Windows loopback, as [xXPBSXx measured on main](https://github.com/boykopovar/AnyPS5/pull/4898#issuecomment-6142193367). The wait is test synchronization; it introduces no production retry, sleep or fallback. The empty-accept `EAGAIN`, inherited mode, independent mode changes and data checks remain. The branch is rebased after #4391, retaining its socket descriptor model. The unverified PS5 hardware behavior is now recorded under **Unknown function infos** in the debt file. ### Tested Exact source: `b2243e14a60af0df15988b3f8dc394ff022bf930`, based on main `bb9a4d8a244cb4cbe3a8c9f69a21074b696e7684`. - **Windows 11 Pro 26100, WinLibs GCC 15.2.0 r7, Ninja, Release:** full `libs`, `relinker` and targeted test executables build. Local `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`. - `guest_sce_net` passes **100 consecutive runs**, including IPv4 and IPv6. The exact updated head after #5025 passes all eight focused tests (`guest_sce_net`, `guest_tcp`, `guest_udp`, four `guest_datagram_*` cases and `patched_libraries`) five times each. The initial local 100-run stability check was on preceding head `62df1d73f` with identical readiness/network code; the new public Windows job repeats and passes all 100 on final head `b2243e14a`. - The extended test against main's `libSceNet/Export.cpp` still fails at `sceNetAccept did not inherit listener nonblocking mode`; restoring this PR passes. The readiness wait therefore does not hide the original regression. - The earlier Windows `patched_libraries` failure was the unrelated `libkernel_sys`/`rename` import regression. #5025 is now merged into this baseline; the full build and all eight local tests pass without an overlay or exclusion. - **Public validation:** [Windows and Linux on the exact updated head](https://github.com/Lorkydey/AnyPS5/actions/runs/38379188198) passes. Both jobs build runtime/relinker, pass all eight tests five times, verify the inheritance negative control and pass conventions/registration. Windows also passes 100 consecutive runs of the readiness regression. The [previous run](https://github.com/Lorkydey/AnyPS5/actions/runs/38376629958) passed Linux, while Windows reached the known load failure now fixed by #5025. - Local conventions, test registration and whitespace pass on the updated head. - This is focused validation, not the full suite or a title run. No compatibility-percentage increase is claimed. ### Overlap #4391 is merged and included in the baseline. A pairwise merge with the current #5004 head is clean after placing the hardware uncertainty in the proper debt section; its libc signature cleanup does not implement socket-mode inheritance. #4613 changes address-length reporting, and #3958 handles libkernel `accept`, not this implementation. ### 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](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 - [x] Unblocks: none - [x] AI-assisted: yes (Codex)
xXPBSXx commented 2026-10-13 08:20:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T08:20:39Z.


Windows test of this PR: the new check in guest_sce_net fails intermittently.

Environment: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, BUILD_TESTING=ON, -j2, libusb-cmake from a local checkout. Built from main c2565f014 with only this PR merged (no conflict).

Result: guest_sce_net aborted in 5 of 25 runs (instrumented copy) and in 3 of 12 runs (unmodified test); on plain main c2565f014 it passed 12 of 12. In the instrumented runs every failure is at Require(accepted[i] >= 0); in CheckAcceptedNonblocking (line 137 of GuestSceNet.cpp on this branch): sceNetAccept on the non-blocking listener (the i == 1 case) returns an error right after sceNetConnect returned 0. It looks like the pending connection is not yet visible to a non-blocking accept on Windows loopback; that is a guess, not measured. The check passes when the accept succeeds.

Suggestion (untested): wait until the listener is readable (poll with a timeout) or retry on EAGAIN before treating the accept as failed.

Not checked: whether the same race exists in the implementation and not only in the test; the PR base is older than #4391, so the interaction with the new descriptor model is also open; Linux not tested; no title run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141385687 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4898#issuecomment-6141385687). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T08:20:39Z. --- Windows test of this PR: the new check in `guest_sce_net` fails intermittently. Environment: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, `BUILD_TESTING=ON`, `-j2`, `libusb-cmake` from a local checkout. Built from `main` `c2565f014` with only this PR merged (no conflict). Result: `guest_sce_net` aborted in 5 of 25 runs (instrumented copy) and in 3 of 12 runs (unmodified test); on plain `main` `c2565f014` it passed 12 of 12. In the instrumented runs every failure is at `Require(accepted[i] >= 0);` in `CheckAcceptedNonblocking` (line 137 of `GuestSceNet.cpp` on this branch): `sceNetAccept` on the non-blocking listener (the `i == 1` case) returns an error right after `sceNetConnect` returned 0. It looks like the pending connection is not yet visible to a non-blocking accept on Windows loopback; that is a guess, not measured. The check passes when the accept succeeds. Suggestion (untested): wait until the listener is readable (poll with a timeout) or retry on `EAGAIN` before treating the accept as failed. Not checked: whether the same race exists in the implementation and not only in the test; the PR base is older than #4391, so the interaction with the new descriptor model is also open; Linux not tested; no title run. AI-assisted (Claude Code).
xXPBSXx commented 2026-10-13 09:08:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T09:08:46Z.


Follow-up on the intermittent guest_sce_net abort (Windows 10, MinGW GCC 15.2, -j2).
With only this PR merged onto main c2565f014, guest_sce_net aborted in 3 of 12 runs; every failure of an instrumented copy was at Require(accepted[i] >= 0) in CheckAcceptedNonblocking, the sceNetAccept that follows sceNetConnect on the non-blocking listener. main alone passed 12 of 12.
A separate probe on main db3d379c8 (400 iterations of: non-blocking listener, blocking sceNetConnect, immediate sceNetAccept; 46 runs evaluated, 18 400 attempts): 16 418 accepted at once, 1 982 (10.8 %) returned EAGAIN and succeeded on a retry, 0 other failures. So an immediate non-blocking accept after connect can return EAGAIN on Windows loopback without this PR; the check as written does not retry.
A wait for readability or a retry on EAGAIN before the accept would make the check deterministic (untested).
AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142193367 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4898#issuecomment-6142193367). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T09:08:46Z. --- Follow-up on the intermittent `guest_sce_net` abort (Windows 10, MinGW GCC 15.2, `-j2`). With only this PR merged onto `main` `c2565f014`, `guest_sce_net` aborted in 3 of 12 runs; every failure of an instrumented copy was at `Require(accepted[i] >= 0)` in `CheckAcceptedNonblocking`, the `sceNetAccept` that follows `sceNetConnect` on the non-blocking listener. `main` alone passed 12 of 12. A separate probe on `main` `db3d379c8` (400 iterations of: non-blocking listener, blocking `sceNetConnect`, immediate `sceNetAccept`; 46 runs evaluated, 18 400 attempts): 16 418 accepted at once, 1 982 (10.8 %) returned `EAGAIN` and succeeded on a retry, 0 other failures. So an immediate non-blocking accept after `connect` can return `EAGAIN` on Windows loopback without this PR; the check as written does not retry. A wait for readability or a retry on `EAGAIN` before the accept would make the check deterministic (untested). AI-assisted (Claude Code).
coltken95 commented 2026-10-13 11:11:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-13T11:11:44Z.


Linux validation (Ubuntu 24.04, GCC 13.3, Release), this PR's commits on main at 77b9f7270: guest_sce_net runs CheckAcceptedNonblocking(2) and every check before the IPv6 ones, all passing; the host has no IPv6 loopback, so the IPv6 cases (including CheckAcceptedNonblocking(28)) are skipped and the test exits 77. With main's sources and this PR's test it aborts in the IPv4 accept check.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6144254884 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4898#issuecomment-6144254884). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-13T11:11:44Z. --- Linux validation (Ubuntu 24.04, GCC 13.3, Release), this PR's commits on `main` at 77b9f7270: `guest_sce_net` runs `CheckAcceptedNonblocking(2)` and every check before the IPv6 ones, all passing; the host has no IPv6 loopback, so the IPv6 cases (including `CheckAcceptedNonblocking(28)`) are skipped and the test exits 77. With `main`'s sources and this PR's test it aborts in the IPv4 accept check. AI-assisted: yes
oneandonlydean commented 2026-10-14 02:32:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:32:58Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159587945 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4898#issuecomment-6159587945). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:32:58Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Pull request closed

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!4898
No description provided.