Skip to content

Commit

Permalink
Fix process table panic (#435)
Browse files Browse the repository at this point in the history
* Limit table scope

* Rename pid to id
  • Loading branch information
vinc authored Nov 8, 2022
1 parent 778de3c commit 7ee8852
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/sys/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ impl Process {
}

pub fn spawn(bin: &[u8], args_ptr: usize, args_len: usize) -> Result<(), ExitCode> {
if let Ok(pid) = Self::create(bin) {
if let Ok(id) = Self::create(bin) {
let proc = {
let table = PROCESS_TABLE.read();
table[pid].clone()
table[id].clone()
};
proc.exec(args_ptr, args_len);
Ok(())
Expand Down Expand Up @@ -297,15 +297,19 @@ impl Process {
return Err(());
}

let mut table = PROCESS_TABLE.write();
let parent = &table[id()];
let parent = {
let table = PROCESS_TABLE.read();
table[id()].clone()
};

let data = parent.data.clone();
let registers = parent.registers;
let stack_frame = parent.stack_frame;

let id = MAX_PID.fetch_add(1, Ordering::SeqCst);
let proc = Process { id, code_addr, stack_addr, entry_point, data, stack_frame, registers };

let mut table = PROCESS_TABLE.write();
table[id] = Box::new(proc);

Ok(id)
Expand Down

0 comments on commit 7ee8852

Please sign in to comment.