From 7090ddc7b9ef69666231f0fba7b0408ab2bb9e66 Mon Sep 17 00:00:00 2001 From: ZhiyuanSue <2262387848@qq.com> Date: Sun, 22 Dec 2024 15:59:20 +0800 Subject: [PATCH] fix the bug of sc control judge and add mcs code of cancel badged sends --- .../decode/decode_sched_invocation.rs | 7 ++- sel4_ipc/src/endpoint.rs | 43 ++++++++++++++++--- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/kernel/src/syscall/invocation/decode/decode_sched_invocation.rs b/kernel/src/syscall/invocation/decode/decode_sched_invocation.rs index cafc4dc..cea6aff 100644 --- a/kernel/src/syscall/invocation/decode/decode_sched_invocation.rs +++ b/kernel/src/syscall/invocation/decode/decode_sched_invocation.rs @@ -107,11 +107,10 @@ pub fn decode_sched_control_invocation( &convert_to_mut_type_ref::(unsafe { current_extra_caps.excaprefs[0] }) .capability; if unlikely(targetCap.get_tag() != cap_tag::cap_sched_context_cap) { - debug!("SchedControl_ConfigureFlags: budget out of range."); + debug!("SchedControl_ConfigureFlags: target cap not a scheduling context cap"); unsafe { - current_syscall_error._type = seL4_RangeError; - current_syscall_error.rangeErrorMin = MIN_BUDGET_US(); - current_syscall_error.rangeErrorMax = MAX_PERIOD_US(); + current_syscall_error._type = seL4_InvalidCapability; + current_syscall_error.invalidCapNumber = 1; return exception_t::EXCEPTION_SYSCALL_ERROR; } } diff --git a/sel4_ipc/src/endpoint.rs b/sel4_ipc/src/endpoint.rs index 2355142..f21b1e7 100644 --- a/sel4_ipc/src/endpoint.rs +++ b/sel4_ipc/src/endpoint.rs @@ -1,14 +1,14 @@ use crate::transfer::Transfer; -use sel4_common::arch::ArchReg; -use sel4_common::structures_gen::endpoint; #[cfg(feature = "KERNEL_MCS")] use sel4_common::structures_gen::seL4_Fault_tag::seL4_Fault_NullFault; +use sel4_common::structures_gen::endpoint; use sel4_common::utils::{convert_to_mut_type_ref, convert_to_option_mut_type_ref}; +use sel4_common::arch::ArchReg; #[cfg(feature = "KERNEL_MCS")] use sel4_task::{ksCurSC, reply::reply_t, sched_context::sched_context_t}; use sel4_task::{ possible_switch_to, rescheduleRequired, schedule_tcb, set_thread_state, tcb_queue_t, tcb_t, - ThreadState, + thread_state_func, ThreadState, }; use sel4_vspace::pptr_t; @@ -180,10 +180,40 @@ impl endpoint_func for endpoint { while thread_ptr != 0 { let thread = convert_to_mut_type_ref::(thread_ptr); thread_ptr = thread.tcbEPNext; + #[cfg(feature = "KERNEL_MCS")] + { + assert!(thread.tcbState.get_replyObject() == 0); + } if thread.tcbState.get_blockingIPCBadge() as usize == badge { - set_thread_state(thread, ThreadState::ThreadStateRestart); - thread.sched_enqueue(); - queue.ep_dequeue(thread); + #[cfg(not(feature = "KERNEL_MCS"))] + { + set_thread_state(thread, ThreadState::ThreadStateRestart); + thread.sched_enqueue(); + queue.ep_dequeue(thread); + } + #[cfg(feature = "KERNEL_MCS")] + { + if thread.tcbFault.get_tag() == seL4_Fault_NullFault { + set_thread_state(thread, ThreadState::ThreadStateRestart); + if convert_to_mut_type_ref::( + thread.tcbSchedContext, + ) + .sc_sporadic() + { + assert!(thread.tcbSchedContext != unsafe { ksCurSC }); + if thread.tcbSchedContext != unsafe { ksCurSC } { + convert_to_mut_type_ref::( + thread.tcbSchedContext, + ) + .refill_unblock_check(); + } + } + possible_switch_to(thread); + } else { + set_thread_state(thread, ThreadState::ThreadStateInactive); + } + queue.ep_dequeue(thread); + } } } self.set_queue(&queue); @@ -495,6 +525,7 @@ impl endpoint_func for endpoint { convert_to_mut_type_ref::(replyptr) .push(sender, thread, canDonate); } else { + sel4_common::println!("receive ipc inactive"); set_thread_state(sender, ThreadState::ThreadStateInactive); } } else {