Chapter2: Clear .bss inside application.
This commit is contained in:
parent
6671f99afb
commit
1414d05325
3 changed files with 13 additions and 1 deletions
|
@ -7,7 +7,7 @@ extern crate user_lib;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
fn main() -> i32 {
|
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!");
|
println!("Kernel should kill this application!");
|
||||||
unsafe { (0x0 as *mut u8).write_volatile(0); }
|
unsafe { (0x0 as *mut u8).write_volatile(0); }
|
||||||
0
|
0
|
||||||
|
|
|
@ -11,6 +11,7 @@ mod lang_items;
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[link_section = ".text.entry"]
|
#[link_section = ".text.entry"]
|
||||||
pub extern "C" fn _start() -> ! {
|
pub extern "C" fn _start() -> ! {
|
||||||
|
clear_bss();
|
||||||
syscall::sys_exit(main());
|
syscall::sys_exit(main());
|
||||||
panic!("unreachable after sys_exit!");
|
panic!("unreachable after sys_exit!");
|
||||||
}
|
}
|
||||||
|
@ -21,3 +22,12 @@ fn main() -> i32 {
|
||||||
panic!("Cannot find main!");
|
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); }
|
||||||
|
});
|
||||||
|
}
|
|
@ -17,7 +17,9 @@ SECTIONS
|
||||||
*(.data .data.*)
|
*(.data .data.*)
|
||||||
}
|
}
|
||||||
.bss : {
|
.bss : {
|
||||||
|
start_bss = .;
|
||||||
*(.bss .bss.*)
|
*(.bss .bss.*)
|
||||||
|
end_bss = .;
|
||||||
}
|
}
|
||||||
/DISCARD/ : {
|
/DISCARD/ : {
|
||||||
*(.eh_frame)
|
*(.eh_frame)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue