
Linux per thread kernel stack size code#
That said, interrupts that occur while executing kernel code will simply (continue to) use the kernel stack in place at that point. The CPU itself when dispatching an interrupt might execute a privilege and/or stack switch, and this is used/set up by the kernel so that the common interrupt entry code can already rely on a kernel stack being present. The kernel (Linux kernel, that is) does not hook ISRs directly to the x86 architecture's interrupt gates but instead delegates the interrupt dispatch to a common kernel interrupt entry/exit mechanism which saves pre-interrupt register state before calling the registered handler(s). If a local variable is declared in an ISR, where will it be stored ?.Different CPU architectures implement this in different ways x86 CPUs automatically switch stack pointers when privilege mode switches occur, and the values to be used for different privilege levels are configurable - by privileged code (i.e. The kernel therefore cannot trust the user space stack pointer to be valid nor usable, and therefore will require one set under its own control. For one, user space programs can make their stack (pointer) anything they want, and there is usually no architectural requirement to even have a valid one. Vice versa, without explicitly being requested by the kernel code (in Linux, through functions like copy_from_user()), user memory (including the user stack) is not usually directly accessible.

when executing in user mode, kernel memory (part of which is the kernel stack) will not be accessible even if mapped. In short, nothing - apart from using a different location in memory (and hence a different value for the stack pointer register), and usually different memory access protections.

What's the difference between kernel stack and user stack ?.
