From a7c1b897e198750612dd22437e0d93a9d842b5e5 Mon Sep 17 00:00:00 2001 From: Dmugetsu Date: Thu, 6 Mar 2025 11:18:52 -0600 Subject: [PATCH] =?UTF-8?q?Fixing=20some=20issues=20introduced=20by=20the?= =?UTF-8?q?=20Fix=20time=20-=20sceKernelClockGettime=E2=80=A6=20#2766?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/libraries/kernel/time.cpp | 31 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/core/libraries/kernel/time.cpp b/src/core/libraries/kernel/time.cpp index 508e54089..d57929855 100644 --- a/src/core/libraries/kernel/time.cpp +++ b/src/core/libraries/kernel/time.cpp @@ -97,7 +97,8 @@ int PS4_SYSV_ABI sceKernelClockGettime(s32 clock_id, OrbisKernelTimespec* tp) { if (tp == nullptr) { return ORBIS_KERNEL_ERROR_EFAULT; } - clockid_t pclock_id = CLOCK_REALTIME; + + clockid_t pclock_id; switch (clock_id) { case ORBIS_CLOCK_REALTIME: case ORBIS_CLOCK_REALTIME_PRECISE: @@ -111,18 +112,26 @@ int PS4_SYSV_ABI sceKernelClockGettime(s32 clock_id, OrbisKernelTimespec* tp) { pclock_id = CLOCK_MONOTONIC; break; default: - LOG_ERROR(Lib_Kernel, "unsupported = {} using CLOCK_REALTIME", clock_id); - break; - } - - time_t raw_time = time(nullptr); - - if (raw_time == (time_t)(-1)) { + LOG_ERROR(Lib_Kernel, "unsupported clock_id = {}. Returning error.", clock_id); return ORBIS_KERNEL_ERROR_EINVAL; } - tp->tv_sec = static_cast(raw_time); - tp->tv_nsec = 0; + struct timespec ts; + if (clock_gettime(pclock_id, &ts) != 0) { + return ORBIS_KERNEL_ERROR_EINVAL; + } + + if (pclock_id == CLOCK_REALTIME) { + time_t raw_time = time(nullptr); + if (raw_time == (time_t)(-1)) { + return ORBIS_KERNEL_ERROR_EINVAL; + } + tp->tv_sec = static_cast(raw_time); + tp->tv_nsec = ts.tv_nsec; + } else { + tp->tv_sec = ts.tv_sec; + tp->tv_nsec = ts.tv_nsec; + } return ORBIS_OK; } @@ -130,7 +139,7 @@ int PS4_SYSV_ABI sceKernelClockGettime(s32 clock_id, OrbisKernelTimespec* tp) { int PS4_SYSV_ABI posix_clock_gettime(s32 clock_id, OrbisKernelTimespec* time) { int result = sceKernelClockGettime(clock_id, time); if (result < 0) { - UNREACHABLE(); // TODO return posix error code + return ORBIS_KERNEL_ERROR_EINVAL; // this should return a proper error } return result; }