[PATCH] Fix start-stop-daemon on no-MMU

Alex Landau landau_alex at yahoo.com
Fri Aug 3 09:14:45 UTC 2007


--- Denis Vlasenko <vda.linux at googlemail.com> wrote:

> I was specifically thinking how our trick is working on _NOMMU_.
> Mostly for self-education. So, after execve on NOMMU old process
> is not destroyed, but "returned" to parent-after-vfork, and
> while parent does something, new process is already has memory
> allocated for it?
> 
> OIW: at execve, does kernel do something like this?
> 
>  if (vfork_was_done) {
>     create_and_start_new_process();
>     wake_up_parent_in_vfork();
>  } else {
>     destroy_current_process();
>     create_and_start_new_process();
>  }
> 
> 
> --
> vda
> 

No, vfork creates a new process (just like fork). I mean it creates a new struct
task_struct, copies the kernel stack, and so on. So the child is an entirely new process
with its own PID. What it does not copy is the mm_struct, but instead the child's one
points to the parent's one. So now the parent and child are different processes sharing
the same address space (due to CLONE_VM).
vfork on Blackfin calls do_fork() with flags CLONE_VFORK | CLONE_VM | SIGCHLD, see
kernel/fork.c for do_fork().
Inside do_fork(), if CLONE_VFORK is set, the parent waits on a completion variable until
the child signals it, which happens on execve() and on exit().

On execve(), the child detaches from the parent mm_struct (flush_old_exec() which calls
exec_mmap(), and itself called from the binary handler, e.g. load_flat_file() in
fs/binfmt_flat.c for FLAT), and sets the child's mm to point to a newly allocated
mm_struct (do_execve() does the allocation).
mm_release() called from exec_mmap() (on execve) and from exit_mm() (called itself from
do_exit()) checks whether the parent wait for a vfork completion, and if yes, signals it.

I hope that helps.
Regards,
Alex


      ____________________________________________________________________________________
Park yourself in front of a world of choices in alternative vehicles. Visit the Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 



More information about the busybox mailing list