mirror of
https://github.com/hexagonal-sun/moss-kernel.git
synced 2026-05-19 14:21:02 -04:00
implement clock_settime
This commit is contained in:
@@ -112,7 +112,7 @@
|
||||
| 0x6d (109) | timer_getoverrun | (timer_t timer_id) | __arm64_sys_timer_getoverrun | false |
|
||||
| 0x6e (110) | timer_settime | (timer_t timer_id, int flags, const struct __kernel_itimerspec *new_setting, struct __kernel_itimerspec *old_setting) | __arm64_sys_timer_settime | false |
|
||||
| 0x6f (111) | timer_delete | (timer_t timer_id) | __arm64_sys_timer_delete | false |
|
||||
| 0x70 (112) | clock_settime | (const clockid_t which_clock, const struct __kernel_timespec *tp) | __arm64_sys_clock_settime | false |
|
||||
| 0x70 (112) | clock_settime | (const clockid_t which_clock, const struct __kernel_timespec *tp) | __arm64_sys_clock_settime | true |
|
||||
| 0x71 (113) | clock_gettime | (const clockid_t which_clock, struct __kernel_timespec *tp) | __arm64_sys_clock_gettime | true |
|
||||
| 0x72 (114) | clock_getres | (const clockid_t which_clock, struct __kernel_timespec *tp) | __arm64_sys_clock_getres | false |
|
||||
| 0x73 (115) | clock_nanosleep | (const clockid_t which_clock, int flags, const struct __kernel_timespec *rqtp, struct __kernel_timespec *rmtp) | __arm64_sys_clock_nanosleep | partially |
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::{
|
||||
arch::{Arch, ArchImpl},
|
||||
clock::{
|
||||
gettime::sys_clock_gettime,
|
||||
settime::sys_clock_settime,
|
||||
timeofday::{sys_gettimeofday, sys_settimeofday},
|
||||
},
|
||||
fs::{
|
||||
@@ -419,6 +420,7 @@ pub async fn handle_syscall() {
|
||||
}
|
||||
0x63 => sys_set_robust_list(TUA::from_value(arg1 as _), arg2 as _).await,
|
||||
0x65 => sys_nanosleep(TUA::from_value(arg1 as _), TUA::from_value(arg2 as _)).await,
|
||||
0x70 => sys_clock_settime(arg1 as _, TUA::from_value(arg2 as _)).await,
|
||||
0x71 => sys_clock_gettime(arg1 as _, TUA::from_value(arg2 as _)).await,
|
||||
0x73 => {
|
||||
sys_clock_nanosleep(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod gettime;
|
||||
pub mod realtime;
|
||||
pub mod settime;
|
||||
pub mod timeofday;
|
||||
pub mod timespec;
|
||||
|
||||
|
||||
27
src/clock/settime.rs
Normal file
27
src/clock/settime.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use crate::clock::ClockId;
|
||||
use crate::clock::realtime::set_date;
|
||||
use crate::clock::timespec::TimeSpec;
|
||||
use crate::memory::uaccess::copy_from_user;
|
||||
use libkernel::error::KernelError;
|
||||
use libkernel::memory::address::TUA;
|
||||
|
||||
pub async fn sys_clock_settime(
|
||||
clockid: i32,
|
||||
time_spec: TUA<TimeSpec>,
|
||||
) -> libkernel::error::Result<usize> {
|
||||
let time_spec = copy_from_user(time_spec).await?;
|
||||
if time_spec.tv_sec < 0 || time_spec.tv_nsec >= 1_000_000_000 {
|
||||
return Err(KernelError::InvalidValue);
|
||||
}
|
||||
match ClockId::try_from(clockid).map_err(|_| KernelError::InvalidValue)? {
|
||||
ClockId::Monotonic | ClockId::MonotonicCoarse | ClockId::MonotonicRaw => {
|
||||
// Monotonic clock cannot be set
|
||||
Err(KernelError::InvalidValue)
|
||||
}
|
||||
ClockId::Realtime => {
|
||||
set_date(time_spec.into());
|
||||
Ok(0)
|
||||
}
|
||||
_ => Err(KernelError::NotSupported),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user