Implement many process syscalls.

This commit is contained in:
Yifan Wu 2020-12-10 11:57:26 +08:00
parent 81bef97f09
commit 3642f9c56d
20 changed files with 383 additions and 88 deletions

View file

@ -12,7 +12,7 @@ const DL: u8 = 0x7fu8;
const BS: u8 = 0x08u8;
use alloc::string::String;
use user_lib::{fork, exec, wait};
use user_lib::{fork, exec, waitpid, yield_};
use user_lib::console::getchar;
#[no_mangle]
@ -37,8 +37,17 @@ pub fn main() -> i32 {
unreachable!();
} else {
let mut xstate: i32 = 0;
wait(&mut xstate);
println!("Shell: Process {} exited with code {}", pid, xstate);
let mut exit_pid: isize = 0;
loop {
exit_pid = waitpid(pid as usize, &mut xstate);
if exit_pid == -1 {
yield_();
} else {
assert_eq!(pid, exit_pid);
println!("Shell: Process {} exited with code {}", pid, xstate);
break;
}
}
}
line.clear();
}

View file

@ -42,7 +42,7 @@ fn main() -> i32 {
pub fn read(fd: usize, buf: &mut [u8]) -> isize { sys_read(fd, buf) }
pub fn write(fd: usize, buf: &[u8]) -> isize { sys_write(fd, buf) }
pub fn exit(xstate: i32) -> ! { sys_exit(xstate); }
pub fn exit(exit_code: i32) -> ! { sys_exit(exit_code); }
pub fn yield_() -> isize { sys_yield() }
pub fn get_time() -> isize { sys_get_time() }
pub fn getpid() -> isize { sys_getpid() }

View file

@ -29,8 +29,8 @@ pub fn sys_write(fd: usize, buffer: &[u8]) -> isize {
syscall(SYSCALL_WRITE, [fd, buffer.as_ptr() as usize, buffer.len()])
}
pub fn sys_exit(xstate: i32) -> ! {
syscall(SYSCALL_EXIT, [xstate as usize, 0, 0]);
pub fn sys_exit(exit_code: i32) -> ! {
syscall(SYSCALL_EXIT, [exit_code as usize, 0, 0]);
panic!("sys_exit never returns!");
}