fix sys_wait -1. update fs.

master
WangRunji 6 years ago
parent 0666a5a7ee
commit fdc28724a3

4
kernel/Cargo.lock generated

@ -282,12 +282,12 @@ dependencies = [
[[package]] [[package]]
name = "rcore-fs" name = "rcore-fs"
version = "0.1.0" 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]] [[package]]
name = "rcore-fs-sfs" name = "rcore-fs-sfs"
version = "0.1.0" 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 = [ dependencies = [
"bitvec 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",

@ -81,7 +81,7 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
058 => sys_fork(tf), 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), 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), 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]), 062 => sys_kill(args[0]),
063 => sys_uname(args[0] as *mut u8), 063 => sys_uname(args[0] as *mut u8),
// 072 => sys_fcntl(), // 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"); warn!("sys_exit_group is unimplemented");
sys_exit(args[0] as isize); sys_exit(args[0] as isize);
} }
280 => {
warn!("sys_utimensat is unimplemented");
Ok(0)
}
302 => { 302 => {
warn!("sys_prlimit64 is unimplemented"); warn!("sys_prlimit64 is unimplemented");
Ok(0) Ok(0)

@ -12,19 +12,29 @@ pub fn sys_fork(tf: &TrapFrame) -> SysResult {
/// Wait the process exit. /// Wait the process exit.
/// Return the PID. Store exit code to `code` if it's not null. /// Return the PID. Store exit code to `code` if it's not null.
pub fn sys_wait(pid: usize, code: *mut i32) -> SysResult { pub fn sys_wait4(pid: isize, code: *mut i32) -> SysResult {
info!("wait: pid {} code {:?}", pid, code); info!("wait4: pid: {}, code: {:?}", pid, code);
if !code.is_null() { if !code.is_null() {
process().memory_set.check_mut_ptr(code)?; 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 { loop {
use alloc::vec; use alloc::vec;
let wait_procs = match pid { let wait_procs = match target {
0 => processor().manager().get_children(thread::current().id()), WaitFor::AnyChild => processor().manager().get_children(thread::current().id()),
// check if pid is a child WaitFor::Pid(pid) => {
_ => { // check if pid is a child
if processor().manager().get_children(thread::current().id()).iter() if processor().manager().get_children(thread::current().id()).iter()
.find(|p| **p == pid).is_some() { .find(|&&p| p == pid).is_some() {
vec![pid] vec![pid]
} else { } else {
vec![] vec![]
@ -49,14 +59,12 @@ pub fn sys_wait(pid: usize, code: *mut i32) -> SysResult {
_ => {} _ => {}
} }
} }
info!("wait: {} -> {}, sleep", thread::current().id(), pid); info!("wait: {} -> {:?}, sleep", thread::current().id(), target);
if pid == 0 { match target {
processor().manager().wait_child(thread::current().id()); WaitFor::AnyChild => processor().manager().wait_child(thread::current().id()),
processor().yield_now(); WaitFor::Pid(pid) => processor().manager().wait(thread::current().id(), pid),
} else {
processor().manager().wait(thread::current().id(), pid);
processor().yield_now();
} }
processor().yield_now();
} }
} }

Loading…
Cancel
Save