1 use core::ptr::null_mut; 2 3 use crate::{ 4 syscall::{Syscall, SystemError}, 5 time::{sleep::nanosleep, TimeSpec}, 6 }; 7 8 impl Syscall { 9 /// @brief 休眠指定时间(单位:纳秒)(提供给C的接口) 10 /// 11 /// @param sleep_time 指定休眠的时间 12 /// 13 /// @param rm_time 剩余休眠时间(传出参数) 14 /// 15 /// @return Ok(i32) 0 16 /// 17 /// @return Err(SystemError) 错误码 18 pub fn nanosleep( 19 sleep_time: *const TimeSpec, 20 rm_time: *mut TimeSpec, 21 ) -> Result<usize, SystemError> { 22 if sleep_time == null_mut() { 23 return Err(SystemError::EFAULT); 24 } 25 let slt_spec = TimeSpec { 26 tv_sec: unsafe { *sleep_time }.tv_sec, 27 tv_nsec: unsafe { *sleep_time }.tv_nsec, 28 }; 29 30 let r: Result<usize, SystemError> = nanosleep(slt_spec).map(|slt_spec| { 31 if rm_time != null_mut() { 32 unsafe { *rm_time }.tv_sec = slt_spec.tv_sec; 33 unsafe { *rm_time }.tv_nsec = slt_spec.tv_nsec; 34 } 35 0 36 }); 37 38 return r; 39 } 40 41 /// 获取cpu时间 42 /// 43 /// todo: 该系统调用与Linux不一致,将来需要删除该系统调用!!! 删的时候记得改C版本的libc 44 pub fn clock() -> Result<usize, SystemError> { 45 return Ok(super::timer::clock() as usize); 46 } 47 } 48