feat: kernel/objects/tcb: add get_message_info

This commit is contained in:
Paul Pan 2024-09-03 19:58:06 +08:00
parent 13180fe9f4
commit 8918dac00c
2 changed files with 19 additions and 14 deletions

View File

@ -6,6 +6,7 @@ use core::fmt::Debug;
use core::sync::atomic::{AtomicUsize, Ordering}; use core::sync::atomic::{AtomicUsize, Ordering};
use uapi::cap::ObjectType; use uapi::cap::ObjectType;
use uapi::fault::Fault; use uapi::fault::Fault;
use uapi::syscall::*;
use utils::{ use utils::{
addr::*, addr::*,
linked_list::{Link, LinkHelper}, linked_list::{Link, LinkHelper},
@ -124,19 +125,6 @@ impl TcbObject {
self.state 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) { pub fn set_state(&mut self, state: ThreadState) {
self.state = state; self.state = state;
} }
@ -157,6 +145,19 @@ impl TcbObject {
self.time_tick = self.time_tick.saturating_sub(1); 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) { pub fn activate_vspace(&self) {
let cap = TableCap::try_from(&self.vspace).expect("activate_vspace: invalid cap"); let cap = TableCap::try_from(&self.vspace).expect("activate_vspace: invalid cap");
let paddr = cap.as_object::<Level0>().paddr(); let paddr = cap.as_object::<Level0>().paddr();
@ -169,6 +170,10 @@ impl TcbObject {
self.trapframe.handle_trap(false); self.trapframe.handle_trap(false);
} }
pub fn get_message_info(&self) -> SysResult<MessageInfo> {
MessageInfo::try_from(self.trapframe.get_reg(REG_MESSAGE_INFO))
}
pub fn handle_syscall(&mut self) { pub fn handle_syscall(&mut self) {
// TODO: don't panic here, return error to user instead, create SysRespInfo // TODO: don't panic here, return error to user instead, create SysRespInfo
handle_syscall(self).unwrap(); handle_syscall(self).unwrap();

View File

@ -11,7 +11,7 @@ macro_rules! assert_length {
} }
pub fn handle_syscall(tcb: &mut TcbObject) -> SysResult { 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 // Invalid, Debug*, Yield will bypass the capability check
match info.label() { match info.label() {