From e1a92e929c95dce4a89f39a35859a09f605d7ed8 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Sat, 4 Jul 2020 11:58:18 +0800 Subject: [PATCH] kernel: replace more `unimplemented!()` with UnhandledSyscall This should prevent pacnics when calling unhandled functions. Signed-off-by: Sean Cross --- kernel/src/arch/hosted/irq.rs | 4 ++-- kernel/src/arch/hosted/process.rs | 37 ------------------------------- kernel/src/arch/riscv/irq.rs | 3 ++- kernel/src/irq.rs | 4 ++-- kernel/src/server.rs | 5 ++++- kernel/src/services.rs | 11 ++++----- 6 files changed, 16 insertions(+), 48 deletions(-) diff --git a/kernel/src/arch/hosted/irq.rs b/kernel/src/arch/hosted/irq.rs index 59a1dd6b4..8f797d588 100644 --- a/kernel/src/arch/hosted/irq.rs +++ b/kernel/src/arch/hosted/irq.rs @@ -12,8 +12,8 @@ pub fn enable_irq(_irq_no: usize) { unimplemented!(); } -pub fn disable_irq(_irq_no: usize) { - unimplemented!(); +pub fn disable_irq(_irq_no: usize) -> Result<(), xous::Error> { + Err(xous::Error::UnhandledSyscall) } pub unsafe fn take_isr_return_pair() -> Option<(PID, CtxID)> { diff --git a/kernel/src/arch/hosted/process.rs b/kernel/src/arch/hosted/process.rs index 057303c18..72c42c919 100644 --- a/kernel/src/arch/hosted/process.rs +++ b/kernel/src/arch/hosted/process.rs @@ -167,7 +167,6 @@ impl Process { } pub fn destroy(pid: PID) -> Result<(), xous::Error> { - println!("KERNEL: Destroying PID {}", pid); PROCESS_TABLE.with(|pt| { let mut process_table = pt.borrow_mut(); let pid_idx = pid.get() as usize - 1; @@ -191,39 +190,3 @@ impl Process { } impl Context {} - -// pub struct ProcessHandle { -// inner: RefCell, -// } - -// /// Wraps the MemoryManager in a safe mutex. Because of this, accesses -// /// to the Memory Manager should only be made during interrupt contexts. -// impl ProcessHandle { -// /// Get the singleton Process. -// pub fn get() -> ProcessHandle { -// ProcessHandle { -// inner: *PROCESS_TABLE.with(|pt| pt.clone()), -// } -// } -// } - -// // impl<'a> Drop for ProcessHandle<'a> { -// // fn drop(&mut self) { -// // println!("<<< Dropping ProcessHandle"); -// // } -// // } - -// use core::ops::{Deref, DerefMut}; -// impl Deref for ProcessHandle { -// type Target = Process; -// fn deref(&self) -> &Process { -// &self.inner.table[self.inner.current] -// } -// } - -// impl DerefMut for ProcessHandle { -// fn deref_mut(&mut self) -> &mut Process { -// let current = self.inner.current; -// &mut self.inner.table[current] -// } -// } diff --git a/kernel/src/arch/riscv/irq.rs b/kernel/src/arch/riscv/irq.rs index 89712208c..85b348f07 100644 --- a/kernel/src/arch/riscv/irq.rs +++ b/kernel/src/arch/riscv/irq.rs @@ -30,8 +30,9 @@ pub fn enable_irq(irq_no: usize) { sim::write(sim::read() | (1 << irq_no)); } -pub fn disable_irq(irq_no: usize) { +pub fn disable_irq(irq_no: usize) -> Result<(), xous::Error> { sim::write(sim::read() & !(1 << irq_no)); + Ok(()) } static mut PREVIOUS_PAIR: Option<(PID, CtxID)> = None; diff --git a/kernel/src/irq.rs b/kernel/src/irq.rs index 72a23a5e4..5825fd2f6 100644 --- a/kernel/src/irq.rs +++ b/kernel/src/irq.rs @@ -4,6 +4,7 @@ use xous::{MemoryAddress, PID}; static mut IRQ_HANDLERS: [Option<(PID, MemoryAddress, Option)>; 32] = [None; 32]; +#[allow(dead_code)] pub fn handle(irqs_pending: usize) -> Result { // Unsafe is required here because we're accessing a static // mutable value, and it could be modified from various threads. @@ -32,8 +33,7 @@ pub fn handle(irqs_pending: usize) -> Result { // If there is no handler, mask this interrupt // to prevent an IRQ storm. This is considered // an error. - // println!("Shutting it up"); - arch::irq::disable_irq(irq_no); + arch::irq::disable_irq(irq_no)?; } } } diff --git a/kernel/src/server.rs b/kernel/src/server.rs index ad6ccc379..d133c6170 100644 --- a/kernel/src/server.rs +++ b/kernel/src/server.rs @@ -222,7 +222,10 @@ impl Server { } } } - x => (), + // For "Scalar" and "Move" messages, this memory has already + // been moved into this process, so memory will be reclaimed + // when the process terminates. + _ => (), } } } diff --git a/kernel/src/services.rs b/kernel/src/services.rs index aaef4390e..ed1e0cdaa 100644 --- a/kernel/src/services.rs +++ b/kernel/src/services.rs @@ -361,6 +361,7 @@ impl SystemServices { /// 1. Pause the current process and switch to the new one /// 2. Save the process state, if it hasn't already been saved /// 3. Run the new process, returning to an illegal instruction + #[allow(dead_code)] pub fn finish_callback_and_resume( &mut self, pid: PID, @@ -412,12 +413,12 @@ impl SystemServices { /// 3. Run the new process, returning to an illegal instruction pub fn make_callback_to( &mut self, - pid: PID, - pc: *const usize, - irq_no: usize, - arg: *mut usize, + _pid: PID, + _pc: *const usize, + _irq_no: usize, + _arg: *mut usize, ) -> Result<(), xous::Error> { - unimplemented!() + Err(xous::Error::UnhandledSyscall) // // Get the current process (which was just interrupted) and mark it as // // "ready to run". If this function is called when the current process // // isn't running, that means the system has gotten into an invalid