mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-22 01:16:26 +04:00
cargo fmt
This commit is contained in:
parent
243b07f749
commit
7183091ac9
@ -4,8 +4,8 @@
|
||||
#[macro_use]
|
||||
extern crate user_lib;
|
||||
|
||||
use user_lib::sbrk;
|
||||
use core::ptr::slice_from_raw_parts_mut;
|
||||
use user_lib::sbrk;
|
||||
|
||||
#[no_mangle]
|
||||
fn main() -> i32 {
|
||||
@ -15,12 +15,14 @@ fn main() -> i32 {
|
||||
println!("origin break point = {:x}", origin_brk);
|
||||
let brk = sbrk(PAGE_SIZE as i32);
|
||||
if brk != origin_brk {
|
||||
return -1
|
||||
return -1;
|
||||
}
|
||||
let brk = sbrk(0);
|
||||
println!("one page allocated, break point = {:x}", brk);
|
||||
println!("try write to allocated page");
|
||||
let new_page = unsafe { &mut *slice_from_raw_parts_mut(origin_brk as usize as *const u8 as *mut u8, PAGE_SIZE) };
|
||||
let new_page = unsafe {
|
||||
&mut *slice_from_raw_parts_mut(origin_brk as usize as *const u8 as *mut u8, PAGE_SIZE)
|
||||
};
|
||||
for pos in 0..PAGE_SIZE {
|
||||
new_page[pos] = 1;
|
||||
}
|
||||
@ -35,7 +37,7 @@ fn main() -> i32 {
|
||||
let ret = sbrk(PAGE_SIZE as i32 * -1);
|
||||
if ret != -1 {
|
||||
println!("Test sbrk failed!");
|
||||
return -1
|
||||
return -1;
|
||||
}
|
||||
println!("Test sbrk almost OK!");
|
||||
println!("now write to deallocated page, should cause page fault.");
|
||||
|
@ -38,4 +38,4 @@ pub fn sys_get_time() -> isize {
|
||||
|
||||
pub fn sys_sbrk(size: i32) -> isize {
|
||||
syscall(SYSCALL_SBRK, [size as usize, 0, 0])
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user