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

Ignore thumb bit when checking for repeated frames #50

Merged
merged 1 commit into from
Sep 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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