feat(libSceNpCommon): implement the online ID utilities and the mutex, condition and clock wrappers #9037

Merged
YossiYad merged 5 commits from upstream-pr/9037 into main 2026-10-23 09:23:15 +00:00
YossiYad commented 2026-10-21 10:22:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-21T10:22:22Z.


What

21 libSceNpCommon calls threw. They now follow shadPS4's np_common.cpp:

  • Online IDs and NpIds (4): sceNpCmpOnlineId compares the 16 handle characters (NP_UTIL_ERROR_NOT_MATCH on a mismatch); sceNpCmpNpIdInOrder orders by handle, then opt, then reserved, and writes -1, 0 or 1; sceNpGetPlatformType reads the tag at opt[4..7] (none, PS3, Vita, PS4, else INVALID_PLATFORM_TYPE); sceNpIntIsValidOnlineId accepts 3 to 16 characters, the first alphanumeric and the rest alphanumeric, _ or -. A null argument is NP_ERROR_INVALID_ARGUMENT.
  • Mutexes (10): sceNpMutex* and sceNpLwMutex* call the libkernel scePthreadMutex* functions; flag bit 0 makes the mutex recursive, and a busy try-lock is NP_LW_MUTEX_ERROR_BUSY.
  • Conditions, threads and time (7): sceNpCondInit, Destroy, Signal and Timedwait (0 microseconds waits without a timeout, a timeout is NP_LW_COND_ERROR_TIMEDOUT), sceNpJoinThread, sceNpGetSystemClockUsec from the monotonic clock, and sceNpGetSdkVersion, which formats the system software version as major.minor.

sceNpCreateThread and the callout calls are left out. AnyPS5's scePthread* functions already return SCE errors, so only the two NP-specific codes are mapped; shadPS4 converts errno values first. None of this is measured on a PS5; the debt entry says so, and the 21 "unknown signature" lines are removed.

#6977, now merged, added a sceNpCmpNpId stub to PendingExports.cpp. This PR does not implement it, so the stub stays.

Tested

Linux (Fedora 44, GCC, Ninja, -DBUILD_TESTING=ON), based on main 2abfb1beb4:

  • New guest_np_common_ids, guest_np_common_sync and guest_np_common_clock (core/libs/tests/GuestNpCommon.cpp): ID comparison and ordering (including opt taking precedence over reserved), all four platform tags and an unknown one, valid and invalid online IDs (2 and 16 characters, unterminated, leading -, .), a plain mutex reporting BUSY on a held try-lock while a flag-1 mutex locks twice, a 2 ms timed wait returning TIMEDOUT with the mutex held again, a join returning the thread's value, the clock falling between two sceKernelClockGettime reads, and the version 1.00 written within 8 bytes. They abort on main. Each of these breaks at least one case: ignoring the recursive flag, skipping either NP error mapping, a wrong platform number, dropping the opt comparison, a 2 character minimum, rejecting _, a wrong clock id or unit, an unpadded minor version, and dropping the join value.
  • Full ctest: 1787 of 1795 pass. The 8 failures fail the same way on main on this machine and do not link libSceNpCommon: application_heap_scripting, application_heap_lazy, agc_driver_guest_memory_lifetime, agc_driver_image_array_window_past_layer_limit, agc_driver_tessellation and the three net_dontwait_blocking_* cases.
  • tools/progress.py --compare: libraries +0.24%, 21 functions implemented, none lost.
  • tools/check_conventions.py --base upstream/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:4950037469 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9037). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-21T10:22:22Z. --- ### What 21 libSceNpCommon calls threw. They now follow [shadPS4's np_common.cpp](https://github.com/shadps4-emu/shadPS4/blob/a808e76/src/core/libraries/np/np_common.cpp): - **Online IDs and NpIds (4):** `sceNpCmpOnlineId` compares the 16 handle characters (`NP_UTIL_ERROR_NOT_MATCH` on a mismatch); `sceNpCmpNpIdInOrder` orders by handle, then `opt`, then `reserved`, and writes -1, 0 or 1; `sceNpGetPlatformType` reads the tag at `opt[4..7]` (none, PS3, Vita, PS4, else `INVALID_PLATFORM_TYPE`); `sceNpIntIsValidOnlineId` accepts 3 to 16 characters, the first alphanumeric and the rest alphanumeric, `_` or `-`. A null argument is `NP_ERROR_INVALID_ARGUMENT`. - **Mutexes (10):** `sceNpMutex*` and `sceNpLwMutex*` call the libkernel `scePthreadMutex*` functions; flag bit 0 makes the mutex recursive, and a busy try-lock is `NP_LW_MUTEX_ERROR_BUSY`. - **Conditions, threads and time (7):** `sceNpCondInit`, `Destroy`, `Signal` and `Timedwait` (0 microseconds waits without a timeout, a timeout is `NP_LW_COND_ERROR_TIMEDOUT`), `sceNpJoinThread`, `sceNpGetSystemClockUsec` from the monotonic clock, and `sceNpGetSdkVersion`, which formats the system software version as `major.minor`. `sceNpCreateThread` and the callout calls are left out. AnyPS5's `scePthread*` functions already return SCE errors, so only the two NP-specific codes are mapped; shadPS4 converts errno values first. None of this is measured on a PS5; the debt entry says so, and the 21 "unknown signature" lines are removed. #6977, now merged, added a `sceNpCmpNpId` stub to `PendingExports.cpp`. This PR does not implement it, so the stub stays. ### Tested Linux (Fedora 44, GCC, Ninja, `-DBUILD_TESTING=ON`), based on `main` `2abfb1beb4`: - New `guest_np_common_ids`, `guest_np_common_sync` and `guest_np_common_clock` (`core/libs/tests/GuestNpCommon.cpp`): ID comparison and ordering (including `opt` taking precedence over `reserved`), all four platform tags and an unknown one, valid and invalid online IDs (2 and 16 characters, unterminated, leading `-`, `.`), a plain mutex reporting `BUSY` on a held try-lock while a flag-1 mutex locks twice, a 2 ms timed wait returning `TIMEDOUT` with the mutex held again, a join returning the thread's value, the clock falling between two `sceKernelClockGettime` reads, and the version `1.00` written within 8 bytes. They abort on `main`. Each of these breaks at least one case: ignoring the recursive flag, skipping either NP error mapping, a wrong platform number, dropping the `opt` comparison, a 2 character minimum, rejecting `_`, a wrong clock id or unit, an unpadded minor version, and dropping the join value. - Full `ctest`: 1787 of 1795 pass. The 8 failures fail the same way on `main` on this machine and do not link libSceNpCommon: `application_heap_scripting`, `application_heap_lazy`, `agc_driver_guest_memory_lifetime`, `agc_driver_image_array_window_past_layer_limit`, `agc_driver_tessellation` and the three `net_dontwait_blocking_*` cases. - `tools/progress.py --compare`: libraries +0.24%, 21 functions implemented, none lost. - `tools/check_conventions.py --base upstream/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-21 10:23:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T10:23:12Z.


