fix(libSceNpUniversalDataSystem): fail a repeated Initialize as the 13.42 module does #21983

Merged
brajankw merged 1 commit from upstream-pr/21983 into main 2026-11-17 02:10:16 +00:00
brajankw commented 2026-11-17 00:45:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by brajankw on 2026-11-17T00:45:11Z.


What

sceNpUniversalDataSystemInitialize kept no state, so a call after a successful call returned 0. The 13.42 module returns 0x80553118 for every call after a success, before it checks any argument (the sceNpUniversalDataSystemInitialize entry in docs/dev/debt/libSceNpUniversalDataSystem.md, from the module run in https://github.com/boykopovar/AnyPS5/pull/12803#issuecomment-6517047831). #16324 implemented the other return codes and left this one open.

  • Initialize tests a process-wide flag first and returns SCE_NP_UNIVERSAL_DATA_SYSTEM_ERROR_ALREADY_INITIALIZED (0x80553118) when it is set, for any argument. It sets the flag only after its argument checks pass, as sceNpUniversalDataSystemIntInitialize already does with its own state.
  • sceNpUniversalDataSystemTerminate clears the flag and still returns 0, as it did on main; sceNpUniversalDataSystemIntTerminate clears its own flag the same way. Without the clear, the new state would make every Initialize after a Terminate fail. The harness run did not cover Terminate, so the debt fragment now records that what it returns and whether Initialize succeeds after it are unverified.
  • GuestNpUniversalDataSystemQueries.cpp: after the successful call, Initialize with the valid parameters, with size 0x18 and with nullptr each return 0x80553118; after Terminate, Initialize succeeds once more and fails again after that.
  • #19606 also edits Initialize (it reads param through GuestCopyIn_nid_no_patch); the two conflict textually and whichever lands second needs a rebase.

Tested

Linux (Debian 13, GCC 14.2.0, Release), on main 258ab7b6bd.

  • ctest -R '^guest_np_uds': 2/2 passed (guest_np_uds_queries, guest_np_uds_records).
  • Negative control: with main's libSceNpUniversalDataSystem sources and this branch's test, guest_np_uds_queries fails with UDS query check failed at line 52, the first repeated Initialize.
  • Full ctest (5891 tests, -j 12) with this branch merged together with four unrelated fixes of mine: 5875 passed. The 16 failures are the set that fails on main in the same environment: six agc_driver cases (agc_driver_image_table_packed_guards passes when run on its own) and ten that need a .git directory, network or a passwd entry for the user.
  • python3 tools/check_conventions.py --base origin/main: passed.
  • python3 tools/pr_overlap.py --branch: #19606 only, the textual conflict above.
  • Not tested on Windows or macOS. No title.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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:5348076818 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21983). Originally posted by [brajankw](https://github.com/brajankw) on 2026-11-17T00:45:11Z. --- ### What `sceNpUniversalDataSystemInitialize` kept no state, so a call after a successful call returned 0. The 13.42 module returns `0x80553118` for every call after a success, before it checks any argument (the `sceNpUniversalDataSystemInitialize` entry in `docs/dev/debt/libSceNpUniversalDataSystem.md`, from the module run in https://github.com/boykopovar/AnyPS5/pull/12803#issuecomment-6517047831). #16324 implemented the other return codes and left this one open. - `Initialize` tests a process-wide flag first and returns `SCE_NP_UNIVERSAL_DATA_SYSTEM_ERROR_ALREADY_INITIALIZED` (`0x80553118`) when it is set, for any argument. It sets the flag only after its argument checks pass, as `sceNpUniversalDataSystemIntInitialize` already does with its own state. - `sceNpUniversalDataSystemTerminate` clears the flag and still returns 0, as it did on `main`; `sceNpUniversalDataSystemIntTerminate` clears its own flag the same way. Without the clear, the new state would make every `Initialize` after a `Terminate` fail. The harness run did not cover `Terminate`, so the debt fragment now records that what it returns and whether `Initialize` succeeds after it are unverified. - `GuestNpUniversalDataSystemQueries.cpp`: after the successful call, `Initialize` with the valid parameters, with size `0x18` and with `nullptr` each return `0x80553118`; after `Terminate`, `Initialize` succeeds once more and fails again after that. - #19606 also edits `Initialize` (it reads `param` through `GuestCopyIn_nid_no_patch`); the two conflict textually and whichever lands second needs a rebase. ### 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. --> Linux (Debian 13, GCC 14.2.0, Release), on `main` `258ab7b6bd`. - `ctest -R '^guest_np_uds'`: 2/2 passed (`guest_np_uds_queries`, `guest_np_uds_records`). - Negative control: with `main`'s `libSceNpUniversalDataSystem` sources and this branch's test, `guest_np_uds_queries` fails with `UDS query check failed at line 52`, the first repeated `Initialize`. - Full `ctest` (5891 tests, `-j 12`) with this branch merged together with four unrelated fixes of mine: 5875 passed. The 16 failures are the set that fails on `main` in the same environment: six `agc_driver` cases (`agc_driver_image_table_packed_guards` passes when run on its own) and ten that need a `.git` directory, network or a passwd entry for the user. - `python3 tools/check_conventions.py --base origin/main`: passed. - `python3 tools/pr_overlap.py --branch`: #19606 only, the textual conflict above. - Not tested on Windows or macOS. No title. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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
PrivacyOnion commented 2026-11-17 00:51:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-17T00:51:16Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 0c37572c31:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_np_uds_queries_tests built cleanly.
  • CTest (guest_np_uds_queries):
    1/1 Test #4627: guest_np_uds_queries .............   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNpUniversalDataSystem/src/NpUniversalDataSystem.hpp, core/libs/prx/libSceNpUniversalDataSystem/src/System.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4627: guest_np_uds_queries .............Subprocess aborted***Exception:   0.35 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified sceNpUniversalDataSystemInitialize checks g_systemInitialized prior to checking param pointer and struct fields in System.cpp:18, returning SCE_NP_UNIVERSAL_DATA_SYSTEM_ERROR_ALREADY_INITIALIZED
    • Verified argument checks for param == nullptr, param->size != sizeof(NpUniversalDataSystemInitParam), and param->pool_size == 0 return SCE_NP_UNIVERSAL_DATA_SYSTEM_ERROR_INVALID_ARGUMENT and SCE_NP_UNIVERSAL_DATA_SYSTEM_ERROR_INVALID_PARAM_SIZE in System.cpp:21-29
    • Verified thread-safety of initialization state using std::atomic g_systemInitialized with atomic load and exchange(true) in System.cpp:12, 18, 31
    • Verified sceNpUniversalDataSystemTerminate resets g_systemInitialized to false in System.cpp:37, allowing subsequent Initialize calls
    • Verified constant SCE_NP_UNIVERSAL_DATA_SYSTEM_ERROR_ALREADY_INITIALIZED (-2141900520 / 0x80553118) in NpUniversalDataSystem.hpp:18 and test assertions in GuestNpUniversalDataSystemQueries.cpp
    • Verified AGENTS.md technical debt fragment format and conventions compliance in docs/dev/debt/changes/fix-libSceNpUniversalDataSystem-initialize-state.md

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5930693384 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21983#pullrequestreview-5930693384). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-17T00:51:16Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `0c37572c31`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_np_uds_queries_tests` built cleanly. - **CTest** (`guest_np_uds_queries`): ``` 1/1 Test #4627: guest_np_uds_queries ............. Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNpUniversalDataSystem/src/NpUniversalDataSystem.hpp`, `core/libs/prx/libSceNpUniversalDataSystem/src/System.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #4627: guest_np_uds_queries .............Subprocess aborted***Exception: 0.35 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified sceNpUniversalDataSystemInitialize checks g_systemInitialized prior to checking param pointer and struct fields in System.cpp:18, returning SCE_NP_UNIVERSAL_DATA_SYSTEM_ERROR_ALREADY_INITIALIZED - Verified argument checks for param == nullptr, param->size != sizeof(NpUniversalDataSystemInitParam), and param->pool_size == 0 return SCE_NP_UNIVERSAL_DATA_SYSTEM_ERROR_INVALID_ARGUMENT and SCE_NP_UNIVERSAL_DATA_SYSTEM_ERROR_INVALID_PARAM_SIZE in System.cpp:21-29 - Verified thread-safety of initialization state using std::atomic<bool> g_systemInitialized with atomic load and exchange(true) in System.cpp:12, 18, 31 - Verified sceNpUniversalDataSystemTerminate resets g_systemInitialized to false in System.cpp:37, allowing subsequent Initialize calls - Verified constant SCE_NP_UNIVERSAL_DATA_SYSTEM_ERROR_ALREADY_INITIALIZED (-2141900520 / 0x80553118) in NpUniversalDataSystem.hpp:18 and test assertions in GuestNpUniversalDataSystemQueries.cpp - Verified AGENTS.md technical debt fragment format and conventions compliance in docs/dev/debt/changes/fix-libSceNpUniversalDataSystem-initialize-state.md Looks Good To Me
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!21983
No description provided.