Skip to content

Process Memory Layout

A simple view looks like this (from top to bottom):

  1. Kernel Space (not directly accessible)

  2. Stack: At the top, you have the stack, which grows downwards↓.

  3. Heap: A region called the heap, used for dynamically allocated memory like malloc.
  4. .bss / .data: Here we have global variables and static data.
  5. .text: At the bottom, you have the program’s code section, where the machine instructions live.

We care most about the stack.

Whenever a function is called, some important things are placed on the stack:

  1. The return address – this is the address of the instruction where the program should continue after the function finishes.
  2. The saved base pointer (the saved RBP), which helps the function keep track of its local variables.
  3. The local variables themselves, like small arrays or integers.