kern_descrip.c (152280) | kern_descrip.c (152948) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94 35 */ 36 37#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1982, 1986, 1989, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 21 unchanged lines hidden (view full) --- 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94 35 */ 36 37#include <sys/cdefs.h> |
38__FBSDID("$FreeBSD: head/sys/kern/kern_descrip.c 152280 2005-11-10 13:26:29Z rwatson $"); | 38__FBSDID("$FreeBSD: head/sys/kern/kern_descrip.c 152948 2005-11-30 05:12:03Z davidxu $"); |
39 40#include "opt_compat.h" 41#include "opt_ddb.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> 45 46#include <sys/conf.h> 47#include <sys/fcntl.h> 48#include <sys/file.h> 49#include <sys/filedesc.h> 50#include <sys/filio.h> 51#include <sys/jail.h> 52#include <sys/kernel.h> 53#include <sys/limits.h> 54#include <sys/lock.h> 55#include <sys/malloc.h> 56#include <sys/mount.h> | 39 40#include "opt_compat.h" 41#include "opt_ddb.h" 42 43#include <sys/param.h> 44#include <sys/systm.h> 45 46#include <sys/conf.h> 47#include <sys/fcntl.h> 48#include <sys/file.h> 49#include <sys/filedesc.h> 50#include <sys/filio.h> 51#include <sys/jail.h> 52#include <sys/kernel.h> 53#include <sys/limits.h> 54#include <sys/lock.h> 55#include <sys/malloc.h> 56#include <sys/mount.h> |
57#include <sys/mqueue.h> |
|
57#include <sys/mutex.h> 58#include <sys/namei.h> 59#include <sys/proc.h> 60#include <sys/resourcevar.h> 61#include <sys/signalvar.h> 62#include <sys/socketvar.h> 63#include <sys/stat.h> 64#include <sys/sx.h> --- 64 unchanged lines hidden (view full) --- 129 130/* 131 * Descriptor management. 132 */ 133struct filelist filehead; /* head of list of open files */ 134int openfiles; /* actual number of open files */ 135struct sx filelist_lock; /* sx to protect filelist */ 136struct mtx sigio_lock; /* mtx to protect pointers to sigio */ | 58#include <sys/mutex.h> 59#include <sys/namei.h> 60#include <sys/proc.h> 61#include <sys/resourcevar.h> 62#include <sys/signalvar.h> 63#include <sys/socketvar.h> 64#include <sys/stat.h> 65#include <sys/sx.h> --- 64 unchanged lines hidden (view full) --- 130 131/* 132 * Descriptor management. 133 */ 134struct filelist filehead; /* head of list of open files */ 135int openfiles; /* actual number of open files */ 136struct sx filelist_lock; /* sx to protect filelist */ 137struct mtx sigio_lock; /* mtx to protect pointers to sigio */ |
138void (*mq_fdclose)(struct thread *td, int fd, struct file *fp); |
|
137 138/* A mutex to protect the association between a proc and filedesc. */ 139static struct mtx fdesc_mtx; 140 141/* 142 * Find the first zero bit in the given bitmap, starting at low and not 143 * exceeding size - 1. 144 */ --- 563 unchanged lines hidden (view full) --- 708 * If we dup'd over a valid file, we now own the reference to it 709 * and must dispose of it using closef() semantics (as if a 710 * close() were performed on it). 711 * 712 * XXX this duplicates parts of close(). 713 */ 714 if (delfp != NULL) { 715 knote_fdclose(td, new); | 139 140/* A mutex to protect the association between a proc and filedesc. */ 141static struct mtx fdesc_mtx; 142 143/* 144 * Find the first zero bit in the given bitmap, starting at low and not 145 * exceeding size - 1. 146 */ --- 563 unchanged lines hidden (view full) --- 710 * If we dup'd over a valid file, we now own the reference to it 711 * and must dispose of it using closef() semantics (as if a 712 * close() were performed on it). 713 * 714 * XXX this duplicates parts of close(). 715 */ 716 if (delfp != NULL) { 717 knote_fdclose(td, new); |
718 if (delfp->f_type == DTYPE_MQUEUE) 719 mq_fdclose(td, new, delfp); |
|
716 FILEDESC_UNLOCK(fdp); 717 (void) closef(delfp, td); 718 if (holdleaders) { 719 FILEDESC_LOCK_FAST(fdp); 720 fdp->fd_holdleaderscount--; 721 if (fdp->fd_holdleaderscount == 0 && 722 fdp->fd_holdleaderswakeup != 0) { 723 fdp->fd_holdleaderswakeup = 0; --- 273 unchanged lines hidden (view full) --- 997 /* 998 * We now hold the fp reference that used to be owned by the descriptor 999 * array. 1000 * We have to unlock the FILEDESC *AFTER* knote_fdclose to prevent a 1001 * race of the fd getting opened, a knote added, and deleteing a knote 1002 * for the new fd. 1003 */ 1004 knote_fdclose(td, fd); | 720 FILEDESC_UNLOCK(fdp); 721 (void) closef(delfp, td); 722 if (holdleaders) { 723 FILEDESC_LOCK_FAST(fdp); 724 fdp->fd_holdleaderscount--; 725 if (fdp->fd_holdleaderscount == 0 && 726 fdp->fd_holdleaderswakeup != 0) { 727 fdp->fd_holdleaderswakeup = 0; --- 273 unchanged lines hidden (view full) --- 1001 /* 1002 * We now hold the fp reference that used to be owned by the descriptor 1003 * array. 1004 * We have to unlock the FILEDESC *AFTER* knote_fdclose to prevent a 1005 * race of the fd getting opened, a knote added, and deleteing a knote 1006 * for the new fd. 1007 */ 1008 knote_fdclose(td, fd); |
1009 if (fp->f_type == DTYPE_MQUEUE) 1010 mq_fdclose(td, fd, fp); |
|
1005 FILEDESC_UNLOCK(fdp); 1006 1007 error = closef(fp, td); 1008 if (holdleaders) { 1009 FILEDESC_LOCK_FAST(fdp); 1010 fdp->fd_holdleaderscount--; 1011 if (fdp->fd_holdleaderscount == 0 && 1012 fdp->fd_holdleaderswakeup != 0) { --- 748 unchanged lines hidden (view full) --- 1761 FILEDESC_LOCK(fdp); 1762 1763 /* 1764 * We cannot cache fd_ofiles or fd_ofileflags since operations 1765 * may block and rip them out from under us. 1766 */ 1767 for (i = 0; i <= fdp->fd_lastfile; i++) { 1768 if (fdp->fd_ofiles[i] != NULL && | 1011 FILEDESC_UNLOCK(fdp); 1012 1013 error = closef(fp, td); 1014 if (holdleaders) { 1015 FILEDESC_LOCK_FAST(fdp); 1016 fdp->fd_holdleaderscount--; 1017 if (fdp->fd_holdleaderscount == 0 && 1018 fdp->fd_holdleaderswakeup != 0) { --- 748 unchanged lines hidden (view full) --- 1767 FILEDESC_LOCK(fdp); 1768 1769 /* 1770 * We cannot cache fd_ofiles or fd_ofileflags since operations 1771 * may block and rip them out from under us. 1772 */ 1773 for (i = 0; i <= fdp->fd_lastfile; i++) { 1774 if (fdp->fd_ofiles[i] != NULL && |
1769 (fdp->fd_ofileflags[i] & UF_EXCLOSE)) { | 1775 (fdp->fd_ofiles[i]->f_type == DTYPE_MQUEUE || 1776 (fdp->fd_ofileflags[i] & UF_EXCLOSE))) { |
1770 struct file *fp; 1771 1772 knote_fdclose(td, i); 1773 /* 1774 * NULL-out descriptor prior to close to avoid 1775 * a race while close blocks. 1776 */ 1777 fp = fdp->fd_ofiles[i]; 1778 fdp->fd_ofiles[i] = NULL; 1779 fdp->fd_ofileflags[i] = 0; 1780 fdunused(fdp, i); | 1777 struct file *fp; 1778 1779 knote_fdclose(td, i); 1780 /* 1781 * NULL-out descriptor prior to close to avoid 1782 * a race while close blocks. 1783 */ 1784 fp = fdp->fd_ofiles[i]; 1785 fdp->fd_ofiles[i] = NULL; 1786 fdp->fd_ofileflags[i] = 0; 1787 fdunused(fdp, i); |
1788 if (fp->f_type == DTYPE_MQUEUE) 1789 mq_fdclose(td, i, fp); |
|
1781 FILEDESC_UNLOCK(fdp); 1782 (void) closef(fp, td); 1783 FILEDESC_LOCK(fdp); 1784 } 1785 } 1786 FILEDESC_UNLOCK(fdp); 1787} 1788 --- 882 unchanged lines hidden --- | 1790 FILEDESC_UNLOCK(fdp); 1791 (void) closef(fp, td); 1792 FILEDESC_LOCK(fdp); 1793 } 1794 } 1795 FILEDESC_UNLOCK(fdp); 1796} 1797 --- 882 unchanged lines hidden --- |