feat(libSceNpCommon): implement sce::np::RefObject #13431
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13431"
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 hypermoist on 2026-10-30T14:19:59Z.
What
Implements
sce::np::RefObject(7 exports) fromlibSceNpCommon.sprxof firmware 13.60 (read from disassembly, not measured on a console).main: 3 had placeholderint (void)declarations:C1,D1andRelease.C2,D0,D2andAddRef.NpRefObject(declared inApi.hpp, 16 bytes): a vtable, thenint32_t refCountat+8. The vtable is{0, 0, D1, D0}.sce::np::Object::operator delete(void*).AddRef:sceNpAtomicInc32(&refCount) + 1, the new count.Release:sceNpAtomicDec32(&refCount) - 1. When that is exactly 0, it calls the deleting destructor from vtable slot 1; it returns the new count either way.Tested
The results below are for head
502ef67d9dd. Linux (CachyOS, GCC 16.2, Release):ctest --test-dir build -R 'np_common|public_headers' --output-on-failurepassed 70/70.guest_np_common_runtimepassed 3 of 3 runs.guest_freetype. That one fails here because my local3rdparty/freetypecheckout is not at the pinned commit; this PR does not touch FreeType.Firmware differential: 7,200 cases, run from the module's code under unicorn and replayed through this implementation, with 0 mismatches.
AddRefandRelease: 3,000 cases each. Counts include 0, ±1, 2, the 32-bit limits and random values. The object's vtable is a fake whose slot 1 records the destructor call.np_ref_object_make_cases.pyandnp_ref_object_replay.cppin this gist, with theemucall.pyrunner. It needs a decrypted module, which is not attached.Guest test:
TestRefObjectsinGuestNpCommonRuntime.cppchecks:AddRefandReleasereturn;Object::operator new: a release that is not the last keeps the object, and the last one deletes it through the stored allocator viaD0.Mutation check: I changed 6 single lines, one at a time, and the differential catches all 6 (248–3,000 mismatches each):
AddRefreturning the old count;Releasereturning the old count;Releasedeleting at<= 0;Releasenever deleting;D1clearing it.Windows not built. Not run on a console.
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)main(AddRef,C2,D0,D2) asNotImplementedstubs, so it drops them fromInventoryExports.cppafter this lands. Agreed with its author (comment): #13120 has removed the four declarations and declaresDepends on: #13130, #13270, #13277, #13281, #13345, #13408, #13431.Api.hppand debt lines;Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console.
🤖 Generated with Claude Code