Add exit status to status enum

This commit is contained in:
Jeremy Soller 2016-09-17 09:23:36 -06:00
parent da9e703c4d
commit dfbcca99dd
3 changed files with 13 additions and 6 deletions

View file

@ -11,7 +11,7 @@ use super::memory::{Memory, SharedMemory};
pub enum Status { pub enum Status {
Runnable, Runnable,
Blocked, Blocked,
Exited Exited(usize)
} }
/// A context, which identifies either a process or a thread /// A context, which identifies either a process or a thread

View file

@ -57,3 +57,7 @@ pub fn contexts() -> RwLockReadGuard<'static, ContextList> {
pub fn contexts_mut() -> RwLockWriteGuard<'static, ContextList> { pub fn contexts_mut() -> RwLockWriteGuard<'static, ContextList> {
CONTEXTS.call_once(init_contexts).write() CONTEXTS.call_once(init_contexts).write()
} }
pub fn context_id() -> usize {
CONTEXT_ID.load(Ordering::SeqCst)
}

View file

@ -52,10 +52,10 @@ pub const CLONE_FS: usize = 0x200;
pub const CLONE_FILES: usize = 0x400; pub const CLONE_FILES: usize = 0x400;
pub const CLONE_VFORK: usize = 0x4000; pub const CLONE_VFORK: usize = 0x4000;
pub fn clone(flags: usize, stack_base: usize) -> Result<usize> { pub fn clone(flags: usize, stack_base: usize) -> Result<usize> {
//TODO: Implement flags
//TODO: Copy on write? //TODO: Copy on write?
println!("Clone {:X}: {:X}", flags, stack_base); println!("Clone {:X}: {:X}", flags, stack_base);
let ppid;
let pid; let pid;
{ {
let arch; let arch;
@ -71,6 +71,9 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<usize> {
let contexts = context::contexts(); let contexts = context::contexts();
let context_lock = contexts.current().ok_or(Error::NoProcess)?; let context_lock = contexts.current().ok_or(Error::NoProcess)?;
let context = context_lock.read(); let context = context_lock.read();
ppid = context.id;
arch = context.arch.clone(); arch = context.arch.clone();
if let Some(ref stack) = context.kstack { if let Some(ref stack) = context.kstack {
@ -300,8 +303,6 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<usize> {
} }
pub fn exit(status: usize) -> ! { pub fn exit(status: usize) -> ! {
println!("Exit {}", status);
{ {
let contexts = context::contexts(); let contexts = context::contexts();
let context_lock = contexts.current().expect("tried to exit without context"); let context_lock = contexts.current().expect("tried to exit without context");
@ -309,7 +310,7 @@ pub fn exit(status: usize) -> ! {
context.image.clear(); context.image.clear();
drop(context.heap.take()); drop(context.heap.take());
drop(context.stack.take()); drop(context.stack.take());
context.status = context::Status::Exited; context.status = context::Status::Exited(status);
} }
unsafe { context::switch(); } unsafe { context::switch(); }
@ -365,6 +366,7 @@ pub fn sched_yield() -> Result<usize> {
} }
pub fn waitpid(pid: usize, _status_ptr: usize, _options: usize) -> Result<usize> { pub fn waitpid(pid: usize, _status_ptr: usize, _options: usize) -> Result<usize> {
//TODO: Implement status_ptr and options
loop { loop {
{ {
let mut exited = false; let mut exited = false;
@ -373,7 +375,8 @@ pub fn waitpid(pid: usize, _status_ptr: usize, _options: usize) -> Result<usize>
let contexts = context::contexts(); let contexts = context::contexts();
let context_lock = contexts.get(pid).ok_or(Error::NoProcess)?; let context_lock = contexts.get(pid).ok_or(Error::NoProcess)?;
let context = context_lock.read(); 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; exited = true;
} }
} }