Part 1 of 7 · 1 min read
Why this page comes third
In this module you will
- Describe a stack frame and say what it holds.
- Explain how the stack of a process grows, and where its limit is set.
- Estimate how deep a recursion can go for a given frame size and stack limit.
- Explain guard pages, and why thread stacks have them.
- Say what a stack canary does, and what a plain run does without it.
Page 1 covered the heap, where memory is requested by size and freed by the program. The stack is the other half of the usual process picture (page 1 of Level 6): memory that is claimed and released automatically as functions are called and return. It is fast and simple, and its fixed limit is the cause of one famous crash. This page also keeps a promise of Level 6, the guard page that stops a stack that grows too far. Page 4 then moves to files mapped into memory. The sources are OSTEP chapter 14, TLPI chapters 6 and 29, and OSC chapter 9. The test programs were compiled with gcc -O0 -Wall -Wextra and run on a Linux machine with an 8 MiB stack limit.
About this example About this example
Real: The C programs, commands and outputs on this page were compiled with gcc -Wall -Wextra -pthread and run on a Linux test machine (2 processors, kernel 6.18, glibc 2.39).
Scripted: The worked traces use small numbers chosen so they can be followed by hand.
Not real: The page simplifies real systems. Actual kernels add more cases, limits and tuning than a short page can show.