-
-
Notifications
You must be signed in to change notification settings - Fork 75
Approximated stack overflow detection via stack canaries #31
Comments
I would be against this particular variant. Polling a second memory block can easily halve the throughput of the log stream data and probe-rs's RTT implementation is already rather slow.
I don't think there are strong guidelines but either a chunk of Related feature: optionally we can "paint" all the potential stack memory with a known pattern and once the program has finished we look for the "watermark" level and report the max stack usage for this particular program run. |
It seems that c-m-rt places the heap start symbol That means there's no section we can use to detect presence of a heap. Can we detect whether the symbol was referenced by looking for it in the ELF file or will it always be there? |
I guess for compatibility with other runtimes we could look for any symbol that points to the first address after |
Looks like |
While it is possible to link an embedded app in a way that will detect stack overflows immediately and (mostly) reliably, few people actually do this as it requires using a linker wrapper to link the app twice. cortex-m-rt also doesn't do it by default at the moment.
However, we can still do our best to help out when no built-in stack overflow protection is used: After uploading the program, but before starting it, we can fill the space in RAM right after the data used by ELF sections with a unique pattern. Then, after the program exits (or even while it still runs), we scan the filled area and look for bytes that were changed from our pattern. If we find any changed bytes, there is a high probability that the program has used too much stack and overwrote its own data sections.
There are a few things to keep in mind here:
The text was updated successfully, but these errors were encountered: