Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys - Amend fd_hold() to take an argument and add assert (re...



details:   https://anonhg.NetBSD.org/src/rev/1d2f1525cfd7
branches:  trunk
changeset: 748563:1d2f1525cfd7
user:      rmind <rmind%NetBSD.org@localhost>
date:      Tue Oct 27 02:58:28 2009 +0000

description:
- 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().

diffstat:

 sys/kern/kern_descrip.c |  10 ++++++----
 sys/kern/kern_lwp.c     |   6 +++---
 sys/sys/filedesc.h      |   4 ++--
 3 files changed, 11 insertions(+), 9 deletions(-)

diffs (78 lines):

diff -r 9ec1d4aa3b91 -r 1d2f1525cfd7 sys/kern/kern_descrip.c
--- a/sys/kern/kern_descrip.c   Tue Oct 27 02:55:07 2009 +0000
+++ b/sys/kern/kern_descrip.c   Tue Oct 27 02:58:28 2009 +0000
@@ -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 @@
  * 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 -r 9ec1d4aa3b91 -r 1d2f1525cfd7 sys/kern/kern_lwp.c
--- a/sys/kern/kern_lwp.c       Tue Oct 27 02:55:07 2009 +0000
+++ b/sys/kern/kern_lwp.c       Tue Oct 27 02:58:28 2009 +0000
@@ -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 @@
        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 -r 9ec1d4aa3b91 -r 1d2f1525cfd7 sys/sys/filedesc.h
--- a/sys/sys/filedesc.h        Tue Oct 27 02:55:07 2009 +0000
+++ b/sys/sys/filedesc.h        Tue Oct 27 02:58:28 2009 +0000
@@ -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 @@
 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);



Home | Main Index | Thread Index | Old Index