mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
feat: kernel/syscall: wire up endpoint operations
This commit is contained in:
parent
46a8ff9691
commit
e6d6a2ee21
@ -3,11 +3,16 @@ use log::trace;
|
||||
use uapi::{error::*, syscall::*};
|
||||
|
||||
macro_rules! assert_length {
|
||||
($info:expr, $len:expr) => {
|
||||
($info:ident, $len:expr) => {
|
||||
if $info.length() != $len {
|
||||
return Err(SysError::InvalidArgument);
|
||||
}
|
||||
};
|
||||
($info:ident >= $len:expr) => {
|
||||
if $info.length() >= $len {
|
||||
return Err(SysError::InvalidArgument);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub fn handle_syscall(tcb: &mut TcbObject) -> SysResult {
|
||||
@ -29,17 +34,33 @@ pub fn handle_syscall(tcb: &mut TcbObject) -> SysResult {
|
||||
_ => (),
|
||||
};
|
||||
|
||||
let cspace = tcb.cspace()?;
|
||||
assert_length!(info >= 2);
|
||||
|
||||
// workaround ownership check
|
||||
let tcb_cspace = unsafe { &mut *(tcb as *mut TcbObject) };
|
||||
let cspace = tcb_cspace.cspace()?;
|
||||
|
||||
let cap_ptr = tcb.trapframe.get_reg(REG_CAP_PTR);
|
||||
let cap = cspace.resolve_address_bits(cap_ptr, info.bits()).map_err(SysError::from)?;
|
||||
|
||||
trace!("handle_syscall: info={:?} cap={:?}", info, cap);
|
||||
trace!("[Syscall] info={:?} cap={:?}", info, cap);
|
||||
|
||||
match info.label() {
|
||||
Syscall::InvokeNtfn => {
|
||||
assert_length!(info, 2);
|
||||
unimplemented!("[Syscall] InvokeNtfn: {:?}", info.label());
|
||||
// Endpoint
|
||||
Syscall::EpSend => {
|
||||
let mut cap = EndpointCap::try_from(cap)?;
|
||||
cap.do_send(tcb)
|
||||
},
|
||||
_ => unimplemented!("handle_syscall: {:?}, {:?}", info.label(), cap),
|
||||
Syscall::EpRecv => {
|
||||
let mut cap = EndpointCap::try_from(cap)?;
|
||||
cap.do_recv(tcb)
|
||||
},
|
||||
Syscall::IrqSet => {
|
||||
unimplemented!("[Syscall] IrqSet: {:?}", info.label())
|
||||
},
|
||||
Syscall::IrqAck => {
|
||||
unimplemented!("[Syscall] IrqAck: {:?}", info.label())
|
||||
},
|
||||
_ => todo!("[Syscall] unhandled syscall: {:?}, {:?}", info.label(), cap),
|
||||
}
|
||||
}
|
||||
|
@ -8,11 +8,12 @@ pub enum Syscall {
|
||||
Invalid = 0,
|
||||
DebugPutChar = 1,
|
||||
Yield = 2,
|
||||
InvokeNtfn = 3,
|
||||
// Send = 4,
|
||||
// Recv = 5,
|
||||
// Call = 6,
|
||||
// Reply = 7,
|
||||
|
||||
// endpoint
|
||||
EpSend = 3,
|
||||
EpRecv = 4,
|
||||
IrqSet = 5,
|
||||
IrqAck = 6,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, FromPrimitive, ToPrimitive)]
|
||||
|
Loading…
Reference in New Issue
Block a user