feat(libSceNpCommon): implement 95 more of the module's exports #9063
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9063"
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-21T11:24:52Z.
What
Implements 95 more of the 150 libSceNpCommon exports declared by #8983, alongside #9037 (now merged), in new
Runtime.cppandStrings.cppfiles (#9037'sExport.cppis unchanged):sceNpArchInit/sceNpArchTerm, the IPC client heap, kernel memory allocation and the allocator tables.sceNpCmpNpId, added tomainas a throwing stub after this PR opened: it checks both ids for null (0x80550003) and the flag byte at 0x1C (0x80550605), compares the online id and the words at 0x14 and 0x18, and treats an empty first byte at 0x18 on either id as matching (0x80550609otherwise).Behaviour, argument checks, error codes and their order come from
libSceNpCommon.sprx, firmware 13.60, read from disassembly, not measured on a console. No code, tables or strings were copied from it. The tables are rebuilt from public standards.The other 35 exports still throw, and
docs/dev/debt/libSceNpCommon.mdsays why:The same file lists where implemented exports differ from the console.
Tested
Linux (CachyOS, GCC). New
guest_np_common_runtimetest (core/libs/tests/GuestNpCommonRuntime.cpp, registered next to #9037's) covers:ctest -R guest_np_commonpasses, including #9037's own suites. Rerun on a merge ofmaine3d03fbae6(16aae7d289): the fourguest_np_commonsuites pass on Linux and, cross-built with WinLibs GCC 15.2.0 and run under Wine, on Windows, and the patchedlibSceNpCommon.prxbuilds.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 But all test done locally on actual hardware
https://claude.ai/code/session_013XFS3FUfBtqCVfwmBrRQ6q
Imported from boykopovar/AnyPS5. Originally posted by pipe1os on 2026-10-21T17:00:23Z.
Built and ran this on Windows, since there's no Windows run yet.
Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 (ucrt-posix-seh r7), Ninja, Release,
BUILD_TESTING=ON.736ee67cafmerged ontomaincecb540a63without conflicts, so #9037 is in too.libSceNpCommonand both test executables build with no warnings.guest_np_common_runtimefails on Windows:That's
GuestNpCommonRuntime.cpp:446.sceNpStrToInt32parses withstd::strtolinto along(Strings.cpp:360-364), andlongis 32 bits on Windows. Sostrtol("3000000000")saturates toLONG_MAXwithERANGEandParseIntegerreturns before writingparsedLength. On Linux the 64-bitlongholds the value and the int32 check afterwards catches it. Usinglong long/std::strtoll/LLONG_MIN/LLONG_MAXthere, likesceNpStrToInt64already does, fixes it. With just that change all four tests pass, three runs each (ctest -R ^guest_np_common --repeat until-fail:3).ids,syncandclockpass on the PR as is.Without the change: with
core/libs/prx/libSceNpCommonback tomain,guest_np_common_ids,_syncand_clockabort withsceNpCmpOnlineId not implemented,sceNpMutexInit not implementedandsceNpGetSystemClockUsec not implemented.guest_np_common_runtime_testsdoesn't even link onmain. ThesceNpUtilJsonUnescapestub there sits after the}that closesextern "C"inPendingExports.cpp(line 755), so it gets a mangled C++ name and an import of it can't resolve. This PR fixes that on the way, since the function moves intoStrings.cpp. With that brace moved locally, the runtime test aborts onsceNpAtomicInc32 not implemented.I also compared the callouts with shadPS4 a808e76 (
np_common.cpp:405-554). Context layout (0x28, same offsets), the three error codes (0x80558001,0x80558002,0x80558006), ordering on equal deadlines, the 32-bit delay ofsceNpCalloutStartOnCtx, stop and term all match. One difference:NpCallouthere is 0x28 with a trailingreserved(Runtime.cpp:69-76), andsceNpCalloutStartOnCtx64does*callout = {}, which clears all 0x28 bytes. shadPS4'sOrbisNpCalloutEntryis 0x20 (np_common.h:25-30, asserted innp_common.cpp:23) and only writes its four fields. If the console's entry is 0x20, a caller that allocates exactly that gets the 8 bytes after its entry zeroed. Does the 0x28 come from the module, i.e. does it write at +0x20?Not run: the full suite or any title.
Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-22T01:19:10Z.
@pipe1os thanks for the Windows run. Fixed in
962b88a9e1:sceNpStrToInt32now parses withstd::strtollinto along longand checks againstLLONG_MIN/LLONG_MAX, assceNpStrToInt64does. Nothing else in the module uses the host'slong.ctest -R guest_np_commonpasses on Linux (4 of 4).On the callout size: 0x28 comes from the module. In
libSceNpCommon.sprx(firmware 12.00, read from disassembly, not measured on a console),sceNpCalloutStartOnCtx64clears the entry with a 32-byte store at +0 and then an 8-byte store of 0 at +0x20, before it fills in the deadline, handler and argument. So the console also clears all 0x28 bytes, and a 0x20-byte entry would have its next 8 bytes cleared there too.