kern_descrip.c (92641) | kern_descrip.c (92654) |
---|---|
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. --- 22 unchanged lines hidden (view full) --- 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94 | 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. --- 22 unchanged lines hidden (view full) --- 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94 |
39 * $FreeBSD: head/sys/kern/kern_descrip.c 92641 2002-03-19 04:30:04Z alfred $ | 39 * $FreeBSD: head/sys/kern/kern_descrip.c 92654 2002-03-19 09:11:49Z jeff $ |
40 */ 41 42#include "opt_compat.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/lock.h> 47#include <sys/malloc.h> --- 14 unchanged lines hidden (view full) --- 62#include <sys/event.h> 63#include <sys/sx.h> 64#include <sys/socketvar.h> 65 66#include <machine/limits.h> 67 68#include <vm/vm.h> 69#include <vm/vm_extern.h> | 40 */ 41 42#include "opt_compat.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/lock.h> 47#include <sys/malloc.h> --- 14 unchanged lines hidden (view full) --- 62#include <sys/event.h> 63#include <sys/sx.h> 64#include <sys/socketvar.h> 65 66#include <machine/limits.h> 67 68#include <vm/vm.h> 69#include <vm/vm_extern.h> |
70#include <vm/vm_zone.h> |
|
70 71static MALLOC_DEFINE(M_FILEDESC, "file desc", "Open file descriptor table"); | 71 72static MALLOC_DEFINE(M_FILEDESC, "file desc", "Open file descriptor table"); |
72MALLOC_DEFINE(M_FILE, "file", "Open file structure"); | |
73static MALLOC_DEFINE(M_SIGIO, "sigio", "sigio structures"); 74 | 73static MALLOC_DEFINE(M_SIGIO, "sigio", "sigio structures"); 74 |
75uma_zone_t file_zone; 76 |
|
75static d_open_t fdopen; 76#define NUMFDESC 64 77 78#define CDEV_MAJOR 22 79static struct cdevsw fildesc_cdevsw = { 80 /* open */ fdopen, 81 /* close */ noclose, 82 /* read */ noread, --- 1007 unchanged lines hidden (view full) --- 1090 nfiles++; 1091 sx_xunlock(&filelist_lock); 1092 /* 1093 * Allocate a new file descriptor. 1094 * If the process has file descriptor zero open, add to the list 1095 * of open files at that point, otherwise put it at the front of 1096 * the list of open files. 1097 */ | 77static d_open_t fdopen; 78#define NUMFDESC 64 79 80#define CDEV_MAJOR 22 81static struct cdevsw fildesc_cdevsw = { 82 /* open */ fdopen, 83 /* close */ noclose, 84 /* read */ noread, --- 1007 unchanged lines hidden (view full) --- 1092 nfiles++; 1093 sx_xunlock(&filelist_lock); 1094 /* 1095 * Allocate a new file descriptor. 1096 * If the process has file descriptor zero open, add to the list 1097 * of open files at that point, otherwise put it at the front of 1098 * the list of open files. 1099 */ |
1098 MALLOC(fp, struct file *, sizeof(struct file), M_FILE, M_WAITOK | M_ZERO); | 1100 fp = uma_zalloc(file_zone, M_WAITOK); 1101 bzero(fp, sizeof(*fp)); |
1099 1100 /* 1101 * wait until after malloc (which may have blocked) returns before 1102 * allocating the slot, else a race might have shrunk it if we had 1103 * allocated it before the malloc. 1104 */ 1105 FILEDESC_LOCK(p->p_fd); 1106 if ((error = fdalloc(td, 0, &i))) { 1107 FILEDESC_UNLOCK(p->p_fd); 1108 sx_xlock(&filelist_lock); 1109 nfiles--; 1110 sx_xunlock(&filelist_lock); | 1102 1103 /* 1104 * wait until after malloc (which may have blocked) returns before 1105 * allocating the slot, else a race might have shrunk it if we had 1106 * allocated it before the malloc. 1107 */ 1108 FILEDESC_LOCK(p->p_fd); 1109 if ((error = fdalloc(td, 0, &i))) { 1110 FILEDESC_UNLOCK(p->p_fd); 1111 sx_xlock(&filelist_lock); 1112 nfiles--; 1113 sx_xunlock(&filelist_lock); |
1111 FREE(fp, M_FILE); | 1114 uma_zfree(file_zone, fp); |
1112 return (error); 1113 } 1114 fp->f_mtxp = mtx_pool_alloc(); 1115 fp->f_gcflag = 0; 1116 fp->f_count = 1; 1117 fp->f_cred = crhold(td->td_ucred); 1118 fp->f_ops = &badfileops; 1119 fp->f_seqcount = 1; --- 24 unchanged lines hidden (view full) --- 1144{ 1145 1146 KASSERT((fp->f_count == 0), ("ffree: fp_fcount not 0!")); 1147 sx_xlock(&filelist_lock); 1148 LIST_REMOVE(fp, f_list); 1149 nfiles--; 1150 sx_xunlock(&filelist_lock); 1151 crfree(fp->f_cred); | 1115 return (error); 1116 } 1117 fp->f_mtxp = mtx_pool_alloc(); 1118 fp->f_gcflag = 0; 1119 fp->f_count = 1; 1120 fp->f_cred = crhold(td->td_ucred); 1121 fp->f_ops = &badfileops; 1122 fp->f_seqcount = 1; --- 24 unchanged lines hidden (view full) --- 1147{ 1148 1149 KASSERT((fp->f_count == 0), ("ffree: fp_fcount not 0!")); 1150 sx_xlock(&filelist_lock); 1151 LIST_REMOVE(fp, f_list); 1152 nfiles--; 1153 sx_xunlock(&filelist_lock); 1154 crfree(fp->f_cred); |
1152 FREE(fp, M_FILE); | 1155 uma_zfree(file_zone, fp); |
1153} 1154 1155/* 1156 * Build a new filedesc structure. 1157 */ 1158struct filedesc * 1159fdinit(td) 1160 struct thread *td; --- 945 unchanged lines hidden (view full) --- 2106static void filelistinit __P((void *)); 2107SYSINIT(select, SI_SUB_LOCK, SI_ORDER_FIRST, filelistinit, NULL) 2108 2109/* ARGSUSED*/ 2110static void 2111filelistinit(dummy) 2112 void *dummy; 2113{ | 1156} 1157 1158/* 1159 * Build a new filedesc structure. 1160 */ 1161struct filedesc * 1162fdinit(td) 1163 struct thread *td; --- 945 unchanged lines hidden (view full) --- 2109static void filelistinit __P((void *)); 2110SYSINIT(select, SI_SUB_LOCK, SI_ORDER_FIRST, filelistinit, NULL) 2111 2112/* ARGSUSED*/ 2113static void 2114filelistinit(dummy) 2115 void *dummy; 2116{ |
2117 file_zone = uma_zcreate("Files", sizeof(struct file), NULL, NULL, 2118 NULL, NULL, UMA_ALIGN_PTR, 0); 2119 |
|
2114 sx_init(&filelist_lock, "filelist lock"); 2115} | 2120 sx_init(&filelist_lock, "filelist lock"); 2121} |