/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include namespace Kernel { KResultOr Process::sys$clock_gettime(clockid_t clock_id, Userspace user_ts) { REQUIRE_PROMISE(stdio); if (!TimeManagement::is_valid_clock_id(clock_id)) return EINVAL; auto ts = TimeManagement::the().current_time(clock_id).to_timespec(); if (!copy_to_user(user_ts, &ts)) return EFAULT; return 0; } KResultOr Process::sys$clock_settime(clockid_t clock_id, Userspace user_ts) { REQUIRE_PROMISE(settime); if (!is_superuser()) return EPERM; auto ts = copy_time_from_user(user_ts); if (!ts.has_value()) return EFAULT; switch (clock_id) { case CLOCK_REALTIME: TimeManagement::the().set_epoch_time(ts.value()); break; default: return EINVAL; } return 0; } KResultOr Process::sys$clock_nanosleep(Userspace user_params) { REQUIRE_PROMISE(stdio); Syscall::SC_clock_nanosleep_params params; if (!copy_from_user(¶ms, user_params)) return EFAULT; Optional