Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Ignore thumb bit when checking for repeated frames
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Schievink committed Sep 2, 2020
1 parent 4c7a543 commit caa697a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use structopt::StructOpt;

const TIMEOUT: Duration = Duration::from_secs(1);
const STACK_CANARY: u8 = 0xAA;
const THUMB_BIT: u32 = 1;

fn main() -> Result<(), anyhow::Error> {
notmain().map(|code| process::exit(code))
Expand Down Expand Up @@ -582,7 +583,10 @@ fn backtrace(
break;
}

if !cfa_changed && lr == pc {
// If the frame didn't move, and the program counter didn't change, bail out (otherwise we
// might print the same frame over and over).
// Since we strip the thumb bit from `pc`, ignore it in this comparison.
if !cfa_changed && lr & !THUMB_BIT == pc & !THUMB_BIT {
println!("error: the stack appears to be corrupted beyond this point");
return Ok(top_exception);
}
Expand Down Expand Up @@ -616,7 +620,7 @@ fn backtrace(
if lr & 1 == 0 {
bail!("bug? LR ({:#010x}) didn't have the Thumb bit set", lr)
}
pc = lr & !1;
pc = lr & !THUMB_BIT;
}

frame += 1;
Expand Down

0 comments on commit caa697a

Please sign in to comment.