Qualcomm Interview Question

How does OS detects stack overflow

Interview Answer

Anonymous

Dec 8, 2020

There are multiple ways of detecting stack overflow. Modern processors have a special register known as stack_limit_register. Whenever the SP value goes higher (or lower) it causes an exception. You can do it using software techniques as well by writing a predefined value to the top (or bottom) of the stack and then comparing the value on every context switch. Thus, it is important to initialise new variables inside a function to zero so that the predefined value gets overwritten.