Progress report (4a17c71 → 4aba717)

📈 System libraries: 42.18% (+0.19%, +21 implemented functions)

✅ 21 implemented
Library Name
libSceNpCommon sceNpCmpNpIdInOrder
libSceNpCommon sceNpCmpOnlineId
libSceNpCommon sceNpCondDestroy
libSceNpCommon sceNpCondInit
libSceNpCommon sceNpCondSignal
libSceNpCommon sceNpCondTimedwait
libSceNpCommon sceNpGetPlatformType
libSceNpCommon sceNpGetSdkVersion
libSceNpCommon sceNpGetSystemClockUsec
libSceNpCommon sceNpIntIsValidOnlineId
libSceNpCommon sceNpJoinThread
libSceNpCommon sceNpLwMutexDestroy
libSceNpCommon sceNpLwMutexInit
libSceNpCommon sceNpLwMutexLock
libSceNpCommon sceNpLwMutexTryLock
libSceNpCommon sceNpLwMutexUnlock
libSceNpCommon sceNpMutexDestroy
libSceNpCommon sceNpMutexInit
libSceNpCommon sceNpMutexLock
libSceNpCommon sceNpMutexTryLock
libSceNpCommon sceNpMutexUnlock
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6313665273 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9037#issuecomment-6313665273). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T10:23:12Z. --- <!-- progress-report --> ### Progress report (4a17c71 → 4aba717) 📈 **System libraries**: 42.18% (+0.19%, +21 implemented functions) <details> <summary>✅ 21 implemented</summary> | Library | Name | | - | - | | libSceNpCommon | `sceNpCmpNpIdInOrder` | | libSceNpCommon | `sceNpCmpOnlineId` | | libSceNpCommon | `sceNpCondDestroy` | | libSceNpCommon | `sceNpCondInit` | | libSceNpCommon | `sceNpCondSignal` | | libSceNpCommon | `sceNpCondTimedwait` | | libSceNpCommon | `sceNpGetPlatformType` | | libSceNpCommon | `sceNpGetSdkVersion` | | libSceNpCommon | `sceNpGetSystemClockUsec` | | libSceNpCommon | `sceNpIntIsValidOnlineId` | | libSceNpCommon | `sceNpJoinThread` | | libSceNpCommon | `sceNpLwMutexDestroy` | | libSceNpCommon | `sceNpLwMutexInit` | | libSceNpCommon | `sceNpLwMutexLock` | | libSceNpCommon | `sceNpLwMutexTryLock` | | libSceNpCommon | `sceNpLwMutexUnlock` | | libSceNpCommon | `sceNpMutexDestroy` | | libSceNpCommon | `sceNpMutexInit` | | libSceNpCommon | `sceNpMutexLock` | | libSceNpCommon | `sceNpMutexTryLock` | | libSceNpCommon | `sceNpMutexUnlock` | </details>
pipe1os commented 2026-10-21 17:00:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pipe1os on 2026-10-21T17:00:25Z.


