Stack overflow prevention (STOP) technology
SEGGER's cutting-edge technology to reliably prevent stack overflows.
Overview
SEGGER’s Stack Overflow Prevention (STOP) technology is designed to reliably prevent stack overflows.
It is a compiler option for the Clang-based, highly optimizing SEGGER Compiler and can be easily enabled in any application, without any change to application code.
The Stack Overflow Prevention technology can be evaluated in the demonstration project provided in the Embedded Studio simulator.
More technical details, source listing, and examples of how STOP works are available on our STOP wiki page.
Key features
- Prevents stack overflow
- Easily enabled in any application
- Can be used with any RTOS
- Very low impact on size and speed
System insight
With STOP, the compiler calls a stack limit-check routine wherever necessary, before adjusting the stack pointer. This way, all stack overflows are prevented. The protection also covers the standard C library. If a stack overflow has been prevented, the system can enter a safe state and recover.
STOP protects all stacks in the system, including the process stack as well as the "main" stack used for interrupts.It can be used with any RTOS, provided the RTOS updates the stack-limit variable on a context switch.
Detection and overflow
A stack overflow can cause all kinds of failures in an embedded system, from hard-to-detect, seemingly random miscomputations to severe malfunctions or even crashes.
To compute the required stack size at compile time is not possible for most systems, as function pointers make an analysis at compile or link time impossible. In addition, every program modification, compiler optimization or change of compiler can change the stack requirements, making run time stack checking a must.
Performance and resource usage
STOP has a very low impact on size and speed. It adds about 2 to 5 % to code size and execution time, which typically does not have a significant impact on the performance of the system.
Supported architecture
STOP is currently available for Thumb-2 architectures, such as Cortex-M4, Cortex-M7, Cortex-A9, and Cortex-A15.
On ARMv7M architectures, STOP is ready to use in Embedded Studio with a single project option switch.