DragonOS/kernel/src/time/syscall.rs
login ab5c8ca46d
重构系统调用模块 (#267)
* 完成系统调用模块重构

* 更新github workflow
2023-05-24 17:05:33 +08:00

48 lines
1.3 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use core::ptr::null_mut;
use crate::{
syscall::{Syscall, SystemError},
time::{sleep::nanosleep, TimeSpec},
};
impl Syscall {
/// @brief 休眠指定时间单位纳秒提供给C的接口
///
/// @param sleep_time 指定休眠的时间
///
/// @param rm_time 剩余休眠时间(传出参数)
///
/// @return Ok(i32) 0
///
/// @return Err(SystemError) 错误码
pub fn nanosleep(
sleep_time: *const TimeSpec,
rm_time: *mut TimeSpec,
) -> Result<usize, SystemError> {
if sleep_time == null_mut() {
return Err(SystemError::EFAULT);
}
let slt_spec = TimeSpec {
tv_sec: unsafe { *sleep_time }.tv_sec,
tv_nsec: unsafe { *sleep_time }.tv_nsec,
};
let r: Result<usize, SystemError> = nanosleep(slt_spec).map(|slt_spec| {
if rm_time != null_mut() {
unsafe { *rm_time }.tv_sec = slt_spec.tv_sec;
unsafe { *rm_time }.tv_nsec = slt_spec.tv_nsec;
}
0
});
return r;
}
/// 获取cpu时间
///
/// todo: 该系统调用与Linux不一致将来需要删除该系统调用 删的时候记得改C版本的libc
pub fn clock() -> Result<usize, SystemError> {
return Ok(super::timer::clock() as usize);
}
}