diff --git a/kernel/src/process/structs.rs b/kernel/src/process/structs.rs index dbf9bca..8754f1e 100644 --- a/kernel/src/process/structs.rs +++ b/kernel/src/process/structs.rs @@ -98,6 +98,11 @@ impl Pid { pub fn get(&self) -> usize { self.0.unwrap() } + + /// Return whether this pid represents the init process + pub fn is_init(&self) -> bool { + self.0 == Some(0) + } } impl fmt::Display for Pid { diff --git a/kernel/src/shell.rs b/kernel/src/shell.rs index ab5b1e0..1bd28b0 100644 --- a/kernel/src/shell.rs +++ b/kernel/src/shell.rs @@ -8,7 +8,7 @@ use crate::process::*; pub fn run_user_shell() { //use crate::net::server; //processor().manager().add(Thread::new_kernel(server, 0), 0); - if let Ok(inode) = ROOT_INODE.lookup("sh") { + if let Ok(inode) = ROOT_INODE.lookup("rust/sh") { println!("Going to user mode shell."); println!("Use 'ls' to list available programs."); let data = inode.read_as_vec().unwrap(); diff --git a/kernel/src/syscall/fs.rs b/kernel/src/syscall/fs.rs index e0a8143..167052f 100644 --- a/kernel/src/syscall/fs.rs +++ b/kernel/src/syscall/fs.rs @@ -12,8 +12,11 @@ use crate::drivers::SOCKET_ACTIVITY; use super::*; pub fn sys_read(fd: usize, base: *mut u8, len: usize) -> SysResult { - info!("read: fd: {}, base: {:?}, len: {:#x}", fd, base, len); let mut proc = process(); + if !proc.pid.is_init() { + // we trust pid 0 process + info!("read: fd: {}, base: {:?}, len: {:#x}", fd, base, len); + } proc.memory_set.check_mut_array(base, len)?; match proc.files.get(&fd) { Some(FileLike::File(_)) => sys_read_file(&mut proc, fd, base, len), @@ -23,8 +26,11 @@ pub fn sys_read(fd: usize, base: *mut u8, len: usize) -> SysResult { } pub fn sys_write(fd: usize, base: *const u8, len: usize) -> SysResult { - info!("write: fd: {}, base: {:?}, len: {:#x}", fd, base, len); let mut proc = process(); + if !proc.pid.is_init() { + // we trust pid 0 process + info!("write: fd: {}, base: {:?}, len: {:#x}", fd, base, len); + } proc.memory_set.check_array(base, len)?; match proc.files.get(&fd) { diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index ad8856f..8c3b714 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -35,7 +35,10 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { process().pid.clone() }; let tid = processor().tid(); - debug!("{}:{}:{} syscall id {} begin", cid, pid, tid, id); + if !pid.is_init() { + // we trust pid 0 process + debug!("{}:{}:{} syscall id {} begin", cid, pid, tid, id); + } let ret = match id { // file 000 => sys_read(args[0], args[1] as *mut u8, args[2]), @@ -211,7 +214,10 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize { crate::trap::error(tf); } }; - debug!("{}:{}:{} syscall id {} ret with {:x?}", cid, pid, tid, id, ret); + if !pid.is_init() { + // we trust pid 0 process + debug!("{}:{}:{} syscall id {} ret with {:x?}", cid, pid, tid, id, ret); + } match ret { Ok(code) => code as isize, Err(err) => -(err as isize), diff --git a/kernel/src/syscall/proc.rs b/kernel/src/syscall/proc.rs index b2eab2d..3c258f9 100644 --- a/kernel/src/syscall/proc.rs +++ b/kernel/src/syscall/proc.rs @@ -104,6 +104,7 @@ pub fn sys_exec(name: *const u8, argv: *const *const u8, envp: *const *const u8, let mut args = Vec::new(); unsafe { let mut current_argv = argv as *const *const u8; + proc.memory_set.check_ptr(current_argv)?; while !(*current_argv).is_null() { let arg = proc.memory_set.check_and_clone_cstr(*current_argv)?; args.push(arg); @@ -125,6 +126,9 @@ pub fn sys_exec(name: *const u8, argv: *const *const u8, envp: *const *const u8, let mut thread = Thread::new_user(buf.as_slice(), iter); thread.proc.lock().files = proc.files.clone(); thread.proc.lock().cwd = proc.cwd.clone(); + thread.proc.lock().pid = proc.pid.clone(); + thread.proc.lock().parent = proc.parent.clone(); + thread.proc.lock().threads = proc.threads.clone(); // Activate new page table unsafe { thread.proc.lock().memory_set.activate(); } diff --git a/user b/user index bae6866..f0441d1 160000 --- a/user +++ b/user @@ -1 +1 @@ -Subproject commit bae6866610fc24ca66584c1a5200648d2de7d767 +Subproject commit f0441d1fe30022acfadced2224b00ed9a29db455