[Solved] How is recursion call stack maintained in GCC? [closed]


Linux uses a “guard area”. It puts one or more access-protect pages at the end of the stack for each thread.

If the program accesses the guard area, the OS handles the fault. If the thread is already using its max permitted stack then it terminates something (the thread or the whole process, I don’t remember which). Otherwise it tries to map memory to the addresses occupied by the guard area for use as stack, and protects a new area beyond the end of the newly-enlarged stack.

Prompting the user isn’t really suitable for an OS like Linux, in which many processes are not monitored by a user, and for that matter there may not be any logged-in user at the time the problem arises. So your process just fails. Since it’s an all-purpose compiler, gcc doesn’t attempt runtime user interaction either.

Other OSes and platforms may or may not have stack guard pages (Windows does). About all gcc really needs to do is to ensure that if the stack is going to be exceeded, it doesn’t “miss” the guard page by jumping a long way forward.

solved How is recursion call stack maintained in GCC? [closed]