feat(libs): implement NpCppWebApi IntrusivePtr construction, copy, release and access #631

Merged
DotDebian merged 1 commit from upstream-pr/631 into main 2026-10-05 13:33:43 +00:00
DotDebian commented 2026-10-05 09:18:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DotDebian on 2026-10-05T09:18:56Z.


What

sce::Np::CppWebApi::Common::IntrusivePtr<T> in the HLE libSceNpCppWebApi: the 26 members already exported (7 default constructors, 2 copy constructors, 8 destructors, 9 operator->, 1 operator*) were either no-ops that left the guest object uninitialised or NotImplemented. They now behave as the library does:

  • layout, 0x18 bytes: +0x00 object, +0x08 deleter void(*)(T*) (may be null), +0x10 LibContext*;
  • default constructor zeroes the three fields;
  • copy constructor copies the three fields and increments the pointee's reference count when the object is non-null;
  • operator-> / operator* return the object pointer, null included;
  • destructor: nothing for a null object; otherwise decrements the reference count, and when that was the last reference calls the deleter with the object and clears object and deleter (LibContext* is kept). With other references left the three fields are not modified.

The reference count is the 32-bit RefObject counter of the pointee: at +0x00 for the Leaderboards request/response bodies, User and RecordScoreResponseHeaders, at +0x30 for Vector<IntrusivePtr<Entry>>.

Not implemented, still throws: the last-reference release of a pointer without a deleter. The library then runs T's destructor and frees the object from the LibContext memory pool; the HLE has neither. It cannot be reached today since every factory and request returns SCE_NP_WEBAPI_ERROR_UNAVAILABLE and no object is ever created.

