- Add __cacheline_aligned for nprocs, make fork_tfmrate static.
- Fix indentation, remove whitespaces and redundant brackets.
This commit is contained in:
parent
0303786ef2
commit
1f1468fdc5
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: kern_fork.c,v 1.187 2012/02/02 02:44:06 christos Exp $ */
|
||||
/* $NetBSD: kern_fork.c,v 1.188 2012/03/02 21:23:05 rmind Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
|
||||
@ -67,7 +67,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.187 2012/02/02 02:44:06 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.188 2012/03/02 21:23:05 rmind Exp $");
|
||||
|
||||
#include "opt_ktrace.h"
|
||||
|
||||
@ -84,7 +84,6 @@ __KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.187 2012/02/02 02:44:06 christos Exp
|
||||
#include <sys/file.h>
|
||||
#include <sys/acct.h>
|
||||
#include <sys/ktrace.h>
|
||||
#include <sys/vmmeter.h>
|
||||
#include <sys/sched.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/kauth.h>
|
||||
@ -99,13 +98,13 @@ __KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.187 2012/02/02 02:44:06 christos Exp
|
||||
/*
|
||||
* DTrace SDT provider definitions
|
||||
*/
|
||||
SDT_PROBE_DEFINE(proc,,,create,
|
||||
SDT_PROBE_DEFINE(proc,,,create,
|
||||
"struct proc *", NULL, /* new process */
|
||||
"struct proc *", NULL, /* parent process */
|
||||
"int", NULL, /* flags */
|
||||
NULL, NULL, NULL, NULL);
|
||||
|
||||
u_int nprocs = 1; /* process 0 */
|
||||
u_int nprocs __cacheline_aligned = 1; /* process 0 */
|
||||
|
||||
/*
|
||||
* Number of ticks to sleep if fork() would fail due to process hitting
|
||||
@ -113,45 +112,43 @@ u_int nprocs = 1; /* process 0 */
|
||||
*/
|
||||
int forkfsleep = 0;
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
sys_fork(struct lwp *l, const void *v, register_t *retval)
|
||||
{
|
||||
|
||||
return (fork1(l, 0, SIGCHLD, NULL, 0, NULL, NULL, retval, NULL));
|
||||
return fork1(l, 0, SIGCHLD, NULL, 0, NULL, NULL, retval, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* vfork(2) system call compatible with 4.4BSD (i.e. BSD with Mach VM).
|
||||
* Address space is not shared, but parent is blocked until child exit.
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
sys_vfork(struct lwp *l, const void *v, register_t *retval)
|
||||
{
|
||||
|
||||
return (fork1(l, FORK_PPWAIT, SIGCHLD, NULL, 0, NULL, NULL,
|
||||
retval, NULL));
|
||||
return fork1(l, FORK_PPWAIT, SIGCHLD, NULL, 0, NULL, NULL,
|
||||
retval, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* New vfork(2) system call for NetBSD, which implements original 3BSD vfork(2)
|
||||
* semantics. Address space is shared, and parent is blocked until child exit.
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
sys___vfork14(struct lwp *l, const void *v, register_t *retval)
|
||||
{
|
||||
|
||||
return (fork1(l, FORK_PPWAIT|FORK_SHAREVM, SIGCHLD, NULL, 0,
|
||||
NULL, NULL, retval, NULL));
|
||||
return fork1(l, FORK_PPWAIT|FORK_SHAREVM, SIGCHLD, NULL, 0,
|
||||
NULL, NULL, retval, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Linux-compatible __clone(2) system call.
|
||||
*/
|
||||
int
|
||||
sys___clone(struct lwp *l, const struct sys___clone_args *uap, register_t *retval)
|
||||
sys___clone(struct lwp *l, const struct sys___clone_args *uap,
|
||||
register_t *retval)
|
||||
{
|
||||
/* {
|
||||
syscallarg(int) flags;
|
||||
@ -163,14 +160,14 @@ sys___clone(struct lwp *l, const struct sys___clone_args *uap, register_t *retva
|
||||
* We don't support the CLONE_PID or CLONE_PTRACE flags.
|
||||
*/
|
||||
if (SCARG(uap, flags) & (CLONE_PID|CLONE_PTRACE))
|
||||
return (EINVAL);
|
||||
return EINVAL;
|
||||
|
||||
/*
|
||||
* Linux enforces CLONE_VM with CLONE_SIGHAND, do same.
|
||||
*/
|
||||
if (SCARG(uap, flags) & CLONE_SIGHAND
|
||||
&& (SCARG(uap, flags) & CLONE_VM) == 0)
|
||||
return (EINVAL);
|
||||
return EINVAL;
|
||||
|
||||
flags = 0;
|
||||
|
||||
@ -187,7 +184,7 @@ sys___clone(struct lwp *l, const struct sys___clone_args *uap, register_t *retva
|
||||
|
||||
sig = SCARG(uap, flags) & CLONE_CSIGNAL;
|
||||
if (sig < 0 || sig >= _NSIG)
|
||||
return (EINVAL);
|
||||
return EINVAL;
|
||||
|
||||
/*
|
||||
* Note that the Linux API does not provide a portable way of
|
||||
@ -195,18 +192,20 @@ sys___clone(struct lwp *l, const struct sys___clone_args *uap, register_t *retva
|
||||
* grows up or down. So, we pass a stack size of 0, so that the
|
||||
* code that makes this adjustment is a noop.
|
||||
*/
|
||||
return (fork1(l, flags, sig, SCARG(uap, stack), 0,
|
||||
NULL, NULL, retval, NULL));
|
||||
return fork1(l, flags, sig, SCARG(uap, stack), 0,
|
||||
NULL, NULL, retval, NULL);
|
||||
}
|
||||
|
||||
/* print the 'table full' message once per 10 seconds */
|
||||
struct timeval fork_tfmrate = { 10, 0 };
|
||||
/*
|
||||
* Print the 'table full' message once per 10 seconds.
|
||||
*/
|
||||
static struct timeval fork_tfmrate = { 10, 0 };
|
||||
|
||||
/*
|
||||
* General fork call. Note that another LWP in the process may call exec()
|
||||
* or exit() while we are forking. It's safe to continue here, because
|
||||
* neither operation will complete until all LWPs have exited the process.
|
||||
*/
|
||||
*/
|
||||
int
|
||||
fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
|
||||
void (*func)(void *), void *arg, register_t *retval,
|
||||
@ -243,7 +242,7 @@ fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
|
||||
tablefull("proc", "increase kern.maxproc or NPROC");
|
||||
if (forkfsleep)
|
||||
kpause("forkmx", false, forkfsleep, NULL);
|
||||
return (EAGAIN);
|
||||
return EAGAIN;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -256,7 +255,7 @@ fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
|
||||
atomic_dec_uint(&nprocs);
|
||||
if (forkfsleep)
|
||||
kpause("forkulim", false, forkfsleep, NULL);
|
||||
return (EAGAIN);
|
||||
return EAGAIN;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -268,7 +267,7 @@ fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
|
||||
if (__predict_false(uaddr == 0)) {
|
||||
(void)chgproccnt(uid, -1);
|
||||
atomic_dec_uint(&nprocs);
|
||||
return (ENOMEM);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -310,7 +309,7 @@ fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
|
||||
if (flags & FORK_SYSTEM) {
|
||||
/*
|
||||
* Mark it as a system process. Set P_NOCLDWAIT so that
|
||||
* children are reparented to init(8) when they exit.
|
||||
* children are reparented to init(8) when they exit.
|
||||
* init(8) can easily wait them out for us.
|
||||
*/
|
||||
p2->p_flag |= (PK_SYSTEM | PK_NOCLDWAIT);
|
||||
@ -573,15 +572,16 @@ fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
|
||||
while (p2->p_lflag & PL_PPWAIT)
|
||||
cv_wait(&p1->p_waitcv, proc_lock);
|
||||
|
||||
/*
|
||||
* Let the parent know that we are tracing its child.
|
||||
*/
|
||||
/*
|
||||
* Let the parent know that we are tracing its child.
|
||||
*/
|
||||
if (tracefork) {
|
||||
ksiginfo_t ksi;
|
||||
KSI_INIT_EMPTY(&ksi);
|
||||
ksi.ksi_signo = SIGTRAP;
|
||||
ksi.ksi_lid = l1->l_lid;
|
||||
kpsignal(p1, &ksi, NULL);
|
||||
|
||||
KSI_INIT_EMPTY(&ksi);
|
||||
ksi.ksi_signo = SIGTRAP;
|
||||
ksi.ksi_lid = l1->l_lid;
|
||||
kpsignal(p1, &ksi, NULL);
|
||||
}
|
||||
|
||||
mutex_exit(proc_lock);
|
||||
@ -595,5 +595,5 @@ fork1(struct lwp *l1, int flags, int exitsig, void *stack, size_t stacksize,
|
||||
retval[1] = 0;
|
||||
}
|
||||
|
||||
return (0);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user