Following my question yesterday, I tried to learn a bit more about the architecture of call stacks. Online and SO searches have not yielded the answer I'm looking for, which could be because I don't know precisely which keywords to use. Anyway, I'm sure someone here can help me...
First, lets start with an excerpt from Wikipedia's entry for stack buffer overflow:
In software, a stack buffer overflow occurs when a program writes to a memory address on the program's call stack outside of the intended data structure; usually a fixed length buffer.
A colleague told me he remembered learning that, on Linux, the stack is at the very end of a process' virtual memory and grows backwards as needed -- hence it would not be a 'fixed length buffer'. However I have not been able to confirm that. So my questions are:
- On Windows and Linux is the call stack always a fixed size buffer? If not, how does it grow? How does it manage sharing the virtual memory with the heap?
- Does the architecture of the stack depends on the compiled language used? On the OS? On the hardware?
- Is the size of the stack determined at compile-time or can it be changed a posteriori?
- How and where are individual thread's call stacks allocated?