lab-04: mmap, munmap
This commit is contained in:
parent
eaacb4fa25
commit
cc1a9a4751
14 changed files with 311 additions and 2 deletions
26
user/src/bin/ch4_mmap2.rs
Normal file
26
user/src/bin/ch4_mmap2.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::mmap;
|
||||
|
||||
/*
|
||||
理想结果:程序触发访存异常,被杀死。不输出 error 就算过。
|
||||
*/
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
let start: usize = 0x10000000;
|
||||
let len: usize = 4096;
|
||||
let prot: usize = 2;
|
||||
assert_eq!(0, mmap(start, len, prot));
|
||||
let addr: *mut u8 = start as *mut u8;
|
||||
unsafe {
|
||||
// *addr = start as u8; // can't write, R == 0 && W == 1 is illegal in riscv
|
||||
assert!(*addr != 0);
|
||||
}
|
||||
println!("Should cause error, Test 04_2 fail!");
|
||||
0
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue