Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix process table panic #435

Merged
merged 2 commits into from
Nov 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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