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]]
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)",

@ -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)

@ -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();
}
}

Loading…
Cancel
Save