diff options
author | 2010-06-30 00:40:28 +0000 | |
---|---|---|
committer | 2010-06-30 00:40:28 +0000 | |
commit | e88d58b26ba3c1eb3d963ca7eef30960d3ac48c2 (patch) | |
tree | f6f18e1d3fc2197aba53475fa5a13d78c3ee417c | |
parent | Only two variables - HOME and SHELL - are from the environment, so just fill (diff) | |
download | wireguard-openbsd-e88d58b26ba3c1eb3d963ca7eef30960d3ac48c2.tar.xz wireguard-openbsd-e88d58b26ba3c1eb3d963ca7eef30960d3ac48c2.zip |
Move the plimit and pcred bits in fork1() into process_new() and make
process_new() handle the new struct process like fork1() does struct proc,
with a range of members zeroed and a range copied from the parent process.
ok tedu@
-rw-r--r-- | sys/kern/kern_fork.c | 31 | ||||
-rw-r--r-- | sys/sys/proc.h | 21 |
2 files changed, 35 insertions, 17 deletions
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 1e31a449f8a..c55dffdbc88 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_fork.c,v 1.116 2010/06/29 20:25:57 guenther Exp $ */ +/* $OpenBSD: kern_fork.c,v 1.117 2010/06/30 00:40:28 guenther Exp $ */ /* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */ /* @@ -156,14 +156,29 @@ process_new(struct proc *newproc, struct proc *parentproc) { struct process *pr, *parent; - pr = pool_get(&process_pool, PR_WAITOK | PR_ZERO); + pr = pool_get(&process_pool, PR_WAITOK); pr->ps_mainproc = newproc; TAILQ_INIT(&pr->ps_threads); TAILQ_INSERT_TAIL(&pr->ps_threads, newproc, p_thr_link); pr->ps_refcnt = 1; parent = parentproc->p_p; - pr->ps_rdomain = parent->ps_rdomain; + + /* + * Make a process structure for the new process. + * Start by zeroing the section of proc that is zero-initialized, + * then copy the section that is copied directly from the parent. + */ + bzero(&pr->ps_startzero, + (unsigned) ((caddr_t)&pr->ps_endzero - (caddr_t)&pr->ps_startzero)); + bcopy(&parent->ps_startcopy, &pr->ps_startcopy, + (unsigned) ((caddr_t)&pr->ps_endcopy - (caddr_t)&pr->ps_startcopy)); + + /* post-copy fixups */ + pr->ps_cred = pool_get(&pcred_pool, PR_WAITOK); + bcopy(parent->ps_cred, pr->ps_cred, sizeof(*pr->ps_cred)); + crhold(parent->ps_cred->pc_ucred); + pr->ps_limit->p_refcnt++; newproc->p_p = pr; } @@ -281,11 +296,6 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize, atomic_setbits_int(&p2->p_flag, p1->p_flag & (P_SUGID | P_SUGIDEXEC)); if (flags & FORK_PTRACE) atomic_setbits_int(&p2->p_flag, p1->p_flag & P_TRACED); - if ((flags & FORK_THREAD) == 0) { - p2->p_p->ps_cred = pool_get(&pcred_pool, PR_WAITOK); - bcopy(p1->p_p->ps_cred, p2->p_p->ps_cred, sizeof(*p2->p_p->ps_cred)); - crhold(p1->p_ucred); - } /* bump references to the text vnode (for procfs) */ p2->p_textvp = p1->p_textvp; @@ -299,11 +309,6 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize, else p2->p_fd = fdcopy(p1); - if ((flags & FORK_THREAD) == 0) { - p2->p_p->ps_limit = p1->p_p->ps_limit; - p2->p_p->ps_limit->p_refcnt++; - } - if (p1->p_session->s_ttyvp != NULL && p1->p_flag & P_CONTROLT) atomic_setbits_int(&p2->p_flag, P_CONTROLT); if (flags & FORK_PPWAIT) diff --git a/sys/sys/proc.h b/sys/sys/proc.h index e80e98536d4..dc350e3b493 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.128 2010/06/29 20:25:57 guenther Exp $ */ +/* $OpenBSD: proc.h,v 1.129 2010/06/30 00:40:28 guenther Exp $ */ /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ /*- @@ -140,13 +140,26 @@ struct process { */ struct proc *ps_mainproc; struct pcred *ps_cred; /* Process owner's identity. */ - struct plimit *ps_limit; /* Process limits. */ TAILQ_HEAD(,proc) ps_threads; /* Threads in this process. */ - int ps_refcnt; /* Number of references. */ - u_int ps_rdomain; /* Process routing domain. */ +/* The following fields are all zeroed upon creation in process_new. */ +#define ps_startzero ps_klist struct klist ps_klist; /* knotes attached to this process */ + +/* End area that is zeroed on creation. */ +#define ps_endzero ps_startcopy + +/* The following fields are all copied upon creation in process_new. */ +#define ps_startcopy ps_limit + + struct plimit *ps_limit; /* Process limits. */ + u_int ps_rdomain; /* Process routing domain. */ + +/* End area that is copied on creation. */ +#define ps_endcopy ps_refcnt + + int ps_refcnt; /* Number of references. */ }; #else struct process; |