Home | History | Annotate | Line # | Download | only in freebsd
freebsd_fork.c revision 1.3
      1  1.3    perry /*	$NetBSD: freebsd_fork.c,v 1.3 2005/02/26 23:10:18 perry Exp $	*/
      2  1.1    pooka 
      3  1.1    pooka /*-
      4  1.1    pooka  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  1.1    pooka  * All rights reserved.
      6  1.1    pooka  *
      7  1.3    perry  * Redistribution and use in source and binary forms, with or without
      8  1.1    pooka  * modification, are permitted provided that the following conditions
      9  1.1    pooka  * are met:
     10  1.1    pooka  * 1. Redistributions of source code must retain the above copyright
     11  1.1    pooka  *    notice, this list of conditions and the following disclaimer.
     12  1.1    pooka  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1    pooka  *    notice, this list of conditions and the following disclaimer in the
     14  1.1    pooka  *    documentation and/or other materials provided with the distribution.
     15  1.1    pooka  * 3. All advertising materials mentioning features or use of this software
     16  1.1    pooka  *    must display the following acknowledgement:
     17  1.1    pooka  *	This product includes software developed by the NetBSD
     18  1.1    pooka  *	Foundation, Inc. and its contributors.
     19  1.1    pooka  * 4. Neither the name of The NetBSD Foundation nor the names of its
     20  1.1    pooka  *    contributors may be used to endorse or promote products derived
     21  1.1    pooka  *    from this software without specific prior written permission.
     22  1.3    perry  *
     23  1.1    pooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     24  1.1    pooka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25  1.1    pooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26  1.1    pooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     27  1.1    pooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28  1.1    pooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  1.1    pooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  1.1    pooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  1.1    pooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32  1.1    pooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33  1.1    pooka  * POSSIBILITY OF SUCH DAMAGE.
     34  1.3    perry  */
     35  1.1    pooka 
     36  1.1    pooka #include <sys/cdefs.h>
     37  1.3    perry __KERNEL_RCSID(0, "$NetBSD: freebsd_fork.c,v 1.3 2005/02/26 23:10:18 perry Exp $");
     38  1.1    pooka 
     39  1.1    pooka #include <sys/param.h>
     40  1.1    pooka #include <sys/systm.h>
     41  1.1    pooka #include <sys/proc.h>
     42  1.1    pooka #include <sys/errno.h>
     43  1.1    pooka #include <sys/uio.h>
     44  1.1    pooka #include <sys/signal.h>
     45  1.1    pooka #include <sys/mount.h>
     46  1.1    pooka #include <sys/syscallargs.h>
     47  1.1    pooka 
     48  1.1    pooka #include <machine/freebsd_machdep.h>
     49  1.1    pooka 
     50  1.1    pooka #include <compat/freebsd/freebsd_syscallargs.h>
     51  1.1    pooka #include <compat/freebsd/freebsd_fork.h>
     52  1.1    pooka 
     53  1.1    pooka /*
     54  1.1    pooka  * rfork()
     55  1.1    pooka  */
     56  1.1    pooka int
     57  1.2  thorpej freebsd_sys_rfork(struct lwp *l, void *v, register_t *retval)
     58  1.1    pooka {
     59  1.1    pooka 	struct freebsd_sys_rfork_args /* {
     60  1.1    pooka 		syscallargs(int) flags;
     61  1.1    pooka 	} */ *uap = v;
     62  1.1    pooka 	int flags;
     63  1.1    pooka 
     64  1.1    pooka 	flags = 0;
     65  1.1    pooka 
     66  1.1    pooka 	if ((SCARG(uap, flags)
     67  1.1    pooka 	    & (FREEBSD_RFFDG | FREEBSD_RFCFDG))
     68  1.1    pooka 	    == (FREEBSD_RFFDG | FREEBSD_RFCFDG))
     69  1.1    pooka 		return (EINVAL);
     70  1.1    pooka 
     71  1.1    pooka 	if ((SCARG(uap, flags) & FREEBSD_RFPROC) == 0)
     72  1.1    pooka 		return (EINVAL);
     73  1.1    pooka 
     74  1.1    pooka 	if (SCARG(uap, flags) & FREEBSD_RFNOWAIT)
     75  1.1    pooka 		flags |= FORK_NOWAIT;
     76  1.1    pooka 	if (SCARG(uap, flags) & FREEBSD_RFMEM)
     77  1.1    pooka 		flags |= FORK_SHAREVM;
     78  1.1    pooka 	if (SCARG(uap, flags) & FREEBSD_RFSIGSHARE)
     79  1.1    pooka 		flags |= FORK_SHARESIGS;
     80  1.1    pooka 
     81  1.1    pooka 	if (SCARG(uap, flags) & FREEBSD_RFCFDG)
     82  1.1    pooka 		flags |= FORK_CLEANFILES;
     83  1.1    pooka 	else if ((SCARG(uap, flags) & FREEBSD_RFFDG) == 0)
     84  1.1    pooka 		flags |= FORK_SHAREFILES;
     85  1.1    pooka 
     86  1.2  thorpej 	return (fork1(l, flags,
     87  1.1    pooka 	    SCARG(uap, flags) & FREEBSD_RFLINUXTHPN ? SIGUSR1 : SIGCHLD,
     88  1.1    pooka 	    NULL, 0, NULL, NULL, retval, NULL));
     89  1.1    pooka }
     90