feat(libSceNetCtl): implement the NpToolkit callback register, unregister and check #8398
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8398"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Chikimaro on 2026-10-20T12:14:57Z.
What
Implements three of the
libSceNetCtlexports #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_ADDRfor a null callback or id pointer,CALLBACK_MAXpast eight,INVALID_IDoutside 0-7,ID_NOT_FOUNDfor an empty slot). The event delivery ofsceNetCtlCheckCallbackmoves into a helper that takes the table; both checks call it, so the NpToolkit check reports the statesceNetCtlCheckCallbackreports (IPOBTAINEDorDISCONNECTED, once per change), and each check only calls its own table's callbacks. They followmain'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, andsceNetCtlTermstays the no-opmainmeasured, 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'snet_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 followsceNetCtlUnregisterCallbackandsceNetCtlCheckCallback. None of this is measured on a console; the three "unknown signature" lines indocs/dev/debt/libSceNetCtl.mdbecome one entry that says so.sceNetCtlClearEventForNpToolkitstays a throwing stub, as its behaviour is not known.No open PR names these functions.
tools/pr_overlap.pycould not compare #5836, #6039, #6044, #7201, #7332 and #8204 because they conflict withmain; their diffs touch neither these functions, the callback helpers,sceNetCtlTermnor 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, onmaind50ec76da; after the rebase onto56b299c3athe 23 tests matchingsce_net|datagram|socket_host_write|refused_connect|net_ctl|guest_netwere run again and pass.guest_sce_netgains a block for the three functions: null callback and id pointer, ids 0-7, the ninth registration failing withCALLBACK_MAX, the IPv4 table still free while the NpToolkit table is full, invalid ids, slot reuse, the check calling a callback once with the statesceNetCtlGetStatereports and its argument, no second call without a change,sceNetCtlCheckCallbacknot 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.Export.cppfrommain,guest_sce_netfails withsceNetCtlRegisterCallbackForNpToolkit not implemented.sce_net|datagram|socket_host_write|refused_connect|memory_pool|net_ctl|guest_netpass, including the existing IPv4 and IPv6 callback checks that now go through the moved delivery.maintwice, for its initialization and callback validation changes (head7854d1993), the 24 net tests pass again, includingguest_net_ctl, which now also checks the NpToolkit functions' argument errors beforesceNetCtlInit.python3 tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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
sceNetCtlCheckCallbackForNpToolkitsceNetCtlRegisterCallbackForNpToolkitsceNetCtlUnregisterCallbackForNpToolkitImported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-20T22:03:59Z.
core/libs/tests/GuestSceNet.cppline 1955 compares the event the NpToolkit callback received with the statesceNetCtlGetStatereturns:These two values are equal only when the host is connected, where both are
IPOBTAINED= 3. On a host with no non-loopback address,CheckCallbackssendsNET_CTL_EVENT_DISCONNECTED= 1 (Export.cpp L403), butsceNetCtlGetStatereturnsNET_CTL_STATE_DISCONNECTED= 0 (L483; the constants are at L42-L45, and shadPS4'snet_ctl_codes.huses the same values). SoRequireaborts. The rest ofguest_sce_netaccepts the disconnected case (L1856-L1858, L1880), andGuestNetCtl.cppconverts the state to an event before it compares (L104).I built
guest_sce_net_testson Linux (GCC, Release) and ran it in a network namespace with only loopback up (unshare -rn, thenip link set lo up). That is the same situation asdocker run --network noneor a build sandbox without network.56b299c3a: exit 0 (3 of 3 runs).toolkit.event == 1andcurrent == 0.With the host network, all three exit 0, so CI runners will not show the failure. A fix in the style of
GuestNetCtl.cpp: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.hand the debt entry is accurate. One blocker, already reported by @nikowolf123:core/libs/tests/GuestSceNet.cpp:1992:toolkit.event == currentcompares 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, asGuestNetCtl.cppdoes:Everything else checked out (error codes, separate tables, slot reuse,
Term). Happy to merge once this is pushed.Imported from boykopovar/AnyPS5. Originally posted by Chikimaro on 2026-10-21T19:53:17Z.
Pushed
d7f459115with your suggested line: the check now compares the callback's event with the event of the current state. Thanks @nikowolf123 for the report.