Skip to content

Handling Kernel Stack

eXpOS requires that when the OS enters an interrupt handler that runs in kernel mode, the interrupt handler must switch to a different stack so that the user program does not hack into kernel using the stack.

OS Kernel must maintain two stacks Kernel and User stack to isolate the kernel from the user stack. One page called the User Area is allocated for each process, and a part of the space in this page will be used for the kernel stack.

Whenever there is a transfer of program control from the user mode to kernel during the interrupts, the interrupt handler will change the stack to the kernel stack (SP register must point to the top of the kernel stack of the program). Before the machine returns back, SP must be restored.

Process Table lets you store the SP values of the two stacks.

The Kernel Stack is used for storing the context of the registers.

Why tho?

So that kernel can use those registers without user's data.

Kernel Stack Management