diff --git a/sys/arch/alpha/alpha/db_trace.c b/sys/arch/alpha/alpha/db_trace.c index c1cadb06f0df..119c2a385e99 100644 --- a/sys/arch/alpha/alpha/db_trace.c +++ b/sys/arch/alpha/alpha/db_trace.c @@ -1,4 +1,4 @@ -/* $NetBSD: db_trace.c,v 1.23 2008/04/28 20:23:10 martin Exp $ */ +/* $NetBSD: db_trace.c,v 1.24 2008/07/02 19:49:58 rmind Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.23 2008/04/28 20:23:10 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.24 2008/07/02 19:49:58 rmind Exp $"); #include #include @@ -226,7 +226,8 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count, (*pr)("not found\n"); return; } - l = proc_representative_lwp(p, NULL, 0); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); } (*pr)("lid %d ", l->l_lid); if ((l->l_flag & LW_INMEM) == 0) { diff --git a/sys/arch/amd64/amd64/db_trace.c b/sys/arch/amd64/amd64/db_trace.c index 53d1382d4fe2..f589ec55e20e 100644 --- a/sys/arch/amd64/amd64/db_trace.c +++ b/sys/arch/amd64/amd64/db_trace.c @@ -1,4 +1,4 @@ -/* $NetBSD: db_trace.c,v 1.12 2007/12/22 18:35:00 dsl Exp $ */ +/* $NetBSD: db_trace.c,v 1.13 2008/07/02 19:49:58 rmind Exp $ */ /* * Mach Operating System @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.12 2007/12/22 18:35:00 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.13 2008/07/02 19:49:58 rmind Exp $"); #include #include @@ -351,7 +351,8 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count, (*pr)("not found\n"); return; } - l = proc_representative_lwp(p, NULL, 0); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); } (*pr)("lid %d ", l->l_lid); if (!(l->l_flag & LW_INMEM)) { diff --git a/sys/arch/arm/arm/db_trace.c b/sys/arch/arm/arm/db_trace.c index a88ebc2cedd5..2768711e8047 100644 --- a/sys/arch/arm/arm/db_trace.c +++ b/sys/arch/arm/arm/db_trace.c @@ -1,4 +1,4 @@ -/* $NetBSD: db_trace.c,v 1.16 2007/02/22 05:14:04 thorpej Exp $ */ +/* $NetBSD: db_trace.c,v 1.17 2008/07/02 19:49:58 rmind Exp $ */ /* * Copyright (c) 2000, 2001 Ben Harris @@ -31,7 +31,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.16 2007/02/22 05:14:04 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.17 2008/07/02 19:49:58 rmind Exp $"); #include #include @@ -124,7 +124,8 @@ db_stack_trace_print(addr, have_addr, count, modif, pr) (*pr)("not found\n"); return; } - l = proc_representative_lwp(p, NULL, 0); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); } (*pr)("lid %d ", l->l_lid); if (!(l->l_flag & LW_INMEM)) { diff --git a/sys/arch/hppa/hppa/db_trace.c b/sys/arch/hppa/hppa/db_trace.c index 1bdad4cbea08..6116b99b8bfe 100644 --- a/sys/arch/hppa/hppa/db_trace.c +++ b/sys/arch/hppa/hppa/db_trace.c @@ -1,4 +1,4 @@ -/* $NetBSD: db_trace.c,v 1.1 2008/04/24 07:28:30 skrll Exp $ */ +/* $NetBSD: db_trace.c,v 1.2 2008/07/02 19:49:58 rmind Exp $ */ /* $OpenBSD: db_interface.c,v 1.16 2001/03/22 23:31:45 mickey Exp $ */ @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.1 2008/04/24 07:28:30 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.2 2008/07/02 19:49:58 rmind Exp $"); #include #include @@ -94,7 +94,8 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count, (*pr)("not found\n"); return; } - l = proc_representative_lwp(p, NULL, 0); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); } (*pr)("lid %d ", l->l_lid); if (!(l->l_flag & LW_INMEM)) { diff --git a/sys/arch/i386/i386/db_trace.c b/sys/arch/i386/i386/db_trace.c index ce31244dda60..44002665e4e5 100644 --- a/sys/arch/i386/i386/db_trace.c +++ b/sys/arch/i386/i386/db_trace.c @@ -1,4 +1,4 @@ -/* $NetBSD: db_trace.c,v 1.59 2008/05/03 05:50:33 yamt Exp $ */ +/* $NetBSD: db_trace.c,v 1.60 2008/07/02 19:49:58 rmind Exp $ */ /* * Mach Operating System @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.59 2008/05/03 05:50:33 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.60 2008/07/02 19:49:58 rmind Exp $"); #include #include @@ -435,7 +435,8 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count, (*pr)("not found\n"); return; } - l = proc_representative_lwp(p, NULL, 0); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); } (*pr)("lid %d ", l->l_lid); if (!(l->l_flag & LW_INMEM)) { diff --git a/sys/arch/m68k/m68k/db_trace.c b/sys/arch/m68k/m68k/db_trace.c index cd9abecf8a94..746b9e235396 100644 --- a/sys/arch/m68k/m68k/db_trace.c +++ b/sys/arch/m68k/m68k/db_trace.c @@ -1,4 +1,4 @@ -/* $NetBSD: db_trace.c,v 1.52 2007/10/17 19:55:12 garbled Exp $ */ +/* $NetBSD: db_trace.c,v 1.53 2008/07/02 19:49:58 rmind Exp $ */ /* * Mach Operating System @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.52 2007/10/17 19:55:12 garbled Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.53 2008/07/02 19:49:58 rmind Exp $"); #include #include @@ -443,7 +443,8 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count, (*pr)("not found\n"); return; } - l = proc_representative_lwp(p, NULL, 0); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); } (*pr)("lid %d ", l->l_lid); if (!(l->l_flag & LW_INMEM)) { diff --git a/sys/arch/powerpc/powerpc/db_trace.c b/sys/arch/powerpc/powerpc/db_trace.c index d6eb48a2c77e..73a00dc7c86f 100644 --- a/sys/arch/powerpc/powerpc/db_trace.c +++ b/sys/arch/powerpc/powerpc/db_trace.c @@ -1,4 +1,4 @@ -/* $NetBSD: db_trace.c,v 1.47 2008/02/05 22:31:50 garbled Exp $ */ +/* $NetBSD: db_trace.c,v 1.48 2008/07/02 19:49:58 rmind Exp $ */ /* $OpenBSD: db_trace.c,v 1.3 1997/03/21 02:10:48 niklas Exp $ */ /* @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.47 2008/02/05 22:31:50 garbled Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.48 2008/07/02 19:49:58 rmind Exp $"); #include "opt_ppcarch.h" @@ -146,7 +146,8 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, db_expr_t count, (*pr)("not found\n"); return; } - l = proc_representative_lwp(p, NULL, 0); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); } (*pr)("lid %d ", l->l_lid); if ((l->l_flag & LW_INMEM) == 0) { diff --git a/sys/arch/sparc/sparc/db_trace.c b/sys/arch/sparc/sparc/db_trace.c index 6cd0dc43334a..cd50e37d5942 100644 --- a/sys/arch/sparc/sparc/db_trace.c +++ b/sys/arch/sparc/sparc/db_trace.c @@ -1,4 +1,4 @@ -/* $NetBSD: db_trace.c,v 1.29 2007/02/22 16:48:59 thorpej Exp $ */ +/* $NetBSD: db_trace.c,v 1.30 2008/07/02 19:49:58 rmind Exp $ */ /* * Mach Operating System @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.29 2007/02/22 16:48:59 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.30 2008/07/02 19:49:58 rmind Exp $"); #include #include @@ -91,7 +91,8 @@ db_stack_trace_print(db_expr_t addr, bool have_addr, (*pr)("not found\n"); return; } - l = proc_representative_lwp(p, NULL, 0); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); } (*pr)("lid %d ", l->l_lid); if ((l->l_flag & LW_INMEM) == 0) { diff --git a/sys/arch/sparc64/sparc64/db_trace.c b/sys/arch/sparc64/sparc64/db_trace.c index 46138c38f2d5..2b122ae96980 100644 --- a/sys/arch/sparc64/sparc64/db_trace.c +++ b/sys/arch/sparc64/sparc64/db_trace.c @@ -1,4 +1,4 @@ -/* $NetBSD: db_trace.c,v 1.39 2007/03/04 06:00:50 christos Exp $ */ +/* $NetBSD: db_trace.c,v 1.40 2008/07/02 19:49:58 rmind Exp $ */ /* * Copyright (c) 1996-2002 Eduardo Horvath. All rights reserved. @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.39 2007/03/04 06:00:50 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_trace.c,v 1.40 2008/07/02 19:49:58 rmind Exp $"); #include #include @@ -97,7 +97,8 @@ db_stack_trace_print(addr, have_addr, count, modif, pr) (*pr)("not found\n"); return; } - l = proc_representative_lwp(p, NULL, 0); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); } (*pr)("lid %d ", l->l_lid); if ((l->l_flag & LW_INMEM) == 0) { diff --git a/sys/compat/darwin/darwin_signal.c b/sys/compat/darwin/darwin_signal.c index 6031d3789742..3132b3d62286 100644 --- a/sys/compat/darwin/darwin_signal.c +++ b/sys/compat/darwin/darwin_signal.c @@ -1,4 +1,4 @@ -/* $NetBSD: darwin_signal.c,v 1.29 2008/04/28 20:23:41 martin Exp $ */ +/* $NetBSD: darwin_signal.c,v 1.30 2008/07/02 19:49:58 rmind Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: darwin_signal.c,v 1.29 2008/04/28 20:23:41 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: darwin_signal.c,v 1.30 2008/07/02 19:49:58 rmind Exp $"); #include #include @@ -124,7 +124,8 @@ darwin_tracesig(struct proc *p, int signo) code[0] = MACH_SOFT_SIGNAL; code[1] = signo; - l = proc_representative_lwp(p, NULL, 0); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); error = mach_exception(l, MACH_EXC_SOFTWARE, code); /* Inhibit normal signal delivery */ diff --git a/sys/compat/darwin/darwin_sysctl.c b/sys/compat/darwin/darwin_sysctl.c index f74c16adb618..e94abfe7cde4 100644 --- a/sys/compat/darwin/darwin_sysctl.c +++ b/sys/compat/darwin/darwin_sysctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: darwin_sysctl.c,v 1.60 2008/06/16 12:25:54 ad Exp $ */ +/* $NetBSD: darwin_sysctl.c,v 1.61 2008/07/02 19:49:58 rmind Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: darwin_sysctl.c,v 1.60 2008/06/16 12:25:54 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: darwin_sysctl.c,v 1.61 2008/07/02 19:49:58 rmind Exp $"); #include #include @@ -728,7 +728,8 @@ darwin_fill_kproc(struct proc *p, struct darwin_kinfo_proc *dkp) struct darwin_eproc *de; printf("fillkproc: pid %d\n", p->p_pid); - l = proc_representative_lwp(p, NULL, 1); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); (void)memset(dkp, 0, sizeof(*dkp)); dep = (struct darwin_extern_proc *)&dkp->kp_proc; @@ -840,8 +841,12 @@ native_to_darwin_pflag(int *dfp, struct proc *p) int bf = p->p_flag; int bsf = p->p_sflag; int bslf = p->p_slflag; - struct lwp *l = proc_representative_lwp(p, NULL, 1); - int lf = l->l_flag; + struct lwp *l; + int lf; + + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); + lf = l->l_flag; if (bf & PK_ADVLOCK) df |= DARWIN_P_ADVLOCK; diff --git a/sys/compat/irix/irix_prctl.c b/sys/compat/irix/irix_prctl.c index 437ee836e8bd..f956c2b864ec 100644 --- a/sys/compat/irix/irix_prctl.c +++ b/sys/compat/irix/irix_prctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: irix_prctl.c,v 1.47 2008/04/28 20:23:41 martin Exp $ */ +/* $NetBSD: irix_prctl.c,v 1.48 2008/07/02 19:49:58 rmind Exp $ */ /*- * Copyright (c) 2001-2002 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: irix_prctl.c,v 1.47 2008/04/28 20:23:41 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: irix_prctl.c,v 1.48 2008/07/02 19:49:58 rmind Exp $"); #include #include @@ -584,9 +584,12 @@ irix_sys_procblk(struct lwp *l, const struct irix_sys_procblk_args *uap, registe rw_enter(&isg->isg_lock, RW_READER); LIST_FOREACH(iedp, &isg->isg_head, ied_sglist) { + struct proc *p; /* Recall procblk for this process */ - SCARG(&cup, pid) = iedp->ied_p->p_pid; - ied_lwp = proc_representative_lwp(iedp->ied_p, NULL, 0); + p = iedp->ied_p; + SCARG(&cup, pid) = p->p_pid; + ied_lwp = LIST_FIRST(&p->p_lwps); + KASSERT(ied_lwp != NULL); error = irix_sys_procblk(ied_lwp, &cup, retval); if (error != 0) last_error = error; @@ -629,7 +632,10 @@ irix_prda_init(struct proc *p) evc.ev_len = sizeof(struct irix_prda); evc.ev_prot = UVM_PROT_RW; evc.ev_proc = *vmcmd_map_zero; - l = proc_representative_lwp(p, NULL, 0); + + /* XXXSMP */ + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); if ((error = (*evc.ev_proc)(l, &evc)) != 0) return error; diff --git a/sys/compat/mach/mach_exec.c b/sys/compat/mach/mach_exec.c index 480967475637..31cb55555d62 100644 --- a/sys/compat/mach/mach_exec.c +++ b/sys/compat/mach/mach_exec.c @@ -1,4 +1,4 @@ -/* $NetBSD: mach_exec.c,v 1.68 2008/04/28 20:23:44 martin Exp $ */ +/* $NetBSD: mach_exec.c,v 1.69 2008/07/02 19:49:58 rmind Exp $ */ /*- * Copyright (c) 2001-2003 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mach_exec.c,v 1.68 2008/04/28 20:23:44 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mach_exec.c,v 1.69 2008/07/02 19:49:58 rmind Exp $"); #include "opt_syscall_debug.h" @@ -189,8 +189,11 @@ mach_e_proc_exec(struct proc *p, struct exec_package *epp) { mach_e_proc_init(p, p->p_vmspace); - if (p->p_emul != epp->ep_esch->es_emul) - mach_e_lwp_fork(NULL, proc_representative_lwp(p, NULL, 1)); + if (p->p_emul != epp->ep_esch->es_emul) { + struct lwp *l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); + mach_e_lwp_fork(NULL, l); + } return; } @@ -346,10 +349,13 @@ mach_e_proc_exit(struct proc *p) { struct mach_emuldata *med; struct mach_right *mr; + struct lwp *l; int i; /* There is only one lwp remaining... */ - mach_e_lwp_exit(proc_representative_lwp(p, NULL, 1)); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); + mach_e_lwp_exit(l); med = (struct mach_emuldata *)p->p_emuldata; diff --git a/sys/compat/mach/mach_message.c b/sys/compat/mach/mach_message.c index ab83e9da7713..ccabcf7c92a4 100644 --- a/sys/compat/mach/mach_message.c +++ b/sys/compat/mach/mach_message.c @@ -1,4 +1,4 @@ -/* $NetBSD: mach_message.c,v 1.56 2008/04/28 20:23:44 martin Exp $ */ +/* $NetBSD: mach_message.c,v 1.57 2008/07/02 19:49:58 rmind Exp $ */ /*- * Copyright (c) 2002-2003 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mach_message.c,v 1.56 2008/04/28 20:23:44 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mach_message.c,v 1.57 2008/07/02 19:49:58 rmind Exp $"); #include "opt_compat_mach.h" /* For COMPAT_MACH in */ #include "opt_compat_darwin.h" @@ -676,7 +676,8 @@ mach_get_target_task(struct lwp *l, struct mach_port *mp) switch (mp->mp_datatype) { case MACH_MP_PROC: tp = (struct proc *)mp->mp_data; - tl = proc_representative_lwp(tp, NULL, 1); + tl = LIST_FIRST(&tp->p_lwps); + KASSERT(tl != NULL); break; case MACH_MP_LWP: diff --git a/sys/kern/init_sysctl.c b/sys/kern/init_sysctl.c index 66034ce26515..f1369b12bb49 100644 --- a/sys/kern/init_sysctl.c +++ b/sys/kern/init_sysctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: init_sysctl.c,v 1.142 2008/06/16 11:26:28 ad Exp $ */ +/* $NetBSD: init_sysctl.c,v 1.143 2008/07/02 19:49:58 rmind Exp $ */ /*- * Copyright (c) 2003, 2007, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.142 2008/06/16 11:26:28 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_sysctl.c,v 1.143 2008/07/02 19:49:58 rmind Exp $"); #include "opt_sysv.h" #include "opt_posix.h" @@ -2879,7 +2879,6 @@ fill_kproc2(struct proc *p, struct kinfo_proc2 *ki, bool zombie) sigset_t ss1, ss2; struct rusage ru; struct vmspace *vm; - int tmp; KASSERT(mutex_owned(proc_lock)); KASSERT(mutex_owned(p->p_lock)); @@ -2954,10 +2953,11 @@ fill_kproc2(struct proc *p, struct kinfo_proc2 *ki, bool zombie) ki->p_vm_dsize = vm->vm_dsize; ki->p_vm_ssize = vm->vm_ssize; - /* Pick a "representative" LWP */ - l = proc_representative_lwp(p, &tmp, 1); + /* Pick the primary (first) LWP */ + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); lwp_lock(l); - ki->p_nrlwps = tmp; + ki->p_nrlwps = p->p_nrlwps; ki->p_forw = 0; ki->p_back = 0; ki->p_addr = PTRTOUINT64(l->l_addr); @@ -3122,8 +3122,9 @@ fill_eproc(struct proc *p, struct eproc *ep, bool zombie) ep->e_vm.vm_dsize = vm->vm_dsize; ep->e_vm.vm_ssize = vm->vm_ssize; - /* Pick a "representative" LWP */ - l = proc_representative_lwp(p, NULL, 1); + /* Pick the primary (first) LWP */ + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); lwp_lock(l); if (l->l_wchan) strncpy(ep->e_wmesg, l->l_wmesg, WMESGLEN); diff --git a/sys/kern/kern_lwp.c b/sys/kern/kern_lwp.c index 50d952a8ac77..08904a4d6506 100644 --- a/sys/kern/kern_lwp.c +++ b/sys/kern/kern_lwp.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_lwp.c,v 1.119 2008/06/16 09:45:20 ad Exp $ */ +/* $NetBSD: kern_lwp.c,v 1.120 2008/07/02 19:49:58 rmind Exp $ */ /*- * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -206,7 +206,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.119 2008/06/16 09:45:20 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.120 2008/07/02 19:49:58 rmind Exp $"); #include "opt_ddb.h" #include "opt_lockdebug.h" @@ -938,115 +938,6 @@ lwp_free(struct lwp *l, bool recycle, bool last) pool_cache_put(lwp_cache, l); } -/* - * Pick a LWP to represent the process for those operations which - * want information about a "process" that is actually associated - * with a LWP. - * - * If 'locking' is false, no locking or lock checks are performed. - * This is intended for use by DDB. - * - * We don't bother locking the LWP here, since code that uses this - * interface is broken by design and an exact match is not required. - */ -struct lwp * -proc_representative_lwp(struct proc *p, int *nrlwps, int locking) -{ - struct lwp *l, *onproc, *running, *sleeping, *stopped, *suspended; - struct lwp *signalled; - int cnt; - - if (locking) { - KASSERT(mutex_owned(p->p_lock)); - } - - /* Trivial case: only one LWP */ - if (p->p_nlwps == 1) { - l = LIST_FIRST(&p->p_lwps); - if (nrlwps) - *nrlwps = (l->l_stat == LSONPROC || l->l_stat == LSRUN); - return l; - } - - cnt = 0; - switch (p->p_stat) { - case SSTOP: - case SACTIVE: - /* Pick the most live LWP */ - onproc = running = sleeping = stopped = suspended = NULL; - signalled = NULL; - LIST_FOREACH(l, &p->p_lwps, l_sibling) { - if ((l->l_flag & LW_IDLE) != 0) { - continue; - } - if (l->l_lid == p->p_sigctx.ps_lwp) - signalled = l; - switch (l->l_stat) { - case LSONPROC: - onproc = l; - cnt++; - break; - case LSRUN: - running = l; - cnt++; - break; - case LSSLEEP: - sleeping = l; - break; - case LSSTOP: - stopped = l; - break; - case LSSUSPENDED: - suspended = l; - break; - } - } - if (nrlwps) - *nrlwps = cnt; - if (signalled) - l = signalled; - else if (onproc) - l = onproc; - else if (running) - l = running; - else if (sleeping) - l = sleeping; - else if (stopped) - l = stopped; - else if (suspended) - l = suspended; - else - break; - return l; -#ifdef DIAGNOSTIC - case SIDL: - case SZOMB: - case SDYING: - case SDEAD: - if (locking) - mutex_exit(p->p_lock); - /* We have more than one LWP and we're in SIDL? - * How'd that happen? - */ - panic("Too many LWPs in idle/dying process %d (%s) stat = %d", - p->p_pid, p->p_comm, p->p_stat); - break; - default: - if (locking) - mutex_exit(p->p_lock); - panic("Process %d (%s) in unknown state %d", - p->p_pid, p->p_comm, p->p_stat); -#endif - } - - if (locking) - mutex_exit(p->p_lock); - panic("proc_representative_lwp: couldn't find a lwp for process" - " %d (%s)", p->p_pid, p->p_comm); - /* NOTREACHED */ - return NULL; -} - /* * Migrate the LWP to the another CPU. Unlocks the LWP. */ diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 7d2e637918cf..2c2341c64b9b 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -1,4 +1,4 @@ -/* $NetBSD: sys_process.c,v 1.140 2008/05/13 09:16:11 yamt Exp $ */ +/* $NetBSD: sys_process.c,v 1.141 2008/07/02 19:49:58 rmind Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -115,7 +115,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.140 2008/05/13 09:16:11 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.141 2008/07/02 19:49:58 rmind Exp $"); #include "opt_coredump.h" #include "opt_ptrace.h" @@ -364,7 +364,8 @@ sys_ptrace(struct lwp *l, const struct sys_ptrace_args *uap, register_t *retval) * this; memory access will be fine, but register access will * be weird. */ - lt = proc_representative_lwp(t, NULL, 1); + lt = LIST_FIRST(&t->p_lwps); + KASSERT(lt != NULL); lwp_addref(lt); /* diff --git a/sys/miscfs/procfs/procfs_subr.c b/sys/miscfs/procfs/procfs_subr.c index 4260e595f644..68d471a7eebd 100644 --- a/sys/miscfs/procfs/procfs_subr.c +++ b/sys/miscfs/procfs/procfs_subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: procfs_subr.c,v 1.90 2008/05/05 17:11:17 ad Exp $ */ +/* $NetBSD: procfs_subr.c,v 1.91 2008/07/02 19:49:58 rmind Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -102,7 +102,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.90 2008/05/05 17:11:17 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.91 2008/07/02 19:49:58 rmind Exp $"); #include #include @@ -372,7 +372,8 @@ procfs_rw(v) #undef M2K mutex_enter(p->p_lock); - l = proc_representative_lwp(p, NULL, 1); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); lwp_addref(l); mutex_exit(p->p_lock); diff --git a/sys/miscfs/procfs/procfs_vnops.c b/sys/miscfs/procfs/procfs_vnops.c index 34897cc0f89e..40e65064b46d 100644 --- a/sys/miscfs/procfs/procfs_vnops.c +++ b/sys/miscfs/procfs/procfs_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: procfs_vnops.c,v 1.169 2008/04/28 20:24:08 martin Exp $ */ +/* $NetBSD: procfs_vnops.c,v 1.170 2008/07/02 19:49:58 rmind Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -105,7 +105,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.169 2008/04/28 20:24:08 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.170 2008/07/02 19:49:58 rmind Exp $"); #include #include @@ -1069,7 +1069,8 @@ procfs_lookup(v) int found; mutex_enter(p->p_lock); - plwp = proc_representative_lwp(p, NULL, 1); + plwp = LIST_FIRST(&p->p_lwps); + KASSERT(plwp != NULL); lwp_addref(plwp); mutex_exit(p->p_lock); found = cnp->cn_namelen == pt->pt_namlen && @@ -1302,7 +1303,8 @@ procfs_readdir(v) if (pt->pt_valid) { /* XXXSMP LWP can disappear */ mutex_enter(p->p_lock); - l = proc_representative_lwp(p, NULL, 1); + l = LIST_FIRST(&p->p_lwps); + KASSERT(l != NULL); mutex_exit(p->p_lock); if ((*pt->pt_valid)(l, vp->v_mount) == 0) continue;