diff --git a/kernel/src/objects/tcb.rs b/kernel/src/objects/tcb.rs index 9955bb3..18162ab 100644 --- a/kernel/src/objects/tcb.rs +++ b/kernel/src/objects/tcb.rs @@ -6,6 +6,7 @@ use core::fmt::Debug; use core::sync::atomic::{AtomicUsize, Ordering}; use uapi::cap::ObjectType; use uapi::fault::Fault; +use uapi::syscall::*; use utils::{ addr::*, linked_list::{Link, LinkHelper}, @@ -124,19 +125,6 @@ impl TcbObject { self.state } - pub fn tid(&self) -> usize { - self.tid - } - - pub fn schedulable(&self) -> bool { - matches!(self.state, ThreadState::Idle | ThreadState::Running) - } - - pub fn schedule_next(&self) { - self.sched_queue.detach(); - SCHEDULER.add_next(self); - } - pub fn set_state(&mut self, state: ThreadState) { self.state = state; } @@ -157,6 +145,19 @@ impl TcbObject { self.time_tick = self.time_tick.saturating_sub(1); } + pub fn tid(&self) -> usize { + self.tid + } + + pub fn schedulable(&self) -> bool { + matches!(self.state, ThreadState::Idle | ThreadState::Running) + } + + pub fn schedule_next(&self) { + self.sched_queue.detach(); + SCHEDULER.add_next(self); + } + pub fn activate_vspace(&self) { let cap = TableCap::try_from(&self.vspace).expect("activate_vspace: invalid cap"); let paddr = cap.as_object::().paddr(); @@ -169,6 +170,10 @@ impl TcbObject { self.trapframe.handle_trap(false); } + pub fn get_message_info(&self) -> SysResult { + MessageInfo::try_from(self.trapframe.get_reg(REG_MESSAGE_INFO)) + } + pub fn handle_syscall(&mut self) { // TODO: don't panic here, return error to user instead, create SysRespInfo handle_syscall(self).unwrap(); diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index 3250a10..e943c50 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -11,7 +11,7 @@ macro_rules! assert_length { } pub fn handle_syscall(tcb: &mut TcbObject) -> SysResult { - let info = MessageInfo::try_from(tcb.trapframe.get_reg(REG_MESSAGE_INFO))?; + let info = tcb.get_message_info()?; // Invalid, Debug*, Yield will bypass the capability check match info.label() {