feat(libSceNetCtl): implement the NpToolkit callback register, unregister and check #8398

Merged
Chikimaro merged 4 commits from upstream-pr/8398 into main 2026-10-24 16:42:46 +00:00
Chikimaro commented 2026-10-20 12:14:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Chikimaro on 2026-10-20T12:14:57Z.


What

Implements three of the libSceNetCtl exports #8018 declared without parameters:

  • sceNetCtlRegisterCallbackForNpToolkit(callback, void* arg, int* cid)
  • sceNetCtlUnregisterCallbackForNpToolkit(int cid)
  • sceNetCtlCheckCallbackForNpToolkit()

They keep their own table of eight callbacks next to the IPv4 and IPv6 ones and reuse the existing register and unregister helpers, so they return the same errors (INVALID_ADDR for a null callback or id pointer, CALLBACK_MAX past eight, INVALID_ID outside 0-7, ID_NOT_FOUND for an empty slot). The event delivery of sceNetCtlCheckCallback moves into a helper that takes the table; both checks call it, so the NpToolkit check reports the state sceNetCtlCheckCallback reports (IPOBTAINED or DISCONNECTED, once per change), and each check only calls its own table's callbacks. They follow main's initialization behaviour: the shared helpers, the NpToolkit check included, apply the same initialization check as their IPv4 counterparts, the library starts initialized as titles find it, and sceNetCtlTerm stays the no-op main measured, so it leaves the NpToolkit table as it leaves the IPv4 and IPv6 ones.

The register's (callback, arg, int* cid) signature, the (int eventType, void* arg) callback and the separate eight-entry table follow shadPS4's net_ctl_obj.h, whose NpToolkit check delivers the same events to that table. shadPS4 leaves the NpToolkit unregister and check as stubs, so their (int cid) and () signatures follow sceNetCtlUnregisterCallback and sceNetCtlCheckCallback. None of this is measured on a console; the three "unknown signature" lines in docs/dev/debt/libSceNetCtl.md become one entry that says so. sceNetCtlClearEventForNpToolkit stays a throwing stub, as its behaviour is not known.

No open PR names these functions. tools/pr_overlap.py could not compare #5836, #6039, #6044, #7201, #7332 and #8204 because they conflict with main; their diffs touch neither these functions, the callback helpers, sceNetCtlTerm nor the debt lines changed here.