Windows run: Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 (ucrt-posix-seh r7), Ninja, Release, BUILD_TESTING=ON. e0df782d2c merged onto main cecb540a63 without conflicts, and libSceNpCommon and guest_np_common_tests build with no warnings.

  • guest_np_common_ids, _sync and _clock pass, three runs each.
  • With core/libs/prx/libSceNpCommon back to main they abort with sceNpCmpOnlineId not implemented, sceNpMutexInit not implemented and sceNpGetSystemClockUsec not implemented.
  • I checked the 21 against shadPS4 a808e76 np_common.cpp. Compare/order/validate, the platform tags, bit 0 as recursive, the BUSY and TIMEDOUT mappings, the monotonic clock and the %u.%02u version all match. The only difference is the error mapping, and the description already covers it (AnyPS5's scePthread* already return SCE codes).

The Windows failure I hit is in #9063, not here. Details are over there.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6321715490 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9037#issuecomment-6321715490). Originally posted by [pipe1os](https://github.com/pipe1os) on 2026-10-21T17:00:25Z. --- Windows run: Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 (ucrt-posix-seh r7), Ninja, Release, `BUILD_TESTING=ON`. e0df782d2c merged onto `main` cecb540a63 without conflicts, and `libSceNpCommon` and `guest_np_common_tests` build with no warnings. - `guest_np_common_ids`, `_sync` and `_clock` pass, three runs each. - With `core/libs/prx/libSceNpCommon` back to `main` they abort with `sceNpCmpOnlineId not implemented`, `sceNpMutexInit not implemented` and `sceNpGetSystemClockUsec not implemented`. - I checked the 21 against shadPS4 a808e76 `np_common.cpp`. Compare/order/validate, the platform tags, bit 0 as recursive, the BUSY and TIMEDOUT mappings, the monotonic clock and the `%u.%02u` version all match. The only difference is the error mapping, and the description already covers it (AnyPS5's `scePthread*` already return SCE codes). The Windows failure I hit is in #9063, not here. Details are over there.
YossiYad commented 2026-10-21 19:43:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-21T19:43:22Z.


Thanks @pipe1os for the Windows run and for going through all 21 against np_common.cpp. Good to have the error mapping difference confirmed as the only one.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6324961329 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9037#issuecomment-6324961329). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-21T19:43:22Z. --- Thanks @pipe1os for the Windows run and for going through all 21 against `np_common.cpp`. Good to have the error mapping difference confirmed as the only one.
YossiYad commented 2026-10-22 05:34:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-22T05:34:51Z.


Rebased onto main da54c652e (head 4aba71700). #6977 had added a sceNpCmpNpId stub to PendingExports.cpp, which this PR doesn't implement, so I kept it. Otherwise the change is line for line the same as before, and guest_np_common passes 3 of 3.

@oneandonlydean @adriadam10 ready from my side: CI is green, and pipe1os ran it on Windows and checked the 21 calls against shadPS4.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6333572405 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9037#issuecomment-6333572405). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-22T05:34:51Z. --- Rebased onto `main` `da54c652e` (head `4aba71700`). #6977 had added a `sceNpCmpNpId` stub to `PendingExports.cpp`, which this PR doesn't implement, so I kept it. Otherwise the change is line for line the same as before, and `guest_np_common` passes 3 of 3. @oneandonlydean @adriadam10 ready from my side: CI is green, and pipe1os ran it on Windows and checked the 21 calls against shadPS4.
oneandonlydean commented 2026-10-22 06:13:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-22T06:13:58Z.


@YossiYad thanks, it's in my review queue now. I'll come back here with the result.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6334113507 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9037#issuecomment-6334113507). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-22T06:13:58Z. --- @YossiYad thanks, it's in my review queue now. I'll come back here with the result.
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!9037
No description provided.