freebsd-dev/sys
John Baldwin 5fc3031366 - Change falloc() to acquire an fd from the process table last so that
it can do it w/o needing to hold the filelist_lock sx lock.
- fdalloc() doesn't need Giant to call free() anymore.  It also doesn't
  need to drop and reacquire the filedesc lock around free() now as a
  result.
- Try to make the code that copies fd tables when extending the fd table in
  fdalloc() a bit more readable by performing assignments in separate
  statements.  This is still a bit ugly though.
- Use max() instead of an if statement so to figure out the starting point
  in the search-for-a-free-fd loop in fdalloc() so it reads better next to
  the min() in the previous line.
- Don't grow nfiles in steps up to the size needed if we dup2() to some
  really large number.  Go ahead and double 'nfiles' in a loop prior
  to doing the malloc().
- malloc() doesn't need Giant now.
- Use malloc() and free() instead of MALLOC() and FREE() in fdalloc().
- Check to see if the size we are going to grow to is too big, not if the
  current size of the fd table is too big in the loop in fdalloc().  This
  means if we are out of space or if dup2() requests too high of a fd,
  then we will return an error before we go off and try to allocate some
  huge table and copy the existing table into it.
- Move all of the logic for dup'ing a file descriptor into do_dup() instead
  of putting some of it in do_dup() and duplicating other parts in four
  different places.  This makes dup(), dup2(), and fcntl(F_DUPFD) basically
  wrappers of do_dup now.  fcntl() still has an extra check since it uses
  a different error return value in one case then the other functions.
- Add a KASSERT() for an assertion that may not always be true where the
  fdcheckstd() function assumes that falloc() returns the fd requested and
  not some other fd.  I think that the assertion is always true because we
  are always single-threaded when we get to this point, but if one was
  using rfork() and another process sharing the fd table were playing with
  the fd table, there might could be a problem.
- To handle the problem of a file descriptor we are dup()'ing being closed
  out from under us in dup() in general, do_dup() now obtains a reference
  on the file in question before calling fdalloc().  If after the call to
  fdalloc() the file for the fd we are dup'ing is a different file, then
  we drop our reference on the original file and return EBADF.  This
  race was only handled in the dup2() case before and would just retry
  the operation.  The error return allows the user to know they are being
  stupid since they have a locking bug in their app instead of dup'ing
  some other descriptor and returning it to them.

