feat(libSceNpSignaling): model contexts and connections offline #9886

Merged
MarrasFederico merged 4 commits from upstream-pr/9886 into main 2026-10-23 12:14:46 +00:00
MarrasFederico commented 2026-10-22 20:37:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-10-22T20:37:06Z.


What

All eight libSceNpSignaling exports threw. They now follow shadPS4's np_signaling.cpp offline, the way #9009 modelled libSceNpTus:

  • Initialize and terminate: a second sceNpSignalingInitialize is ALREADY_INITIALIZED; every other call before it, and sceNpSignalingTerminate twice, is NOT_INITIALIZED, checked before any argument. Terminating releases the contexts.
  • Contexts: sceNpSignalingCreateContext refuses a null NpId or output and an NpId whose online ID breaks the rule shadPS4's NormalizeNpId applies (term 0, 3 to 16 characters, the first an ASCII letter or digit, then ASCII letters, digits, _ or -; checked byte by byte, so the host locale does not change it) with INVALID_ARGUMENT. Ids 1 to 8 are handed out round-robin as in AllocateContextIdLocked; a ninth context is CTXID_NOT_AVAILABLE. sceNpSignalingDeleteContext succeeds for any id, as shadPS4's does. sceNpSignalingSetContextOption takes option 1 with value 0 or 1, after the context check.
  • Connections: sceNpSignalingActivateConnection runs shadPS4's checks up to OWN_NP_ID (the context's own NpId, from ActivateSig1) and returns SCE_NP_ERROR_SIGNED_OUT without writing a connection id. No connection exists, so sceNpSignalingTerminateConnection and sceNpSignalingGetConnectionInfo answer CONN_NOT_FOUND after their context checks and write nothing.

Left out: shadPS4's heap and thread start in Initialize (its arguments are not checked), its app-type checks and its activation rate limit. Nothing here is measured on a PS5; the new debt file says so. Callbacks are never called.

#9896 adds a sceNpSignalingDeactivateConnection declaration to this Export.cpp and creates the same debt file; the Export.cpp changes merge cleanly, and whichever lands second keeps both debt entries.

Tested

Ubuntu 26.04.1, kernel 7.0.0-38, GCC 15.2.0, Release, full build with BUILD_TESTING=ON. Windows was not compiled. No title was run.

  • New guest_np_signaling_offline (core/libs/tests/GuestNpSignalingOffline.cpp): NOT_INITIALIZED before initialization (ahead of null arguments), double initialization, each NpId rule (2 characters, leading _, ., a byte outside ASCII, unterminated, 16 characters and upper case with digits accepted), ids 1 to 8 with a freed id skipped until the allocation wraps, the ninth context, the option checks and their order, OWN_NP_ID, SIGNED_OUT with no id written, the connection calls writing nothing, deleting an unknown context, and termination releasing contexts and restarting ids at 1.
  • It aborts on main (sceNpSignalingCreateContext not implemented) and passes with this change. 14 mutations of the new code (check order in three calls, each NpId rule including upper case, round-robin allocation, OWN_NP_ID, the flag values, deleting an unknown context, both parts of the termination reset) each fail it.
  • tools/check_conventions.py --base upstream/main passes; tools/pr_overlap.py reports no overlap.

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:4973783448 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9886). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-10-22T20:37:06Z. --- ### What All eight libSceNpSignaling exports threw. They now follow [shadPS4's np_signaling.cpp](https://github.com/shadps4-emu/shadPS4/blob/91e6afa69b0a64b0afaa0281b80f8fbb0cd88136/src/core/libraries/np/np_signaling/np_signaling.cpp) offline, the way #9009 modelled libSceNpTus: - **Initialize and terminate:** a second `sceNpSignalingInitialize` is `ALREADY_INITIALIZED`; every other call before it, and `sceNpSignalingTerminate` twice, is `NOT_INITIALIZED`, checked before any argument. Terminating releases the contexts. - **Contexts:** `sceNpSignalingCreateContext` refuses a null NpId or output and an NpId whose online ID breaks the rule shadPS4's [`NormalizeNpId`](https://github.com/shadps4-emu/shadPS4/blob/91e6afa69b0a64b0afaa0281b80f8fbb0cd88136/src/core/libraries/np/np_signaling/np_signaling_state.cpp#L120-L142) applies (`term` 0, 3 to 16 characters, the first an ASCII letter or digit, then ASCII letters, digits, `_` or `-`; checked byte by byte, so the host locale does not change it) with `INVALID_ARGUMENT`. Ids 1 to 8 are handed out round-robin as in [`AllocateContextIdLocked`](https://github.com/shadps4-emu/shadPS4/blob/91e6afa69b0a64b0afaa0281b80f8fbb0cd88136/src/core/libraries/np/np_signaling/np_signaling_state.cpp#L156-L170); a ninth context is `CTXID_NOT_AVAILABLE`. `sceNpSignalingDeleteContext` succeeds for any id, as shadPS4's does. `sceNpSignalingSetContextOption` takes option 1 with value 0 or 1, after the context check. - **Connections:** `sceNpSignalingActivateConnection` runs shadPS4's checks up to `OWN_NP_ID` (the context's own NpId, from [`ActivateSig1`](https://github.com/shadps4-emu/shadPS4/blob/91e6afa69b0a64b0afaa0281b80f8fbb0cd88136/src/core/libraries/np/signaling_handler.cpp#L1397-L1423)) and returns `SCE_NP_ERROR_SIGNED_OUT` without writing a connection id. No connection exists, so `sceNpSignalingTerminateConnection` and `sceNpSignalingGetConnectionInfo` answer `CONN_NOT_FOUND` after their context checks and write nothing. Left out: shadPS4's heap and thread start in `Initialize` (its arguments are not checked), its app-type checks and its activation rate limit. Nothing here is measured on a PS5; the new debt file says so. Callbacks are never called. #9896 adds a `sceNpSignalingDeactivateConnection` declaration to this `Export.cpp` and creates the same debt file; the `Export.cpp` changes merge cleanly, and whichever lands second keeps both debt entries. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Ubuntu 26.04.1, kernel 7.0.0-38, GCC 15.2.0, Release, full build with `BUILD_TESTING=ON`. Windows was not compiled. No title was run. - New `guest_np_signaling_offline` (`core/libs/tests/GuestNpSignalingOffline.cpp`): `NOT_INITIALIZED` before initialization (ahead of null arguments), double initialization, each NpId rule (2 characters, leading `_`, `.`, a byte outside ASCII, unterminated, 16 characters and upper case with digits accepted), ids 1 to 8 with a freed id skipped until the allocation wraps, the ninth context, the option checks and their order, `OWN_NP_ID`, `SIGNED_OUT` with no id written, the connection calls writing nothing, deleting an unknown context, and termination releasing contexts and restarting ids at 1. - It aborts on `main` (`sceNpSignalingCreateContext not implemented`) and passes with this change. 14 mutations of the new code (check order in three calls, each NpId rule including upper case, round-robin allocation, `OWN_NP_ID`, the flag values, deleting an unknown context, both parts of the termination reset) each fail it. - `tools/check_conventions.py --base upstream/main` passes; `tools/pr_overlap.py` reports no overlap. ### 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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
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!9886
No description provided.