From fdc28724a324933fbf28d87a39e40216eecc552a Mon Sep 17 00:00:00 2001 From: WangRunji Date: Fri, 8 Mar 2019 15:54:03 +0800 Subject: [PATCH] fix sys_wait -1. update fs. --- kernel/Cargo.lock | 4 ++-- kernel/src/syscall/mod.rs | 6 +++++- kernel/src/syscall/proc.rs | 36 ++++++++++++++++++++++-------------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index a856fd5..2738127 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -282,12 +282,12 @@ dependencies = [ [[package]] name = "rcore-fs" version = "0.1.0" -source = "git+https://github.com/wangrunji0408/rcore-fs?branch=sefs#379a58cd6d5854db31d03c38ddf688adf8c774ed" +source = "git+https://github.com/wangrunji0408/rcore-fs?branch=sefs#af02ecfb3fb0da641ebe07c37af094c42dd60c2e" [[package]] name = "rcore-fs-sfs" version = "0.1.0" -source = "git+https://github.com/wangrunji0408/rcore-fs?branch=sefs#379a58cd6d5854db31d03c38ddf688adf8c774ed" +source = "git+https://github.com/wangrunji0408/rcore-fs?branch=sefs#af02ecfb3fb0da641ebe07c37af094c42dd60c2e" dependencies = [ "bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index ad2d8f4..953d02c 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -81,7 +81,7 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { 058 => sys_fork(tf), 059 => sys_exec(args[0] as *const u8, args[1] as *const *const u8, args[2] as *const *const u8, tf), 060 => sys_exit(args[0] as isize), - 061 => sys_wait(args[0], args[1] as *mut i32), // TODO: wait4 + 061 => sys_wait4(args[0] as isize, args[1] as *mut i32), // TODO: wait4 062 => sys_kill(args[0]), 063 => sys_uname(args[0] as *mut u8), // 072 => sys_fcntl(), @@ -173,6 +173,10 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { warn!("sys_exit_group is unimplemented"); sys_exit(args[0] as isize); } + 280 => { + warn!("sys_utimensat is unimplemented"); + Ok(0) + } 302 => { warn!("sys_prlimit64 is unimplemented"); Ok(0) diff --git a/kernel/src/syscall/proc.rs b/kernel/src/syscall/proc.rs index 926b700..0bf6917 100644 --- a/kernel/src/syscall/proc.rs +++ b/kernel/src/syscall/proc.rs @@ -12,19 +12,29 @@ pub fn sys_fork(tf: &TrapFrame) -> SysResult { /// Wait the process exit. /// Return the PID. Store exit code to `code` if it's not null. -pub fn sys_wait(pid: usize, code: *mut i32) -> SysResult { - info!("wait: pid {} code {:?}", pid, code); +pub fn sys_wait4(pid: isize, code: *mut i32) -> SysResult { + info!("wait4: pid: {}, code: {:?}", pid, code); if !code.is_null() { process().memory_set.check_mut_ptr(code)?; } + #[derive(Debug)] + enum WaitFor { + AnyChild, + Pid(usize), + } + let target = match pid { + -1 => WaitFor::AnyChild, + p if p > 0 => WaitFor::Pid(p as usize), + _ => unimplemented!(), + }; loop { use alloc::vec; - let wait_procs = match pid { - 0 => processor().manager().get_children(thread::current().id()), - // check if pid is a child - _ => { + let wait_procs = match target { + WaitFor::AnyChild => processor().manager().get_children(thread::current().id()), + WaitFor::Pid(pid) => { + // check if pid is a child if processor().manager().get_children(thread::current().id()).iter() - .find(|p| **p == pid).is_some() { + .find(|&&p| p == pid).is_some() { vec![pid] } else { vec![] @@ -49,14 +59,12 @@ pub fn sys_wait(pid: usize, code: *mut i32) -> SysResult { _ => {} } } - info!("wait: {} -> {}, sleep", thread::current().id(), pid); - if pid == 0 { - processor().manager().wait_child(thread::current().id()); - processor().yield_now(); - } else { - processor().manager().wait(thread::current().id(), pid); - processor().yield_now(); + info!("wait: {} -> {:?}, sleep", thread::current().id(), target); + match target { + WaitFor::AnyChild => processor().manager().wait_child(thread::current().id()), + WaitFor::Pid(pid) => processor().manager().wait(thread::current().id(), pid), } + processor().yield_now(); } }