Files
AnyPS5/core/libs/tests/GuestProcessTime.cpp
T
TideOPLandClaude Opus 5.5 383770ff65 fix(libkernel): read the process start before the clock in process time
sceKernelGetProcessTime and sceKernelGetProcessTimeCounter subtracted
GetStartNanos() from GetMonotonicNanos() in one expression. GCC reads the
clock first, so on the first call in a process the start was captured
after it and the result wrapped to about 2^64.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 10:59:30 +01:00

25 lines
795 B
C++

#include "prx/libkernel/Time/include/Time.hpp"
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
static void Require(bool condition, const char* message) {
if (!condition) {
std::fprintf(stderr, "%s\n", message);
std::abort();
}
}
int main(int argc, char** argv) {
constexpr std::uint64_t minuteMicros = 60ULL * 1000 * 1000;
if (argc > 1 && std::strcmp(argv[1], "counter") == 0) {
Require(sceKernelGetProcessTimeCounter() < minuteMicros * 1000, "first process time counter wrapped");
return 0;
}
const std::uint64_t first = sceKernelGetProcessTime();
Require(first < minuteMicros, "first process time wrapped");
Require(sceKernelGetProcessTime() >= first, "process time went backwards");
return 0;
}