lkml.org 
[lkml]   [1999]   [Jan]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Porting vfork()
On Wed, 6 Jan 1999, Linus Torvalds wrote:

>
>
> On Wed, 6 Jan 1999, Perry Harrington wrote:
> >
> > I think that the traditional sense of vfork() is more akin to the clone() call
> > with all of the special "hide me in my parents PID" options turned off.
> > Perhaps vfork() should simply be an alias to clone() with the appropriate flags
> > set?
>
> It _should_ be reasonably straightforward to do vfork() by using clone().
> It would go something like this:

uClinux has had a vfork for some time (had to), so it's interesting to
compare your attempt with mine. uClinux had one additional requirement of
the user's vfork() syscall being implemented as a macro, not a function
call, because vfork() doesn't (can't) clone the stack in uClinux.

> Add the field
>
> struct wait_queue *sleep;
>
> to "struct mm_struct" in include/linux/sched.h. Add the code to initialize
> it
>
> init_waitqueue(&mm->sleep);
>
> in mm_alloc() in kernel/fork.c, and then in kernel/fork.c: mmput() you'd
> add a
>
> wake_up(&mm->sleep);
>
> at the top of the function.

You'll also need a wake_up in kernel/exit.c.

> Finally, add the following system call to arch/i386/kernel/process.c:

Now this is a bit different. I worked it by adding a CLONE_ flag, and let
do_fork() do all the work. This is cleaner, though, as there's no need for
the kernel to vfork.

> asmlinkage int sys_vfork(struct pt_regs regs)
> {
> /*
> * This only works for a traditional process: don't
> * try to do recursive vforks or mix clone and vfork.
> */
> if (current->mm->count != 1)
> return -EINVAL;

Oh, yes, that should solve the recursion issue nicely. I hadn't thought of
that for some reason.

> child = do_fork(CLONE_VM | SIGCHLD, regs.esp, &regs);
> if (child > 0) {
> while (current->mm->count > 1)
> sleep_on(current->mm->sleep);
> }
> return child;
> }

Interesting. Did you have a particular reason to expect this loop to be
triggered?

> And you're done. Maybe. Apart from debugging the thing.
>
> Linus

--
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:49    [W:0.090 / U:0.376 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site