From a318bf0c2cdec028ac78e5de92887491319e0acb Mon Sep 17 00:00:00 2001 From: Mark Poliakov Date: Tue, 22 Mar 2022 18:36:45 +0200 Subject: [PATCH] feature: x86_64 all syscalls --- kernel/src/proc/process.rs | 13 +++++++++++++ kernel/src/syscall/mod.rs | 35 ++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/kernel/src/proc/process.rs b/kernel/src/proc/process.rs index b5fa27d..94c0436 100644 --- a/kernel/src/proc/process.rs +++ b/kernel/src/proc/process.rs @@ -160,6 +160,19 @@ impl Process { // thread.enter_signal(signal, table); // } + /// Crates a new thread in the process + pub fn new_user_thread(&self, entry: usize, stack: usize, arg: usize) -> Result { + let mut lock = self.inner.lock(); + + let table = Self::space_phys(&mut lock); + let thread = Thread::new_user(lock.id, entry, stack, arg, table)?; + let tid = thread.id(); + lock.threads.push(tid); + SCHED.enqueue(tid); + + Ok(tid) + } + /// Creates a new kernel process pub fn new_kernel(entry: extern "C" fn(usize) -> !, arg: usize) -> Result { let id = new_kernel_pid(); diff --git a/kernel/src/syscall/mod.rs b/kernel/src/syscall/mod.rs index e3ca1a8..9270731 100644 --- a/kernel/src/syscall/mod.rs +++ b/kernel/src/syscall/mod.rs @@ -2,7 +2,7 @@ use crate::arch::{machine, platform::ForkFrame}; use crate::debug::Level; -// use crate::dev::timer::TimestampSource; +use crate::dev::timer::TimestampSource; use crate::fs::create_filesystem; use crate::mem::{ phys::PageUsage, @@ -249,16 +249,17 @@ fn _syscall(num: SystemCall, args: &[usize]) -> Result { proc.manipulate_space(move |space| space.free(addr, len / 4096))?; Ok(0) } - // // Process - // SystemCall::Clone => { - // let entry = args[0]; - // let stack = args[1]; - // let arg = args[2]; - // Process::current() - // .new_user_thread(entry, stack, arg) - // .map(|e| u32::from(e) as usize) - // } + // Process + SystemCall::Clone => { + let entry = args[0]; + let stack = args[1]; + let arg = args[2]; + + Process::current() + .new_user_thread(entry, stack, arg) + .map(|e| u32::from(e) as usize) + } SystemCall::Exec => { let filename = arg::str_ref(args[0], args[1])?; let argv = arg::struct_buf_ref::<&str>(args[2], args[3])?; @@ -412,11 +413,11 @@ fn _syscall(num: SystemCall, args: &[usize]) -> Result { Ok(u32::from(proc.pgid()) as usize) } - // // System - // SystemCall::GetCpuTime => { - // let time = machine::local_timer().timestamp()?; - // Ok(time.as_nanos() as usize) - // } + // System + SystemCall::GetCpuTime => { + let time = machine::local_timer().timestamp()?; + Ok(time.as_nanos() as usize) + } SystemCall::Mount => { let target = arg::str_ref(args[0], args[1])?; let options = arg::struct_ref::(args[2])?; @@ -446,8 +447,8 @@ fn _syscall(num: SystemCall, args: &[usize]) -> Result { Ok(args[1]) } - // // Handled elsewhere - // SystemCall::Fork => unreachable!(), + // Handled elsewhere + SystemCall::Fork => unreachable!(), _ => panic!("Unimplemented: {:?}", num), } }