Re: Re: kernel stack vs. user stack

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

 



Hello...

> Could you explain me, what exactly a stack segment is? Is it a memory
> range, where the stack data (I mean, something, that I push on the
> stack) is saved?

yes...a memory range (segment) where stack lives. user stack lives on 
virtual address less than PAGE_OFFSET, whereas kernel stack can be 
anywhere on virtual address equal or greater than PAGE_OFFSET. 
PAGE_OFFSET is a virtual address which split address space into user 
and kernel space. for the exact virtual address of user space stack, 
try to dump a task struct of a process and look at the 
task_struct->mm>start_stack, or simply use "pmap" utility to list VMAs 
of a process

Perhaps you can re-read any books about general programming. There you 
will find out that stack contains local variable of a function (which 
is currently running, of course), return address when a function finish 
and so on. Of course, if you push something explicitly e.g via "push" 
assembly operation, it will be saved to the stack too. I forget the 
exact contents, but I hope you got a picture.

As Jan Hudec previously said, remember that kernel stack is only 8kb 
(IIRC now it is 4k, depends on kernel config). That means two things:
1. don't declare too many local variables on function, e.g very long 
array
2. don't do function call to deep....so something like recursion must be 
done carefully

If you do something that overflow kernel stack, anything can happen. I 
can only imagine that it can cause memory corruption

regards

Mulyadi



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           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