Embedded Stack Overflow Prevention via Pre-calculated Usage Limits
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Embedded systems face challenges in preventing stack overflow due to limited memory resources and dynamic changes in system components, where existing techniques either require offline analysis or incur run-time overhead.
Innovation Solution
A method that reads the maximum stack usage of functions from a kernel and selectively processes operations based on the available stack size, preventing additional interrupts or device driver calls when stack overflow is imminent, and dynamically allocates or loads threads and device drivers based on calculated stack requirements.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If static analysis technique is used to predict stack usage offline, then run-time overhead is eliminated, but the technique cannot be applied to systems with dynamically changed components
Solution Approach 1:
The patent pre-calculates and stores maximum stack usage values for all functions in a lookup table during system initialization or compilation. This preliminary action allows the system to quickly retrieve pre-computed stack requirements without performing complex analysis at runtime, enabling both efficient stack management and adaptability to dynamic component changes.
Solution Approach 2:
The patent implements dynamic stack usage tracking by maintaining a stack usage counter that is updated whenever functions are called or return. This dynamic approach allows the system to adapt to changing execution patterns and component states while still preventing stack overflow through real-time monitoring against pre-determined limits.
2Reliability
If run-time check technique is used to continuously check stack overflow, then stack overflow can be prevented in dynamic systems, but run-time overhead occurs
Solution Approach 1:
The patent performs stack usage analysis and determines maximum stack requirements during compilation or initialization, storing these values in advance. This preliminary computation eliminates the need for complex runtime analysis, reducing runtime overhead to simple counter updates and comparisons while maintaining reliable stack overflow prevention.
Solution Approach 2:
The patent uses a simple stack usage counter that can be quickly incremented and decremented, rather than maintaining complex data structures or performing expensive analysis at runtime. This lightweight approach provides continuous monitoring with minimal performance impact.
3Reliability
If predetermined stack allocation is used without dynamic adjustment, then stack overflow is prevented, but memory resources are not efficiently utilized
Solution Approach 1:
The patent implements dynamic stack allocation by adjusting the stack usage counter based on actual function calls and returns. The system allocates stack memory dynamically according to real-time needs while ensuring the total usage never exceeds pre-determined safe limits, thus preventing overflow while maximizing memory utilization efficiency.
Solution Approach 2:
The patent changes the stack allocation parameters dynamically by modifying the usable stack size based on current system state and pre-calculated requirements. This allows the system to adapt stack allocation to actual needs while maintaining safety margins, optimizing both reliability and resource efficiency.
Data Source
AI summary
Provided is a method and apparatus for preventing a stack overflow in an embedded system. The method of preventing a stack overflow includes: reading a maximum stack usage of at least one function for executing a requested operation from maximum stack usages of functions provided from a kernel, which are stored in advance; and processing the requested operation on the basis of the read maximum stack usage of the at least one function and a size of a usable region in a stack for the requested operation. Accordingly, the stack overflow can be prevented without generating a run-time overhead.


