Re: Why two stacks per process?

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

 



Hi!

On 14:41 Thu 24 Apr     , sahlot arvind 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?

It is not just cleaning the stack up. You have to make sure that no other
thread in the userspace accesses it. This means you have to unmap it first.
Doing this on every syscall is probably more expensive than a 4kb page. Even
if it is not, you risk breaking some weird user-space programs which abuse
unused stack space (e.g. functions returning pointers to local variables...).
	-Michi
-- 
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.homelinux.net


--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[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