Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Feb 1998 06:01:29 -0500
From:      "Alfred Perlstein" <perlsta@sunyit.edu>
To:        <hackers@FreeBSD.ORG>
Subject:   implementing linux's clone()
Message-ID:  <199802041111.GAA01268@demeter.sunyit.edu>

next in thread | raw e-mail | index | archive | help
is there any function that offers the clone() call that linux has?

specifically i have to set the new process's stack frame to a specific
place,
and implement the linux clone features, all this is in an attempt to port
wine to freebsd and also make building programs that use clone() possible
under freebsd.

so far i need to implement the clone features:
CLONE_VM CLONE_FS CLONE_FILES and i also have to have the child process
send back a SIGCHLD

CLONE_VM = the parent and child both share the same virtual memory
CLONE_FS = the parent and child share same filesystem (fs in the linux
header file)
CLONE_FILES = the parent and chile share file descriptors...

the sigchild if i'm not mistaken is by default ignored in freebsd while in
linux it is by default listened for? so all i would have to do there is
unmask the signal, correct?

maybe i'm missing something in the threads that freebsd offers....

currently the implementation of the port makes it unable to do threads, if
i could emulate clone() it would be a major advantage.

so far the only thing i can think of is fork'ing or rfork'ing the child
process, immediately wait for a signal and then the parent would use
proc_fs to munge up the stack frame and file descriptors then signal the
child to proceed...

i thought i had an answer with vfork(), however this seems to be a very
poor choice as it doesn't really fork() it kinda just makes a backtracing
point in the program as the parent is suspended while the child executes. 

rfork() seems to be what i need, however i'm not totally sure of the
differences between it and clone() as clone seems to have more options,
plus i don't know how to set the stack to point towards something else in
the child process, however i have done some reading up on it:

reading more into the proc_fs, this seems like the way to do it, but can i
use the "regs" file in the procfs entry and change the stack register sp to
point to a memory location owned by another process? would i have to mmap()
it in the parent, use shared-memory? or just copy the pointer? arrrgh!!! ;)

i'm also unsure of the clone'ing of the FS and VM, although FILES seems
trivial enough...

btw, clone is a neeto interface, but very weird... something that could be
of use in freebsd as a almost lightweight way of doing nasty threads....
i don't think this should become part of freebsd as a function implemented
by the kernel, but perhaps as a .c/.h combination that emulates the clone()
interface, that way it might be useful to other operating systems.

-Alfred



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199802041111.GAA01268>