mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-22 17:36:25 +04:00
update ch4:add some exception support in trap_handler function, add two *_fault.rs apps
This commit is contained in:
parent
badc110584
commit
d99d4f754f
@ -48,7 +48,8 @@ pub fn trap_handler() -> ! {
|
||||
cx.sepc += 4;
|
||||
cx.x[10] = syscall(cx.x[17], [cx.x[10], cx.x[11], cx.x[12]]) as usize;
|
||||
}
|
||||
Trap::Exception(Exception::StoreFault) | Trap::Exception(Exception::StorePageFault) => {
|
||||
Trap::Exception(Exception::StoreFault) | Trap::Exception(Exception::StorePageFault) |
|
||||
Trap::Exception(Exception::LoadFault) | Trap::Exception(Exception::LoadPageFault) => {
|
||||
println!("[kernel] PageFault in application, bad addr = {:#x}, bad instruction = {:#x}, kernel killed it.", stval, cx.sepc);
|
||||
exit_current_and_run_next();
|
||||
}
|
||||
|
18
user/src/bin/04load_fault.rs
Normal file
18
user/src/bin/04load_fault.rs
Normal file
@ -0,0 +1,18 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use core::ptr::{read_volatile,null_mut};
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
println!("\nload_fault APP running...\n");
|
||||
println!("Into Test load_fault, we will insert an invalid load operation...");
|
||||
println!("Kernel should kill this application!");
|
||||
unsafe {
|
||||
let _i=read_volatile(null_mut::<u8>());
|
||||
}
|
||||
0
|
||||
}
|
18
user/src/bin/05store_fault.rs
Normal file
18
user/src/bin/05store_fault.rs
Normal file
@ -0,0 +1,18 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use core::ptr::null_mut;
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
println!("\nstore_fault APP running...\n");
|
||||
println!("Into Test store_fault, we will insert an invalid store operation...");
|
||||
println!("Kernel should kill this application!");
|
||||
unsafe {
|
||||
null_mut::<u8>().write_volatile(1);
|
||||
}
|
||||
0
|
||||
}
|
Loading…
Reference in New Issue
Block a user