Question d’entretien chez Qualcomm

How does OS detects stack overflow

Réponse à la question d'entretien

Utilisateur anonyme

8 déc. 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.