feat(libSceNpCommon): implement sce::np::Time #12859
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12859"
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:59:05Z.
What
Implements all 35 exports of
sce::np::TimefromlibSceNpCommon.sprxof firmware 13.60 (read from disassembly, not measured on a console):NotImplementedstubs with placeholderint (void)declarations;sce::np::Timeis a wrapper around a single 64-bitSceRtcTick, soApi.hppdeclaresusing NpTime = RtcTick;. The code sits inRuntime.cppnext tosceNpRtcConvertToPosixTime, which it uses.GetUserClock,GetNetworkClockandGetDebugNetworkClock(Time*)callsceRtcGetCurrentTick,…NetworkTickand…DebugNetworkTickon the time. On failure they set it to 0 and return the error; otherwise they return 0.SetDateTime(const DateTime&)runssceRtcGetTickon a copy of the date-time.GetDateTime(DateTime*)runssceRtcSetTickand copies the date-time out only on success.ConvertToPosixTime(long*)forwards tosceNpRtcConvertToPosixTime.AddMicroSeconds,AddSeconds,AddMinutes,AddHoursandAddDays(long)call the matchingsceRtcTickAdd*on the time in place and return it.operator+(const Time&)andoperator+(const SceRtcTick&), throughsceRtcTickAddTicks.AddHoursandAddDayspass their 64-bit count to the 32-bit libSceRtc parameter, so only the low 32 bits count, as in the module.FormatRFC3339(char*, size_t, int): a size below 0x80 returns0x80558008without formatting. Otherwise it callssceRtcFormatRFC3339and, on success, terminates the last byte.IsTimedoutSinceMicroSeconds(const Time& since, long, long*), its(unsigned, unsigned*)form andIsTimedoutSinceSeconds(const Time&, long, long*). Each:now < since, when the timeout is negative, or when the elapsed time reaches the timeout;==,!=,<,<=,>,>=operators, forTime/Time,SceRtcTick/TimeandTime/SceRtcTick, compare the ticks unsigned.Gap (debt entry): where the module asserts and calls
sceNpPanicafter a failed libSceRtc add, theAdd*helpers andoperator+throwstd::invalid_argument. The debt file drops the six "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.GuestNpCommonRtc.cppnow covers, against this tree's libSceRtc:Add*, including the 32-bitAddHourscount, and bothoperator+;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).
2^63and2^64 - 1.nowbefore, at and aftersince, and timeouts at, around and far from the elapsed time (negative,2^63, and the 32-bit edges for theunsignedform), with and without the out pointer.AddHourspassing the untruncated 64-bit count;The generator and harness are
np_time_make_cases.py/np_time_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)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-29T13:35:37Z.
Review: COMMENTED
Reviewed head
bedde4268fon macOS 26 arm64 (Apple clang, C++20). The submodules aren't initialised here, so I couldn't build the full tree. Instead I built a standalone harness: this PR'sRuntime.cppblock fromsceNpRtcConvertToPosixTimetosceNpRtcFormatRFC3339copied verbatim, this tree'slibSceRtc/Export.cppunchanged (it needs three small link shims: process params, title ID, NotImplemented) andGuestNpCommonRtc.cppunchanged. Built with ASan+UBSan, it passes.Checked:
git merge-treeagainst main95137178d0is clean,git diff --checkis clean, andcheck_conventions --base upstream/mainpasses.pr_overlap(1419 probed) reports only the stub-neighbour conflicts the body already lists: #12818, #12823, #12836, #12839, #12852. No other PR exports the same functions. #12866 has dropped itssce::np::Timeoperators (head9533395d76), so the duplicate exports are gone.Mutation testing: 46 single-line mutants of the new functions. The current test kills 12 and 34 survive:
ne(Time,Time) →==,gt(Time,Time) →>=, a 32-biteq, and a signedlt(Time,Tick) all pass;GetNetworkClock/GetDebugNetworkClockreading the wrong clock;now < sincedropped from all three timeout forms;unsignedform truncatingelapsedto 32 bits before comparing;IsTimedoutSinceSecondsaccepting a negative timeout, using<at the boundary, or comparing whole seconds;AddDaysnot reaching the 32-bit count (onlyAddHourshas that row).The diff below adds rows only, about 50 lines in
GuestNpCommonRtc.cpp. It runs every operator in all three forms over four pairs, including two ticks that are equal in their low 32 bits, plus clock, timeout,AddDaysand invalid-date rows. It passes on this head and kills all 36 killable mutants. The 10 that still survive can't be distinguished on this tree:GetDateTimecopy can't be reached;AddDays/AddHourswithout the cast narrow implicitly to the sameint32_t;Please check against your unicorn differential:
IsTimedoutSinceSeconds(later, start, 1ll << 58):timeout * 1000000wraps to 0 in uint64, so this head reports a timeout with 0 left. That row is what catches the whole-seconds mutant. If the module doesn't multiply with wrapping, drop the row or fix the expectation.GetNetworkClock/GetDebugNetworkClockaftersceRtcSetCurrent{Network,DebugNetwork}Tick: this tests this tree's libSceRtc together with your wrappers, not just the wrappers.Test diff
Nits (optional):
NP_TIME_RFC3339_SIZEduplicates the existingNP_RFC3339_BUFFER_MIN(0x80) in the same file.Time::FormatRFC3339is the body ofsceNpRtcFormatRFC3339with the arguments reordered. If the module does the same thing,return sceNpRtcFormatRFC3339(text, size, self, timeZoneMinutes);would remove the copy.GetUserClockrow.AI-assisted: yes (review, harness and mutation run).
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T15:18:44Z.
Review: APPROVED
Re-reviewed head
a70c6808bcon macOS 26 arm64 (Apple clang, C++20). I used the same standalone harness as last time, rebuilt from this head: theRuntime.cppblock fromsceNpRtcConvertToPosixTimetosceNpRtcFormatRFC3339copied verbatim with its helpers and constants, this tree'slibSceRtc/Export.cppunchanged plus three link shims (process params, title ID, NotImplemented), andGuestNpCommonRtc.cppunchanged. Built with ASan+UBSan, it passes.Checked:
1 << 58wrap and the clock NIDs against the module.Time::FormatRFC3339now forwards tosceNpRtcFormatRFC3339. Both use the same 0x80 minimum, return the same error, and terminate atsize - 1, so behaviour doesn't change. The duplicate constant is gone.git diff --checkis clean,git merge-treeagainst mainbb04a4f1eais clean,check_conventions --base upstream/mainpasses, and CI shows 5 pass and 5 skipped.Mutation testing: 85 single-line mutants. These cover all 18 comparison operators (each operator swapped, compared as 32-bit, compared as signed), both clock getters, all three timeout forms (negative timeout,
now < since, boundary, 32-bit elapsed, whole seconds), theAddDays/AddHoursnarrowing, theFormatRFC3339size forwarding,operator+, andSet/GetDateTime. 76 are killed, including all 34 survivors from my first review. The 9 survivors:eq/necompared as signed.elapsed >= timeoutgives the same remaining time (0) at the boundary.AddDays/AddHoursto 16 bits.0x100000001has the same low 16 bits as 1, so the test can't tell them apart. This is optional: a0x10001row would catch them. I'm not asking for it, since the 32-bit narrowing is what the module does and the test already pins it.Optional rows (pass on this head, kill both 16-bit mutants)
LGTM.
AI-assisted: yes (review, harness and mutation run).