mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2025-01-19 05:27:13 +04:00
Chapter2: Clear .bss inside application.
This commit is contained in:
parent
5e5ed05399
commit
f53f5e4b98
@ -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
|
||||
|
@ -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); }
|
||||
});
|
||||
}
|
@ -17,7 +17,9 @@ SECTIONS
|
||||
*(.data .data.*)
|
||||
}
|
||||
.bss : {
|
||||
start_bss = .;
|
||||
*(.bss .bss.*)
|
||||
end_bss = .;
|
||||
}
|
||||
/DISCARD/ : {
|
||||
*(.eh_frame)
|
||||
|
Loading…
Reference in New Issue
Block a user