fix(libSceNetCtl): keep the callback argument and deliver the state from sceNetCtlCheckCallback #6138
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6138"
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 fdfawef324 on 2026-10-14T23:07:32Z.
What
Stop 2 of the Minecraft Preview bring-up (#1277), NetCtl half: "NetCtl must store the callback argument and deliver the state from
sceNetCtlCheckCallback". Onmain,sceNetCtlRegisterCallbackandsceNetCtlRegisterCallbackV6store only the function and droparg, andsceNetCtlCheckCallbackreturns 0 without calling anything, so a title that pollssceNetCtlCheckCallbackuntil its callback reports the connection state never gets it.NetCtlCallbackinSceTypes.hppis nowvoid (APS5_VABI *)(int, void*). WithoutAPS5_VABI, the Windows build would call the guest function with the Microsoft ABI. The captureless lambda inGuestSceNet.cppno longer converts to it, so it becomes anAPS5_VABIfunction.{func, arg, lastEvent}. Registration storesfuncandargin an empty slot and writes*cid; unregistration clears the slot. Error codes, and the result for an empty slot, are unchanged.sceNetCtlRegisterCallbackcallback registered,sceNetCtlCheckCallbackreturns 0 without querying the host.sceNetCtlGetStateuses:IPOBTAINED(3) while the host has a non-loopback address,DISCONNECTED(1) otherwise. The values come from shadPS4net_ctl_codes.hL27-29. Under the lock it marks the IPv4 slots whoselastEventdiffers. After the lock is released, it calls each of them on the calling thread asfunc(event, arg), so a callback can unregister itself without deadlocking (tested).network.cpp@9e41d832 (NetCtlCallbackSlotL3447-3451,NetCtlCheckCallbackL3648-3661,NetCtlRegisterCallbackL3687-3707). shadPS4net_ctl_obj.cppL47-57 delivers the state on every check instead. Neither model is measured on hardware, and the debt entry records the difference.NetCtlUnregisterCallbackwaits for a running check. Here they are called from a copy of their slots, so an unregister orsceNetCtlTermon another thread that returns while a check is in flight does not stop that check from calling the callback once more with its old argument. The debt entry records this.sceNetCtlTermclears both tables, as KytyPS5NetCtlTerm(L3625-3633) does.A Functional entry in
docs/dev/debt/libSceNetCtl.mdrecords that the delivery model comes from KytyPS5 and is not measured on hardware, that the state comes from the host interfaces, the in-flight call after a concurrent unregister, and that V6 callbacks get no event.Cost: on Windows the host query is two
GetAdaptersAddressescalls, the same as onesceNetCtlGetStateonmain. On this host a check with a callback registered costs about 8.6 ms when the host is idle and 10-23 ms while parallel builds run;sceNetCtlGetStatecosts the same. With no callback registered, a check returns before the query (under 1 us). A follow-up PR will cache the predicate on Windows (invalidated byNotifyUnicastIpAddressChange/NotifyIpInterfaceChange, or built onGetUnicastIpAddressTable) and retryGetAdaptersAddressesonERROR_BUFFER_OVERFLOW. Until then, an address added between the size query and the fetch reads as no address, as it already does forsceNetCtlGetState, and here it deliversDISCONNECTEDand thenIPOBTAINEDon the next check.This covers only the NetCtl half of stop 2. The NpManager half (state callbacks and SIGNED_OUT from
sceNpCheckCallback) is a separate change. Minecraft Bedrock (PPSA17221) is playable onmainwithout this change (#5744), so the change was not needed there. The Preview needs it for stop 2 of #1277. No open PR covers these functions; the last change to them was #5427 (RegisterCallbackV6/UnregisterCallbackV6). #6039 also appends todocs/dev/debt/libSceNetCtl.md; whichever merges second resolves a two-line append.Test:
guest_net_ctl(core/libs/tests/GuestNetCtl.cpp) now runs callback cases before its existing exit 77 for a host without an IPv4 address. The expected event comes fromsceNetCtlGetState, so the result does not depend on the host's connectivity.sceNetCtlTerm(cid 0 both times); it is never called.&probeand a check, the callback has been called exactly once, witharg == &probeand the expected event. A second check calls nothing.sceNetCtlTermis not called by a check after it. Registering again afterTermgets cid 0, and the next check delivers the current state again.Tested
Windows Server 2025 (10.0.26100), WinLibs MinGW-w64 GCC 15.2.0, Ninja, Release,
BUILD_TESTING=ON, onmaineea428ca8.mainwith only the new test:GuestNetCtl.cppdoes not compile on Windows, because anAPS5_VABIfunction does not convert tomain'sNetCtlCallback. Red, with theNetCtlCallbacktype change andmain'sExport.cpp:guest_net_ctlaborts (0xc0000409) in 2 of 2 runs oneea428ca8, 2 of 2 on922abe6a4and 3 of 3 on153d5d469, because the callback is never called.153d5d469: this change withsceNetCtlCheckCallbackalso walking the V6 table aborts (0xc0000409) in 3 of 3 runs, and this change with the callbacks called under the lock times out at 20 s (deadlock in the self-unregister case).guest_net_ctlpasses in 5 of 5 runs oneea428ca8and 6 of 6 on922abe6a4(0.4-1.3 s on a host running parallel builds), and 8 of 8 on153d5d469. The host has an address, so the cases ran with event 3 and the test did not skip.ctest -R 'Net|net'oneea428ca8and on922abe6a4: 9 of 9 passed (guest_net_ctl,guest_sce_net,guest_netctl_ap_dialog,guest_datagram_*,guest_socket_host_write_*).python tools/check_conventions.py --base upstream/main(the tools frommain): passed.git merge-treeagainst the open PRs that touch the same files (#6044, #6039, #6023, #5995, #5991, #5967, #5966, #5965, #5928, #5836, #5659, #5611, #5473; #5536 has since merged and is in the base): the only conflict this change adds is the #6039 append to the debt file, described above.Not tested: Linux and macOS (there
APS5_VABIis empty and the test fails at runtime instead of at compile time), and any title. I did not run Minecraft Preview.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T23:16:33Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/tests/GuestNetCtl.cppL20-21, L24, L91-92docs/dev/debt/libSceNetCtl.mdL9core/libs/tests/GuestNetCtl.cppL24, L92docs/dev/debt/libSceNetCtl.mdL9Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/tests/GuestSceNet.cppdocs/dev/debt/libSceNetCtl.mdcore/libs/tests/GuestNetCtl.cppcore/libs/tests/GuestSceNet.cppcore/libs/SceTypes.hppcore/libs/prx/libSceNetCtl/Export.cppcore/libs/prx/libSceNetCtl/Export.cppcore/libs/tests/GuestNetCtl.cppdocs/dev/debt/libSceNetCtl.mdImported from boykopovar/AnyPS5. Originally posted by isnisk on 2026-10-15T14:50:19Z.
Checked on Linux: Ubuntu 26.04 (WSL2), GCC 15.2.0, Release, this head (
a5e4164ed) merged ontomain489466d3f(clean merge).guest_net_ctl,guest_sce_netandguest_netctl_ap_dialogpass, 3 rounds; no warnings from the changed files.main'sExport.cpp, the new test and theNetCtlCallbacktype change kept):guest_net_ctlaborts 3 of 3. As you expected, on Linux it compiles and fails at runtime instead of at compile time.check_conventions.py --base origin/mainpasses.Not checked: macOS, the title.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-17T00:07:13Z.
Checked the diff against KytyPS5
NetCtlCheckCallback/RegisterCallbackand the debt entry, and built and ranguest_net_ctl+guest_sce_neton the merged tree (35/35 in scope pass;guest_net_ctlfails with the non-test changes reverted, matching isnisk's Linux run). Callbacks run outside the lock, so the self-unregister case is covered; merging once the Windows build is green.