feat(libSceNpCommon): implement sce::np::NpTitleId #12899
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12899"
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-29T13:52:22Z.
What
Implements 25
sce::np::NpTitleIdexports fromlibSceNpCommon.sprxof firmware 13.60 (read from disassembly, not measured on a console). Two of them wereNotImplementedstubs with placeholderint (void)declarations (Parse(NpTitleId*, const char*, size_t)andC2(const SceNpTitleId&)). The other 23 are exported by the module but were missing from AnyPS5.operator==(const SceNpTitleId&, const NpTitleId&)is left as a stub, because open #12866 implements it.The object is 24 bytes: a vtable pointer, then the existing 16-byte
NpTitleId(SceNpTitleId). It is declared asNpTitleIdObjectinApi.hpp.C1Ev/C2Ev) sets the vtable and zeroes the 16 bytes;NpTitleIdor from aSceNpTitleId;operator=copies the 16 bytes and leaves the vtable unchanged.D1/D2do nothing.D0frees throughsce::np::Object::operator delete(void*), so it is stacked on #12836. The vtable is{0, 0, D1, D0}.Clear/IsEmpty: zero the 16 bytes / check whether the first byte is 0.Parse(const char*, orconst char*, size_t):_and 2 digits;_00, so the parsed suffix is dropped, as in the module;0x80559E11and leaves the object unchanged.ConstructFromTitleId: the same, but needs exactly the 9-character code.Build(const NpTitleId&, char*, size_t): returns0x80559E0Dwhensize <= 12; otherwise it clears allsizebytes and copies 13.Equals(3 forms),operator==(2 forms),operator!=(3 forms):strncmpover the first 12 characters.The module classifies characters with the C-locale
_Getpctypetable, so only ASCII letters and digits are accepted. The debt file records the dropped suffix, the ASCII-only rule and the exact lengths, and drops the two "signature unknown" entries.Tested
Linux (CachyOS, GCC 16.2, Release):
ctest --test-dir build -R 'np_common|public_headers' --output-on-failure, 70/70 passed.TestTitleIdObjectsinGuestNpCommonRuntime.cppchecks:_00, the 9-character form rejected, and bad letters, digits and separator rejected;D0freeing through the allocator stored byObject::operator new.Comparison against the firmware code: I relinked the 13.60 module with this repo's relinker and ran the exports under unicorn (x86-64 emulation on a PC, not a console).
0x77), or the whole output buffer plus 4 guard bytes.The constructors,
operator=,Clearand the destructors are straight stores; I compared them with the disassembly instead.The generator and harness are
np_title_id_make_cases.py/np_title_id_replay.cppin https://gist.github.com/hypermoist/1834cf221fd737cdb4cca272cc1156d1. The gist has no module or recorded output.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)D0usessce::np::Object::operator deletefrom #12836, which is merged;mainis merged in. Other open PRs touching neighbouring lines: #12825, #12829, #12830 and #12859 touch neighbouring stub or declaration lines. Whichever lands second needs a trivial merge, and I will do it.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 MarcZX10 on 2026-10-29T14:00:45Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The object allocation size can wrap, and the added overflow assertion masks that case because its test allocator is already forced to fail.
What I ran
949680de9a0114553b53a6436ea11449765a7714against currentmain1408347b2e28d28d1feeee33214d9ce7ba1d3842.cea897be597889f7165cc21982b5fa498369957e.Results
cea897be597889f7165cc21982b5fa498369957eUnedited output
Negative control
SIZE_MAX - 15must not be accepted as an allocation size when the 16-byte header is addedTestObjectsThroughStoredAllocatorshowsrecord.failis set before this assertion and remains trueFindings
Blocking
AllocateObjectaddsNP_OBJECT_HEADER_SIZEto the caller'ssizewithout checking for overflow. ForSIZE_MAX - 15, this addition wraps to zero. The new test at the cited lines setsrecord.fail = truebefore making that call;RecordAllocatetherefore returns null for every request and makes the expected result pass without exercising the implementation's overflow behavior. With a succeeding allocator, the current implementation can return an object pointer backed by a zero-byte allocation, leaving no room for the object or header.Please reject sizes greater than
SIZE_MAX - NP_OBJECT_HEADER_SIZEbefore adding the header, and resetrecord.failbefore the overflow assertion so it can detect the missing guard. For example:Non-blocking
The PR reports 70/70
np_commonand public-header tests and 15,100 firmware-module comparison cases; those results were not reproduced locally. The module comparison is described as Unicorn emulation on a PC, not a physical-console run.Sources
Not verified
I did not run the focused C++ test suite or Linux/Windows builds. The local full CMake configuration could not proceed: the SDL2 submodule is not initialized, and using system dependencies stops because the installed Vulkan headers lack
VK_KHR_maintenance8. Hosted policy checks were pending.To get this to a good state
Add the overflow guard and make the overflow test run with a succeeding allocator. I will rerun the focused C++ tests, convention check, and current-main merge preview on the new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T04:02:29Z.
Review: APPROVED
Re-checked — new head, looks good
The revised overflow test uses a succeeding allocator and matches the documented firmware 13.60 behavior; the current-main preview is clean and the remaining stack dependency is declared.
What I ran
d6ce925c509ef8f9e0385a28cd487ca16386830f; PR base:24bfebf9574dbfe97b589142653f7be7e4d7d980.main5ecef095b61e7a406b279c97896f3a8a6fbd6353; merge preview was clean, tree44396a6edd7f4ca4eb1a3f689f54e22e1cc1d4db.Results
44396a6edd7f4ca4eb1a3f689f54e22e1cc1d4dbgit diff --checknp_commonand public-header tests on the Linux stack; I did not run them locally.Unedited local command output
git diff --checkexited 0 with no output.Findings
Blocking
None found. The overflow assertion now runs before the test allocator is configured to fail, so it checks that a zero-byte allocation request succeeds and the object pointer is advanced by the 16-byte header. This matches the author-reported firmware disassembly and emulator comparison.
Non-blocking
#12836remains an open declared dependency because the deleting destructor uses itsObject::operator deleteimplementation. The PR description records this stack relationship.Sources
Not verified
I did not run a local build or C++ tests and did not test on a physical console. Hosted Linux product CI is skipped; the firmware comparison described by the author used PC emulation.