feat(libSceNpCommon): implement the _sceNpAllocatorEx helpers #12839
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12839"
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:07:03Z.
What
Implements the six
_sceNpAllocatorEx*helpers fromlibSceNpCommon.sprxof firmware 13.60 (read from disassembly, not measured on a console).ReallocandFreewereNotImplementedstubs with placeholderint (void)declarations.Malloc,Strdup,StrndupandConvertAllocatorare exported by the module but were missing from AnyPS5.This is stacked on #12836. Only the last commit (
feat(libSceNpCommon): implement the _sceNpAllocatorEx helpers) is new. Both add declarations at the same place inApi.hppand code at the same place inRuntime.cpp.Each helper takes the
SceNpAllocatorEx*first and uses its allocator's own functions with itscontext, with no null checks, as in the module:NpAllocator* _sceNpAllocatorExConvertAllocator(ex): returns its argument (the allocator is the first member).void* _sceNpAllocatorExMalloc(ex, size):allocate(size, context).void* _sceNpAllocatorExRealloc(ex, pointer, size):reallocate(pointer, size, context).void _sceNpAllocatorExFree(ex, pointer):release(pointer, context).char* _sceNpAllocatorExStrdup(ex, text): allocatesstrlen(text) + 1bytes and copies the string with its terminator. Returns null if the allocation fails.char* _sceNpAllocatorExStrndup(ex, text, maxLength): allocatesstrnlen(text, maxLength) + 1bytes, copies that many bytes and terminates them. Returns null if the allocation fails.The debt file drops the two "signature unknown" entries. The existing entry that says the exports in
Runtime.cppfollow firmware 13.60 covers the source.Tested
Linux (CachyOS, GCC, Release):
ctest --test-dir build -R 'np_common|public_headers' --output-on-failure, 70/70 passed.TestAllocatorExinGuestNpCommonRuntime.cppchecks:Strndup;Comparison against the firmware code: I relinked the 13.60 module with this repo's relinker and ran the six helpers under unicorn (x86-64 emulation on a PC, not a console). The allocator's three functions were bound to recording handlers, and the module's
strlen,strnlenandstrncpyimports to C implementations.Strdup;Strndup, with lengths around the string length plus a random one and2^64 - 1;MallocandRealloc;FreeandConvertAllocator.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)mainis merged in)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:14:07Z.
Review: COMMENTED
I reviewed only the new commit,
4dc74fc967(#12836 is reviewed separately). I tested it on macOS arm64 with Apple clang, ASan + UBSan and-fno-sanitize-recover=all. The six helpers andTestAllocatorExwere built verbatim as a standalone program, using theNpAllocator/NpAllocatorExlayouts fromApi.hppand a stand-in memory heap whose blocks are prefilled with 0xEE. I didn't run the full CMake lane.TestAllocatorExpasses as written.tools/nid_names.pymaps the two removed stubs to the NIDs in the debt entries this commit deletes (kKF3w-XkCWA,Zh23aSLeeZo). The four new exports hash toa2qdVU8RWb4(Malloc),Cmd4+m7V00c(Strdup),EziLjfyTnKI(Strndup) and0gdlCVNNHCI(ConvertAllocator). Apart fromApi.hpp, nothing else in the tree refers to the oldint (void)declarations.check_conventions.pypasses for both--base 72cde05a64(this commit only) and--base main.git diff --checkis clean. The branch is based on current main5454cd2e45, andgit merge-treeagainst main is clean.pr_overlap.py --branchprobed 1,396 PRs and found #12825, #12829 and #12830. #12836 conflicts with those three in the same three files, so the overlap comes from the stack you already declare under Depends on, not from this commit.Using
strncpyin the module andmemcpyhere gives the same result:length = strnlen(text, maxLength), so the firstlengthbytes never contain a NUL.Test coverage. I ran 19 single-change mutants of the six helpers. One is equivalent: allocating
min(length, maxLength) + 1changes nothing becausestrnlennever returns more thanmaxLength.TestAllocatorExkills 8 of the other 18 (the Strdup and Strndup sizes, the copy lengths, the missing terminator, and returningtextwhen allocation fails). These 10 still pass:Reallocreturnspointerand never calls the allocator.Reallocpasses a fixed size (16) toreallocate.Reallocis built fromallocate+memcpy+release.block[15]survives this, and so does the memory heap.Reallocreturns the old pointer whenreallocatefails.Mallocretriesallocateafter a failure.Free(ex, nullptr)returns early. Your description says there are no null checks, but no test pins this.FreechecksoutOfMemoryErrorfirst (the onlyFreetest uses 0).Strndupasks formaxLength + 1bytes. The prefix row hasstrnlen == maxLength, the failing-allocator row has 3 == 3, and the 16-byte request in the short-string row isn't checked.Strndupusesmin(strlen(text), maxLength). The result is the same, but it reads past an unterminated buffer, and nothing checks this.StrndupwithmaxLength == SIZE_MAXis handled as 0. Your differential covered2^64 - 1.The rows below kill all 10. They pass on your head, and the 8 mutants already killed stay killed. They use their own recording allocator because
AllocatorRecordhas noreallocateand doesn't count calls:The unterminated row only fails under ASan for mutant 9, so it is a sanitizer-lane check. "Freeing null still calls release" and "a failed reallocation keeps the old block" come from what your description says the module does (no null checks,
reallocatecalled directly), so please confirm both against your differential before adding them.The "actual hardware" wording I noted on #12825–#12836 is fixed in this body.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T12:43:02Z.
Review: APPROVED
Re-review at
1088b5575a. The implementation hasn't changed since4dc74fc967(git diff 4dc74fc967 1088b5575a -- Runtime.cppis empty), so this pass only covers the test commits.Tested on macOS arm64 with Apple clang, ASan + UBSan and
-fno-sanitize-recover=all. The six helpers fromRuntime.cppandTestAllocatorEx+ExRecord/TestAllocatorExRecordedfrom the head were built verbatim as a standalone program. A malloc-backed stand-in heap fills new blocks with 0xEE.Reallocrows. Alloc+copy+free → ASan on the 1-byteold. Malloc retry → "a failed allocation is one call to allocate". Free null early-return and theoutOfMemoryErrorgate → "freeing null still calls release".maxLength + 1→ the short-string row.SIZE_MAX→ 0 → the unbounded row.strlenover-read → ASan on the unterminated row.Freeand failed-Reallocrows against the 13.60 differential. Those were the two I couldn't confirm on my side.check_conventions.py --base main --head 1088b5575apasses,git diff --checkis clean, andgit merge-treeagainst main5454cd2e45is clean.One non-blocking note:
1a6579414astill has four conflict markers inGuestNpCommonRuntime.cpp. This repo merges PRs with merge commits, so that commit would land in main's history andgit bisectthrough the test would fail to build there. Squashing or rebasing the test-fix commits together before merge would avoid that. The head itself is fine.Approving.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:54:09Z.
Review: COMMENTED
Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (
Unblocks: noneis allowed), and it contained no code review.