aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/filedesc.h
Commit message (Collapse)AuthorAgeFilesLines
* Remove advertising clause from University of California Regent's license,Warner Losh2004-04-071-4/+0
| | | | | | | | | per letter dated July 22, 1999. Approved by: core Notes: svn path=/head/; revision=127976
* Fixed the XXX'ed namespace pollution in rev.1.54 by usingBruce Evans2004-03-041-2/+3
| | | | | | | | <machine/limits.h> and __CHAR_BIT instead of <sys/limits.h> and CHAR_BIT. some reason I didn't use the BSD spelling NBBY. Notes: svn path=/head/; revision=126593
* Don't manually optimize for 20 year old compilers by casting to u_intBruce Evans2004-03-041-2/+1
| | | | | | | | to get a free check for negative ints. Rev.1.35 got my request to remove the cast mostly backwards. Notes: svn path=/head/; revision=126592
* Fixed some style bugs (mainly misformatting, and pointers to `struct thread'Bruce Evans2004-03-041-15/+14
| | | | | | | named p). Notes: svn path=/head/; revision=126591
* Fixed insertion sort errors in includes and prototypes. This was moreBruce Evans2004-03-041-13/+7
| | | | | | | | | | | | than a style bug for the includes -- queue.h is a prerequisite for _lock.h and _mutex.h but was included after them. Removed bogus prototype for fget_locked(). The prototype was originally needed to support K&R but was bogotified by converting the function header to new-style. Notes: svn path=/head/; revision=126590
* Restore correct semantics for F_DUPFD fcntl. This should fix the errorsDag-Erling Smørgrav2004-01-171-1/+1
| | | | | | | people have been getting with configure scripts. Notes: svn path=/head/; revision=124602
* New file descriptor allocation code, derived from similar code introducedDag-Erling Smørgrav2004-01-151-6/+13
| | | | | | | | | | | | | | in OpenBSD by Niels Provos. The patch introduces a bitmap of allocated file descriptors which is used to locate available descriptors when a new one is needed. It also moves the task of growing the file descriptor table out of fdalloc(), reducing complexity in both fdalloc() and do_dup(). Debts of gratitude are owed to tjr@ (who provided the original patch on which this work is based), grog@ (for the gdb(4) man page) and rwatson@ (for assistance with pxeboot(8)). Notes: svn path=/head/; revision=124548
* Remove long dead code, specifically, code related to munmapfd().Alan Cox2004-01-111-3/+0
| | | | | | | (See also vm/vm_mmap.c revision 1.173.) Notes: svn path=/head/; revision=124366
* Add an implementation of turnstiles and change the sleep mutex code to useJohn Baldwin2003-11-111-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | turnstiles to implement blocking isntead of implementing a thread queue directly. These turnstiles are somewhat similar to those used in Solaris 7 as described in Solaris Internals but are also different. Turnstiles do not come out of a fixed-sized pool. Rather, each thread is assigned a turnstile when it is created that it frees when it is destroyed. When a thread blocks on a lock, it donates its turnstile to that lock to serve as queue of blocked threads. The queue associated with a given lock is found by a lookup in a simple hash table. The turnstile itself is protected by a lock associated with its entry in the hash table. This means that sched_lock is no longer needed to contest on a mutex. Instead, sched_lock is only used when manipulating run queues or thread priorities. Turnstiles also implement priority propagation inherently. Currently turnstiles only support mutexes. Eventually, however, turnstiles may grow two queue's to support a non-sleepable reader/writer lock implementation. For more details, see the comments in sys/turnstile.h and kern/subr_turnstile.c. The two primary advantages from the turnstile code include: 1) the size of struct mutex shrinks by four pointers as it no longer stores the thread queue linkages directly, and 2) less contention on sched_lock in SMP systems including the ability for multiple CPUs to contend on different locks simultaneously (not that this last detail is necessarily that much of a big win). Note that 1) means that this commit is a kernel ABI breaker, so don't mix old modules with a new kernel and vice versa. Tested on: i386 SMP, sparc64 SMP, alpha SMP Notes: svn path=/head/; revision=122514
* Add tracking of process leaders sharing a file descriptor table andTor Egge2003-06-021-0/+29
| | | | | | | | | | allow a file descriptor table to be shared between multiple process leaders. PR: 50923 Notes: svn path=/head/; revision=115702
* Fix LOR with PROC/filedesc. Introduce fdesc_mtx that will be used as aAlfred Perlstein2003-02-151-0/+2
| | | | | | | | | barrier between free'ing filedesc structures. Basically if you want to access another process's filedesc, you want to hold this mutex over the entire operation. Notes: svn path=/head/; revision=110906
* When compiling the kernel do not implicitly include filedesc.h from proc.h,Alfred Perlstein2003-01-011-30/+0
| | | | | | | | | this was causing filedesc work to be very painful. In order to make this work split out sigio definitions to thier own header (sigio.h) which is included from proc.h for the time being. Notes: svn path=/head/; revision=108524
* fdcopy() only needs a filedesc pointer.Alfred Perlstein2003-01-011-1/+1
| | | | Notes: svn path=/head/; revision=108522
* Since fdshare() and fdinit() only operate on filedescs, make themAlfred Perlstein2003-01-011-2/+2
| | | | | | | | | | | take pointers to filedesc structures instead of threads. This makes it more clear that they do not do any voodoo with the thread/proc or anything other than the filedesc passed in or returned. Remove some XXX KSE's as this resolves the issue. Notes: svn path=/head/; revision=108520
* In an SMP environment post-Giant it is no longer safe to blindlyDon Lewis2002-10-031-1/+1
| | | | | | | | | | | | dereference the struct sigio pointer without any locking. Change fgetown() to take a reference to the pointer instead of a copy of the pointer and call SIGIO_LOCK() before copying the pointer and dereferencing it. Reviewed by: rwatson Notes: svn path=/head/; revision=104393
* ISOfy and minor warnsfix.Mark Murray2002-07-151-4/+2
| | | | Notes: svn path=/head/; revision=100072
* Make funsetown() take a 'struct sigio **' so that the locking canAlfred Perlstein2002-05-061-1/+1
| | | | | | | | | | | | | | | | | | | be done internally. Ensure that no one can fsetown() to a dying process/pgrp. We need to check the process for P_WEXIT to see if it's exiting. Process groups are already safe because there is no such thing as a pgrp zombie, therefore the proctree lock completely protects the pgrp from having sigio structures associated with it after it runs funsetownlst. Add sigio lock to witness list under proctree and allproc, but over proc and pgrp. Seigo Tanimura helped with this. Notes: svn path=/head/; revision=96122
* Revert the change of #includes in sys/filedesc.h and sys/socketvar.h.Seigo Tanimura2002-04-301-15/+2
| | | | | | | | | | | | | Requested by: bde Since locking sigio_lock is usually followed by calling pgsigio(), move the declaration of sigio_lock and the definitions of SIGIO_*() to sys/signalvar.h. While I am here, sort include files alphabetically, where possible. Notes: svn path=/head/; revision=95759
* Add a global sx sigio_lock to protect the pointer to the sigio objectSeigo Tanimura2002-04-271-2/+15
| | | | | | | | | | | | | of a socket. This avoids lock order reversal caused by locking a process in pgsigio(). sowakeup() and the callers of it (sowwakeup, soisconnected, etc.) now require sigio_lock to be locked. Provide sowwakeup_locked(), soisconnected_locked(), and so on in case where we have to modify a socket and wake up a process atomically. Notes: svn path=/head/; revision=95552
* When exec'ing a set[ug]id program, make sure that the stdio file descriptorsJacques Vidrine2002-04-191-0/+1
| | | | | | | | | | | (0, 1, 2) are allocated by opening /dev/null for any which are not already open. Reviewed by: alfred, phk MFC after: 2 days Notes: svn path=/head/; revision=95017
* The description of fd_mtx is "filedesc structure."Seigo Tanimura2002-03-291-0/+2
| | | | Notes: svn path=/head/; revision=93384
* Fixed some style bugs in the removal of __P(()). The main ones wereBruce Evans2002-03-231-2/+2
| | | | | | | | | not removing tabs before "__P((", and not outdenting continuation lines to preserve non-KNF lining up of code with parentheses. Switch to KNF formatting and/or rewrap the whole prototype in some cases. Notes: svn path=/head/; revision=93008
* Remove __PAlfred Perlstein2002-03-191-19/+19
| | | | Notes: svn path=/head/; revision=92719
* Lock struct pgrp, session and sigio.Seigo Tanimura2002-02-231-7/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | New locks are: - pgrpsess_lock which locks the whole pgrps and sessions, - pg_mtx which protects the pgrp members, and - s_mtx which protects the session members. Please refer to sys/proc.h for the coverage of these locks. Changes on the pgrp/session interface: - pgfind() needs the pgrpsess_lock held. - The caller of enterpgrp() is responsible to allocate a new pgrp and session. - Call enterthispgrp() in order to enter an existing pgrp. - pgsignal() requires a pgrp lock held. Reviewed by: jhb, alfred Tested on: cvsup.jp.FreeBSD.org (which is a quad-CPU machine running -current) Notes: svn path=/head/; revision=91140
* Remove an unneeded include of sys/sx.h. An older pre-commit version ofJohn Baldwin2002-02-141-1/+0
| | | | | | | | the filedesc locking used an sx lock for the filedesc lock rather than a mutex which is why the include was here. Notes: svn path=/head/; revision=90658
* fget_locked fixes.Alfred Perlstein2002-01-301-4/+3
| | | | | | | | | | | sort declaration. give paramters names. remove bogus check for negative fd (u_int) cast does this for us. Pointed out by: bde Notes: svn path=/head/; revision=89997
* Attempt to fixup select(2) and poll(2), this should fix some races withAlfred Perlstein2002-01-291-0/+12
| | | | | | | | | | | | | | | | | | | | | | other threads as well as speed up the interfaces. To fix the race and accomplish the speedup, remove selholddrop and pollholddrop. The entire concept is somewhat bogus because holding the individual struct file pointers offers us no guarantees that another thread context won't close it on us thereby removing our access to our own reference. Selholddrop and pollholddrop also would do multiple locks and unlocks of mutexes _per-file_ in the fd arrays to be scanned, this needed to be sped up. Instead of using selholddrop and pollholddrop, simply hold the filedesc lock over the selscan and pollscan functions. This should protect us against close(2)'s on the files as reduce the multiple lock/unlock pairs per fd into a single lock over the filedesc. Notes: svn path=/head/; revision=89969
* Remove holdfp() prototype now that the function no longer existsAlfred Perlstein2002-01-231-1/+0
| | | | Notes: svn path=/head/; revision=89697
* Include sys/_lock.h and sys/_mutex.h to reduce namespace pollution.Alfred Perlstein2002-01-131-2/+2
| | | | | | | Requested by: jhb Notes: svn path=/head/; revision=89316
* Remove file locking debug cruft.Alfred Perlstein2002-01-131-14/+0
| | | | Notes: svn path=/head/; revision=89307
* SMP Lock struct file, filedesc and the global file list.Alfred Perlstein2002-01-131-2/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Seigo Tanimura (tanimura) posted the initial delta. I've polished it quite a bit reducing the need for locking and adapting it for KSE. Locks: 1 mutex in each filedesc protects all the fields. protects "struct file" initialization, while a struct file is being changed from &badfileops -> &pipeops or something the filedesc should be locked. 1 mutex in each struct file protects the refcount fields. doesn't protect anything else. the flags used for garbage collection have been moved to f_gcflag which was the FILLER short, this doesn't need locking because the garbage collection is a single threaded container. could likely be made to use a pool mutex. 1 sx lock for the global filelist. struct file * fhold(struct file *fp); /* increments reference count on a file */ struct file * fhold_locked(struct file *fp); /* like fhold but expects file to locked */ struct file * ffind_hold(struct thread *, int fd); /* finds the struct file in thread, adds one reference and returns it unlocked */ struct file * ffind_lock(struct thread *, int fd); /* ffind_hold, but returns file locked */ I still have to smp-safe the fget cruft, I'll get to that asap. Notes: svn path=/head/; revision=89306
* KSE Milestone 2Julian Elischer2001-09-121-10/+10
| | | | | | | | | | | | | | | | | Note ALL MODULES MUST BE RECOMPILED make the kernel aware that there are smaller units of scheduling than the process. (but only allow one thread per process at this time). This is functionally equivalent to teh previousl -current except that there is a thread associated with each process. Sorry john! (your next MFC will be a doosie!) Reviewed by: peter@freebsd.org, dillon@freebsd.org X-MFC after: ha ha ha ha Notes: svn path=/head/; revision=83366
* style(9) the structure definitions.David E. O'Brien2001-09-051-1/+1
| | | | Notes: svn path=/head/; revision=83045
* o Merge contents of struct pcred into struct ucred. Specifically, add theRobert Watson2001-05-251-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | real uid, saved uid, real gid, and saved gid to ucred, as well as the pcred->pc_uidinfo, which was associated with the real uid, only rename it to cr_ruidinfo so as not to conflict with cr_uidinfo, which corresponds to the effective uid. o Remove p_cred from struct proc; add p_ucred to struct proc, replacing original macro that pointed. p->p_ucred to p->p_cred->pc_ucred. o Universally update code so that it makes use of ucred instead of pcred, p->p_ucred instead of p->p_pcred, cr_ruidinfo instead of p_uidinfo, cr_{r,sv}{u,g}id instead of p_*, etc. o Remove pcred0 and its initialization from init_main.c; initialize cr_ruidinfo there. o Restruction many credential modification chunks to always crdup while we figure out locking and optimizations; generally speaking, this means moving to a structure like this: newcred = crdup(oldcred); ... p->p_ucred = newcred; crfree(oldcred); It's not race-free, but better than nothing. There are also races in sys_process.c, all inter-process authorization, fork, exec, and exit. o Remove sigio->sio_ruid since sigio->sio_ucred now contains the ruid; remove comments indicating that the old arrangement was a problem. o Restructure exec1() a little to use newcred/oldcred arrangement, and use improved uid management primitives. o Clean up exit1() so as to do less work in credential cleanup due to pcred removal. o Clean up fork1() so as to do less work in credential cleanup and allocation. o Clean up ktrcanset() to take into account changes, and move to using suser_xxx() instead of performing a direct uid==0 comparision. o Improve commenting in various kern_prot.c credential modification calls to better document current behavior. In a couple of places, current behavior is a little questionable and we need to check POSIX.1 to make sure it's "right". More commenting work still remains to be done. o Update credential management calls, such as crfree(), to take into account new ruidinfo reference. o Modify or add the following uid and gid helper routines: change_euid() change_egid() change_ruid() change_rgid() change_svuid() change_svgid() In each case, the call now acts on a credential not a process, and as such no longer requires more complicated process locking/etc. They now assume the caller will do any necessary allocation of an exclusive credential reference. Each is commented to document its reference requirements. o CANSIGIO() is simplified to require only credentials, not processes and pcreds. o Remove lots of (p_pcred==NULL) checks. o Add an XXX to authorization code in nfs_lock.c, since it's questionable, and needs to be considered carefully. o Simplify posix4 authorization code to require only credentials, not processes and pcreds. Note that this authorization, as well as CANSIGIO(), needs to be updated to use the p_cansignal() and p_cansched() centralized authorization routines, as they currently do not take into account some desirable restrictions that are handled by the centralized routines, as well as being inconsistent with other similar authorization instances. o Update libkvm to take these changes into account. Obtained from: TrustedBSD Project Reviewed by: green, bde, jhb, freebsd-arch, freebsd-audit Notes: svn path=/head/; revision=77183
* This patchset fixes a large number of file descriptor race conditions.Matthew Dillon2000-11-181-2/+4
| | | | | | | | | | | | | | | Pre-rfork code assumed inherent locking of a process's file descriptor array. However, with the advent of rfork() the file descriptor table could be shared between processes. This patch closes over a dozen serious race conditions related to one thread manipulating the table (e.g. closing or dup()ing a descriptor) while another is blocked in an open(), close(), fcntl(), read(), write(), etc... PR: kern/11629 Discussed with: Alexander Viro <viro@math.psu.edu> Notes: svn path=/head/; revision=68883
* Fixed disordering and misformatting in previous commit.Bruce Evans2000-06-141-1/+1
| | | | Notes: svn path=/head/; revision=61691
* unstatic getfp() so that other subsystems can use it.Alfred Perlstein2000-06-121-0/+2
| | | | | | | | | make sendfile() use it. Approved by: dg Notes: svn path=/head/; revision=61591
* Back out the previous change to the queue(3) interface.Jake Burkholder2000-05-261-2/+2
| | | | | | | | | It was not discussed and should probably not happen. Requested by: msmith and others Notes: svn path=/head/; revision=60938
* Change the way that the queue(3) structures are declared; don't assume thatJake Burkholder2000-05-231-2/+2
| | | | | | | | | | | the type argument to *_HEAD and *_ENTRY is a struct. Suggested by: phk Reviewed by: phk Approved by: mdodd Notes: svn path=/head/; revision=60833
* Removed superfluous forward declaration of struct klist. ForwardBruce Evans2000-04-301-22/+16
| | | | | | | | | | | | | | declarations of structs for use in prototypes are only necessary if the struct is not otherwise declared in scope. Removed prototypes for fdissequential() and fdsequential(). These functions never existed in FreeBSD. Fixed most style bugs in FreeBSD changes (mainly disordered prototypes and prototypes without parameter names). Notes: svn path=/head/; revision=59774
* Introduce kqueue() and kevent(), a kernel event notification facility.Jonathan Lemon2000-04-161-0/+7
| | | | Notes: svn path=/head/; revision=59288
* When we are execing a setugid program, and we have a procfs filesystemWarner Losh2000-01-201-0/+1
| | | | | | | | | | | file open in one of the special file descriptors (0, 1, or 2), close it before completing the exec. Submitted by: nergal@idea.avet.com.pl Constructive comments: deraadt@openbsd.org, sef, peter, jkh Notes: svn path=/head/; revision=56313
* Change #ifdef KERNEL to #ifdef _KERNEL in the public headers. "KERNEL"Peter Wemm1999-12-291-1/+1
| | | | | | | | | is an application space macro and the applications are supposed to be free to use it as they please (but cannot). This is consistant with the other BSD's who made this change quite some time ago. More commits to come. Notes: svn path=/head/; revision=55205
* Fix a hole in jail(2).Poul-Henning Kamp1999-09-251-0/+1
| | | | | | | Noticed by: Alexander Bezroutchko <abb@zenon.net> Notes: svn path=/head/; revision=51649
* $Id$ -> $FreeBSD$Peter Wemm1999-08-281-1/+1
| | | | Notes: svn path=/head/; revision=50477
* I got another batch of suggestions for cosmetic changes from bde.Don Lewis1998-11-111-5/+5
| | | | Notes: svn path=/head/; revision=41087
* Installed the second patch attached to kern/7899 with some changes suggestedDon Lewis1998-11-111-1/+31
| | | | | | | | | | | | | | | | | | | by bde, a few other tweaks to get the patch to apply cleanly again and some improvements to the comments. This change closes some fairly minor security holes associated with F_SETOWN, fixes a few bugs, and removes some limitations that F_SETOWN had on tty devices. For more details, see the description on the PR. Because this patch increases the size of the proc and pgrp structures, it is necessary to re-install the includes and recompile libkvm, the vinum lkm, fstat, gcore, gdb, ipfilter, ps, top, and w. PR: kern/7899 Reviewed by: bde, elvind Notes: svn path=/head/; revision=41086
* Moved declaration of M_IOV to a less bogus place. It belongs inBruce Evans1997-12-051-4/+1
| | | | | | | | <sys/uio.h>, but it doesn't work there because of header pollution (<sys/uio.h> is prematurely included by <sys/param.h>). Notes: svn path=/head/; revision=31558
* Last major round (Unless Bruce thinks of somthing :-) of malloc changes.Poul-Henning Kamp1997-10-121-1/+4
| | | | | | | | | | | Distribute all but the most fundamental malloc types. This time I also remembered the trick to making things static: Put "static" in front of them. A couple of finer points by: bde Notes: svn path=/head/; revision=30354
* Back out part 1 of the MCFH that changed $Id$ to $FreeBSD$. We are notPeter Wemm1997-02-221-1/+1
| | | | | | | ready for it yet. Notes: svn path=/head/; revision=22975