mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-10 08:15:36 +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
|
// board initialization
|
||||||
dk::init().unwrap();
|
dk::init().unwrap();
|
||||||
|
|
||||||
log::info!("fib(100) = {:?}", fib(100));
|
log::info!("provoking stack overflow...");
|
||||||
|
spam();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
asm::bkpt();
|
asm::bkpt();
|
||||||
|
@ -18,13 +19,12 @@ fn main() -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn fib(n: u32) -> u32 {
|
fn spam() {
|
||||||
// allocate and initialize one kilobyte of stack memory to provoke stack overflow
|
// allocate and initialize one kilobyte of stack memory to provoke stack overflow quicker
|
||||||
let _use_stack = [0xAA; 1024];
|
let use_stack = [0xAA; 1024];
|
||||||
|
let addr = &use_stack as *const i32;
|
||||||
|
|
||||||
if n < 2 {
|
log::info!("address of current `use_stack`: {:?}", addr);
|
||||||
1
|
|
||||||
} else {
|
spam(); // infinite recursion
|
||||||
fib(n - 1) + fib(n - 2) // recursion
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue