linux-mips
[Top] [All Lists]

parent and child processes share the same stack.

To: <linux-mips@oss.sgi.com>
Subject: parent and child processes share the same stack.
From: "Steven Liu" <stevenliu@psdc.com>
Date: Tue, 6 Nov 2001 17:27:08 -0800
Cc: "Steven Liu" <stevenliu@psdc.com>
Sender: owner-linux-mips@oss.sgi.com
Thread-index: AcFnK1Av0WRceLoAQpK3YiWILOm51A==
Thread-topic: parent and child processes share the same stack.
Hi All:

I am porting Linux to my r3000 cpu now and meet with a problem when the
init program is running. 

When the init process (pid=1) forks the first child (pid=7), the parent
process called copy_thread( ) which did the following assignment:
childregs->regs[29] = usp ( Here, usp is the parent's stack pointer)
(see arch/mips/kerenel/process.c).  So, the child and the parent share
the same stack.

After the fork, the parent called write_utmp_wtmp( ) which then called
memset(&utmp,0,sizeof(utmp)) and erased the stack. As we know, this
stack is shared by the parent and the child, the child will die when the
child is scheduled to run because the contents of the stack are all
zeros.

I think the stack should not be shared by the parent and the child after
anyone tries to modify the stack, that is, the child and parent should
have separete stacks. I searched the code and could not find the place
where the separation is given. 

Any help would be greatly appreciated.

Thanks,

Steven Liu

<Prev in Thread] Current Thread [Next in Thread>
  • parent and child processes share the same stack., Steven Liu <=