From 3219f9f3989238e48d2c6eeb05a2431877fe5d8d Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Thu, 12 Apr 2012 14:40:42 +0000 Subject: If the "main" thread exits it stays around but unlinks itself from the threads list. Calling TAILQ_NEXT on them is a bad idea and will panic the kernel. So check the P_WEXIT flag and pretend the thread doesn't exist if it is set. Also make PT_GET_THREAD_FIRST return the first thread on the threads list instead of the "main" thread, such that you can actually keep enumerating the threads in this case. ok guenther@, miod@ --- sys/kern/sys_process.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'sys/kern') diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 0d5248d29c0..480f42dd0e3 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_process.c,v 1.54 2012/04/12 12:09:05 kettenis Exp $ */ +/* $OpenBSD: sys_process.c,v 1.55 2012/04/12 14:40:41 kettenis Exp $ */ /* $NetBSD: sys_process.c,v 1.55 1996/05/15 06:17:47 tls Exp $ */ /*- @@ -308,11 +308,13 @@ sys_ptrace(struct proc *p, void *v, register_t *retval) return (error); t = pfind(pts.pts_tid - THREAD_PID_OFFSET); - if (t == NULL) + if (t == NULL || ISSET(t->p_flag, P_WEXIT)) return (ESRCH); if (t->p_p != tr) return (EINVAL); t = TAILQ_NEXT(t, p_thr_link); + } else { + t = TAILQ_FIRST(&tr->ps_threads); } if (t == NULL) -- cgit v1.2.3