lab-04: mmap, munmap

This commit is contained in:
Tateisi 2025-08-03 13:48:14 +08:00
parent eaacb4fa25
commit cc1a9a4751
14 changed files with 311 additions and 2 deletions

26
user/src/bin/ch4_mmap2.rs Normal file
View 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
}