operating-systems

Definition

Kernel Stack

The kernel stack (system stack) is a separate stack used by the OS when executing in kernel mode. Each process typically has its own kernel stack.

The kernel stack stores:

  • Parameters and return addresses for system calls
  • Saved hardware context (PC, PSW, registers) during interrupts or traps
  • Local variables for kernel-level routines

Separation from User Stack

Security

If the kernel used the user stack, a malicious process could modify return addresses or parameters during a system call.

Robustness

If a user process exhausts its stack (overflow), the kernel remains functional because its stack is separate and protected.

Context Switching

Role in Process Switch

During a process switch, the process state is pushed onto its kernel stack before being saved to the PCB for long-term storage.