Skip to content

Commit

Permalink
try to fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhiyuanSue committed Dec 19, 2024
1 parent 04a5466 commit eb6e67a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
2 changes: 1 addition & 1 deletion kernel/src/interfaces_impl/cspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _,
);
}
Expand Down
42 changes: 36 additions & 6 deletions kernel/src/syscall/invocation/decode/decode_sched_invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},
};
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions sel4_cspace/src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
4 changes: 4 additions & 0 deletions sel4_cspace/src/arch/riscv64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
16 changes: 8 additions & 8 deletions sel4_task/src/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<sched_context_t>(tcb_caller.tcbSchedContext);
// sel4_common::println!("reply push");

assert!(tcb_caller.get_ptr() != 0);
assert!(self.get_ptr() != 0);
Expand All @@ -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::<reply_t>(sc_donated.scReply);
if tcb_caller.tcbSchedContext != 0 && tcb_callee.tcbSchedContext == 0 && canDonate {
let sc_donated = convert_to_mut_type_ref::<sched_context_t>(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::<reply_t>(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::<reply_t>(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();
Expand Down

0 comments on commit eb6e67a

Please sign in to comment.