Chapter2: Clear .bss inside application.

This commit is contained in:
Yifan Wu 2020-11-22 13:05:16 +08:00
parent 5e5ed05399
commit f53f5e4b98
3 changed files with 13 additions and 1 deletions

View File

@ -7,7 +7,7 @@ extern crate user_lib;
#[no_mangle]
fn main() -> i32 {
println!("Into Test store_fault, we will insert an invalid store behavior...");
println!("Into Test store_fault, we will insert an invalid store operation...");
println!("Kernel should kill this application!");
unsafe { (0x0 as *mut u8).write_volatile(0); }
0

View File

@ -11,6 +11,7 @@ mod lang_items;
#[no_mangle]
#[link_section = ".text.entry"]
pub extern "C" fn _start() -> ! {
clear_bss();
syscall::sys_exit(main());
panic!("unreachable after sys_exit!");
}
@ -21,3 +22,12 @@ fn main() -> i32 {
panic!("Cannot find main!");
}
fn clear_bss() {
extern "C" {
fn start_bss();
fn end_bss();
}
(start_bss as usize..end_bss as usize).for_each(|addr| {
unsafe { (addr as *mut u8).write_volatile(0); }
});
}

View File

@ -17,7 +17,9 @@ SECTIONS
*(.data .data.*)
}
.bss : {
start_bss = .;
*(.bss .bss.*)
end_bss = .;
}
/DISCARD/ : {
*(.eh_frame)