Nothing else in the file changes: String, Binary, Vector, iterators, LibContext, initialize/terminate and the transactions are untouched, and nothing is added at the end of the file (#545 and #407 append there). #630 implements Common::String on other lines of the same file; the two are independent.

Source of the behaviour. There is no public description of this class, so the layout and the semantics above were read from a disassembly of the retail libSceNpCppWebApi.prx bundled with one title (a local dump, one build of the module). Export names were matched by hashing the mangled names to their NIDs. No code, listing or data from the module is in this PR.

  • Observed in the code: field offsets and size, the zeroing in the default constructor, the three copies plus the conditional increment, the plain load in the accessors, the decrement / compare-with-previous-value-1 / deleter call / 16-byte clear in the destructors, and the +0x30 counter offset for the Vector instantiation.
  • Inferred: the field names; that the counter is RefObject (the helpers called hash to RefObject::AddRef and RefObject::Release); that the third field is the LibContext* (it is what the no-deleter path resolves to find the pool).
  • Not checked: other builds of the module.

The origin of the layout and the remaining gap are recorded in docs/dev/TechnicalDebt.md.

This only affects titles that run on the HLE module. The relinker converts a title's own sce_module/libSceNpCppWebApi.prx to a guest module and resolves imports against it first, so a title that ships the library does not reach this code.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, ctest. New test guest_np_cpp_web_api_intrusive_ptr (core/libs/tests/GuestNpCppWebApiIntrusivePtr.cpp) calls all 26 exports on pre-filled memory and fake pointees: zeroing, field copy and count increment, null copy, accessors on null and non-null, destructor on null / shared / last reference with the deleter recorded, counter at +0x30 for the Vector instantiation, and the throw on a last reference without a deleter. It aborts on main and passes with this change.

Full suite: 280 of 282 pass. agc_driver_f32_output_modifier and agc_driver_scalar_sop1 fail on this machine (NVIDIA GPU); both are AGC shader execution tests that link only libSceAgcDriver and libc, which this PR does not change.

No title was run.

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 in TechnicalDebt
  • 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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4742743650 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/631). Originally posted by [DotDebian](https://github.com/DotDebian) on 2026-10-05T09:18:56Z. --- ### What `sce::Np::CppWebApi::Common::IntrusivePtr<T>` in the HLE `libSceNpCppWebApi`: the 26 members already exported (7 default constructors, 2 copy constructors, 8 destructors, 9 `operator->`, 1 `operator*`) were either no-ops that left the guest object uninitialised or `NotImplemented`. They now behave as the library does: - layout, 0x18 bytes: `+0x00` object, `+0x08` deleter `void(*)(T*)` (may be null), `+0x10` `LibContext*`; - default constructor zeroes the three fields; - copy constructor copies the three fields and increments the pointee's reference count when the object is non-null; - `operator->` / `operator*` return the object pointer, null included; - destructor: nothing for a null object; otherwise decrements the reference count, and when that was the last reference calls the deleter with the object and clears object and deleter (`LibContext*` is kept). With other references left the three fields are not modified. The reference count is the 32-bit `RefObject` counter of the pointee: at `+0x00` for the Leaderboards request/response bodies, `User` and `RecordScoreResponseHeaders`, at `+0x30` for `Vector<IntrusivePtr<Entry>>`. Not implemented, still throws: the last-reference release of a pointer without a deleter. The library then runs `T`'s destructor and frees the object from the `LibContext` memory pool; the HLE has neither. It cannot be reached today since every factory and request returns `SCE_NP_WEBAPI_ERROR_UNAVAILABLE` and no object is ever created. Nothing else in the file changes: `String`, `Binary`, `Vector`, iterators, `LibContext`, `initialize`/`terminate` and the transactions are untouched, and nothing is added at the end of the file (#545 and #407 append there). #630 implements `Common::String` on other lines of the same file; the two are independent. **Source of the behaviour.** There is no public description of this class, so the layout and the semantics above were read from a disassembly of the retail `libSceNpCppWebApi.prx` bundled with one title (a local dump, one build of the module). Export names were matched by hashing the mangled names to their NIDs. No code, listing or data from the module is in this PR. - Observed in the code: field offsets and size, the zeroing in the default constructor, the three copies plus the conditional increment, the plain load in the accessors, the decrement / compare-with-previous-value-1 / deleter call / 16-byte clear in the destructors, and the `+0x30` counter offset for the `Vector` instantiation. - Inferred: the field names; that the counter is `RefObject` (the helpers called hash to `RefObject::AddRef` and `RefObject::Release`); that the third field is the `LibContext*` (it is what the no-deleter path resolves to find the pool). - Not checked: other builds of the module. The origin of the layout and the remaining gap are recorded in `docs/dev/TechnicalDebt.md`. This only affects titles that run on the HLE module. The relinker converts a title's own `sce_module/libSceNpCppWebApi.prx` to a guest module and resolves imports against it first, so a title that ships the library does not reach this code. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, `ctest`. New test `guest_np_cpp_web_api_intrusive_ptr` (`core/libs/tests/GuestNpCppWebApiIntrusivePtr.cpp`) calls all 26 exports on pre-filled memory and fake pointees: zeroing, field copy and count increment, null copy, accessors on null and non-null, destructor on null / shared / last reference with the deleter recorded, counter at `+0x30` for the `Vector` instantiation, and the throw on a last reference without a deleter. It aborts on `main` and passes with this change. Full suite: 280 of 282 pass. `agc_driver_f32_output_modifier` and `agc_driver_scalar_sop1` fail on this machine (NVIDIA GPU); both are AGC shader execution tests that link only `libSceAgcDriver` and `libc`, which this PR does not change. No title was run. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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 (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-05 09:19:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T09:19:21Z.


Progress report (53dc19c → f2fb785)

📈 System libraries: 79.2% (+0.06%, +10 implemented, -8 reverted functions)

✅ 10 implemented
Library Name
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V121GetRankingRequestBodyEEptEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V122GetRankingResponseBodyEEptEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V122RecordScoreRequestBodyEEptEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V123RecordScoreResponseBodyEEptEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V130GetBoardDefinitionResponseBodyEEptEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V14UserEEptEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V15EntryEEptEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V19RecordApi26RecordScoreResponseHeadersEEptEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS2_6BinaryEEptEv
libSceNpCppWebApi _ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS2_6VectorINS3_INS1_12Leaderboards2V15EntryEEEEEEdeEv
⚠️ 8 went back to stubs
Library Name
libSceNpCppWebApi _ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V121GetRankingRequestBodyEED1Ev
libSceNpCppWebApi _ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V122GetRankingResponseBodyEED1Ev
libSceNpCppWebApi _ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V122RecordScoreRequestBodyEED1Ev
libSceNpCppWebApi _ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V123RecordScoreResponseBodyEED1Ev
libSceNpCppWebApi _ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V130GetBoardDefinitionResponseBodyEED1Ev
libSceNpCppWebApi _ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V14UserEED1Ev
libSceNpCppWebApi _ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V19RecordApi26RecordScoreResponseHeadersEED1Ev
libSceNpCppWebApi _ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS2_6VectorINS3_INS1_12Leaderboards2V15EntryEEEEEED1Ev
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5991610013 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/631#issuecomment-5991610013). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-05T09:19:21Z. --- <!-- progress-report --> ### Progress report (53dc19c → f2fb785) 📈 **System libraries**: 79.2% (+0.06%, +10 implemented, -8 reverted functions) <details> <summary>✅ 10 implemented</summary> | Library | Name | | - | - | | libSceNpCppWebApi | `_ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V121GetRankingRequestBodyEEptEv` | | libSceNpCppWebApi | `_ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V122GetRankingResponseBodyEEptEv` | | libSceNpCppWebApi | `_ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V122RecordScoreRequestBodyEEptEv` | | libSceNpCppWebApi | `_ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V123RecordScoreResponseBodyEEptEv` | | libSceNpCppWebApi | `_ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V130GetBoardDefinitionResponseBodyEEptEv` | | libSceNpCppWebApi | `_ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V14UserEEptEv` | | libSceNpCppWebApi | `_ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V15EntryEEptEv` | | libSceNpCppWebApi | `_ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V19RecordApi26RecordScoreResponseHeadersEEptEv` | | libSceNpCppWebApi | `_ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS2_6BinaryEEptEv` | | libSceNpCppWebApi | `_ZNK3sce2Np9CppWebApi6Common12IntrusivePtrINS2_6VectorINS3_INS1_12Leaderboards2V15EntryEEEEEEdeEv` | </details> <details> <summary>⚠️ 8 went back to stubs</summary> | Library | Name | | - | - | | libSceNpCppWebApi | `_ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V121GetRankingRequestBodyEED1Ev` | | libSceNpCppWebApi | `_ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V122GetRankingResponseBodyEED1Ev` | | libSceNpCppWebApi | `_ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V122RecordScoreRequestBodyEED1Ev` | | libSceNpCppWebApi | `_ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V123RecordScoreResponseBodyEED1Ev` | | libSceNpCppWebApi | `_ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V130GetBoardDefinitionResponseBodyEED1Ev` | | libSceNpCppWebApi | `_ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V14UserEED1Ev` | | libSceNpCppWebApi | `_ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS1_12Leaderboards2V19RecordApi26RecordScoreResponseHeadersEED1Ev` | | libSceNpCppWebApi | `_ZN3sce2Np9CppWebApi6Common12IntrusivePtrINS2_6VectorINS3_INS1_12Leaderboards2V15EntryEEEEEED1Ev` | </details>
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!631
No description provided.