Re: Why two stacks per process?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Thu, Apr 24, 2008 at 2:41 PM, sahlot arvind <asahlot@xxxxxxxxx> wrote:
Why do we have two stacks per process i.e. one user mode and other kernel mode?
As soon as process enters into kernel mode it starts using kernel mode stack, but as soon as it comes out of kernel mode stack there is nothing in the kernel mode stack. So cannot we simply have a single stack i.e. just user mode stack which can also be used for kernel mode execution of process after all there wont be any data related to kernel (all would have been popped off) in the stack when we are back in user mode?
 
If you say that its just the stack pointer which is adjusted during pushes and pops and the stack content remains intact and user can try to increment/decrement stack pointer in order to access kernel data (which is stale however) then instead of having two stacks (kernel and user) cannot we simply zero out the stack area used by kernel before returing to user mode? and can we save memory by having just one stack?
 
Best regards
- A
http://linuxexplained.blogspot.com


AFAIK there is only one kernel stack and all the processes share that space. Each user process has its own stack. Whenever a user process has to do some system level processing, it makes a system call which through soft interrupt, makes the kernel to run that process. This is called user process in kernel mode. In this case since existing kernel thread only runs user driven system call, kernel stack don't change. it just loads and unloads the process specific data.

We cannot use single stack because memory is accessed in a different way in user mode and in kernel mode. And in some systems, even the memory area is different for kernel and user processes.

--
Dinesh Bansal
The Law of Win says, "Let's not do it your way or my way; let's do it the best way."

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux