-
-
Notifications
You must be signed in to change notification settings - Fork 75
Conversation
an unmangled symbol named on the other hand, another way to figure out the address of the reset handler is to read the second entry in the vector table. this document states:
thought I'm not sure that is specified in the Cortex-M ISA. I know STM32 devices use yet another way to get the address of the reset handler is to issue a reset-halt and read out the program counter (PC) register. I don't have a link to normative documentation but the Cortex-M ISA states that the program counter is set to the second entry of the vector table (the address of the reset handler) after a system reset. I think this runtime approach would be the sure way to get the address. after a reset-halt you could read the SP register and that would give you |
3a8229b
to
171bc07
Compare
Thank you for the answer @japaric. A few clarification questions:
🥂 |
I've switched to James proposal of ending the unwinding depending on the Atm I extract the stack start by reading the SP after a reset (as you've proposed). It seems to me that |
4fbec69
to
48c318a
Compare
I think it'd be good to check the stack pointer (SP) value against Thinking more about it, I think it may be better not to use
correct.
you should be able to iterate the symbol table to find the size (the API may be called (+) should look bit like $ # first column is start address; second is size; numbers are in hexadecimal format
$ arm-none-eabi-nm -CSn some-elf
(..)
00000100 00000028 T Reset
(..)
0000013c 0000000a T main
00000148 00000028 t hello::__cortex_m_rt_main
00000170 0000000a T app::exit you asked earlier:
you can pretty much always clear the thumb bit (bit 0) when comparing addresses. the start address of a function (as seen in the values that eventually end up in an instructions like |
@japaric said:
What then? That unwinding ends in the reset handler? This is what I implemented in 9f40539. If this is what you mean we would have:
Correct? @japaric said:
Didn't you say earlier that we cannot rely on the symbol table? I talking about following quote. @japaric said:
Or am I misunderstanding something? Can we figure out the mangled name of the symbol? |
@japaric The PR is ready for review again. I think it makes the code oven messier than it already is, and I am working on a follow-up PR to clean things up. But I wouldn't do this in here. |
elf: &Elf, | ||
) -> anyhow::Result<(u32, Range<u32>)> { | ||
let mut core = sess.core(0)?; | ||
core.reset_and_halt(Duration::from_secs(5))?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it necessary to do a reset halt here? there's another call to reset_and_halt in main.rs
due to Canary::install
so this may result in the device being reset twice, which should not be a problem to the operation of probe-run but it's preferable to not do double work.
perhaps the reset_and_halt can be do once before calling this function, then it can also be removed from canary::install
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will address this in the follow-up clean-up PR, since I will change the order of operations there and also touch the canary
bors r=japaric |
Build succeeded:
|
385: Update snapshot tests and test stack canary r=Urhengulas a=Urhengulas This PR does two things: 1. It updates the test_elfs and the respective output. 2. It adds a new test_elf `overflow-no-flip-link` which triggers a stack overflow and does not have stack-overflow protection; therefore `probe-run` reports that data segments might be corrupted Depends on #383; only the last two commits are specific to this PR. Fixes #223. Co-authored-by: Urhengulas <[email protected]>
This PR "fixes" unwinding, by not relying on the sentinel stack frame anymore, but instead checking if unwinding ends in the
Reset
function. If unwinding ends in theReset
function, it is considered NOT corrupted; if it ends somewhere else, it is considered corrupted.Fixes #382
Todo:
Is the-> No, "an unmangled symbol namedReset
symbol always present?Reset
is even less common than main"Does any thumb bit need to be cleared?-> noTest it with an corrupted stack-> not trivially possible from Rust