feat(libSceNpCommon): implement the sce::np::Object new and delete operators #12836
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12836"
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-29T12:02:23Z.
What
Implements the ten
sce::np::Objectallocation operators fromlibSceNpCommon.sprxof firmware 13.60 (read from disassembly, not measured on a console). Five wereNotImplementedstubs with placeholderint (void)declarations. The other five are exported by the module but were missing from AnyPS5:nw…R16SceNpAllocatorEx,na…R16SceNpAllocatorEx,dl…R16SceNpAllocatorEx,da…R14SceNpAllocatoranddaEPv;nw…R14SceNpAllocator,na…R14SceNpAllocator,dl…R14SceNpAllocator,da…R16SceNpAllocatorExanddlEPv.The contract, using the repo's existing
NpAllocatorlayout (allocateat 0,releaseat 0x10,contextat 0x18):new/new[](size_t size, SceNpAllocator&orSceNpAllocatorEx&):allocate(size + 16, context)and returns null if it fails;SceNpAllocatorExitself, whose first member is the allocator (the module's_sceNpAllocatorExConvertAllocatorreturns its argument).delete/delete[](with or without an allocator):release(object - 16, context)through the allocator stored in the header;size + 16is not checked for overflow, as in the module. The debt file states both points and drops the five "signature unknown" entries.Tested
Linux (CachyOS, GCC, Release):
ctest --test-dir build -R 'np_common|public_headers' --output-on-failure, 70/70 passed.TestObjectsinGuestNpCommonRuntime.cppuses a recording allocator to check:Comparison against the firmware code: I relinked the 13.60 module with this repo's relinker and ran all ten operators under unicorn (x86-64 emulation on a PC, not a console). The allocator's
allocateandreleasepointers were bound to recording handlers.2^64 - 16and2^64 - 1, wheresize + 16wraps), with a succeeding and a failing allocator, and for delete with a null and a real object. The header held a different allocator from the argument.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)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
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T12:09:00Z.
Review: COMMENTED
I reviewed
72cde05a64on macOS arm64 (Apple clang, ASan + UBSan,-fno-sanitize-recover=all). I built the newRuntime.cpphunk andTestObjectsas a standalone program against theNpAllocator/NpAllocatorExlayouts fromApi.hpp. I didn't run the full CMake lane.TestObjectspasses as written.tools/nid_names.pygives the same NIDs for the five replaced stubs as the debt entries this PR removes (1x0jThSUr4w,bKMVqRcCQ1U,iwDNdnEGyhI,4il4PZAZOnQ,orRb69nSo64). The five new names hash to0syNkhJANVw,V75N47uYdQc,05KEwpDf4Ls,q2USyzLF4kIandCnDHI7sU+l0.5454cd2e45.git merge-treeagainst main,git diff --checkandcheck_conventions.py --headare all clean.pr_overlap.py --branch(1,395 PRs probed) finds #12825, #12829 and #12830, all from the stub-removal hunks you already disclose; #12829 and #12830 are stacked on #12825. It also finds #12839, which has the same ten exports because it is stacked on this PR and says so.Test coverage. I ran 13 single-change mutants of the new code.
TestObjectskills 3: the header offset, the null-object check and storing a copy of the inner allocator. The other 10 change behaviour, and the test still passes:delete[] (void*, SceNpAllocator&)does nothing. It is only called with a null object.delete (void*, SceNpAllocatorEx&)does nothing. It is only called with a null object.3–5. The three delete forms that take an allocator free through the argument instead of the header. Only
dl…R14SceNpAllocatoris tested with a different allocator;dl…R16,da…R14andda…R16are not.newzeroes the second 8 bytes of the header. The test doesn't check that they are left alone, and your differential recorded all 16 header bytes.newreturns null whensize + 16wraps. The debt file says the module doesn't check this, but no test pins it.na…R16SceNpAllocatorExrequests the wrong size. Its requested size is never checked.9–10. Neither array
newform is run with a failing allocator, so a non-null result on failure survives.These rows kill all 10. They pass on your head, and the three mutants already killed stay killed:
This needs
<algorithm>and<cstdint>. The wrap row assumes a recording allocator fails the 0-byte request; it does here becausefailis still set. The row only shows that the request wraps to 0. Your differential already covered2^64 - 16, so please check this row against it.Nit: the body has "all test done locally on actual hardware" and also "Not run on a console". It's the same wording as on #12825, #12829 and #12830.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T12:40:56Z.
Review: APPROVED
Re-reviewed
2d12b228abon macOS arm64 (Apple clang, ASan + UBSan,-fno-sanitize-recover=all). As before, I built theRuntime.cpphunk and the test as a standalone program, taken verbatim from the PR head with theNpAllocator/NpAllocatorExlayouts fromApi.hpp. This time the program covers bothTestObjectsandTestObjectsThroughStoredAllocator. I didn't run the full CMake lane.72cde05a64; only the test rows are new.dl…R16,da…R14andda…R16, the zeroed header tail, the added overflow check, the wrongna…R16size, and non-null on failure for bothnaforms. The 3 that were already killed still fail.2^64 - 16case.git merge-treeagainst main5454cd2e45,git diff --checkandcheck_conventions.py --headare clean. The overlap picture hasn't changed, because the new commit only touchesGuestNpCommonRuntime.cpp.Approving.