diff --git a/kernel/src/interfaces_impl/cspace.rs b/kernel/src/interfaces_impl/cspace.rs index 903675b..dbed298 100644 --- a/kernel/src/interfaces_impl/cspace.rs +++ b/kernel/src/interfaces_impl/cspace.rs @@ -114,7 +114,7 @@ pub fn Arch_finaliseCap(capability: &cap, final_: bool) -> finaliseCap_ret { cap_tag::cap_vspace_cap => { if final_ && cap::cap_vspace_cap(capability).get_capVSIsMapped() == 1 { deleteASID( - cap::cap_vspace_cap(capability).get_capVSIsMapped() as usize, + cap::cap_vspace_cap(capability).get_capVSMappedASID() as usize, cap::cap_vspace_cap(capability).get_capVSBasePtr() as _, ); } diff --git a/kernel/src/syscall/invocation/decode/decode_sched_invocation.rs b/kernel/src/syscall/invocation/decode/decode_sched_invocation.rs index 4987d27..de46c58 100644 --- a/kernel/src/syscall/invocation/decode/decode_sched_invocation.rs +++ b/kernel/src/syscall/invocation/decode/decode_sched_invocation.rs @@ -30,8 +30,7 @@ use crate::{ syscall::{ get_syscall_arg, invocation::invoke_sched::{ - invokeSchedContext_Bind, invokeSchedContext_Consumed, invokeSchedContext_Unbind, - invokeSchedControl_ConfigureFlags, + invokeSchedContext_Bind, invokeSchedContext_Consumed, invokeSchedContext_Unbind, invokeSchedContext_UnbindObject, invokeSchedControl_ConfigureFlags }, }, }; @@ -186,11 +185,42 @@ pub fn decode_sched_control_invocation( } pub fn decodeSchedContext_UnbindObject(sc: &mut sched_context) -> exception_t { // TODO: MCS - unimplemented!("MCS unbind object"); - if global_ops!(current_extra_caps.excaprefs[0] == 0) { - debug!("") + if get_extra_cap_by_index(0).is_none() { + debug!("SchedContext_Unbind: Truncated message."); + unsafe{current_syscall_error._type= seL4_TruncatedMessage;} + return exception_t::EXCEPTION_SYSCALL_ERROR; } - exception_t::EXCEPTION_NONE + let capability = &get_extra_cap_by_index(0).unwrap().capability; + match capability.clone().splay(){ + cap_Splayed::thread_cap(data)=>{ + if sc.scTcb != data.get_capTCBPtr() as usize{ + debug!("SchedContext UnbindObject: object not bound"); + unsafe{current_syscall_error._type= seL4_IllegalOperation;} + return exception_t::EXCEPTION_SYSCALL_ERROR; + } + if sc.scTcb == unsafe{ ksCurThread}{ + debug!("SchedContext UnbindObject: cannot unbind sc of current thread"); + unsafe{current_syscall_error._type= seL4_IllegalOperation;} + return exception_t::EXCEPTION_SYSCALL_ERROR; + } + } + cap_Splayed::notification_cap(data)=>{ + if sc.scNotification != data.get_capNtfnPtr() as usize { + debug!("SchedContext UnbindObject: object not bound"); + unsafe{current_syscall_error._type= seL4_IllegalOperation;} + return exception_t::EXCEPTION_SYSCALL_ERROR; + } + } + _=>{ + debug!("SchedContext_Unbind: invalid cap"); + unsafe{current_syscall_error._type= seL4_InvalidCapability; + current_syscall_error.invalidCapNumber = 1; + } + return exception_t::EXCEPTION_SYSCALL_ERROR; + } + } + set_thread_state(get_currenct_thread(), ThreadState::ThreadStateRestart); + return invokeSchedContext_UnbindObject(sc,capability.clone()) } pub fn decodeSchedContext_Bind(sc: &mut sched_context) -> exception_t { if get_extra_cap_by_index(0).is_none() { diff --git a/sel4_cspace/src/arch/aarch64/mod.rs b/sel4_cspace/src/arch/aarch64/mod.rs index fe84756..d3d7e8b 100644 --- a/sel4_cspace/src/arch/aarch64/mod.rs +++ b/sel4_cspace/src/arch/aarch64/mod.rs @@ -32,6 +32,8 @@ impl cap_arch_func for cap { cap_tag::cap_asid_pool_cap => cap::cap_asid_pool_cap(self).get_capASIDPool() as usize, #[cfg(feature = "KERNEL_MCS")] cap_tag::cap_reply_cap => cap::cap_reply_cap(self).get_capReplyPtr() as usize, + #[cfg(feature = "KERNEL_MCS")] + cap_tag::cap_sched_context_cap => cap::cap_sched_context_cap(self).get_capSCPtr() as usize, _ => 0, } } diff --git a/sel4_cspace/src/arch/riscv64/mod.rs b/sel4_cspace/src/arch/riscv64/mod.rs index bcba870..5bcda5c 100644 --- a/sel4_cspace/src/arch/riscv64/mod.rs +++ b/sel4_cspace/src/arch/riscv64/mod.rs @@ -30,6 +30,10 @@ impl cap_arch_func for cap { cap::cap_page_table_cap(self).get_capPTBasePtr() as usize } cap_tag::cap_asid_pool_cap => cap::cap_asid_pool_cap(self).get_capASIDPool() as usize, + #[cfg(feature = "KERNEL_MCS")] + cap_tag::cap_reply_cap => cap::cap_reply_cap(self).get_capReplyPtr() as usize, + #[cfg(feature = "KERNEL_MCS")] + cap_tag::cap_sched_context_cap => cap::cap_sched_context_cap(self).get_capSCPtr() as usize, _ => 0, } } diff --git a/sel4_task/src/reply.rs b/sel4_task/src/reply.rs index feb9214..ba172ad 100644 --- a/sel4_task/src/reply.rs +++ b/sel4_task/src/reply.rs @@ -27,7 +27,7 @@ impl reply { set_thread_state(tcb, ThreadState::ThreadStateInactive); } pub fn push(&mut self, tcb_caller: &mut tcb_t, tcb_callee: &mut tcb_t, canDonate: bool) { - let sc_donated = convert_to_mut_type_ref::(tcb_caller.tcbSchedContext); + // sel4_common::println!("reply push"); assert!(tcb_caller.get_ptr() != 0); assert!(self.get_ptr() != 0); @@ -49,19 +49,19 @@ impl reply { tcb_caller.tcbState.set_replyObject(self.get_ptr() as u64); set_thread_state(tcb_caller, ThreadState::ThreadStateBlockedOnReply); - if sc_donated.get_ptr() != 0 && tcb_callee.tcbSchedContext == 0 && canDonate { - let old_caller = convert_to_mut_type_ref::(sc_donated.scReply); + if tcb_caller.tcbSchedContext != 0 && tcb_callee.tcbSchedContext == 0 && canDonate { + let sc_donated = convert_to_mut_type_ref::(tcb_caller.tcbSchedContext); /* check stack integrity */ assert!( - old_caller.get_ptr() == 0 - || old_caller.replyNext.get_callStackPtr() == sc_donated.get_ptr() as u64 + sc_donated.scReply == 0 + || convert_to_mut_type_ref::(sc_donated.scReply).replyNext.get_callStackPtr() == tcb_caller.tcbSchedContext as u64 ); /* push on to stack */ - self.replyPrev = call_stack::new(old_caller.get_ptr() as u64, 0); - if old_caller.get_ptr() != 0 { - old_caller.replyNext = call_stack::new(self.get_ptr() as u64, 0); + self.replyPrev = call_stack::new(sc_donated.scReply as u64, 0); + if sc_donated.scReply != 0 { + convert_to_mut_type_ref::(sc_donated.scReply).replyNext = call_stack::new(self.get_ptr() as u64, 0); } self.replyNext = call_stack::new(sc_donated.get_ptr() as u64, 1); sc_donated.scReply = self.get_ptr();