mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-10 00:05:45 +00:00
provoke stack overflow more blatantly
This commit is contained in:
parent
fdc56a32e2
commit
4cdb377855
1 changed files with 9 additions and 9 deletions
|
@ -10,7 +10,8 @@ fn main() -> ! {
|
|||
// board initialization
|
||||
dk::init().unwrap();
|
||||
|
||||
log::info!("fib(100) = {:?}", fib(100));
|
||||
log::info!("provoking stack overflow...");
|
||||
spam();
|
||||
|
||||
loop {
|
||||
asm::bkpt();
|
||||
|
@ -18,13 +19,12 @@ fn main() -> ! {
|
|||
}
|
||||
|
||||
#[inline(never)]
|
||||
fn fib(n: u32) -> u32 {
|
||||
// allocate and initialize one kilobyte of stack memory to provoke stack overflow
|
||||
let _use_stack = [0xAA; 1024];
|
||||
fn spam() {
|
||||
// allocate and initialize one kilobyte of stack memory to provoke stack overflow quicker
|
||||
let use_stack = [0xAA; 1024];
|
||||
let addr = &use_stack as *const i32;
|
||||
|
||||
if n < 2 {
|
||||
1
|
||||
} else {
|
||||
fib(n - 1) + fib(n - 2) // recursion
|
||||
}
|
||||
log::info!("address of current `use_stack`: {:?}", addr);
|
||||
|
||||
spam(); // infinite recursion
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue