From 47ecfabf1efcadee5a42d3b2185535c3f6acc4d7 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Tue, 8 Nov 2022 19:28:36 +0100 Subject: [PATCH 1/2] Limit table scope --- src/sys/process.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sys/process.rs b/src/sys/process.rs index dbce359ed..38fc57962 100644 --- a/src/sys/process.rs +++ b/src/sys/process.rs @@ -297,8 +297,10 @@ 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; @@ -306,6 +308,8 @@ impl Process { 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) From 5cdeac64213594b3df3d04f0294675e3350ae9f5 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Tue, 8 Nov 2022 19:28:49 +0100 Subject: [PATCH 2/2] Rename pid to id --- src/sys/process.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sys/process.rs b/src/sys/process.rs index 38fc57962..5a3c2e3bc 100644 --- a/src/sys/process.rs +++ b/src/sys/process.rs @@ -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(())