Commit Graph

113 Commits

Author SHA1 Message Date
jdolecek 7cea8a1389 cleanup & uniform descriptor owner handling:
* introduce fsetown(), fgetown(), fownsignal() - this sets/retrieves/signals
  the owner of descriptor, according to appropriate sematics
  of TIOCSPGRP/FIOSETOWN/SIOCSPGRP/TIOCGPGRP/FIOGETOWN/SIOCGPGRP ioctl; use
  these routines instead of custom code where appropriate
* make every place handling TIOCSPGRP/TIOCGPGRP handle also FIOSETOWN/FIOGETOWN
  properly, and remove the translation of FIO[SG]OWN to TIOC[SG]PGRP
  in sys_ioctl() & sys_fcntl()
* also remove the socket-specific hack in sys_ioctl()/sys_fcntl() and
  pass the ioctls down to soo_ioctl() as any other ioctl

change discussed on tech-kern@
2003-09-21 19:16:48 +00:00
jdolecek a034152027 move dupfd from struct proc to struct lwp - it's per-LWP, not per-process; we
use curlwp where the lwp is not directly available, i.e. in device open
routines

briefly discussed on tech-kern
2003-09-13 08:32:10 +00:00
agc aad01611e7 Move UCB-licensed code from 4-clause to 3-clause licence.
Patches provided by Joel Baker in PR 22364, verified by myself.
2003-08-07 16:26:28 +00:00
fvdl d5aece61d6 Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
2003-06-29 22:28:00 +00:00
darrenr 960df3c8d1 Pass lwp pointers throughtout the kernel, as required, so that the lwpid can
be inserted into ktrace records.  The general change has been to replace
"struct proc *" with "struct lwp *" in various function prototypes, pass
the lwp through and use l_proc to get the process pointer when needed.

Bump the kernel rev up to 1.6V
2003-06-28 14:20:43 +00:00
itojun 35e21131ac use strlcat 2003-05-16 14:40:41 +00:00
dsl 6f803e005b Correct rewinding if FIONBIO or FIOASYNC fail in F_SETFL
(code use to always turn off FIONBIO if FIOASYNC fails)
(approved by christos)
2003-03-22 10:39:47 +00:00
dsl 1f2e35430b Change caddr_t to void * 2003-03-22 10:35:01 +00:00
martin 358b4d4e49 When being passed bogus file descriptors make close(2) return EBADF.
From Stephen Ma in PR kern/20762.
2003-03-17 07:57:13 +00:00
yamt ddb9465f5f make fdcheckstd f_slock friendly. 2003-03-01 09:19:53 +00:00
pk 2931081a79 Make updating a file's reference and use count MP-safe. 2003-02-23 14:37:32 +00:00
pk 9a853301e6 Use a mutex to protect the global list of open files. 2003-02-14 21:50:10 +00:00
thorpej b193480908 Add extensible malloc types, adapted from FreeBSD. This turns
malloc types into a structure, a pointer to which is passed around,
instead of an int constant.  Allow the limit to be adjusted when the
malloc type is defined, or with a function call, as suggested by
Jonathan Stone.
2003-02-01 06:23:35 +00:00
simonb d446cbf4ee Remove variable that is only assigned too but not referenced. 2003-01-19 22:52:11 +00:00
thorpej e0d8d366df Merge the nathanw_sa branch. 2003-01-18 10:06:22 +00:00
wiz a2278794f4 descriptor, not decriptor. 2003-01-06 13:19:51 +00:00
scw 0f91ed3dfa Quell uninitialised variable warnings. 2002-11-24 11:37:54 +00:00
jdolecek e0cc03a09b merge kqueue branch into -current
kqueue provides a stateful and efficient event notification framework
currently supported events include socket, file, directory, fifo,
pipe, tty and device changes, and monitoring of processes and signals

kqueue is supported by all writable filesystems in NetBSD tree
(with exception of Coda) and all device drivers supporting poll(2)

based on work done by Jonathan Lemon for FreeBSD
initial NetBSD port done by Luke Mewburn and Jason Thorpe
2002-10-23 09:10:23 +00:00
simonb 333a151694 fp->f_count is unsigned, don't check if it's less than zero. 2002-09-23 04:19:16 +00:00
gehenna 77a6b82b27 Merge the gehenna-devsw branch into the trunk.
This merge changes the device switch tables from static array to
dynamically generated by config(8).

- All device switches is defined as a constant structure in device drivers.