Tested on:	i386, alpha, sparc64
2002-09-03 20:16:31 +00:00
..
alpha Now that _BSD_CLK_TCK_ and _BSD_CLOCKS_PER_SEC_ are the same on all 2002-09-03 00:06:58 +00:00
amd64 Added fields for VM_MIN_ADDRESS, PS_STRINGS and stack protections to 2002-09-01 21:41:24 +00:00
arm Now that _BSD_CLK_TCK_ and _BSD_CLOCKS_PER_SEC_ are the same on all 2002-09-03 00:06:58 +00:00
boot Make SCSI_DELAY setable at boot time and runtime via the 2002-09-02 20:10:19 +00:00
cam Make SCSI_DELAY setable at boot time and runtime via the 2002-09-02 20:10:19 +00:00
coda Fix typo in the last revision. 2002-08-04 19:34:38 +00:00
compat Use the new kern_*() functions to avoid using the stack gap in 2002-09-02 22:46:05 +00:00
conf - Move $FreeBSD$ to the top of the file. 2002-09-03 19:21:39 +00:00
contrib Fix kernel build breakage when ACPI_DEBUG option is specified. 2002-08-29 08:31:06 +00:00
crypto Fix some really pedantic GCC warnings. 2002-07-15 13:45:15 +00:00
ddb db_ps.c: 2002-08-31 04:25:44 +00:00
dev Remove a debug printf. 2002-09-03 11:31:34 +00:00
fs Add a missing #include <sys/lockmgr.h>. 2002-09-01 23:02:10 +00:00
geom Use 'p' as the partition specifier instead of 's'. We continue to use 2002-08-24 22:42:16 +00:00
gnu In order to better support flexible and extensible access control, 2002-08-15 20:55:08 +00:00
i4b Continue de-counting i4b. Devices i4bctl, i4bcapi, iavc, i4bq921, 2002-09-02 00:52:11 +00:00
i386 Now that _BSD_CLK_TCK_ and _BSD_CLOCKS_PER_SEC_ are the same on all 2002-09-03 00:06:58 +00:00
ia64 Make this compile 2002-09-03 04:30:00 +00:00
isa Add suspend/resume method to syscons. This switch the mode 2002-08-25 18:35:44 +00:00
isofs/cd9660 Replace various spelling with FALLTHROUGH which is lint()able 2002-08-25 13:23:09 +00:00
kern - Change falloc() to acquire an fd from the process table last so that 2002-09-03 20:16:31 +00:00
libkern Include sys/libkern.h for the kernel prototypes of these libkern functions 2002-08-22 20:08:07 +00:00
modules Remove aic7xxx from the module build framework until all bootstrapping 2002-09-03 16:54:48 +00:00
net Fix a silly typo in user-setable promisc mode code. 2002-08-30 13:37:13 +00:00
netatalk Introduce experimental support for MAC in the AppleTalk/EtherTalk stack. 2002-08-15 18:58:44 +00:00
netatm Replace various spelling with FALLTHROUGH which is lint()able 2002-08-25 13:23:09 +00:00
netgraph Don't use "NULL" when "0" is really meant. 2002-08-22 00:30:03 +00:00
netinet some ipfilter files that accidently got imported here 2002-08-29 13:27:26 +00:00
netinet6 Lock the sysctl(8) knobs that turn ip{,6}fw(8) firewalling and 2002-08-25 03:50:29 +00:00
netipx Replace various spelling with FALLTHROUGH which is lint()able 2002-08-25 13:23:09 +00:00
netkey - fixed the order of searching SA table for packets. 2002-07-10 16:39:38 +00:00
netnatm Back out my lats commit of locking down a socket, it conflicts with hsu's work. 2002-05-31 11:52:35 +00:00
netncp Wire the sysctl output buffer before grabbing any locks to prevent 2002-07-28 19:59:31 +00:00
netns Replace various spelling with FALLTHROUGH which is lint()able 2002-08-25 13:23:09 +00:00
netsmb <sys/lock.h> is a prerequisite for <sys/mutex.h>, so include the former 2002-08-27 12:22:06 +00:00
nfs
nfsclient Increase size of ifnet.if_flags from 16 bits (short) to 32 bits (int). To avoid 2002-08-18 07:05:00 +00:00
nfsserver Make the V2 errno translation more resistent to new errnos. 2002-08-21 19:28:44 +00:00
pc98 Take a shot at fixing up a whole stack of style and other embarresing 2002-08-31 03:33:32 +00:00
pccard Add 16-bit before bus to keep the words card and bus apart. 2002-07-31 20:01:11 +00:00
pci Add a device description for Intel 82801CA/CAM (ICH3) USB controller 2002-08-28 20:24:49 +00:00
posix4 Part 1 of KSE-III 2002-06-29 17:26:22 +00:00
powerpc Now that _BSD_CLK_TCK_ and _BSD_CLOCKS_PER_SEC_ are the same on all 2002-09-03 00:06:58 +00:00
rpc
security Prefer NULL to 0 when passing a NULL pointer. 2002-08-20 02:54:09 +00:00
sparc64 Now that _BSD_CLK_TCK_ and _BSD_CLOCKS_PER_SEC_ are the same on all 2002-09-03 00:06:58 +00:00
sys In the kernel code, we have the tsleep() call with the PCATCH argument. 2002-09-03 12:56:01 +00:00
tools - Add two new debugging macros: ASSERT_VI_LOCKED and ASSERT_VI_UNLOCKED 2002-08-21 06:19:29 +00:00
ufs Since we have vp and td cached in local variables, use those instead 2002-09-01 16:06:40 +00:00
vm o Synchronize updates to struct vm_page::cow with the page queues lock. 2002-09-02 04:04:12 +00:00
Makefile