Re: Process adress space (during context/process switch) + VM question

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

 



On 8/14/05, Tom Davis <kernel.nb@xxxxxxxxx> wrote:

> I am not clear "where" this stack area is being created. Is the stack
> area of the thread (child thread) created WITHIN the stack area of the
> parent thread/process with that space allocated just for the childs
> usage?

The child-stack will be stored within the parent process' virtual
memory. If you read the man pages for copy_thread, the arguments
ustack-size and ustack-base decide the location and size of the child
process' stack. Here is what a thread creation looks like (approx.):

1) clone() syscall is called in response to thread creation.
2) process-A goes into kernel mode. The pt-regs structure is used to
store all the process related registers. Then, in its kernel stack,
process-A creates a switch-stack structure with the preserved
registers of the process-A (you may need to read up more about scratch
and preserved registers, but for now, assume that they both together
represent the user-level state of the process).
3) Creation of the task_struct for the child thread.
4) copy_thread() called and the child's stack is defined and located
in the process-A's user space. This copies over the pt-regs and
switch-stack structures to the child so that it may return() at the
same location the clone() was called from the parent.

After step 4, the child runs under the syscall return_from_clone() and:

1) calls schedule_tail() to tell scheduler of its existance
2) sets the return value = 0 (remember, child returns 0 to parent?)
3) returns from system call 

After step 4, the parent:

1) finishes task initialization and enters the child in runqueue
2) sets return value of the clone() syscall to the task-ID of the
child (remember, child returns its task-ID to the parent)
3) clear the switch-stack structure from the kernel space of process-A
4) return from syscall

 
> So all the kernel variables "Stay" in the kernel stack all the time
> and so do their mappings into virtual memory?

AFAIK, the process related kernel variables are overwritten at every
context switch. Please CMIIW.

./h
-- 
Operating Systems and Computer Architecture Research  - University of Cincinnati
http://www.ececs.uc.edu/~mohapth

--
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