Stack Overflow Detection Using Dedicated Registers
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing methods for detecting stack overflows are either costly in terms of execution time, require complex hardware, or fail to provide complete protection against overflow errors, especially in programming environments like ADA where stack sizing is challenging.
Innovation Solution
A method using dedicated registers to store and compare stack pointer values, generating an exception when the stack pointer exceeds or falls below permitted limits, implemented in both hardware and software to detect overflows promptly and assist in stack sizing.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If MMU is used to create guard space around stack memory, then stack overflow protection is provided, but hardware complexity and programming constraints increase
Solution Approach 1:
The patent introduces a dedicated stack pointer register that acts as an intermediary between the stack memory and the comparison logic. This register stores the current stack pointer value and automatically compares it with pre-defined minimum and maximum limits, providing overflow protection without requiring complex MMU hardware. The intermediary register simplifies the hardware architecture while maintaining reliable detection of stack boundary violations.
2Reliability
If stack overflow detection is performed after function prologue, then complete protection against overflow risks is achieved, but execution time increases
Solution Approach 1:
The patent implements continuous stack overflow detection by comparing the stack pointer value with predefined limits after every stack operation. Rather than performing detection only at specific checkpoints (such as after function prologue), the comparison mechanism operates continuously, ensuring that overflow conditions are detected immediately when they occur. This eliminates the need for costly periodic checks while maintaining complete protection coverage throughout program execution.
3Speed
If dedicated registers are used to store and compare stack pointer values, then detection speed increases, but device complexity increases
Solution Approach 1:
The patent designs the dedicated stack pointer register to serve multiple functions: it stores the current stack pointer value, enables comparison with minimum and maximum limits, and generates overflow detection signals. By making this register multi-functional, the patent achieves fast detection speed without proportionally increasing device complexity. The same hardware structure supports both normal stack operations and overflow detection, maximizing resource utilization while minimizing additional hardware requirements.
Data Source
AI summary
A method of detecting stack overflows includes the following steps: storing in at least one dedicated register at least one data item chosen from: a data item (SPHaut) indicating a maximum permitted value for a stack pointer, and a data item (SPBas) indicating a minimum permitted value for said stack pointer; effecting a comparison between a current value (SP) or past value (SPMin, SPMax) of said stack pointer and said data item or each of said data items; and generating a stack overflow exception if said comparison indicates that said current or past value of said stack pointer is greater than said maximum permitted value or less than said minimum permitted value. A processor for implementing such a method is also provided.


