- 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().
This commit is contained in:
rmind 2009-10-27 02:58:28 +00:00
parent 0ca6708c13
commit e4be2748a3
3 changed files with 11 additions and 9 deletions

View File

@ -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 <sys/cdefs.h>
__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 <sys/param.h>
#include <sys/systm.h>
@ -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);
}
/*

View File

@ -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 <sys/cdefs.h>
__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);
}

View File

@ -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);