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

Commit

Permalink
Stack end 4 bytes below initial SP, not 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Urhengulas committed Feb 23, 2022
1 parent 4331ea1 commit 67c1576
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/canary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ impl Canary {
}

let stack_start = *stack_info.range.start();
// add 1 to end up with the initial stack pointer, which is always 4-byte-aligned
let stack_end = *stack_info.range.end() + 1;
let stack_available = stack_end - stack_start;
let stack_available = *stack_info.range.end() - stack_start;

let size = if measure_stack {
// When measuring stack consumption, we have to color the whole stack.
Expand Down
4 changes: 2 additions & 2 deletions src/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ fn extract_stack_info(elf: &Elf, ram_range: &Range<u32>) -> Option<StackInfo> {

let initial_stack_pointer = elf.vector_table.initial_stack_pointer;

// SP points one past the end of the stack.
let mut stack_range = ram_range.start..=initial_stack_pointer - 1;
// SP points one word (4-byte) past the end of the stack.
let mut stack_range = ram_range.start..=initial_stack_pointer - 4;

for section in elf.sections() {
let size: u32 = section.size().try_into().expect("expected 32-bit ELF");
Expand Down

0 comments on commit 67c1576

Please sign in to comment.