5fc3031366
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 |
||
---|---|---|
.. | ||
bus_if.m | ||
clock_if.m | ||
device_if.m | ||
genassym.sh | ||
imgact_aout.c | ||
imgact_elf32.c | ||
imgact_elf64.c | ||
imgact_elf.c | ||
imgact_elfN.c | ||
imgact_gzip.c | ||
imgact_shell.c | ||
inflate.c | ||
init_main.c | ||
init_sysent.c | ||
kern_acct.c | ||
kern_acl.c | ||
kern_clock.c | ||
kern_condvar.c | ||
kern_conf.c | ||
kern_descrip.c | ||
kern_environment.c | ||
kern_event.c | ||
kern_exec.c | ||
kern_exit.c | ||
kern_fork.c | ||
kern_idle.c | ||
kern_intr.c | ||
kern_jail.c | ||
kern_kse.c | ||
kern_kthread.c | ||
kern_ktr.c | ||
kern_ktrace.c | ||
kern_linker.c | ||
kern_lock.c | ||
kern_lockf.c | ||
kern_mac.c | ||
kern_malloc.c | ||
kern_mib.c | ||
kern_module.c | ||
kern_mtxpool.c | ||
kern_mutex.c | ||
kern_ntptime.c | ||
kern_physio.c | ||
kern_poll.c | ||
kern_proc.c | ||
kern_prot.c | ||
kern_resource.c | ||
kern_sema.c | ||
kern_shutdown.c | ||
kern_sig.c | ||
kern_subr.c | ||
kern_switch.c | ||
kern_sx.c | ||
kern_synch.c | ||
kern_syscalls.c | ||
kern_sysctl.c | ||
kern_tc.c | ||
kern_thread.c | ||
kern_time.c | ||
kern_timeout.c | ||
kern_uuid.c | ||
kern_xxx.c | ||
ksched.c | ||
link_elf_obj.c | ||
link_elf.c | ||
linker_if.m | ||
Make.tags.inc | ||
Makefile | ||
makesyscalls.sh | ||
md4c.c | ||
md5c.c | ||
p1003_1b.c | ||
posix4_mib.c | ||
subr_acl_posix1e.c | ||
subr_autoconf.c | ||
subr_blist.c | ||
subr_bus.c | ||
subr_clist.c | ||
subr_clock.c | ||
subr_devstat.c | ||
subr_disk.c | ||
subr_disklabel.c | ||
subr_diskmbr.c | ||
subr_diskslice.c | ||
subr_eventhandler.c | ||
subr_hints.c | ||
subr_kobj.c | ||
subr_log.c | ||
subr_mbuf.c | ||
subr_mchain.c | ||
subr_module.c | ||
subr_param.c | ||
subr_pcpu.c | ||
subr_power.c | ||
subr_prf.c | ||
subr_prof.c | ||
subr_rman.c | ||
subr_rtc.c | ||
subr_sbuf.c | ||
subr_scanf.c | ||
subr_smp.c | ||
subr_taskqueue.c | ||
subr_trap.c | ||
subr_turnstile.c | ||
subr_witness.c | ||
subr_xxx.c | ||
sys_generic.c | ||
sys_pipe.c | ||
sys_process.c | ||
sys_socket.c | ||
syscalls.c | ||
syscalls.master | ||
sysv_ipc.c | ||
sysv_msg.c | ||
sysv_sem.c | ||
sysv_shm.c | ||
tty_compat.c | ||
tty_conf.c | ||
tty_cons.c | ||
tty_pty.c | ||
tty_subr.c | ||
tty_tty.c | ||
tty.c | ||
uipc_accf.c | ||
uipc_cow.c | ||
uipc_domain.c | ||
uipc_jumbo.c | ||
uipc_mbuf2.c | ||
uipc_mbuf.c | ||
uipc_proto.c | ||
uipc_sockbuf.c | ||
uipc_socket2.c | ||
uipc_socket.c | ||
uipc_syscalls.c | ||
uipc_usrreq.c | ||
vfs_acl.c | ||
vfs_aio.c | ||
vfs_bio.c | ||
vfs_cache.c | ||
vfs_cluster.c | ||
vfs_default.c | ||
vfs_export.c | ||
vfs_extattr.c | ||
vfs_init.c | ||
vfs_lookup.c | ||
vfs_mount.c | ||
vfs_subr.c | ||
vfs_syscalls.c | ||
vfs_vnops.c | ||
vnode_if.src |