From 11306d7121f414695c46ef9d6a46125c2cc5db9b Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Wed, 5 May 2021 16:51:06 +0000 Subject: [PATCH] Kernel: Modify TimeManagement::current_time(..) API so it can't fail. (#6869) The fact that current_time can "fail" makes its use a bit awkward. All callers in the Kernel are trusted besides syscalls, so assert that they never get there, and make sure all current callers perform validation of the clock_id with TimeManagement::is_valid_clock_id(). I have fuzzed this change locally for a bit to make sure I didn't miss any obvious regression. --- Kernel/Syscalls/alarm.cpp | 2 +- Kernel/Syscalls/clock.cpp | 8 ++++---- Kernel/ThreadBlockers.cpp | 4 ++-- Kernel/Time/TimeManagement.cpp | 5 +++-- Kernel/Time/TimeManagement.h | 2 +- Kernel/TimerQueue.cpp | 6 +++--- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Kernel/Syscalls/alarm.cpp b/Kernel/Syscalls/alarm.cpp index 144f70ce85..221df0d233 100644 --- a/Kernel/Syscalls/alarm.cpp +++ b/Kernel/Syscalls/alarm.cpp @@ -25,7 +25,7 @@ KResultOr Process::sys$alarm(unsigned seconds) } if (seconds > 0) { - auto deadline = TimeManagement::the().current_time(CLOCK_REALTIME_COARSE).value(); + auto deadline = TimeManagement::the().current_time(CLOCK_REALTIME_COARSE); deadline = deadline + Time::from_seconds(seconds); m_alarm_timer = TimerQueue::the().add_timer_without_id(CLOCK_REALTIME_COARSE, deadline, [this]() { [[maybe_unused]] auto rc = send_signal(SIGALRM, nullptr); diff --git a/Kernel/Syscalls/clock.cpp b/Kernel/Syscalls/clock.cpp index 15f83bdfcf..a1bdac9bd6 100644 --- a/Kernel/Syscalls/clock.cpp +++ b/Kernel/Syscalls/clock.cpp @@ -14,13 +14,13 @@ KResultOr Process::sys$clock_gettime(clockid_t clock_id, Userspace TimeManagement::current_time(clockid_t clock_id) const +Time TimeManagement::current_time(clockid_t clock_id) const { switch (clock_id) { case CLOCK_MONOTONIC: @@ -58,7 +58,8 @@ KResultOr