kernel: add in_irq parameter to syscall::handle()

This parameter will determine whether a syscall is being handled from
within an interrupt context. This is because certain calls cannot be
called from such a context.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-11-01 16:27:39 +08:00
parent bb304d412a
commit 7ab2338ff3
3 changed files with 17 additions and 11 deletions

View file

@ -544,14 +544,14 @@ pub fn idle() -> bool {
"Unable to send response to process: {:?} -- terminating",
_e
);
crate::syscall::handle(pid, thread_id, SysCall::TerminateProcess).ok();
crate::syscall::handle(pid, thread_id, false, SysCall::TerminateProcess).ok();
});
// println!("KERNEL: Done sending");
}
// Handle the syscall within the Xous kernel
let response =
crate::syscall::handle(pid, thread_id, call).unwrap_or_else(Result::Error);
crate::syscall::handle(pid, thread_id, false, call).unwrap_or_else(Result::Error);
// println!("KERNEL({}): Syscall response {:?}", pid, response);
// There's a response if it wasn't a blocked process and we're not terminating.
@ -580,7 +580,7 @@ pub fn idle() -> bool {
"KERNEL({}): Unable to send response to process: {:?} -- terminating",
pid, _e
);
crate::syscall::handle(pid, thread_id, SysCall::TerminateProcess).ok();
crate::syscall::handle(pid, thread_id, false, SysCall::TerminateProcess).ok();
});
crate::arch::process::set_current_pid(existing_pid);
// SystemServices::with_mut(|ss| {

View file

@ -96,8 +96,8 @@ pub extern "C" fn trap_handler(
})
});
let response =
crate::syscall::handle(pid, tid, call).unwrap_or_else(|e| xous_kernel::Result::Error(e));
let response = crate::syscall::handle(pid, tid, unsafe { PREVIOUS_PAIR.is_some() }, call)
.unwrap_or_else(|e| xous_kernel::Result::Error(e));
// println!("Syscall Result: {:?}", response);
ArchProcess::with_current_mut(|p| {
@ -122,7 +122,10 @@ pub extern "C" fn trap_handler(
match ex {
RiscvException::StorePageFault(pc, addr) | RiscvException::LoadPageFault(pc, addr) => {
#[cfg(any(feature = "debug-print", feature = "print-panics"))]
println!("KERNEL({}): RISC-V fault: {} @ {:08x}, addr {:08x}", pid, ex, pc, addr);
println!(
"KERNEL({}): RISC-V fault: {} @ {:08x}, addr {:08x}",
pid, ex, pc, addr
);
let entry = crate::arch::mem::pagetable_entry(addr).unwrap_or_else(|x| {
// MemoryManagerHandle::get().print_ownership();
MemoryMapping::current().print_map();
@ -212,9 +215,6 @@ pub extern "C" fn trap_handler(
if PREVIOUS_PAIR.is_none() {
let tid = crate::arch::process::current_tid();
PREVIOUS_PAIR = Some((pid, tid));
// println!("ISR: Setting previous pair to ({}, {})", pid, tid);
// } else {
// println!("ISR: Previous pair is not None");
}
}
crate::irq::handle(irqs_pending).expect("Couldn't handle IRQ");

View file

@ -514,10 +514,16 @@ fn receive_message(pid: PID, tid: TID, sid: SID) -> SysCallResult {
})
}
pub fn handle(pid: PID, tid: TID, call: SysCall) -> SysCallResult {
pub fn handle(pid: PID, tid: TID, irq: bool, call: SysCall) -> SysCallResult {
#[cfg(feature = "debug-print")]
print!("KERNEL({}:{}): Syscall {:x?}", pid, tid, call);
let result = handle_inner(pid, tid, call);
let result = if irq && !call.can_call_from_interrupt() {
Err(xous_kernel::Error::InvalidSyscall)
} else {
handle_inner(pid, tid, call)
};
#[cfg(feature = "debug-print")]
println!(
" -> ({}:{}) {:?}",