bug fix: unknown syscall may happened. log: add some debug log

This commit is contained in:
DeathWish5 2022-05-18 17:02:42 +08:00
parent 19bc2b7991
commit c3ab0d38c4
9 changed files with 42 additions and 15 deletions

View File

@ -1,5 +1,5 @@
[alias]
xtask = "run --package xtask --"
xtask = "run --package xtask --release --"
git-proxy = "xtask git-proxy"
setup = "xtask setup"
update-all = "xtask update-all"

View File

@ -14,4 +14,4 @@ default-members = ["xtask"]
exclude = ["zircon-user", "rboot"]
[profile.release]
lto = true
lto = true

View File

@ -26,7 +26,12 @@ pub(super) fn super_soft() {
#[no_mangle]
pub extern "C" fn trap_handler(tf: &mut TrapFrame) {
let scause = scause::read();
trace!("trap happened: {:?}", TrapReason::from(scause));
debug!("kernel trap happened: {:?}", TrapReason::from(scause));
trace!(
"sepc = 0x{:x} pgtoken = 0x{:x}",
tf.sepc,
crate::vm::current_vmtoken()
);
match TrapReason::from(scause) {
TrapReason::SoftwareBreakpoint => breakpoint(&mut tf.sepc),
TrapReason::PageFault(vaddr, flags) => crate::KHANDLER.handle_page_fault(vaddr, flags),

View File

@ -117,7 +117,7 @@ impl TrapReason {
/// User context saved on trap.
#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct UserContext(UserContextInner);
pub struct UserContext(pub UserContextInner);
impl UserContext {
/// Create an empty user context.

View File

@ -94,19 +94,27 @@ impl Syscall<'_> {
return Err(PagingError::NoMemory);
}
Err(PagingError::AlreadyMapped) => {
panic!("get_vaddr_flags error!!!");
panic!("get_vaddr_flags error vaddr(0x{:x})", vaddr);
}
}
if is_handle_read_pagefault {
if let Err(err) = vmar.handle_page_fault(vaddr, MMUFlags::READ) {
panic!("into_out_userptr handle_page_fault: {:?}", err);
error!(
"into_out_userptr handle_page_fault: {:?} vaddr(0x{:x})",
err, vaddr
);
return Err(PagingError::NotMapped);
}
}
if is_handle_write_pagefault {
if let Err(err) = vmar.handle_page_fault(vaddr, MMUFlags::WRITE) {
panic!("into_out_userptr handle_page_fault: {:?}", err);
error!(
"into_out_userptr handle_page_fault: {:?} vaddr(0x{:x})",
err, vaddr
);
return Err(PagingError::NotMapped);
}
}
Ok(())

View File

@ -106,7 +106,7 @@ impl Syscall<'_> {
Err(_e) => return Err(LxError::EACCES),
}
};
warn!(
debug!(
"Futex uaddr: {:#x}, op: {:x}, val: {}, timeout_ptr: {:x?}, val2: {}",
uaddr,
op.bits(),

View File

@ -72,9 +72,7 @@ async fn run_user(thread: CurrentThread) {
// run
trace!("go to user: tid = {} ctx = {:#x?}", thread.id(), ctx);
kernel_hal::interrupt::intr_off(); // trapframe can't be interrupted
ctx.enter_uspace();
kernel_hal::interrupt::intr_on();
trace!("back from user: tid = {} ctx = {:#x?}", thread.id(), ctx);
// handle trap/interrupt/syscall
if let Err(err) = handle_user_trap(&thread, ctx).await {
@ -143,6 +141,16 @@ pub unsafe fn push_stack<T>(stack_top: usize, val: T) -> usize {
stack_top as usize
}
use kernel_hal::interrupt::{intr_off, intr_on};
macro_rules! run_with_irq_enable {
($($statements:stmt)*) => {
intr_on();
$($statements)*
intr_off();
};
}
async fn handle_user_trap(thread: &CurrentThread, mut ctx: Box<UserContext>) -> ZxResult {
let reason = ctx.trap_reason();
if let TrapReason::Syscall = reason {
@ -156,7 +164,10 @@ async fn handle_user_trap(thread: &CurrentThread, mut ctx: Box<UserContext>) ->
syscall_entry: kernel_hal::context::syscall_entry as usize,
};
trace!("Syscall : {} {:x?}", num as u32, args);
let ret = syscall.syscall(num as u32, args).await as usize;
run_with_irq_enable! {
let ret = syscall.syscall(num as u32, args).await as usize
}
kernel_hal::interrupt::intr_off();
thread.with_context(|ctx| ctx.set_field(UserContextField::ReturnValue, ret))?;
return Ok(());
}
@ -166,7 +177,9 @@ async fn handle_user_trap(thread: &CurrentThread, mut ctx: Box<UserContext>) ->
let pid = thread.proc().id();
match reason {
TrapReason::Interrupt(vector) => {
kernel_hal::interrupt::handle_irq(vector);
run_with_irq_enable! {
kernel_hal::interrupt::handle_irq(vector)
}
#[cfg(not(feature = "libos"))]
if vector == kernel_hal::context::TIMER_INTERRUPT_VEC {
kernel_hal::thread::yield_now().await;

View File

@ -3,8 +3,9 @@ set architecture riscv:rv64
target remote 127.0.0.1:15234
symbol-file ../target/riscv64/release/zcore
display/10i $pc
break *0x8020003a
# tbreak *(&jump_higher - 0xffffffff00000000)
tbreak *0x802623b4
c
si
si
si
si

View File

@ -10,7 +10,7 @@ fn panic(info: &PanicInfo) -> ! {
println!("\n\n{info}");
error!("\n\n{info}");
if cfg!(feature = "baremetal-test") {
if cfg!(any(feature = "baremetal-test", feature = "board-qemu")) {
kernel_hal::cpu::reset();
} else {
loop {