From owner-freebsd-hackers Wed Feb 4 03:11:54 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id DAA00488 for hackers-outgoing; Wed, 4 Feb 1998 03:11:54 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from demeter.sunyit.edu (demeter2.sunyit.edu [150.156.16.5]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id DAA00482 for ; Wed, 4 Feb 1998 03:11:48 -0800 (PST) (envelope-from perlsta@sunyit.edu) Received: from win95.local.sunyit.edu (A-T34.rh.sunyit.edu [150.156.210.241]) by demeter.sunyit.edu with ESMTP (8.7.1/8.7.1) id GAA01268 for ; Wed, 4 Feb 1998 06:11:23 -0500 (EST) Message-Id: <199802041111.GAA01268@demeter.sunyit.edu> From: "Alfred Perlstein" To: Subject: implementing linux's clone() Date: Wed, 4 Feb 1998 06:01:29 -0500 X-MSMail-Priority: Normal X-Priority: 3 X-Mailer: Microsoft Internet Mail 4.70.1161 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG X-To-Unsubscribe: mail to majordomo@FreeBSD.org "unsubscribe hackers" 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