Search⌘ K
AI Features

Stack in Memory and Registers

Explore how the stack operates in memory and registers on ARM64 Linux platforms. Understand the function call mechanism, register roles like pc, sp, lr, and the use of branch instructions. Learn to analyze call stacks and stack overflow causes using GDB.

Register review

So far, we have seen and used general-purpose CPU registers:

  • x0/w0
  • x1/w1
  • x2/w2
  • x3/w3
  • x4/w4
  • x30/w30

We also have special purpose registers:

  • XZR/WZR (the zero register)
  • pc (the instruction pointer)
  • sp (the stack pointer)

Application memory simplified

When an executable file is loaded into memory, we observe the following:

  • Its header and sections are mapped to memory pages.
  • Some data and code are copied unmodified, but some data is initialized and expanded.
  • The first stack is also created at this stage.
  • A pc register is set to point to the first program instruction, and sp points to the top of the stack.

This simplified process is shown in the figure below:

...