Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhiyuanSue committed Dec 12, 2024
1 parent b824697 commit 51e6f01
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions kernel/src/arch/aarch64/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub fn handleVMFaultEvent(vm_faultType: usize) -> exception_t {
if status != exception_t::EXCEPTION_NONE {
handle_fault(get_currenct_thread());
}
// sel4_common::println!("handle vm fault event");
schedule();
activateThread();
exception_t::EXCEPTION_NONE
Expand Down
19 changes: 17 additions & 2 deletions kernel/src/syscall/invocation/decode/decode_tcb_invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ fn decode_tcb_configure(
target_thread_slot: &mut cte_t,
buffer: &seL4_IPCBuffer,
) -> exception_t {
if msg_length < 4
#[cfg(not(feature = "KERNEL_MCS"))]
let TCBCONFIGURE_ARGS = 3;
#[cfg(feature = "KERNEL_MCS")]
let TCBCONFIGURE_ARGS = 4;
if msg_length < TCBCONFIGURE_ARGS
|| get_extra_cap_by_index(0).is_none()
|| get_extra_cap_by_index(1).is_none()
|| get_extra_cap_by_index(2).is_none()
Expand All @@ -261,11 +265,22 @@ fn decode_tcb_configure(
}
return exception_t::EXCEPTION_SYSCALL_ERROR;
}

#[cfg(not(feature = "KERNEL_MCS"))]
let fault_ep = get_syscall_arg(0, buffer);
#[cfg(not(feature = "KERNEL_MCS"))]
let croot_data = get_syscall_arg(1, buffer);
#[cfg(not(feature = "KERNEL_MCS"))]
let vroot_data = get_syscall_arg(2, buffer);
#[cfg(not(feature = "KERNEL_MCS"))]
let new_buffer_addr = get_syscall_arg(3, buffer);

#[cfg(feature = "KERNEL_MCS")]
let croot_data = get_syscall_arg(0, buffer);
#[cfg(feature = "KERNEL_MCS")]
let vroot_data = get_syscall_arg(1, buffer);
#[cfg(feature = "KERNEL_MCS")]
let new_buffer_addr = get_syscall_arg(2, buffer);

let croot_slot = get_extra_cap_by_index(0).unwrap();
let mut croot_cap = &croot_slot.clone().capability;
let vroot_slot = get_extra_cap_by_index(1).unwrap();
Expand Down
5 changes: 3 additions & 2 deletions kernel/src/syscall/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use sel4_common::arch::ArchReg;
use sel4_common::arch::ArchReg::*;
#[cfg(not(feature = "KERNEL_MCS"))]
use sel4_common::sel4_config::tcbCaller;
#[cfg(feature = "KERNEL_MCS")]
use sel4_task::sched_context::sched_context_t;

pub const SysCall: isize = -1;
Expand Down Expand Up @@ -71,9 +72,9 @@ use sel4_common::structures_gen::{
use sel4_common::utils::{convert_to_mut_type_ref, ptr_to_mut};
use sel4_ipc::{endpoint_func, notification_func, Transfer};
#[cfg(feature = "KERNEL_MCS")]
use sel4_task::mcs_preemption_point;
use sel4_task::{mcs_preemption_point, chargeBudget, ksConsumed, ksCurSC};
use sel4_task::{
activateThread, chargeBudget, get_currenct_thread, ksConsumed, ksCurSC, rescheduleRequired,
activateThread, get_currenct_thread, rescheduleRequired,
schedule, set_thread_state, tcb_t, ThreadState,
};
pub use utils::*;
Expand Down
11 changes: 10 additions & 1 deletion sel4_ipc/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::transfer::Transfer;
use sel4_common::arch::ArchReg;
use sel4_common::structures_gen::endpoint;
use sel4_common::utils::{convert_to_mut_type_ref, convert_to_option_mut_type_ref};
#[cfg(feature = "KERNEL_MCS")]
use sel4_task::reply::reply_t;
use sel4_task::{
possible_switch_to, rescheduleRequired, schedule_tcb, set_thread_state, tcb_queue_t, tcb_t,
ThreadState,
Expand Down Expand Up @@ -98,6 +100,13 @@ impl endpoint_func for endpoint {
if queue.head == 0 {
self.set_state(EPState::Idle as u64);
}
#[cfg(feature = "KERNEL_MCS")]
{
let reply = convert_to_mut_type_ref::<reply_t>(tcb.tcbState.get_replyObject() as usize);
if reply.get_ptr() != 0 {
reply.unlink(tcb);
}
}
set_thread_state(tcb, ThreadState::ThreadStateInactive);
}

Expand Down Expand Up @@ -378,7 +387,7 @@ impl endpoint_func for endpoint {
use core::intrinsics::unlikely;
use log::debug;
use sel4_common::structures_gen::{cap_tag::cap_reply_cap, notification_t, seL4_Fault_tag};
use sel4_task::{ksCurSC, reply::reply_t, sched_context::sched_context_t};
use sel4_task::{ksCurSC, sched_context::sched_context_t};

use crate::notification_func;

Expand Down
7 changes: 7 additions & 0 deletions sel4_ipc/src/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use sel4_common::utils::*;
use sel4_cspace::interface::*;
#[cfg(feature = "KERNEL_MCS")]
use sel4_task::reply::reply_t;
#[cfg(feature = "KERNEL_MCS")]
use sel4_task::reply_remove_tcb;
use sel4_task::{possible_switch_to, set_thread_state, tcb_t, ThreadState};
use sel4_vspace::pptr_t;

Expand Down Expand Up @@ -73,6 +75,10 @@ pub trait Transfer {
impl Transfer for tcb_t {
fn cancel_ipc(&mut self) {
let state = &self.tcbState;
#[cfg(feature = "KERNEL_MCS")]
{
seL4_Fault_NullFault::new();
}
match self.get_state() {
ThreadState::ThreadStateBlockedOnSend | ThreadState::ThreadStateBlockedOnReceive => {
let ep = convert_to_mut_type_ref::<endpoint>(state.get_blockingObject() as usize);
Expand All @@ -89,6 +95,7 @@ impl Transfer for tcb_t {
#[cfg(feature = "KERNEL_MCS")]
{
//TODO
reply_remove_tcb(self);
}
#[cfg(not(feature = "KERNEL_MCS"))]
{
Expand Down
1 change: 1 addition & 0 deletions sel4_task/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ pub fn activateThread() {
ThreadState::ThreadStateRestart => {
let pc = thread.tcbArch.get_register(ArchReg::FaultIP);
// setNextPC(thread, pc);
// sel4_common::println!("restart pc is {:x}",pc);
thread.tcbArch.set_register(ArchReg::NextIP, pc);
// setThreadState(thread, ThreadStateRunning);
set_thread_state(thread, ThreadState::ThreadStateRunning);
Expand Down

0 comments on commit 51e6f01

Please sign in to comment.