add cargo fmt in Makefile, and exec make fmt

This commit is contained in:
Yu Chen 2022-05-20 08:55:07 +08:00
parent e87bb122a8
commit ab99bc8c28
10 changed files with 36 additions and 40 deletions

View file

@ -6,3 +6,5 @@ docker:
build_docker:
docker build -t ${DOCKER_NAME} .
fmt:
cd os ; cargo fmt; cd ../user; cargo fmt; cd ..

View file

@ -1,2 +1 @@
pub const CLOCK_FREQ: usize = 403000000 / 62;

View file

@ -27,7 +27,7 @@ extern "C" {
}
lazy_static! {
/// a memory set instance through lazy_static! managing kernel space
/// a memory set instance through lazy_static! managing kernel space
pub static ref KERNEL_SPACE: Arc<UPSafeCell<MemorySet>> =
Arc::new(unsafe { UPSafeCell::new(MemorySet::new_kernel()) });
}
@ -324,26 +324,20 @@ pub fn remap_test() {
let mid_text: VirtAddr = ((stext as usize + etext as usize) / 2).into();
let mid_rodata: VirtAddr = ((srodata as usize + erodata as usize) / 2).into();
let mid_data: VirtAddr = ((sdata as usize + edata as usize) / 2).into();
assert!(
!kernel_space
.page_table
.translate(mid_text.floor())
.unwrap()
.writable(),
);
assert!(
!kernel_space
.page_table
.translate(mid_rodata.floor())
.unwrap()
.writable(),
);
assert!(
!kernel_space
.page_table
.translate(mid_data.floor())
.unwrap()
.executable(),
);
assert!(!kernel_space
.page_table
.translate(mid_text.floor())
.unwrap()
.writable(),);
assert!(!kernel_space
.page_table
.translate(mid_rodata.floor())
.unwrap()
.writable(),);
assert!(!kernel_space
.page_table
.translate(mid_data.floor())
.unwrap()
.executable(),);
println!("remap_test passed!");
}

View file

@ -6,7 +6,6 @@
//!
//! Every task or process has a memory_set to control its virtual memory.
mod address;
mod frame_allocator;
mod heap_allocator;

View file

@ -37,10 +37,10 @@ impl TrapContext {
let mut cx = Self {
x: [0; 32],
sstatus,
sepc: entry, // entry point of app
kernel_satp, // addr of page table
kernel_sp, // kernel stack
trap_handler,// addr of trap_handler function
sepc: entry, // entry point of app
kernel_satp, // addr of page table
kernel_sp, // kernel stack
trap_handler, // addr of trap_handler function
};
cx.set_sp(sp); // app's user stack pointer
cx // return initial Trap Context of app

View file

@ -64,8 +64,10 @@ 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::LoadFault) | Trap::Exception(Exception::LoadPageFault) => {
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();
}

View file

@ -4,7 +4,7 @@
#[macro_use]
extern crate user_lib;
use core::ptr::{read_volatile,null_mut};
use core::ptr::{null_mut, read_volatile};
#[no_mangle]
fn main() -> i32 {
@ -12,7 +12,7 @@ fn main() -> i32 {
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>());
let _i = read_volatile(null_mut::<u8>());
}
0
}

View file

@ -12,7 +12,7 @@ fn main() -> i32 {
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);
null_mut::<u8>().write_volatile(1);
}
0
}