1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:57:35 +00:00

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.
This commit is contained in:
Brian Gianforcaro 2021-05-05 16:51:06 +00:00 committed by GitHub
parent 64b4e3f34b
commit 11306d7121
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 13 deletions

View file

@ -14,13 +14,13 @@ KResultOr<int> Process::sys$clock_gettime(clockid_t clock_id, Userspace<timespec
{
REQUIRE_PROMISE(stdio);
auto time = TimeManagement::the().current_time(clock_id);
if (time.is_error())
return time.error();
if (!TimeManagement::is_valid_clock_id(clock_id))
return EINVAL;
auto ts = time.value().to_timespec();
auto ts = TimeManagement::the().current_time(clock_id).to_timespec();
if (!copy_to_user(user_ts, &ts))
return EFAULT;
return 0;
}