diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp index a51e092a2ab..0c25547244c 100644 --- a/Kernel/Net/Socket.cpp +++ b/Kernel/Net/Socket.cpp @@ -106,14 +106,24 @@ KResult Socket::setsockopt(int level, int option, Userspace user_va case SO_SNDTIMEO: if (user_value_size != sizeof(timeval)) return EINVAL; - if (!copy_from_user(&m_send_timeout, static_ptr_cast(user_value))) - return EFAULT; + { + auto timeout = copy_time_from_user(static_ptr_cast(user_value)); + if (!timeout.has_value()) + return EFAULT; + // FIXME: Should use AK::Time internally + m_send_timeout = timeout->to_timeval(); + } return KSuccess; case SO_RCVTIMEO: if (user_value_size != sizeof(timeval)) return EINVAL; - if (!copy_from_user(&m_receive_timeout, static_ptr_cast(user_value))) - return EFAULT; + { + auto timeout = copy_time_from_user(static_ptr_cast(user_value)); + if (!timeout.has_value()) + return EFAULT; + // FIXME: Should use AK::Time internally + m_receive_timeout = timeout->to_timeval(); + } return KSuccess; case SO_BINDTODEVICE: { if (user_value_size != IFNAMSIZ) diff --git a/Kernel/Syscalls/clock.cpp b/Kernel/Syscalls/clock.cpp index f70d4572933..4e780706c4c 100644 --- a/Kernel/Syscalls/clock.cpp +++ b/Kernel/Syscalls/clock.cpp @@ -50,13 +50,14 @@ KResultOr Process::sys$clock_settime(clockid_t clock_id, Userspaceto_timespec()); break; default: return EINVAL; @@ -72,9 +73,9 @@ KResultOr Process::sys$clock_nanosleep(Userspace requested_sleep = copy_time_from_user(params.requested_sleep); + if (!requested_sleep.has_value()) + return -EFAULT; bool is_absolute; switch (params.flags) { @@ -93,10 +94,12 @@ KResultOr Process::sys$clock_nanosleep(Userspacesleep_until(params.clock_id, requested_sleep).was_interrupted(); + // FIXME: Should use AK::Time internally + was_interrupted = Thread::current()->sleep_until(params.clock_id, requested_sleep->to_timespec()).was_interrupted(); } else { timespec remaining_sleep; - was_interrupted = Thread::current()->sleep(params.clock_id, requested_sleep, &remaining_sleep).was_interrupted(); + // FIXME: Should use AK::Time internally + was_interrupted = Thread::current()->sleep(params.clock_id, requested_sleep->to_timespec(), &remaining_sleep).was_interrupted(); if (was_interrupted && params.remaining_sleep && !copy_to_user(params.remaining_sleep, &remaining_sleep)) return EFAULT; } @@ -119,16 +122,12 @@ KResultOr Process::sys$adjtime(Userspace user_delta, Usersp REQUIRE_PROMISE(settime); if (!is_superuser()) return EPERM; - timeval delta; - if (!copy_from_user(&delta, user_delta)) + auto delta = copy_time_from_user(user_delta); + if (!delta.has_value()) return EFAULT; - if (delta.tv_usec < 0 || delta.tv_usec >= 1'000'000) - return EINVAL; - - timespec delta_ts; - timeval_to_timespec(delta, delta_ts); - TimeManagement::the().set_remaining_epoch_time_adjustment(delta_ts); + // FIXME: Should use AK::Time internally + TimeManagement::the().set_remaining_epoch_time_adjustment(delta->to_timespec()); } return 0; diff --git a/Kernel/Syscalls/futex.cpp b/Kernel/Syscalls/futex.cpp index dd1aa5c92cd..08ec27d49cd 100644 --- a/Kernel/Syscalls/futex.cpp +++ b/Kernel/Syscalls/futex.cpp @@ -118,12 +118,14 @@ KResultOr Process::sys$futex(Userspace use case FUTEX_REQUEUE: case FUTEX_CMP_REQUEUE: { if (params.timeout) { - timespec ts_stimeout { 0, 0 }; - if (!copy_from_user(&ts_stimeout, params.timeout)) + auto timeout_time = copy_time_from_user(params.timeout); + if (!timeout_time.has_value()) return EFAULT; clockid_t clock_id = (params.futex_op & FUTEX_CLOCK_REALTIME) ? CLOCK_REALTIME_COARSE : CLOCK_MONOTONIC_COARSE; bool is_absolute = cmd != FUTEX_WAIT; - timeout = Thread::BlockTimeout(is_absolute, &ts_stimeout, nullptr, clock_id); + // FIXME: Should use AK::Time internally + timespec timeout_copy = timeout_time->to_timespec(); + timeout = Thread::BlockTimeout(is_absolute, &timeout_copy, nullptr, clock_id); } if (cmd == FUTEX_WAIT_BITSET && params.val3 == FUTEX_BITSET_MATCH_ANY) cmd = FUTEX_WAIT; diff --git a/Kernel/Syscalls/select.cpp b/Kernel/Syscalls/select.cpp index 969de512867..3259e51f077 100644 --- a/Kernel/Syscalls/select.cpp +++ b/Kernel/Syscalls/select.cpp @@ -45,9 +45,11 @@ KResultOr Process::sys$select(Userspace u Thread::BlockTimeout timeout; if (params.timeout) { - timespec timeout_copy; - if (!copy_from_user(&timeout_copy, params.timeout)) + Optional