diff options
author | 2007-04-12 22:14:15 +0000 | |
---|---|---|
committer | 2007-04-12 22:14:15 +0000 | |
commit | e17acf5675eccdc838b1dec9c98991221a92f6b0 (patch) | |
tree | 4bbb1da46b87d5d108cbf35546ac89cc5a7c9091 | |
parent | Remove the i_interlock simplelock from struct ntnode (diff) | |
download | wireguard-openbsd-e17acf5675eccdc838b1dec9c98991221a92f6b0.tar.xz wireguard-openbsd-e17acf5675eccdc838b1dec9c98991221a92f6b0.zip |
move p_limit and p_cred into struct process
leave macros behind for now to keep the commit small
ok art beck miod pedro
-rw-r--r-- | lib/libkvm/kvm_proc.c | 13 | ||||
-rw-r--r-- | sys/kern/init_main.c | 4 | ||||
-rw-r--r-- | sys/kern/kern_acct.c | 12 | ||||
-rw-r--r-- | sys/kern/kern_exit.c | 20 | ||||
-rw-r--r-- | sys/kern/kern_fork.c | 36 | ||||
-rw-r--r-- | sys/kern/kern_resource.c | 10 | ||||
-rw-r--r-- | sys/kern/kern_sysctl.c | 5 | ||||
-rw-r--r-- | sys/sys/proc.h | 21 | ||||
-rw-r--r-- | sys/sys/sysctl.h | 3 |
9 files changed, 69 insertions, 55 deletions
diff --git a/lib/libkvm/kvm_proc.c b/lib/libkvm/kvm_proc.c index db6ebc165d5..604e91f163e 100644 --- a/lib/libkvm/kvm_proc.c +++ b/lib/libkvm/kvm_proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kvm_proc.c,v 1.31 2006/11/29 12:32:57 miod Exp $ */ +/* $OpenBSD: kvm_proc.c,v 1.32 2007/04/12 22:14:15 tedu Exp $ */ /* $NetBSD: kvm_proc.c,v 1.30 1999/03/24 05:50:50 mrg Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -73,7 +73,7 @@ #if 0 static char sccsid[] = "@(#)kvm_proc.c 8.3 (Berkeley) 9/23/93"; #else -static char *rcsid = "$OpenBSD: kvm_proc.c,v 1.31 2006/11/29 12:32:57 miod Exp $"; +static char *rcsid = "$OpenBSD: kvm_proc.c,v 1.32 2007/04/12 22:14:15 tedu Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -269,6 +269,7 @@ kvm_proclist(kvm_t *kd, int what, int arg, struct proc *p, struct session sess; struct eproc eproc; struct proc proc; + struct process process; struct pgrp pgrp; struct tty tty; int cnt = 0; @@ -278,7 +279,11 @@ kvm_proclist(kvm_t *kd, int what, int arg, struct proc *p, _kvm_err(kd, kd->program, "can't read proc at %x", p); return (-1); } - if (KREAD(kd, (u_long)proc.p_cred, &eproc.e_pcred) == 0) + if (KREAD(kd, (u_long)proc.p_p, &process)) { + _kvm_err(kd, kd->program, "can't read process at %x", proc.p_p); + return (-1); + } + if (KREAD(kd, (u_long)process.ps_cred, &eproc.e_pcred) == 0) KREAD(kd, (u_long)eproc.e_pcred.pc_ucred, &eproc.e_ucred); @@ -478,7 +483,7 @@ kvm_getproc2(kvm_t *kd, int op, int arg, size_t esize, int *cnt) kp2p->p_addr = PTRTOINT64(kp->kp_proc.p_addr); kp2p->p_fd = PTRTOINT64(kp->kp_proc.p_fd); kp2p->p_stats = PTRTOINT64(kp->kp_proc.p_stats); - kp2p->p_limit = PTRTOINT64(kp->kp_proc.p_limit); + kp2p->p_limit = PTRTOINT64(kp->kp_eproc.e_limit); kp2p->p_vmspace = PTRTOINT64(kp->kp_proc.p_vmspace); kp2p->p_sigacts = PTRTOINT64(kp->kp_proc.p_sigacts); kp2p->p_sess = PTRTOINT64(kp->kp_eproc.e_sess); diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 01dd7faa856..a8cf415a9df 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.138 2007/04/03 08:05:43 art Exp $ */ +/* $OpenBSD: init_main.c,v 1.139 2007/04/12 22:14:15 tedu Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -303,7 +303,7 @@ main(void *framep) TAILQ_INIT(&p->p_selects); /* Create the limits structures. */ - p->p_limit = &limit0; + p->p_p->ps_limit = &limit0; for (i = 0; i < sizeof(p->p_rlimit)/sizeof(p->p_rlimit[0]); i++) limit0.pl_rlimit[i].rlim_cur = limit0.pl_rlimit[i].rlim_max = RLIM_INFINITY; diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c index 262cda6a6c0..4a78715dcb7 100644 --- a/sys/kern/kern_acct.c +++ b/sys/kern/kern_acct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_acct.c,v 1.20 2007/01/16 17:52:18 thib Exp $ */ +/* $OpenBSD: kern_acct.c,v 1.21 2007/04/12 22:14:15 tedu Exp $ */ /* $NetBSD: kern_acct.c,v 1.42 1996/02/04 02:15:12 christos Exp $ */ /*- @@ -175,9 +175,9 @@ acct_process(struct proc *p) * Raise the file limit so that accounting can't be stopped by the * user. (XXX - we should think about the cpu limit too). */ - if (p->p_limit->p_refcnt > 1) { - oplim = p->p_limit; - p->p_limit = limcopy(p->p_limit); + if (p->p_p->ps_limit->p_refcnt > 1) { + oplim = p->p_p->ps_limit; + p->p_p->ps_limit = limcopy(p->p_p->ps_limit); } p->p_rlimit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; @@ -231,8 +231,8 @@ acct_process(struct proc *p) (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, p->p_ucred, NULL, p); if (oplim) { - limfree(p->p_limit); - p->p_limit = oplim; + limfree(p->p_p->ps_limit); + p->p_p->ps_limit = oplim; } return error; diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index cd9a2692627..4c85dd84543 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exit.c,v 1.70 2007/04/11 14:27:08 tedu Exp $ */ +/* $OpenBSD: kern_exit.c,v 1.71 2007/04/12 22:14:15 tedu Exp $ */ /* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */ /* @@ -325,8 +325,6 @@ exit1(struct proc *p, int rv, int flags) * Other substructures are freed from wait(). */ curproc = NULL; - limfree(p->p_limit); - p->p_limit = NULL; /* * If emulation has process exit hook, call it now. @@ -593,14 +591,6 @@ proc_zap(struct proc *p) (void)chgproccnt(p->p_cred->p_ruid, -1); /* - * Free up credentials. - */ - if (--p->p_cred->p_refcnt == 0) { - crfree(p->p_cred->pc_ucred); - pool_put(&pcred_pool, p->p_cred); - } - - /* * Release reference to text vnode */ if (p->p_textvp) @@ -613,8 +603,14 @@ proc_zap(struct proc *p) #if 0 TAILQ_REMOVE(&p->p_p->ps_threads, p, p_thr_link); #endif - if (TAILQ_EMPTY(&p->p_p->ps_threads)) + if (TAILQ_EMPTY(&p->p_p->ps_threads)) { + limfree(p->p_p->ps_limit); + if (--p->p_p->ps_cred->p_refcnt == 0) { + crfree(p->p_p->ps_cred->pc_ucred); + pool_put(&pcred_pool, p->p_p->ps_cred); + } pool_put(&process_pool, p->p_p); + } pool_put(&proc_pool, p); nprocs--; diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index c187ea87f18..71941682d39 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_fork.c,v 1.89 2007/04/03 08:05:43 art Exp $ */ +/* $OpenBSD: kern_fork.c,v 1.90 2007/04/12 22:14:15 tedu Exp $ */ /* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */ /* @@ -270,10 +270,17 @@ 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); - p2->p_cred = pool_get(&pcred_pool, PR_WAITOK); - bcopy(p1->p_cred, p2->p_cred, sizeof(*p2->p_cred)); - p2->p_cred->p_refcnt = 1; - crhold(p1->p_ucred); +#ifdef RTHREADS + if (flags & FORK_THREAD) { + /* nothing */ + } else +#endif + { + 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)); + p2->p_p->ps_cred->p_refcnt = 1; + crhold(p1->p_ucred); + } TAILQ_INIT(&p2->p_selects); @@ -290,16 +297,23 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize, p2->p_fd = fdcopy(p1); /* - * If p_limit is still copy-on-write, bump refcnt, + * If ps_limit is still copy-on-write, bump refcnt, * otherwise get a copy that won't be modified. * (If PL_SHAREMOD is clear, the structure is shared * copy-on-write.) */ - if (p1->p_limit->p_lflags & PL_SHAREMOD) - p2->p_limit = limcopy(p1->p_limit); - else { - p2->p_limit = p1->p_limit; - p2->p_limit->p_refcnt++; +#ifdef RTHREADS + if (flags & FORK_THREAD) { + /* nothing */ + } else +#endif + { + if (p1->p_p->ps_limit->p_lflags & PL_SHAREMOD) + p2->p_p->ps_limit = limcopy(p1->p_p->ps_limit); + else { + 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) diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index cb146e36d3f..f139dbd2f0a 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_resource.c,v 1.31 2005/11/28 00:14:29 jsg Exp $ */ +/* $OpenBSD: kern_resource.c,v 1.32 2007/04/12 22:14:15 tedu Exp $ */ /* $NetBSD: kern_resource.c,v 1.38 1996/10/23 07:19:38 matthias Exp $ */ /*- @@ -229,10 +229,10 @@ dosetrlimit(struct proc *p, u_int which, struct rlimit *limp) limp->rlim_max > alimp->rlim_max) if ((error = suser(p, 0)) != 0) return (error); - if (p->p_limit->p_refcnt > 1 && - (p->p_limit->p_lflags & PL_SHAREMOD) == 0) { - p->p_limit->p_refcnt--; - p->p_limit = limcopy(p->p_limit); + if (p->p_p->ps_limit->p_refcnt > 1 && + (p->p_p->ps_limit->p_lflags & PL_SHAREMOD) == 0) { + p->p_p->ps_limit->p_refcnt--; + p->p_p->ps_limit = limcopy(p->p_p->ps_limit); alimp = &p->p_rlimit[which]; } diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 0f6b4ae48a5..43e7cbec29b 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.149 2007/03/22 16:55:31 deraadt Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.150 2007/04/12 22:14:15 tedu Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -1175,6 +1175,7 @@ fill_eproc(struct proc *p, struct eproc *ep) strncpy(ep->e_emul, p->p_emul->e_name, EMULNAMELEN); ep->e_emul[EMULNAMELEN] = '\0'; ep->e_maxrss = p->p_rlimit ? p->p_rlimit[RLIMIT_RSS].rlim_cur : 0; + ep->e_limit = p->p_p->ps_limit; } #ifndef SMALL_KERNEL @@ -1193,7 +1194,7 @@ fill_kproc2(struct proc *p, struct kinfo_proc2 *ki) ki->p_paddr = PTRTOINT64(p); ki->p_fd = PTRTOINT64(p->p_fd); ki->p_stats = PTRTOINT64(p->p_stats); - ki->p_limit = PTRTOINT64(p->p_limit); + ki->p_limit = PTRTOINT64(p->p_p->ps_limit); ki->p_vmspace = PTRTOINT64(p->p_vmspace); ki->p_sigacts = PTRTOINT64(p->p_sigacts); ki->p_sess = PTRTOINT64(p->p_session); diff --git a/sys/sys/proc.h b/sys/sys/proc.h index feb003b4190..f0621d493ac 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.94 2007/04/04 13:53:26 pedro Exp $ */ +/* $OpenBSD: proc.h,v 1.95 2007/04/12 22:14:15 tedu Exp $ */ /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ /*- @@ -120,10 +120,7 @@ extern int nemuls; /* Number of emuls */ * These structures contain the information needed to manage a thread of * control, known in UN*X as a process; it has references to substructures * containing descriptions of things that the process uses, but may share - * with related processes. The process structure and the substructures - * are always addressable except for those marked "(PROC ONLY)" below, - * which might be addressable only on a processor on which the process - * is running. + * with related processes. * * struct process is the higher level process containing information * shared by all threads in a process, while struct proc contains the @@ -139,6 +136,8 @@ struct process { * pid semantics we have right now, it's unavoidable. */ 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. */ }; @@ -152,15 +151,13 @@ struct proc { TAILQ_ENTRY(proc) p_thr_link;/* Threads in a process linkage. */ /* substructures: */ - struct pcred *p_cred; /* Process owner's identity. */ struct filedesc *p_fd; /* Ptr to open files structure. */ - struct pstats *p_stats; /* Accounting/statistics (PROC ONLY). */ - struct plimit *p_limit; /* Process limits. */ + struct pstats *p_stats; /* Accounting/statistics */ struct vmspace *p_vmspace; /* Address space. */ - struct sigacts *p_sigacts; /* Signal actions, state (PROC ONLY). */ - + struct sigacts *p_sigacts; /* Signal actions, state */ +#define p_cred p_p->ps_cred #define p_ucred p_cred->pc_ucred -#define p_rlimit p_limit->pl_rlimit +#define p_rlimit p_p->ps_limit->pl_rlimit int p_exitsig; /* Signal to send to parent on exit. */ int p_flag; /* P_* flags. */ @@ -250,7 +247,7 @@ struct proc { /* End area that is copied on creation. */ #define p_endcopy p_addr - struct user *p_addr; /* Kernel virtual addr of u-area (PROC ONLY). */ + struct user *p_addr; /* Kernel virtual addr of u-area */ struct mdproc p_md; /* Any machine-dependent fields. */ u_short p_xstat; /* Exit status for wait; also stop signal. */ diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 0f11b02c58c..9d1897e3dbe 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.h,v 1.90 2007/01/12 07:41:31 art Exp $ */ +/* $OpenBSD: sysctl.h,v 1.91 2007/04/12 22:14:15 tedu Exp $ */ /* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ /* @@ -329,6 +329,7 @@ struct kinfo_proc { #define EMULNAMELEN 7 char e_emul[EMULNAMELEN+1]; /* syscall emulation name */ rlim_t e_maxrss; + struct plimit *e_limit; } kp_eproc; }; |