- The new grammer ``device-major'' is introduced to ``files''.

	device-major <prefix> char <num> [block <num>] [<rules>]

- All device major numbers must be listed up in port dependent majors.<arch>
  by using this grammer.

- Added the new naming convention.
  The name of the device switch must be <prefix>_[bc]devsw for auto-generation
  of device switch tables.

- The backward compatibility of loading block/character device
  switch by LKM framework is broken. This is necessary to convert
  from block/character device major to device name in runtime and vice versa.

- The restriction to assign device major by LKM is completely removed.
  We don't need to reserve LKM entries for dynamic loading of device switch.

- In compile time, device major numbers list is packed into the kernel and
  the LKM framework will refer it to assign device major number dynamically.
2002-09-06 13:18:43 +00:00
thorpej 2d2b1d78ae sys_fpathconf: Don't panic in the default case; just return EOPNOTSUPP. 2002-06-18 02:04:08 +00:00
atatat de7144e830 Maintain a short list of the actual descriptors that were closed and
log that intead of being ambiguous about which of 0, 1, and/or 2 it
was that was closed.
2002-05-09 17:57:07 +00:00
enami cb3d9867b6 Log who invoked the s[ug]id program. Tested by mozilla. 2002-04-28 22:35:19 +00:00
enami 9a9bf29bcf A loop to expand file descriptor table and retry is move from fdalloc()
to caller.  So, no longer need to loop in fdalloc().
2002-04-27 21:36:50 +00:00
enami a58680a4e2 KNF. 2002-04-27 21:31:41 +00:00
christos ce8e03cd9f Avoid file use underflow; thanks to YAMAMOTO Takashi for noticing. 2002-04-24 16:09:24 +00:00
christos 7ad1c0f407 Don't forget to set mature and unuse the file. 2002-04-23 17:20:58 +00:00
christos 1261c89715 From OpenBSD, via FreeBSD: If a set{u,g}id binary is invoked with fd < 3
closed, open those fds to /dev/null.

XXX: This needs to be fixed in a better way. The kernel should not need to
know about /dev/null or special case 0, 1, 2.
2002-04-23 15:11:25 +00:00
thorpej a180cee23b Pool deals fairly well with physical memory shortage, but it doesn't
deal with shortages of the VM maps where the backing pages are mapped
(usually kmem_map).  Try to deal with this:

* Group all information about the backend allocator for a pool in a
  separate structure.  The pool references this structure, rather than
  the individual fields.
* Change the pool_init() API accordingly, and adjust all callers.
* Link all pools using the same backend allocator on a list.
* The backend allocator is responsible for waiting for physical memory
  to become available, but will still fail if it cannot callocate KVA
  space for the pages.  If this happens, carefully drain all pools using
  the same backend allocator, so that some KVA space can be freed.
* Change pool_reclaim() to indicate if it actually succeeded in freeing
  some pages, and use that information to make draining easier and more
  efficient.
* Get rid of PR_URGENT.  There was only one use of it, and it could be
  dealt with by the caller.