Tested

Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7 (UCRT), Release, full build with -DBUILD_TESTING=ON, on main d50ec76da; after the rebase onto 56b299c3a the 23 tests matching sce_net|datagram|socket_host_write|refused_connect|net_ctl|guest_net were run again and pass.

  • guest_sce_net gains a block for the three functions: null callback and id pointer, ids 0-7, the ninth registration failing with CALLBACK_MAX, the IPv4 table still free while the NpToolkit table is full, invalid ids, slot reuse, the check calling a callback once with the state sceNetCtlGetState reports and its argument, no second call without a change, sceNetCtlCheckCallback not calling NpToolkit callbacks and the NpToolkit check not calling IPv4 ones, and a re-registered slot being called again. It passes 5 of 5 runs.
  • With Export.cpp from main, guest_sce_net fails with sceNetCtlRegisterCallbackForNpToolkit not implemented.
  • The 24 tests matching sce_net|datagram|socket_host_write|refused_connect|memory_pool|net_ctl|guest_net pass, including the existing IPv4 and IPv6 callback checks that now go through the moved delivery.
  • After merging main twice, for its initialization and callback validation changes (head 7854d1993), the 24 net tests pass again, including guest_net_ctl, which now also checks the NpToolkit functions' argument errors before sceNetCtlInit.
  • python3 tools/check_conventions.py --base origin/main passes.

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:4935562314 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8398). Originally posted by [Chikimaro](https://github.com/Chikimaro) on 2026-10-20T12:14:57Z. --- ### What Implements three of the `libSceNetCtl` exports #8018 declared without parameters: - `sceNetCtlRegisterCallbackForNpToolkit(callback, void* arg, int* cid)` - `sceNetCtlUnregisterCallbackForNpToolkit(int cid)` - `sceNetCtlCheckCallbackForNpToolkit()` They keep their own table of eight callbacks next to the IPv4 and IPv6 ones and reuse the existing register and unregister helpers, so they return the same errors (`INVALID_ADDR` for a null callback or id pointer, `CALLBACK_MAX` past eight, `INVALID_ID` outside 0-7, `ID_NOT_FOUND` for an empty slot). The event delivery of `sceNetCtlCheckCallback` moves into a helper that takes the table; both checks call it, so the NpToolkit check reports the state `sceNetCtlCheckCallback` reports (`IPOBTAINED` or `DISCONNECTED`, once per change), and each check only calls its own table's callbacks. They follow `main`'s initialization behaviour: the shared helpers, the NpToolkit check included, apply the same initialization check as their IPv4 counterparts, the library starts initialized as titles find it, and `sceNetCtlTerm` stays the no-op `main` measured, so it leaves the NpToolkit table as it leaves the IPv4 and IPv6 ones. The register's `(callback, arg, int* cid)` signature, the `(int eventType, void* arg)` callback and the separate eight-entry table follow [shadPS4's `net_ctl_obj.h`](https://github.com/shadps4-emu/shadPS4/blob/main/src/core/libraries/network/net_ctl_obj.h), whose NpToolkit check delivers the same events to that table. shadPS4 leaves the NpToolkit unregister and check as stubs, so their `(int cid)` and `()` signatures follow `sceNetCtlUnregisterCallback` and `sceNetCtlCheckCallback`. None of this is measured on a console; the three "unknown signature" lines in `docs/dev/debt/libSceNetCtl.md` become one entry that says so. `sceNetCtlClearEventForNpToolkit` stays a throwing stub, as its behaviour is not known. No open PR names these functions. `tools/pr_overlap.py` could not compare #5836, #6039, #6044, #7201, #7332 and #8204 because they conflict with `main`; their diffs touch neither these functions, the callback helpers, `sceNetCtlTerm` nor the debt lines changed here. ### Tested Windows 11 Pro 10.0.26200, WinLibs GCC 15.2.0 r7 (UCRT), Release, full build with `-DBUILD_TESTING=ON`, on `main` d50ec76da; after the rebase onto 56b299c3a the 23 tests matching `sce_net|datagram|socket_host_write|refused_connect|net_ctl|guest_net` were run again and pass. - `guest_sce_net` gains a block for the three functions: null callback and id pointer, ids 0-7, the ninth registration failing with `CALLBACK_MAX`, the IPv4 table still free while the NpToolkit table is full, invalid ids, slot reuse, the check calling a callback once with the state `sceNetCtlGetState` reports and its argument, no second call without a change, `sceNetCtlCheckCallback` not calling NpToolkit callbacks and the NpToolkit check not calling IPv4 ones, and a re-registered slot being called again. It passes 5 of 5 runs. - With `Export.cpp` from `main`, `guest_sce_net` fails with `sceNetCtlRegisterCallbackForNpToolkit not implemented`. - The 24 tests matching `sce_net|datagram|socket_host_write|refused_connect|memory_pool|net_ctl|guest_net` pass, including the existing IPv4 and IPv6 callback checks that now go through the moved delivery. - After merging `main` twice, for its initialization and callback validation changes (head 7854d1993), the 24 net tests pass again, including `guest_net_ctl`, which now also checks the NpToolkit functions' argument errors before `sceNetCtlInit`. - `python3 tools/check_conventions.py --base origin/main` passes. ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-20 12:15:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T12:15:42Z.


Progress report (cc00785 → 7854d19)

📈 System libraries: 43.26% (+0.03%, +3 implemented functions)

✅ 3 implemented
Library Name
libSceNetCtl sceNetCtlCheckCallbackForNpToolkit
libSceNetCtl sceNetCtlRegisterCallbackForNpToolkit
libSceNetCtl sceNetCtlUnregisterCallbackForNpToolkit
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6290616923 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8398#issuecomment-6290616923). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T12:15:42Z. --- <!-- progress-report --> ### Progress report (cc00785 → 7854d19) 📈 **System libraries**: 43.26% (+0.03%, +3 implemented functions) <details> <summary>✅ 3 implemented</summary> | Library | Name | | - | - | | libSceNetCtl | `sceNetCtlCheckCallbackForNpToolkit` | | libSceNetCtl | `sceNetCtlRegisterCallbackForNpToolkit` | | libSceNetCtl | `sceNetCtlUnregisterCallbackForNpToolkit` | </details>
nikowolf123 commented 2026-10-20 22:03:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-20T22:03:59Z.


core/libs/tests/GuestSceNet.cpp line 1955 compares the event the NpToolkit callback received with the state sceNetCtlGetState returns:

Require(sceNetCtlGetState(&current) == 0 && toolkit.event == current);

These two values are equal only when the host is connected, where both are IPOBTAINED = 3. On a host with no non-loopback address, CheckCallbacks sends NET_CTL_EVENT_DISCONNECTED = 1 (Export.cpp L403), but sceNetCtlGetState returns NET_CTL_STATE_DISCONNECTED = 0 (L483; the constants are at L42-L45, and shadPS4's net_ctl_codes.h uses the same values). So Require aborts. The rest of guest_sce_net accepts the disconnected case (L1856-L1858, L1880), and GuestNetCtl.cpp converts the state to an event before it compares (L104).

I built guest_sce_net_tests on Linux (GCC, Release) and ran it in a network namespace with only loopback up (unshare -rn, then ip link set lo up). That is the same situation as docker run --network none or a build sandbox without network.

  • PR base 56b299c3a: exit 0 (3 of 3 runs).
  • This PR: abort, exit 134 (3 of 3). A -O0 build stops at line 1955 with toolkit.event == 1 and current == 0.
  • This PR with the change below: exit 0 (3 of 3).

With the host network, all three exit 0, so CI runners will not show the failure. A fix in the style of GuestNetCtl.cpp:

Require(sceNetCtlGetState(&current) == 0 && toolkit.event == (current == 3 ? 3 : 1));
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6302768277 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8398#issuecomment-6302768277). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-20T22:03:59Z. --- [`core/libs/tests/GuestSceNet.cpp` line 1955](https://github.com/boykopovar/AnyPS5/blob/de2fd5bf6a2f83f2a2521a5df31e125472dc8d80/core/libs/tests/GuestSceNet.cpp#L1955) compares the event the NpToolkit callback received with the state `sceNetCtlGetState` returns: ```cpp Require(sceNetCtlGetState(&current) == 0 && toolkit.event == current); ``` These two values are equal only when the host is connected, where both are `IPOBTAINED` = 3. On a host with no non-loopback address, `CheckCallbacks` sends `NET_CTL_EVENT_DISCONNECTED` = 1 ([Export.cpp L403](https://github.com/boykopovar/AnyPS5/blob/de2fd5bf6a2f83f2a2521a5df31e125472dc8d80/core/libs/prx/libSceNetCtl/Export.cpp#L403)), but `sceNetCtlGetState` returns `NET_CTL_STATE_DISCONNECTED` = 0 ([L483](https://github.com/boykopovar/AnyPS5/blob/de2fd5bf6a2f83f2a2521a5df31e125472dc8d80/core/libs/prx/libSceNetCtl/Export.cpp#L483); the constants are at [L42-L45](https://github.com/boykopovar/AnyPS5/blob/de2fd5bf6a2f83f2a2521a5df31e125472dc8d80/core/libs/prx/libSceNetCtl/Export.cpp#L42-L45), and shadPS4's [`net_ctl_codes.h`](https://github.com/shadps4-emu/shadPS4/blob/041ba9975ea2f65eb4802bd749e8907821382db2/src/core/libraries/network/net_ctl_codes.h#L20-L29) uses the same values). So `Require` aborts. The rest of `guest_sce_net` accepts the disconnected case ([L1856-L1858](https://github.com/boykopovar/AnyPS5/blob/de2fd5bf6a2f83f2a2521a5df31e125472dc8d80/core/libs/tests/GuestSceNet.cpp#L1856-L1858), [L1880](https://github.com/boykopovar/AnyPS5/blob/de2fd5bf6a2f83f2a2521a5df31e125472dc8d80/core/libs/tests/GuestSceNet.cpp#L1880)), and `GuestNetCtl.cpp` converts the state to an event before it compares ([L104](https://github.com/boykopovar/AnyPS5/blob/de2fd5bf6a2f83f2a2521a5df31e125472dc8d80/core/libs/tests/GuestNetCtl.cpp#L104)). I built `guest_sce_net_tests` on Linux (GCC, Release) and ran it in a network namespace with only loopback up (`unshare -rn`, then `ip link set lo up`). That is the same situation as `docker run --network none` or a build sandbox without network. - PR base 56b299c3a: exit 0 (3 of 3 runs). - This PR: abort, exit 134 (3 of 3). A -O0 build stops at line 1955 with `toolkit.event == 1` and `current == 0`. - This PR with the change below: exit 0 (3 of 3). With the host network, all three exit 0, so CI runners will not show the failure. A fix in the style of `GuestNetCtl.cpp`: ```cpp Require(sceNetCtlGetState(&current) == 0 && toolkit.event == (current == 3 ? 3 : 1)); ```
adriadam10 commented 2026-10-21 11:24:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T11:24:47Z.

Review: CHANGES_REQUESTED


The implementation matches shadPS4's net_ctl_obj.h and the debt entry is accurate. One blocker, already reported by @nikowolf123:

  • core/libs/tests/GuestSceNet.cpp:1992: toolkit.event == current compares an event (NET_CTL_EVENT_DISCONNECTED = 1) with a state (NET_CTL_STATE_DISCONNECTED = 0), so the test aborts on a host with no non-loopback address (reproduced in a loopback-only network namespace). Convert the state before comparing, as GuestNetCtl.cpp does:
Require(sceNetCtlGetState(&current) == 0 && toolkit.event == (current == 3 ? 3 : 1));

Everything else checked out (error codes, separate tables, slot reuse, Term). Happy to merge once this is pushed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5598920039 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8398#pullrequestreview-5598920039). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-21T11:24:47Z. **Review:** CHANGES_REQUESTED --- The implementation matches shadPS4's `net_ctl_obj.h` and the debt entry is accurate. One blocker, already reported by @nikowolf123: - `core/libs/tests/GuestSceNet.cpp:1992`: `toolkit.event == current` compares an event (`NET_CTL_EVENT_DISCONNECTED` = 1) with a state (`NET_CTL_STATE_DISCONNECTED` = 0), so the test aborts on a host with no non-loopback address (reproduced in a loopback-only network namespace). Convert the state before comparing, as `GuestNetCtl.cpp` does: ```cpp Require(sceNetCtlGetState(&current) == 0 && toolkit.event == (current == 3 ? 3 : 1)); ``` Everything else checked out (error codes, separate tables, slot reuse, `Term`). Happy to merge once this is pushed.
Chikimaro commented 2026-10-21 19:53:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Chikimaro on 2026-10-21T19:53:17Z.


Pushed d7f459115 with your suggested line: the check now compares the callback's event with the event of the current state. Thanks @nikowolf123 for the report.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6325147887 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8398#issuecomment-6325147887). Originally posted by [Chikimaro](https://github.com/Chikimaro) on 2026-10-21T19:53:17Z. --- Pushed d7f459115 with your suggested line: the check now compares the callback's event with the event of the current state. Thanks @nikowolf123 for the report.
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!8398
No description provided.