From 4484513b45c718807ef681a3ce6ce9daf57a64ca Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 13 Mar 2020 01:17:14 +0200 Subject: [PATCH] Kernel: Add new syscall to allow changing the system date --- Kernel/Process.cpp | 17 +++++++++++++++++ Kernel/Process.h | 1 + Kernel/Syscall.h | 1 + 3 files changed, 19 insertions(+) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 27df56452e6..9c45739ba6a 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -4283,6 +4283,23 @@ int Process::sys$clock_gettime(clockid_t clock_id, timespec* user_ts) return 0; } +int Process::sys$clock_settime(clockid_t clock_id, timespec* user_ts) +{ + SmapDisabler disabler; + REQUIRE_PROMISE(stdio); + if (!validate_write_typed(user_ts)) + return -EFAULT; + + switch (clock_id) { + case CLOCK_REALTIME: + TimeManagement::the().set_epoch_time(user_ts->tv_sec); + break; + default: + return -EINVAL; + } + return 0; +} + int Process::sys$clock_nanosleep(const Syscall::SC_clock_nanosleep_params* user_params) { REQUIRE_PROMISE(stdio); diff --git a/Kernel/Process.h b/Kernel/Process.h index 47ba58315ce..2fefa8aec43 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -213,6 +213,7 @@ public: int sys$usleep(useconds_t usec); int sys$gettimeofday(timeval*); int sys$clock_gettime(clockid_t, timespec*); + int sys$clock_settime(clockid_t, timespec*); int sys$clock_nanosleep(const Syscall::SC_clock_nanosleep_params*); int sys$gethostname(char*, ssize_t); int sys$uname(utsname*); diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index 5cef651458e..9e7dcd7b164 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -158,6 +158,7 @@ namespace Kernel { __ENUMERATE_SYSCALL(getrandom) \ __ENUMERATE_SYSCALL(setkeymap) \ __ENUMERATE_SYSCALL(clock_gettime) \ + __ENUMERATE_SYSCALL(clock_settime) \ __ENUMERATE_SYSCALL(clock_nanosleep) \ __ENUMERATE_SYSCALL(join_thread) \ __ENUMERATE_SYSCALL(module_load) \