From dfbcca99dd736bdcbe447dd2b6710877a51a90ea Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 17 Sep 2016 09:23:36 -0600 Subject: [PATCH] Add exit status to status enum --- kernel/context/context.rs | 2 +- kernel/context/mod.rs | 4 ++++ kernel/syscall/process.rs | 13 ++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/kernel/context/context.rs b/kernel/context/context.rs index bb86bf1..6b4f7c7 100644 --- a/kernel/context/context.rs +++ b/kernel/context/context.rs @@ -11,7 +11,7 @@ use super::memory::{Memory, SharedMemory}; pub enum Status { Runnable, Blocked, - Exited + Exited(usize) } /// A context, which identifies either a process or a thread diff --git a/kernel/context/mod.rs b/kernel/context/mod.rs index 7c85c7f..041eec6 100644 --- a/kernel/context/mod.rs +++ b/kernel/context/mod.rs @@ -57,3 +57,7 @@ pub fn contexts() -> RwLockReadGuard<'static, ContextList> { pub fn contexts_mut() -> RwLockWriteGuard<'static, ContextList> { CONTEXTS.call_once(init_contexts).write() } + +pub fn context_id() -> usize { + CONTEXT_ID.load(Ordering::SeqCst) +} diff --git a/kernel/syscall/process.rs b/kernel/syscall/process.rs index 4530297..fb21a70 100644 --- a/kernel/syscall/process.rs +++ b/kernel/syscall/process.rs @@ -52,10 +52,10 @@ pub const CLONE_FS: usize = 0x200; pub const CLONE_FILES: usize = 0x400; pub const CLONE_VFORK: usize = 0x4000; pub fn clone(flags: usize, stack_base: usize) -> Result { - //TODO: Implement flags //TODO: Copy on write? println!("Clone {:X}: {:X}", flags, stack_base); + let ppid; let pid; { let arch; @@ -71,6 +71,9 @@ pub fn clone(flags: usize, stack_base: usize) -> Result { let contexts = context::contexts(); let context_lock = contexts.current().ok_or(Error::NoProcess)?; let context = context_lock.read(); + + ppid = context.id; + arch = context.arch.clone(); if let Some(ref stack) = context.kstack { @@ -300,8 +303,6 @@ pub fn clone(flags: usize, stack_base: usize) -> Result { } pub fn exit(status: usize) -> ! { - println!("Exit {}", status); - { let contexts = context::contexts(); let context_lock = contexts.current().expect("tried to exit without context"); @@ -309,7 +310,7 @@ pub fn exit(status: usize) -> ! { context.image.clear(); drop(context.heap.take()); drop(context.stack.take()); - context.status = context::Status::Exited; + context.status = context::Status::Exited(status); } unsafe { context::switch(); } @@ -365,6 +366,7 @@ pub fn sched_yield() -> Result { } pub fn waitpid(pid: usize, _status_ptr: usize, _options: usize) -> Result { + //TODO: Implement status_ptr and options loop { { let mut exited = false; @@ -373,7 +375,8 @@ pub fn waitpid(pid: usize, _status_ptr: usize, _options: usize) -> Result let contexts = context::contexts(); let context_lock = contexts.get(pid).ok_or(Error::NoProcess)?; let context = context_lock.read(); - if context.status == context::Status::Exited { + if let context::Status::Exited(status) = context.status { + //TODO: set status_ptr exited = true; } }