From 24d8a8ae8e0ad980ac2054cd99b36c09eb58b945 Mon Sep 17 00:00:00 2001 From: Ivan Chikish Date: Fri, 14 Jul 2023 17:35:37 +0300 Subject: [PATCH] [orbiskernel] +sys_gettimeofday --- orbis-kernel/include/orbis/sys/sysproto.hpp | 16 ++++++++++--- orbis-kernel/src/sys/sys_time.cpp | 26 +++++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/orbis-kernel/include/orbis/sys/sysproto.hpp b/orbis-kernel/include/orbis/sys/sysproto.hpp index bba47387d..bbe2e386f 100644 --- a/orbis-kernel/include/orbis/sys/sysproto.hpp +++ b/orbis-kernel/include/orbis/sys/sysproto.hpp @@ -11,6 +11,16 @@ using cpuwhich_t = sint; using cpulevel_t = sint; using SceKernelModule = ModuleHandle; +struct timeval { + int64_t tv_sec; + int64_t tv_usec; +}; + +struct timezone { + sint tz_minuteswest; + sint tz_dsttime; +}; + struct ModuleInfo; struct ModuleInfoEx; struct KEvent; @@ -120,8 +130,8 @@ SysResult sys_bind(Thread *thread, sint s, caddr_t name, sint namelen); SysResult sys_setsockopt(Thread *thread, sint s, sint level, sint name, caddr_t val, sint valsize); SysResult sys_listen(Thread *thread, sint s, sint backlog); -SysResult sys_gettimeofday(Thread *thread, ptr tp, - ptr tzp); +SysResult sys_gettimeofday(Thread *thread, ptr tp, + ptr tzp); SysResult sys_getrusage(Thread *thread, sint who, ptr rusage); SysResult sys_getsockopt(Thread *thread, sint s, sint level, sint name, caddr_t val, ptr avalsize); @@ -130,7 +140,7 @@ SysResult sys_readv(Thread *thread, sint fd, ptr iovp, SysResult sys_writev(Thread *thread, sint fd, ptr iovp, uint iovcnt); SysResult sys_settimeofday(Thread *thread, ptr tp, - ptr tzp); + ptr tzp); SysResult sys_fchown(Thread *thread, sint fd, sint uid, sint gid); SysResult sys_fchmod(Thread *thread, sint fd, sint mode); SysResult sys_setreuid(Thread *thread, sint ruid, sint euid); diff --git a/orbis-kernel/src/sys/sys_time.cpp b/orbis-kernel/src/sys/sys_time.cpp index e1f3ae9c3..a9d1b2147 100644 --- a/orbis-kernel/src/sys/sys_time.cpp +++ b/orbis-kernel/src/sys/sys_time.cpp @@ -112,12 +112,30 @@ orbis::SysResult orbis::sys_nanosleep(Thread *thread, ptr rqtp, ptr rmtp) { return ErrorCode::NOSYS; } -orbis::SysResult orbis::sys_gettimeofday(Thread *thread, ptr tp, - ptr tzp) { - return ErrorCode::NOSYS; +orbis::SysResult orbis::sys_gettimeofday(Thread *thread, ptr tp, + ptr tzp) { + struct ::timeval tv; + struct ::timezone tz; + if (::gettimeofday(&tv, &tz) != 0) + std::abort(); + if (tp) { + orbis::timeval value; + value.tv_sec = tv.tv_sec; + value.tv_usec = tv.tv_usec; + if (auto e = uwrite(tp, value); e != ErrorCode{}) + return e; + } + if (tzp) { + orbis::timezone value; + value.tz_dsttime = tz.tz_dsttime; + value.tz_minuteswest = tz.tz_minuteswest; + if (auto e = uwrite(tzp, value); e != ErrorCode{}) + return e; + } + return {}; } orbis::SysResult orbis::sys_settimeofday(Thread *thread, ptr tp, - ptr tzp) { + ptr tzp) { return ErrorCode::NOSYS; } orbis::SysResult orbis::sys_getitimer(Thread *thread, uint which,