From e4be2748a36158a82ebe911cf8e102ea5cdf9b8e Mon Sep 17 00:00:00 2001 From: rmind Date: Tue, 27 Oct 2009 02:58:28 +0000 Subject: [PATCH] - Amend fd_hold() to take an argument and add assert (reflects two cases, fork1() and the rest, e.g. kthread_create(), when creating from lwp0). - lwp_create(): do not touch filedesc internals, use fd_hold(). --- sys/kern/kern_descrip.c | 10 ++++++---- sys/kern/kern_lwp.c | 6 +++--- sys/sys/filedesc.h | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index c4ed03721572..a4d200b391bb 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_descrip.c,v 1.199 2009/08/16 11:00:20 yamt Exp $ */ +/* $NetBSD: kern_descrip.c,v 1.200 2009/10/27 02:58:28 rmind Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.199 2009/08/16 11:00:20 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_descrip.c,v 1.200 2009/10/27 02:58:28 rmind Exp $"); #include #include @@ -1326,10 +1326,12 @@ fd_share(struct proc *p2) * Acquire a hold on a filedesc structure. */ void -fd_hold(void) +fd_hold(lwp_t *l) { + filedesc_t *fdp = l->l_fd; - atomic_inc_uint(&curlwp->l_fd->fd_refcnt); + KASSERT(fdp == curlwp->l_fd || fdp == lwp0.l_fd); + atomic_inc_uint(&fdp->fd_refcnt); } /* diff --git a/sys/kern/kern_lwp.c b/sys/kern/kern_lwp.c index ee3f5c6cbf60..df797e31c070 100644 --- a/sys/kern/kern_lwp.c +++ b/sys/kern/kern_lwp.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_lwp.c,v 1.135 2009/10/22 22:28:57 rmind Exp $ */ +/* $NetBSD: kern_lwp.c,v 1.136 2009/10/27 02:58:28 rmind Exp $ */ /*- * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -209,7 +209,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.135 2009/10/22 22:28:57 rmind Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.136 2009/10/27 02:58:28 rmind Exp $"); #include "opt_ddb.h" #include "opt_lockdebug.h" @@ -606,7 +606,7 @@ lwp_create(lwp_t *l1, proc_t *p2, vaddr_t uaddr, int flags, l2->l_fd = p2->p_fd; if (p2->p_nlwps != 0) { KASSERT(l1->l_proc == p2); - atomic_inc_uint(&l2->l_fd->fd_refcnt); + fd_hold(l2); } else { KASSERT(l1->l_proc != p2); } diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index a8329b996bb2..5e4213e9155f 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -1,4 +1,4 @@ -/* $NetBSD: filedesc.h,v 1.56 2009/05/25 03:59:45 yamt Exp $ */ +/* $NetBSD: filedesc.h,v 1.57 2009/10/27 02:58:28 rmind Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -190,7 +190,7 @@ void fd_abort(struct proc *, file_t *, unsigned); filedesc_t *fd_copy(void); filedesc_t *fd_init(filedesc_t *); void fd_share(proc_t *); -void fd_hold(void); +void fd_hold(lwp_t *); void fd_free(void); void fd_closeexec(void); int fd_checkstd(void);