mirror of
https://github.com/rcore-os/rCore.git
synced 2024-11-25 01:16:18 +04:00
Implement sys_ppoll over sys_poll
This commit is contained in:
parent
9b6e963b19
commit
1bba33a05f
@ -66,6 +66,21 @@ pub fn sys_pwrite(fd: usize, base: *const u8, len: usize, offset: usize) -> SysR
|
||||
Ok(len)
|
||||
}
|
||||
|
||||
pub fn sys_ppoll(ufds: *mut PollFd, nfds: usize, timeout: *const TimeSpec) -> SysResult {
|
||||
let proc = process();
|
||||
let timeout_msecs = if timeout.is_null() {
|
||||
1 << 31 // infinity
|
||||
} else {
|
||||
proc.vm.check_read_ptr(timeout)?;
|
||||
unsafe {
|
||||
(*timeout).to_msec()
|
||||
}
|
||||
};
|
||||
drop(proc);
|
||||
|
||||
sys_poll(ufds, nfds, timeout_msecs as usize)
|
||||
}
|
||||
|
||||
pub fn sys_poll(ufds: *mut PollFd, nfds: usize, timeout_msecs: usize) -> SysResult {
|
||||
info!(
|
||||
"poll: ufds: {:?}, nfds: {}, timeout_msecs: {:#x}",
|
||||
@ -472,12 +487,9 @@ pub fn sys_chdir(path: *const u8) -> SysResult {
|
||||
if path.len() > 0 {
|
||||
let cwd = match path.as_bytes()[0] {
|
||||
b'/' => String::from("/"),
|
||||
_ => proc.cwd.clone()
|
||||
_ => proc.cwd.clone(),
|
||||
};
|
||||
let mut cwd_vec:Vec<_> =
|
||||
cwd.split("/")
|
||||
.filter(|&x| x != "")
|
||||
.collect();
|
||||
let mut cwd_vec: Vec<_> = cwd.split("/").filter(|&x| x != "").collect();
|
||||
let path_split = path.split("/").filter(|&x| x != "");
|
||||
for seg in path_split {
|
||||
if seg == ".." {
|
||||
|
@ -275,6 +275,7 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
|
||||
),
|
||||
SYS_SYMLINKAT => Err(SysError::EACCES),
|
||||
SYS_FACCESSAT => sys_faccessat(args[0], args[1] as *const u8, args[2], args[3]),
|
||||
SYS_PPOLL => sys_ppoll(args[0] as *mut PollFd, args[1], args[2] as *const TimeSpec), // ignore sigmask
|
||||
// 280
|
||||
SYS_UTIMENSAT => {
|
||||
warn!("sys_utimensat is unimplemented");
|
||||
@ -340,7 +341,10 @@ fn x86_64_syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> Option<Sys
|
||||
args[4] as *const TimeVal,
|
||||
),
|
||||
SYS_DUP2 => sys_dup2(args[0], args[1]),
|
||||
// SYS_PAUSE => sys_pause(),
|
||||
SYS_ALARM => {
|
||||
warn!("sys_alarm is unimplemented");
|
||||
Ok(0)
|
||||
}
|
||||
SYS_FORK => sys_fork(tf),
|
||||
// use fork for vfork
|
||||
SYS_VFORK => sys_fork(tf),
|
||||
@ -355,16 +359,12 @@ fn x86_64_syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> Option<Sys
|
||||
warn!("sys_chmod is unimplemented");
|
||||
Ok(0)
|
||||
}
|
||||
SYS_ARCH_PRCTL => sys_arch_prctl(args[0] as i32, args[1], tf),
|
||||
SYS_TIME => sys_time(args[0] as *mut u64),
|
||||
SYS_ALARM => {
|
||||
warn!("sys_alarm is unimplemented");
|
||||
Ok(0)
|
||||
}
|
||||
SYS_CHOWN => {
|
||||
warn!("sys_chown is unimplemented");
|
||||
Ok(0)
|
||||
}
|
||||
SYS_ARCH_PRCTL => sys_arch_prctl(args[0] as i32, args[1], tf),
|
||||
SYS_TIME => sys_time(args[0] as *mut u64),
|
||||
SYS_EPOLL_CREATE => {
|
||||
warn!("sys_epoll_create is unimplemented");
|
||||
Err(SysError::ENOSYS)
|
||||
|
@ -19,6 +19,7 @@ const USEC_PER_SEC: u64 = 1_000_000;
|
||||
const MSEC_PER_SEC: u64 = 1_000;
|
||||
const USEC_PER_MSEC: u64 = 1_000;
|
||||
const NSEC_PER_USEC: u64 = 1_000;
|
||||
const NSEC_PER_MSEC: u64 = 1_000_000;
|
||||
|
||||
/// Get time since epoch in usec
|
||||
fn get_epoch_usec() -> u64 {
|
||||
@ -58,6 +59,10 @@ pub struct TimeSpec {
|
||||
}
|
||||
|
||||
impl TimeSpec {
|
||||
pub fn to_msec(&self) -> u64 {
|
||||
self.sec * MSEC_PER_SEC + self.nsec / NSEC_PER_MSEC
|
||||
}
|
||||
|
||||
pub fn to_duration(&self) -> Duration {
|
||||
Duration::new(self.sec, self.nsec as u32)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user