From art@openbsd.org.
2002-03-08 20:48:27 +00:00
kleink 12135360cf fcntl(..., F_GETOWN, ...): fix LP64-BE bug; raised by der Mouse
on tech-kern.
2002-01-31 22:17:33 +00:00
jdolecek 3d4c59a8ee Back off previous for now, Jason thinks it's not right. Will discuss
on tech-kern@
2001-12-07 07:09:29 +00:00
jdolecek 255ce12e50 replace FIF_WANTCLOSE/FIF_LARVAL with FWANTCLOSE/FLARVAL, which are set
in f_flag of struct file
for now, keep former f_iflags of struct file as _f_spare0, it will be g/c'ed
when struct file will be changed (this will happen soon)
2001-12-06 22:34:24 +00:00
lukem adc783d537 add RCSIDs 2001-11-12 15:25:01 +00:00
thorpej 35c5abaeff Unshare the file descriptor table and `cwdinfo' when we exec.
From Matthew Orgass <darkstar@pgh.net>.
2001-07-18 05:34:37 +00:00
thorpej 5bdb21d48a Duh, use fd_getfile() in sys_close(). 2001-07-01 18:12:00 +00:00
jdolecek c57b6d9ba4 Add DTYPE_PIPE (to be used by new pipe implementation) and handle
it accordingly.
2001-06-16 08:28:39 +00:00
thorpej 80cc38a1af Fix a partial construction problem that can cause race conditions
between creation of a file descriptor and close(2) when using kernel
assisted threads.  What we do is stick descriptors in the table, but
mark them as "larval".  This causes essentially everything to treat
it as a non-existent descriptor, except for fdalloc(), which sees a
filled slot so that it won't (incorrectly) allocate it again.  When
a descriptor is fully constructed, the code that has constructed it
marks it as "mature" (which actually clears the "larval" flag), and
things continue to work as normal.

While here, gather all the code that gets a descriptor from the table
into a fd_getfile() function, and call it, rather than having the
same (sometimes incorrect) code copied all over the place.
2001-06-14 20:32:41 +00:00
thorpej d9b3317e3e Rework fdalloc() even further: split fdalloc() into fdalloc() and
fdexpand().  The former will return ENOSPC if there is not space
in the current filedesc table.  The latter performs the expansion
of the filedesc table.  This means that fdalloc() won't ever block,
and it gives callers an opportunity to clean up before the
potentially-blocking fdexpand() call.

Update all fdalloc() callers to deal with the need-to-fdexpand() case.

Rewrite unp_externalize() to use fdalloc() and fdexpand() in a
safe way, using an algorithm suggested by Bill Sommerfeld:
- Use a temporary array of integers to hold the new filedesc table
  indexes.  This allows us to repeat the loop if necessary.
- Loop through the array of file *'s, assigning them to filedesc table
  slots.  If fdalloc() indicates expansion is necessary, undo the
  assignments we've done so far, expand, and retry the whole process.
- Once all file *'s have been assigned to slots, update the f_msgcount
  and unp_rights counters.
- Right before we return, copy the temporary integer array to the message
  buffer, and trim the length as before.
Note that once locking is added to the filedesc array, this entire
operation will be `atomic', in that the lock will be held while
file *'s are assigned to embryonic table slots, thus preventing anything
else from using them.
2001-06-07 01:29:16 +00:00
thorpej c55795d055 Change fdalloc() to return ERESTART if we had to reallocate the
descriptor array, which may have blocked.  Change callers of
fdalloc() to restart whatever they\'re doing if this condition
happens.  (XXX unp_externalize() needs some work, but that will
be tackled later.)

Change finishdup() to close the descriptor in the `new\' slot if
one exists, and change sys_dup2() accordingly.

Closes a race condition when using kernel-assisted user threads.

While here, garbage-collect UF_MAPPED -- it is not used anywhere.
2001-06-06 17:00:00 +00:00
jdolecek b6d1d4db02 Change the first arg to fileops fo_stat routine to struct file *, adjust
callers and appropriate routines to cope. This makes fo_stat more
consistent with rest of fileops routines and also makes the fo_stat
match FreeBSD as an added bonus.
Discussed with Luke Mewburn on tech-kern@.
2001-04-09 10:22:00 +00:00
jdolecek 16b1272b3f Add new 'stat' fileop and call the stat function via f_ops rather
than directly.
For compat syscalls, also add necessary FILE_USE()/FILE_UNUSE().
Now that soo_stat() gets a proc arg, pass it on to usrreq function.
2001-04-07 09:00:57 +00:00
lukem 7fee352603 convert to ANSI KNF 2001-02-26 20:24:30 +00:00
fvdl 4ca7344324 Fix omission in previous. 2000-08-15 17:54:59 +00:00
eeh 2ce37274f1 Fix LP64BE bug. 2000-08-15 16:26:42 +00:00
jdolecek 1ec07d7439 change tablefull() to accept one more parameter - optional hint
use that to inform about way to raise current limit when we reach maximum
number of processes, descriptors or vnodes

XXX hopefully I catched all users of tablefull()
2000-07-04 15:33:28 +00:00
mrg 32aa199ccf remove include of <vm/vm.h> 2000-06-27 17:41:07 +00:00
sommerfeld f822e85903 Eliminate incorrect use of "curproc" in a comment. 2000-05-26 23:10:36 +00:00
augustss 264f1d27c6 Get rid of register declarations. 2000-03-30 09:27:11 +00:00
thorpej dabbfde70a Implement fdremove() which is used in place of all the code that
did the "fdp->fd_ofiles[fd] = 0" assignment; fdremove() make sure
the fd_freefiles hints stay in sync.

From OpenBSD.
2000-03-23 05:16:12 +00:00
thorpej d488aca2aa Pool'ify filedesc0 allocation. 2000-03-22 17:42:57 +00:00