[uClibc]Problem with vfork() followed by exec() on ARM7

Tonny Tzeng tzengym at ms8.hinet.net
Mon Sep 24 08:00:48 UTC 2001


Hi Erik,

I tried to single step the vfork.c program by using JTAG, and
found it's vfork() and wait4()'s problem. In the current uClibc
release, wait4() is implemented by the C function call, which
will save LR on the stack before trap to kernel, but that stack
will be overrided by the child process, so the wait4() never
get return! I use uClinux-2.0.38 kernel, the SP of child process
is the same as parent process after vfork(), so the stack
variables may be destroyed by child processes. Is there any
solution for that situation?

Best regards,
Tonny

> I don't think it's the app's bug, neither fork.c in uClibc/test/unistd
> nor your program below print the last message, but the old
> uC-libc tree in cvs.uclinux.org works together with all these
> sample programs. The following is the output of your code
> on my Arm board:
>
> > ls
> bin
> proc
> sbin
> dev
> usr
> >
> > test
> Hello.  I'm the parent process.
> Hi.  I'm the child process...
> bin
> proc
> sbin
> dev
> usr
> > [sash is waiting for user command here]
>
> BTW, I noticed you are using 2.4.9 kernel, do you think the
> newest uClibc need to be run with 2.4 kernels?
> Thanks for your help. :)
>
> > Your app has several bugs in it.  Try this instead:
> >
> > #include <stdio.h>
> > #include <stdlib.h>
> > #include <unistd.h>
> > #include <sys/wait.h>
> > int main(void)
> > {
> >     pid_t pid;
> >     int status, wpid;
> >     char *argv[] = {
> >         "/bin/ls",
> >         NULL,
> >     };
> >     if ((pid = vfork()) == 0) {
> >         printf("Hi.  I'm the child process...\n");
> >         execvp(argv[0], argv);
> >         _exit(0);
> >     }
> >     printf("Hello.  I'm the parent process.\n");
> >     while (1) {
> >         wpid = wait(&status);
> >         if (wpid > 0 && wpid != pid) {
> >             continue;
> >         }
> >         if (wpid == pid)
> >             break;
> >     }
> >     printf("Child process exited.\nGoodbye.\n");
> >     return EXIT_SUCCESS;
> > }
> >
> > Here it is running on my NetWinder:
> >
> >
> > $ uname -a
> > Linux winder 2.4.9-ac10-rmk1 #1 Wed Sep 19 22:30:24 MDT 2001 armv4l
> unknown
> > $
>
../../extra/gcc-uClibc/arm-uclibc-gcc -fomit-frame-pointer --uclibc-use-buil
> d-dir -c vfork.c -o vfork.o
> > $
>
../../extra/gcc-uClibc/arm-uclibc-gcc -s -Wl,-warn-common --uclibc-use-build
> -dir vfork.o -o vfork
> > $ strip -x -R .note -R .comment vfork
> > $ ./vfork
> > $ ../../ldso/util/ldd ./vfork
> >         libc.so.0 => /usr/arm-linux-uclibc/lib/libc.so.0
> >         /home/andersen/CVS/uClibc/lib/ld-uClibc.so.0 =>
> /home/andersen/CVS/uClibc/lib/ld-uClibc.so.0
> > $ ./vfork
> > Hi.  I'm the child process...
> > Hello.  I'm the parent process.
> > CVS       fork    fork.o      fork_glibc.o  vfork.c  vfork_glibc
> > Makefile  fork.c  fork_glibc  vfork         vfork.o  vfork_glibc.o
> > Child process exited.
> > Goodbye.
> >
> >
> >  -Erik
> >
> > --
> > Erik B. Andersen   email:  andersee at debian.org, formerly of Lineo
> > --This message was written using 73% post-consumer electrons--
>
>
>
>
> _______________________________________________
> uClibc mailing list
> uClibc at uclibc.org
> http://uclibc.org/mailman/listinfo/uclibc







More information about the uClibc mailing list