Dear Phil,
I take this simple example:
int main(void)
{
pid_t pid;
int status, wpid;
if ((pid = vfork()) == 0) {
execvp(argv[0], argv);
_exit(0);
}
return EXIT_SUCCESS;
}
| |
| |
| |
0x60 +-------------+
| |
| | vfork() frame
| |
0x100 +-------------+
| |
| | main() frame
| |
0x200 +-------------+
stack content before processes return vfork
| |
| |
| |
0x60 +-------------+
| |
| | vfork() frame
| |
0x100 +-------------+
| |
| | main() frame
| |
0x200 +-------------+
stack content after child return vfork
| |
| |
0x40 +-------------+
| |
| |
| | execvp() frame
| |
0x100 +-------------+
| |
| | main() frame
| |
0x200 +-------------+
stack content after child call execvp
I observe that after the child process call the execvp(), the vfork()
frame is corrupted.
After the parent process returns from the vfork() system call, the vfork()
frame is corrupted.
So, unexpected result will be occured.
Best regards,
Ahan Hsieh
Phil Wilshire <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
2007/06/06 下午 07:35
Please respond to
uClinux development list <[email protected]>
To
uClinux development list <[email protected]>
cc
Subject
Re: [uClinux-dev] how to implement vfork()
Hi Ahan,
Sorry to state the obvious but limit what you do in the child process
before calling execve.
You can run the same code as the parent using execve and identify it as
a child process by setting some options in its arg list.
You have control over both the arg list and the environment for the new
child process.
Take a look at some examples in
simpleinit and inetd
Regards
Phil Wilshire
Ahan Hsieh 謝武漢 wrote:
>
> Hi folk,
>
> I'm porting uClinux to our new no-mmu architecture.
> There is a trouble occured.
>
> After system call vfork() is called, the parent is suspended and
> cannot continue executing until the child exits or calls exec(),
> the system call used to start a new application.
> The child, directly after returning from vfork(),
> is running on the parent's stack and is using the parent's memory and
data.
> This means the child can corrupt the data structures or the stack in the
> parent, resulting in failure.
>
> How can I avoid the problem? Is there any solution?
>
> Thanks!
>
> Best regards,
> Ahan Hsieh
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> uClinux-dev mailing list
> [email protected]
> http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
> This message was resent by [email protected]
> To unsubscribe see:
> http://mailman.uclinux.org/mailman/options/uclinux-dev
_______________________________________________
uClinux-dev mailing list
[email protected]
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by [email protected]
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev
_______________________________________________
uClinux-dev mailing list
[email protected]
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by [email protected]
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev