Home | History | Annotate | Download | only in kern
History log of /src/sys/kern/tty.c
RevisionDateAuthorComments
 1.313  14-Jul-2024  kre PR kern/58425 -- Disallow INT_MIN as a (negative) pid arg.

Since -INT_MIN is undefined, and to point of negative pid args is
to negate them, and use the result as a pgrp id instead, we need
to avoid accidentally negating INT_MIN.

Since pid_t is just an integral type, of unspecified width, when
testing pid_t value test for <= INT_MIN (or > INT_MIN sometimes)
rather than == INT_MIN. When testing int values, just == INT_MIN
is all that is needed, < INT_MIN cannot occur.

XXX pullup -9, -10
 1.312  07-Dec-2023  pgoyette branches: 1.312.2;
There's no COMPAT_60 code left here, so no need for conditional
inclusion of header file.
 1.311  22-May-2023  riastradh tty(9): Make ttwrite update uio with only how much it has consumed.

As is, it leaves uio in an inconsistent state. Good enough for the
write(2) return value to be correct for a userland caller to restart
write(2) where it left off, but not good enough for a loop in the
kernel to reuse the same uio.

Reported-by: syzbot+e0f56178d0add0d8be20@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=6290eb02b8fe73361dc15c7bc44e1208601e6af8

Reported-by: syzbot+7caa189e8fccd926357e@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=c0a3b77b4831dfa81fc855857bde81755d246bd3

Reported-by: syzbot+4a1eff91eb4e7c1970b6@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=10523a633a4ad9749f57dc7cf03f9447d518c5b8

Reported-by: syzbot+1d3c280f59099dc82e17@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=8e02ebb0da76a8e286461f33502117a1d30275c6

Reported-by: syzbot+080d51214d0634472b12@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=1f617747db8087e5554d3df1b79a545dee26a650

Reported-by: syzbot+dd50b448e49e5020131a@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=f71c8cef4110b7eeac6eca67b6a4d1f4a8b3e96f

Reported-by: syzbot+26b675ecf0cc9dfd8586@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=57b1901f5b3e090a964d08dd0d729f9909f203be

Reported-by: syzbot+87f0df2c9056313a5c4b@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=67994a3da32d075144e25d1ac314be1d9694ae6e

Reported-by: syzbot+e5bc98e18aa42f0cb25d@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=6374bd286532423c63f2b331748280729134224c

Reported-by: syzbot+7e587f4c5aaaf80e84b3@syzkaller.appspotmail.com
https://syzkaller.appspot.com/bug?id=976210ed438d48ac275d77d7ebf4a086e43b5fcb
 1.310  12-Apr-2023  riastradh ttycheckoutq(9): wait=0 always, parameter no longer useful, nix it.

XXX kernel revbump
 1.309  11-Apr-2023  riastradh ttwrite(9): Assert we mangle uio_resid only if we also return error.
 1.308  17-Feb-2023  riastradh ttycheckoutq(9): wait is always 0. Assert it; prune dead branches.

There appear to have been no callers with wait=1 since NetBSD 1.0
from a cursory search. Let's nix the parameter altogether on the
next kernel revbump. This logic is probably broken anyway in the
presence of ttycancel, which is necessary for, e.g., yanking USB
serial adapters.
 1.307  26-Oct-2022  riastradh branches: 1.307.2;
tty(9): New ttylock, ttyunlock, ttylocked functions.

These are wrappers around the global tty_lock for now (and the
continued existence of the tty_lock variable is why the ttylock
function has no underscore in its name). They will assist in
converting drivers to per-tty locking later on.
 1.306  25-Oct-2022  riastradh constty(4): Make MP-safe, take three.

Access to the global constty variable is coordinated as follows:

1. Setting constty to nonnull, with atomic_store_release, is allowed
only under the new adaptive constty_lock in thread context. This
serializes TIOCCONS operations and ensures unlocked readers can
safely use a constty pointer read with atomic_load_consume.

2. Changing constty from nonnull to null, with atomic_cas_ptr, is
allowed in any context -- printf(9) uses this to disable a broken
constty.

3. Reading constty under constty_lock is allowed with
atomic_load_relaxed, because while constty_lock is held, it can
only be made null by some other thread/CPU, never made nonnull.

4. Reading constty outside constty_lock is allowed with
atomic_load_consume in a pserialize read section -- constty is
only ever made nonnull with atomic_store_release, in (1).
ttyclose will wait for all these pserialize read sections to
complete before flushing the tty.

5. To continue to use a struct tty pointer in (4) after the
pserialize read section has completed, caller must use tty_acquire
during the pserialize read section and then tty_release when done.
ttyclose will wait for all these references to drain before
returning.

These access rules allow us to serialize TIOCCONS, and safely destroy
ttys, without putting any locks on the access paths like printf(9)
that use constty. Once we set D_MPSAFE, operations on /dev/console
will contend only with other users of the same tty as constty, which
will be an improvement over contending with all other kernel lock
users in the system.

Changes second time around:
- Fix initialization of ok in cons.c cn_redirect.
- Fix reversed sense of conditional in subr_prf.c putone.

Changes third time around:
- Initialize ttyref_cv so we don't panic when trying to use it,
leading to infinite loop when panic tries to take tty_lock to print
the panic message while we already hold tty_lock.
 1.305  07-Oct-2022  riastradh Revert "constty(4): Make MP-safe."

Something is still busted and this is interfering with the releng
amd64 testbed.
 1.304  06-Oct-2022  riastradh constty(4): Make MP-safe.

Access to the global constty variable is coordinated as follows:

1. Setting constty to nonnull, with atomic_store_release, is allowed
only under the new adaptive constty_lock in thread context. This
serializes TIOCCONS operations and ensures unlocked readers can
safely use a constty pointer read with atomic_load_consume.

2. Changing constty from nonnull to null, with atomic_cas_ptr, is
allowed in any context -- printf(9) uses this to disable a broken
constty.

3. Reading constty under constty_lock is allowed with
atomic_load_relaxed, because while constty_lock is held, it can
only be made null by some other thread/CPU, never made nonnull.

4. Reading constty outside constty_lock is allowed with
atomic_load_consume in a pserialize read section -- constty is
only ever made nonnull with atomic_store_release, in (1).
ttyclose will wait for all these pserialize read sections to
complete before flushing the tty.

5. To continue to use a struct tty pointer in (4) after the
pserialize read section has completed, caller must use tty_acquire
during the pserialize read section and then tty_release when done.
ttyclose will wait for all these references to drain before
returning.

These access rules allow us to serialize TIOCCONS, and safely destroy
ttys, without putting any locks on the access paths like printf(9)
that use constty. Once we set D_MPSAFE, operations on /dev/console
will contend only with other users of the same tty as constty, which
will be an improvement over contending with all other kernel lock
users in the system.

Changes second time around:
- Fix initialization of ok in cons.c cn_redirect.
- Fix reversed sense of conditional in subr_prf.c putone.
 1.303  04-Oct-2022  riastradh Revert "constty(4): Make MP-safe."

Something appears to be wrong with this.
 1.302  03-Oct-2022  riastradh constty(4): Make MP-safe.

Access to the global constty variable is coordinated as follows:

1. Setting constty to nonnull, with atomic_store_release, is allowed
only under the new adaptive constty_lock in thread context. This
serializes TIOCCONS operations and ensures unlocked readers can
safely use a constty pointer read with atomic_load_consume.

2. Changing constty from nonnull to null, with atomic_cas_ptr, is
allowed in any context -- printf(9) uses this to disable a broken
constty.

3. Reading constty under constty_lock is allowed with
atomic_load_relaxed, because while constty_lock is held, it can
only be made null by some other thread/CPU, never made nonnull.

4. Reading constty outside constty_lock is allowed with
atomic_load_consume in a pserialize read section -- constty is
only ever made nonnull with atomic_store_release, in (1).
ttyclose will wait for all these pserialize read sections to
complete before flushing the tty.

5. To continue to use a struct tty pointer in (4) after the
pserialize read section has completed, caller must use tty_acquire
during the pserialize read section and then tty_release when done.
ttyclose will wait for all these references to drain before
returning.

These access rules allow us to serialize TIOCCONS, and safely destroy
ttys, without putting any locks on the access paths like printf(9)
that use constty. Once we set D_MPSAFE, operations on /dev/console
will contend only with other users of the same tty as constty, which
will be an improvement over contending with all other kernel lock
users in the system.
 1.301  07-Apr-2022  riastradh tty(9): New function tty_unit for struct cdevsw::d_devtounit.
 1.300  28-Mar-2022  riastradh tty(9): New ttycancel function.

This causes any current and future ttyopens to fail until ttyclose.

This is necessary for revoke to work reliably for device detach like
ucom(4) removable USB devices. A tty driver for a removable device
needs some way to interrupt a pending .d_open so it returns promptly.
But ttyclose only interrupts ttyopen if it's already sleeping; it
won't cause a concurrent .d_open call which _will call_ but _hasn't
yet called_ ttyopen to avoid sleeping. Using ttycancel in the tty
driver's .d_cancel makes this work.
 1.299  05-Dec-2021  msaitoh s/runable/runnable/
 1.298  29-Sep-2021  thorpej ttyread_filtops, ttywrite_filtops, ptcread_filtops, and ptcwrite_filtops
are MPSAFE.
 1.297  27-Sep-2021  thorpej Consistently reference kn->kn_data only within the lock perimeter in
the filtops f_event() callback.
 1.296  26-Sep-2021  thorpej Change the kqueue filterops::f_isfd field to filterops::f_flags, and
define a flag FILTEROP_ISFD that has the meaning of the prior f_isfd.
Field and flag name aligned with OpenBSD.

This does not constitute a functional or ABI change, as the field location
and size, and the value placed in that field, are the same as the previous
code, but we're bumping __NetBSD_Version__ so 3rd-party module source code
can adapt, as needed.

NetBSD 9.99.89
 1.295  11-Dec-2020  thorpej Use sel{record,remove}_knote().
 1.294  10-Oct-2020  christos branches: 1.294.2;
remove extra break
 1.293  10-Oct-2020  christos remove broken copy of TIOCGSID.
 1.292  10-Oct-2020  christos TIOCGSID is used by tcgetsid() so it is not really compat :-)
This should reduce loading the compat module.
 1.291  10-Oct-2020  nia tty: Negating INT_MIN will overflow int, bail out with EINVAL

Detected by UBSan

Reported-by: syzbot+92c0fca82b74a9798b78@syzkaller.appspotmail.com
 1.290  09-Oct-2020  nia tty: Avoid undefined behaviour (left shift of 1 by 31 places overflows int)

The valid sizes of the tty input and output queues (according to the man page)
are between 1024 and 65536 and input values are converted to a power of two.

The check on the validity of the range is done after the input values are
converted, however, which means that a hostile program can attempt to set
the queue size to a negative value, and cause integer overflow before
the range is validated.

Detected by UBSan

Reported-by: syzbot+521b73969fd233c49e58@syzkaller.appspotmail.com
 1.289  26-Aug-2020  maxv Add a check to prevent shift by -1. Not really important in this case,
but to appease KUBSAN.

Reported-by: syzbot+4026e8201b6b484b8cb4@syzkaller.appspotmail.com
 1.288  22-Jun-2020  maxv Don't leak an unused sysctl log. Found by kLSan.
 1.287  23-May-2020  ad Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.
 1.286  21-Jan-2020  christos Don't crash if we are on a hippie trail, head full of zombie
 1.285  07-Jan-2020  skrll branches: 1.285.2;
Appease gcc
 1.284  06-Jan-2020  ad ttygetinfo(): avoid crash with zombies. From skrll@, tweaked by me.
 1.283  02-Jan-2020  skrll KNF
 1.282  02-Jan-2020  skrll Trailing whitespace
 1.281  01-Mar-2019  pgoyette branches: 1.281.4;
Rename the MODULE_*_HOOK() macros to MODULE_HOOK_*() as briefly
discussed on irc.

NFCI intended.

Ride the earlier kernel bump - it;s getting crowded.
 1.280  29-Jan-2019  pgoyette Normalize all the compat hooks' names to the form

<subsystem>_<function>_<version>_hook

NFCI

XXX Note that although this introduces a change in the kernel-to-
XXX module interface, we are NOT bumping the kernel version number.
XXX We will bump the version number once the interface stabilizes.
 1.279  28-Jan-2019  christos - provide a hook for the 43 tty ioctls
- make the 60 tty ioctl hook look the same
- fix the tty code to call both hooks and remove unused lock
 1.278  27-Jan-2019  pgoyette Merge the [pgoyette-compat] branch
 1.277  03-Sep-2018  riastradh Rename min/max -> uimin/uimax for better honesty.

These functions are defined on unsigned int. The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER! Some subsystems have

#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX. Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate. But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all. (Who knows, maybe in some cases integer
truncation is actually intended!)
 1.276  30-Mar-2018  maya branches: 1.276.2;
correct typo: and and -> and

from chris28.
 1.275  25-Oct-2017  maya branches: 1.275.2;
Use C99 initializer for filterops

Mostly done with spatch with touchups for indentation

@@
expression a;
identifier b,c,d;
identifier p;
@@
const struct filterops p =
- { a, b, c, d
+ {
+ .f_isfd = a,
+ .f_attach = b,
+ .f_detach = c,
+ .f_event = d,
};
 1.274  01-Oct-2016  christos branches: 1.274.6;
Require exact credential match; this way even if we su to the original user
that created the session, we won't match his credentials.
 1.273  01-Oct-2016  christos Weaken the test a bit to still allow non-root to use TIOCSTI; we need to have
the same creds as the session leader process for the tty session.
 1.272  29-Sep-2016  christos Only allow root to use TIOCSTI. Don't eat the kauth error number.
It is unexpected for an unprivileged process to gain privs by
typing to root's tty:

$ cat installer
#!/bin/sh
whoami
/usr/sbin/sti /dev/tty whoami\\n

$ su unprivileged -c ./installer
unprivileged
$ whoami
root
 1.271  07-Jul-2016  msaitoh branches: 1.271.2;
KNF. Remove extra spaces. No functional change.
 1.270  22-Oct-2015  christos Add console-related ioctls.
 1.269  18-Oct-2015  christos add the pty ioctls to pass through.
 1.268  18-Oct-2015  christos handle the hardware layer tty ioctls directly so that we don't need to load
the compat module for normal operations.
 1.267  25-Aug-2015  gson In ttywait_timo(), break out of loop on all errors, not just
EWOULDBLOCK, as ttywait() did prior to 1.265.
 1.266  24-Aug-2015  pooka to garnish, dust with _KERNEL_OPT
 1.265  19-Aug-2015  gson When closing a tty, limit the amount of time spent waiting for the
output to drain to five seconds so that exiting processes with
buffered output for a serial port blocked by flow control or a pty
that is not being read do not hang indefinitely. Should fix PRs
kern/12534 and kern/17171. This is an updated version of the change
of tty.c 1.263.
 1.264  14-Jun-2015  gson Revert previous; it broke the lib/libc/ttyio/t_ttyio/ioctl test case.
 1.263  12-Jun-2015  gson When closing a tty, limit the amount of time spent waiting for the
output to drain to five seconds so that exiting processes with
buffered output for a serial port blocked by flow control do not
hang indefinitely. Should fix PR kern/12534. OK christos.
 1.262  05-Sep-2014  matt branches: 1.262.2;
Don't use catch as a varible name.
 1.261  22-May-2014  dholland Use accessor functions for the tty's table of control characters.
(at least from outside the core tty sources)

Move some xon/xoff code from net/ppp_tty.c to kern/tty.c.
 1.260  22-May-2014  dholland Define TTY_ALLOW_PRIVATE in tty.c, tty_pty.c, and tty_conf.c.

These modules are the core of the tty code that in the long term needs
access to struct tty. (It may be that in the future this can be cut
back to just tty.c; we'll see. For now I'll settle for keeping drivers
out of struct tty.)
 1.259  25-Feb-2014  pooka branches: 1.259.2;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.
 1.258  23-Feb-2014  mlelstv ttioctl always gets a valid lwp reference. Replace attempt to handle a NULL
reference in only one place with a regular assertion.
 1.257  09-Feb-2013  christos branches: 1.257.2;
printflike maintenance.
 1.256  19-Oct-2012  apb Add COMPAT_60 versions of the TIOCPTMGET and TIOCPTSNAME ioctls.
 1.255  02-Oct-2012  mlelstv Don't call ureadc() with a spinlock held because ureadc() may fault when
writing to userspace.
 1.254  30-Sep-2012  mlelstv Provide consistent locking around getc() in ttread(). This is necessary
to prevent crashes in MPSAFE tty drivers like ucom.
 1.253  17-Aug-2012  christos branches: 1.253.2;
Better (not racy fix) from Paul Goyette.
 1.252  17-Aug-2012  christos Use the queue of the tty not garbage from the stack (Paul Goyette)
 1.251  12-Aug-2012  christos PR/46780: Dennis Ferguson: Take the easy way out and return EBUSY when changing
the queue size if the output queue is not empty. Other solutions seemed too
complex/fragile.
 1.250  12-Mar-2012  christos PR/41673: Stathis Kamperis: tcsetpgrp returns EINVAL, but should return EPERM.
 1.249  21-Oct-2011  christos branches: 1.249.2; 1.249.6; 1.249.8;
extract broken proc_compare. lwp compares against self.
 1.248  24-Sep-2011  christos - Introduce a sysctl to control the default tty queue size kern.tty.qsize,
which defaults to 1024 as before.
- Add two ioctls TIOC{G,S}QSIZE to read and adjust the queue size on
individual ptys.

NB: ttys (and ptys) still silently (or beepingly (IMAXBEL)) drop
characters if the queue size is exceeded. I.e. you can appear
to succeed writing to the {p,t}ty, but not all characters will
have made it if the queue overflows. CVS:
 1.247  23-Sep-2011  christos Change obsolete CBSIZE constant (48), to a power of two constant (64) that
is close enough to match the original assumptions.
 1.246  26-Jul-2011  yamt stop using lbolt in tty
 1.245  17-Jul-2011  joerg Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
 1.244  24-Apr-2011  rmind Rename ttymalloc() to tty_alloc(), and ttyfree() to tty_free() for
consistency. Remove some unnecessary malloc.h inclusions as well.
 1.243  09-Apr-2011  martin In ttymalloc() explicitly initialize t_dev to NODEV.
In ptcwakeup() do not bother to wake up a client side if it has not been
opened yet.
The old code would spuriously wakeup the client minor(0) [i.e. ttyp0
typically] or crash the kernel if that wasn't open, see PR kern/40688.
(Old names used to match the PR and test case, adjust names for
/dev/ptm[x] resp. /dev/pts/* accordingly)
 1.242  02-Feb-2011  christos fix locking and remove duplicate code.
 1.241  23-Jan-2011  mbalmer Cast arguments to vaddr_t when using PRIxVADDR in the printf format string.
 1.240  23-Jan-2011  matt Change ^T/SIGINFO to print the PC/CPU# or PC instead of "running"/"runable"
if a port provide LWP_PC.
 1.239  19-Nov-2010  dholland branches: 1.239.2; 1.239.4;
Introduce struct pathbuf. This is an abstraction to hold a pathname
and the metadata required to interpret it. Callers of namei must now
create a pathbuf and pass it to NDINIT (instead of a string and a
uio_seg), then destroy the pathbuf after the namei session is
complete.

Update all namei call sites accordingly. Add a pathbuf(9) man page and
update namei(9).

The pathbuf interface also now appears in a couple of related
additional places that were passing string/uio_seg pairs that were
later fed into NDINIT. Update other call sites accordingly.
 1.238  21-Aug-2010  pgoyette Update the rest of the kernel to conform to the module subsystem's new
locking protocol.
 1.237  01-Jul-2010  rmind Remove pfind() and pgfind(), fix locking in various broken uses of these.
Rename real routines to proc_find() and pgrp_find(), remove PFIND_* flags
and have consistent behaviour. Provide proc_find_raw() for special cases.
Fix memory leak in sysctl_proc_corename().

COMPAT_LINUX: rework ptrace() locking, minimise differences between
different versions per-arch.

Note: while this change adds some formal cosmetics for COMPAT_DARWIN and
COMPAT_IRIX - locking there is utterly broken (for ages).

Fixes PR/43176.
 1.236  13-Jun-2010  yamt update a comment.
 1.235  26-May-2010  pooka Feed dust to a few linkset uses and explicitly call the constructor.
 1.234  11-Oct-2009  dsl branches: 1.234.2; 1.234.4;
Check for zero length read here - and return zero.
Most times we've come through spec_read() which has already done the test,
but not always (eg pty with ptsfs mounted).
Without this there is a simple local-user panic in ureadc().
Noted Matthew Mondor on tech-kern.
 1.233  02-Oct-2009  elad Put the tty opening policy back in the subsystem.

Remove include we don't need from the secmodel code.
 1.232  01-Aug-2009  christos Don't return EWOULDBLOCK on an O_NONBLOCK tty file descriptor that has vmin > 0
and vtime > 0. It should be allowed to go to sleep for the sleep interval
indicated in vtime. Reported by der Mouse a long while ago, and this is what
other unixes do.
 1.231  25-Apr-2009  rmind - Rearrange pg_delete() and pg_remove() (renamed pg_free), thus
proc_enterpgrp() with proc_leavepgrp() to free process group and/or
session without proc_lock held.
- Rename SESSHOLD() and SESSRELE() to to proc_sesshold() and
proc_sessrele(). The later releases proc_lock now.

Quick OK by <ad>.
 1.230  22-Jan-2009  drochner branches: 1.230.2;
Avoid deadlock in tty code if a terminal emulation responds to
type/status/etc inquiries. (PR kern/37915)
This is clearly a design problem in tty, but we need a cheap fix now.
The problem is that ttyinput() tries to pull a spinlock which
is already held on calls to t_oproc.
The workaround is based on the fact that within wscons code, the
wsdisplay_emulinput() function is only called directly from
wsdisplaystart(). So we can be sure that the tty lock is held,
and use an inofficial entry point in ttc.c which avoids the locking.
These ate certainly more assumptions than needed by the fix
proposed in the PR, but it doesn't affect (and slow down) other
tty drivers.
 1.229  22-Jan-2009  yamt malloc -> kmem_alloc
 1.228  19-Nov-2008  ad Make the emulations, exec formats, coredump, NFS, and the NFS server
into modules. By and large this commit:

- shuffles header files and ifdefs
- splits code out where necessary to be modular
- adds module glue for each of the components
- adds/replaces hooks for things that can be installed at runtime
 1.227  08-Aug-2008  uebayasi branches: 1.227.2; 1.227.4;
ttywrite: g/c an unused variable (cnt).
 1.226  31-Jul-2008  uebayasi Display t_outcv* channels as "ttyout*", not "ttycan*".
 1.225  16-Jun-2008  ad branches: 1.225.2;
- PPWAIT is need only be locked by proc_lock, so move it to proc::p_lflag.
- Remove a few needless lock acquires from exec/fork/exit.
- Sprinkle branch hints.

No functional change.
 1.224  25-May-2008  ad branches: 1.224.2;
Properly fix the "hanging in tty" bug that was worked around with cv_wakeup()
some time again.
 1.223  03-May-2008  yamt branches: 1.223.2;
use sigismasked. no functional change.
 1.222  28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.221  24-Apr-2008  ad branches: 1.221.2;
Merge proc::p_mutex and proc::p_smutex into a single adaptive mutex, since
we no longer need to guard against access from hardware interrupt handlers.

Additionally, if cloning a process with CLONE_SIGHAND, arrange to have the
child process share the parent's lock so that signal state may be kept in
sync. Partially addresses PR kern/37437.
 1.220  24-Apr-2008  ad Network protocol interrupts can now block on locks, so merge the globals
proclist_mutex and proclist_lock into a single adaptive mutex (proc_lock).
Implications:

- Inspecting process state requires thread context, so signals can no longer
be sent from a hardware interrupt handler. Signal activity must be
deferred to a soft interrupt or kthread.

- As the proc state locking is simplified, it's now safe to take exit()
and wait() out from under kernel_lock.

- The system spends less time at IPL_SCHED, and there is less lock activity.
 1.219  22-Apr-2008  ad Give callout_halt() an additional 'kmutex_t *interlock' argument. If there
is a need to block and wait for the callout to complete, and there is an
interlock, it will be dropped while waiting and reacquired before return.
 1.218  21-Apr-2008  ad Fix TIOCSIG handling for SIGINFO.
 1.217  21-Apr-2008  yamt ttygetinfo: fix a locking error in rev.1.215.
 1.216  20-Apr-2008  ad ttys are allocated/freed infrequently enough that there is no point having
a seperate pool for them.
 1.215  20-Apr-2008  ad Improve ^T / SIGINFO handling:

- Restore code removed during LWPification.
- Don't touch proc state from a hardware interrupt handler.
- Fix the locking.
 1.214  05-Apr-2008  yamt branches: 1.214.2;
- l_wmesg is not always valid. check l_wchan when using l_wmesg.
should fix a crash reported by Juan RP on current-users@.
- ttyinfo: lock lwp when accessing l_wmesg.
- fill_lwp: add an assertion.
 1.213  01-Mar-2008  rmind Welcome to 4.99.55:

- Add a lot of missing selinit() and seldestroy() calls.

- Merge selwakeup() and selnotify() calls into a single selnotify().

- Add an additional 'events' argument to selnotify() call. It will
indicate which event (POLL_IN, POLL_OUT, etc) happen. If unknown,
zero may be used.

Note: please pass appropriate value of 'events' where possible.
Proposed on: <tech-kern>
 1.212  23-Jan-2008  elad branches: 1.212.2; 1.212.6;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.
 1.211  02-Jan-2008  ad Merge vmlocking2 to head.
 1.210  31-Dec-2007  ad Hang the correct processes when no output/input available. PR kern/37603.
From christos@.
 1.209  26-Dec-2007  ad Merge more changes from vmlocking2, mainly:

- Locking improvements.
- Use pool_cache for more items.
 1.208  08-Dec-2007  pooka branches: 1.208.4;
Remove cn_lwp from struct componentname. curlwp should be used
from on. The NDINIT() macro no longer takes the lwp parameter and
associates the credentials of the calling thread with the namei
structure.
 1.207  04-Dec-2007  ad ttysigintr: proclist_lock can be taken now.
 1.206  26-Nov-2007  pooka branches: 1.206.2;
Remove the "struct lwp *" argument from all VFS and VOP interfaces.
The general trend is to remove it from all kernel interfaces and
this is a start. In case the calling lwp is desired, curlwp should
be used.

quick consensus on tech-kern
 1.205  20-Nov-2007  ad Call ttstart() with tty_lock held.
 1.204  19-Nov-2007  ad Work around another funny until I figure out what is going wrong: somehow,
tp->t_rawq.c_cv.cv_waiters is dropping to zero while there are still LWPs
waiting on the queue. dtrace would be really handy here :-/
 1.203  19-Nov-2007  ad - Factor out too many copies of the same bit of tty code.
- Fix another tty signalling/wakeup problem.
 1.202  14-Nov-2007  ad Fix some problems with the tty signalling code.
 1.201  07-Nov-2007  ad Merge tty changes from the vmlocking branch.
 1.200  06-Nov-2007  ad Merge scheduler changes from the vmlocking branch. All discussed on
tech-kern:

- Invert priority space so that zero is the lowest priority. Rearrange
number and type of priority levels into bands. Add new bands like
'kernel real time'.
- Ignore the priority level passed to tsleep. Compute priority for
sleep dynamically.
- For SCHED_4BSD, make priority adjustment per-LWP, not per-process.
 1.199  18-Oct-2007  joerg branches: 1.199.2;
Initialise the callbacks for tty.t_rstrt_ch in ttymalloc
as all drivers but Sun/SPARC's kd.c use the same arguments.
Separate callout_reset into callout_schedule and the initial
callout_setfunc using that.
 1.198  25-Sep-2007  ad branches: 1.198.2;
Use selinit() / seldestroy().
 1.197  09-Jul-2007  ad branches: 1.197.6; 1.197.8; 1.197.10;
Merge some of the less invasive changes from the vmlocking branch:

- kthread, callout, devsw API changes
- select()/poll() improvements
- miscellaneous MT safety improvements
 1.196  17-May-2007  yamt merge yamt-idlelwp branch. asked by core@. some ports still needs work.

from doc/BRANCHES:

idle lwp, and some changes depending on it.

1. separate context switching and thread scheduling.
(cf. gmcgarry_ctxsw)
2. implement idle lwp.
3. clean up related MD/MI interfaces.
4. make scheduler(s) modular.
 1.195  12-Mar-2007  ad Use mutexes/condvars.
 1.194  12-Mar-2007  ad branches: 1.194.2;
Pass an ipl argument to pool_init/POOL_INIT to be used when initializing
the pool's lock.
 1.193  09-Mar-2007  ad branches: 1.193.2;
- Make the proclist_lock a mutex. The write:read ratio is unfavourable,
and mutexes are cheaper use than RW locks.
- LOCK_ASSERT -> KASSERT in some places.
- Hold proclist_lock/kernel_lock longer in a couple of places.
 1.192  04-Mar-2007  christos Kill caddr_t; there will be some MI fallout, but it will be fixed shortly.
 1.191  17-Feb-2007  dsl Acquire proclist_lock across the p_find() and pg_find() calls while
processing FIOSETOWN and TIOCSPGRP ioctls.
 1.190  09-Feb-2007  ad branches: 1.190.2;
Merge newlock2 to head.
 1.189  04-Jan-2007  elad Consistent usage of KAUTH_GENERIC_ISSUSER.
 1.188  13-Sep-2006  martin Avoid NULL deref (this is called with lwp=NULL from ppp interrupt context)
 1.187  03-Aug-2006  christos branches: 1.187.2; 1.187.4;
PR/34129: Andreas Gustafsson: Nonblocking write to pty can return 0
If we cannot write on the slave side, always return EWOULDBLOCK in the
non-blocking case, because we don't know that the buffer we started
writing is actually in a system call boundary.
 1.186  23-Jul-2006  ad Use the LWP cached credentials where sane.
 1.185  07-Jun-2006  kardel merge FreeBSD timecounters from branch simonb-timecounters
- struct timeval time is gone
time.tv_sec -> time_second
- struct timeval mono_time is gone
mono_time.tv_sec -> time_uptime
- access to time via
{get,}{micro,nano,bin}time()
get* versions are fast but less precise
- support NTP nanokernel implementation (NTP API 4)
- further reading:
Timecounter Paper: http://phk.freebsd.dk/pubs/timecounter.pdf
NTP Nanokernel: http://www.eecis.udel.edu/~mills/ntp/html/kern.html
 1.184  04-Jun-2006  christos Grr, change the code so that it compiles with gcc-3. It was ok with gcc-4.
 1.183  03-Jun-2006  christos Introduce SA_NOKERNINFO, a flag for SIGINFO not to print kernel messages.
 1.182  14-May-2006  elad branches: 1.182.2;
integrate kauth.
 1.181  10-May-2006  mrg quell GCC 4.1 uninitialised variable warnings.

XXX: we should audit the tree for which old ones are no longer needed
after getting the older compilers out of the tree..
 1.180  05-Mar-2006  christos branches: 1.180.2; 1.180.4;
Move ISSET/SET/CLR macros to sys/types.h
 1.179  26-Dec-2005  perry branches: 1.179.4; 1.179.6; 1.179.8;
u_intN_t -> uintN_t
 1.178  11-Dec-2005  christos merge ktrace-lwp.
 1.177  27-Nov-2005  thorpej Overhaul how TTY line disciplines are handled:
- Replace references to linesw[0] with a ttyldisc_default() function
that returns the default ("termios") line discipline.
- The linesw[] array is gone, replaced by a linked list.
- ttyldisc_add() and ttyldisc_remove() have been replaced by
ttyldisc_attach() and ttyldisc_detach().
- Things that provide line disciplines are now responsible for
registering those disciplines with the system. The linesw
structures are no longer declared in tty_conf.c
- Line disciplines are now refcounted; a lookup causes a reference to
be held. ttyldisc_release() releases the reference. Attempts to
detach an in-use line discipline result in EBUSY.
- Fix function signature lossage in if_sl.c, if_strip.c, and tty_tb.c
that was masked by the old tty_conf.c
- tty_init() is no longer necessary; delete it and its call from main().
 1.176  13-Oct-2005  christos branches: 1.176.6;
- lock the tty when playing with the kqueue list.
- don't return 1, when we expect to return errno [EPERM is kind of stupid
in this case :-)]
 1.175  25-Jul-2005  christos In the SIGIO case, only check that we are the controlling tty if we are a
session leader.
 1.174  07-Jul-2005  christos Allow F{G,S}OWN to succeed on a tty that has no session associated with it,
and it is not the controlling tty. This change allows us to use SIGIO on
a non-controlling tty (eg. debug ntpd with a refclock on a tty).
 1.173  11-Jun-2005  christos branches: 1.173.2;
Remove an extraneous TTY_UNLOCK. With a LOCKDEBUG kernel, sending FLUSHO
causes a locking assertion.
 1.172  08-May-2005  christos Panic strings should not end with \n.
 1.171  26-Feb-2005  perry nuke trailing whitespace
 1.170  06-Nov-2004  wrstuden branches: 1.170.4; 1.170.6;
Add support for FIONWRITE and FIONSPACE ioctls. FIONWRITE reports
the number of bytes in the send queue, and FIONSPACE reports the
number of free bytes in the send queue. These ioctls permit applications
to monitor file descriptor transmission dynamics.

In examining prior art, FIONWRITE exists with the semantics given
here. FIONSPACE is provided so that programs may easily determine how
much space is left in the send queue; they do not need to know the
send queue size.

The fact that a write may block even if there is enough space in the
send queue for it is noted in the documentation.

FIONWRITE functionality may be used to implement TIOCOUTQ for Linux
emulation - Linux extended this ioctl to sockets, even though they are
not ttys.
 1.169  15-Oct-2004  thorpej Don't initialize ttylist or tty_count in tty_init().
 1.168  25-May-2004  atatat Remaining sysctl descriptions under kern subtree
 1.167  25-Apr-2004  simonb Initialise (most) pools from a link set instead of explicit calls
to pool_init. Untouched pools are ones that either in arch-specific
code, or aren't initialiased during initial system startup.

Convert struct session, ucred and lockf to pools.
 1.166  25-Apr-2004  matt Constify the table argument to ttspeedtab.
 1.165  24-Mar-2004  atatat branches: 1.165.2;
Tango on sysctl_createv() and flags. The flags have all been renamed,
and sysctl_createv() now uses more arguments.
 1.164  09-Mar-2004  dbj add more spltty() calls around TTY_LOCK/UNLOCK where needed
 1.163  05-Mar-2004  dbj add some spltty() calls around TTY_LOCK() calls that didn't have them
 1.162  22-Feb-2004  jdolecek use the new NOTE_SUBMIT to flag if the locking is necessary
for EVFILT_READ/EVFILT_WRITE knotes

fixes PR kern/23915 by Martin Husemann (pipes), and similar locking problem
in tty code
 1.161  13-Feb-2004  wiz Uppercase CPU, plural is CPUs.
 1.160  06-Feb-2004  pk ioctl TIOCSCTTY: re-arrange SESSHOLD() calls to allow for better code generation.
 1.159  04-Dec-2003  atatat Dynamic sysctl.

Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.

Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.

All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.

PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
 1.158  21-Sep-2003  jdolecek 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@
 1.157  21-Sep-2003  manu Extra sanity checks: all char devices won't have an associated tty.
 1.156  11-Aug-2003  dsl Rework VTIME calculations so that they don't hit numeric overflow (ok now
for hz < ~200kHz). Old code failed VTIME > 214 even with hz=100.
Fixes kern/12285.
 1.155  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22364, verified by myself.
 1.154  29-Jun-2003  fvdl branches: 1.154.2;
Back out the lwp/ktrace changes. They contained a lot of colateral damage,
and need to be examined and discussed more.
 1.153  28-Jun-2003  darrenr 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
 1.152  10-Apr-2003  christos use VREAD instead of VWRITE, this ioctl is used to redirect console output.
 1.151  10-Apr-2003  christos PR/732: Matt Green: TIOCCONS should work if the user owns /dev/console.
 1.150  19-Mar-2003  dsl Alternative pid/proc allocater, removes all searches associated with pid
lookup and allocation, and any dependency on NPROC or MAXUSERS.
NO_PID changed to -1 (and renamed NO_PGID) to remove artificial limit
on PID_MAX.
As discussed on tech-kern.
 1.149  17-Feb-2003  christos Add a ttyprintf_nolock() to be called when we are printing the ttyinfo
stuff, since we already have the lock.
Adjust tputchar so that it does not lock, when NOLOCK is passed in flags.
 1.148  06-Feb-2003  pk XXX ttioctl(): some drivers call back on us from t_param(), so delay acquiring
tty spin lock until after t_param() returns.

Require t_param() to unlock upon callback?
 1.147  05-Feb-2003  pk Make the tty subsystem MP-safe..

..as far as mere mortals are able to, since this code illustrates the finest
points that Italian haute cuisine has to offer.
 1.146  19-Jan-2003  simonb Make the char_type array "unsigned char" since we stuff values > 0x80
into it.
 1.145  18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.144  26-Nov-2002  christos si_ -> sel_ to avoid conflicts with siginfo.
 1.143  23-Oct-2002  jdolecek 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
 1.142  06-Sep-2002  gehenna 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.
 1.141  04-Sep-2002  matt Use the queue macros from <sys/queue.h> instead of referring to the queue
members directly. Use *_FOREACH whenever possible.
 1.140  26-Aug-2002  thorpej Avoid signed/unsigned comparison warnings from GCC 3.3.
 1.139  21-Jul-2002  jdolecek Make sure repeated TIOCSCTTY doesn't corrupt session hold count.
Fixes kern/17382 by David Laight.
 1.138  02-May-2002  enami branches: 1.138.2; 1.138.4;
- Fix more and more white space nits.
- ANSIfy the last K&R function definition in this file.
 1.137  20-Apr-2002  simonb Fix a white-space nit.
 1.136  12-Apr-2002  christos Use SESSHOLD and SESSRELE consistently.
Add SESSHOLD and SESSRELE to the t_session, so that we don't have dangling
references [inspired by OpenBSD].
 1.135  25-Mar-2002  itohy Print ttyinfo *before* (not after) sending SIGINFO to processes.
This generates more useful information of a process who catches SIGINFO,
rather than always printing "runnable" (the process is marked runnable
because of the signal).
Inspired by the behavior of BSD/OS.
 1.134  17-Mar-2002  atatat Convert ioctl code to use EPASSTHROUGH instead of -1 or ENOTTY for
indicating an unhandled "command". ERESTART is -1, which can lead to
confusion. ERESTART has been moved to -3 and EPASSTHROUGH has been
placed at -4. No ioctl code should now return -1 anywhere. The
ioctl() system call is now properly restartable.
 1.133  08-Mar-2002  thorpej 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.
 1.132  04-Mar-2002  simonb nlinesw is already declared in <sys/conf.h>.
 1.131  08-Feb-2002  christos Andrew Brown found that we overflowed all cases in the TTLINEDNAMELEN.
ouch.
 1.130  28-Jan-2002  simonb Add sysctls to read tk_{nin,nout,cancc,rawcc} (under a kern.tkstat node).
"extern" those variables in <sys/dkstat.h>, and add declarations for them
in sys/tty.c
 1.129  12-Nov-2001  lukem add RCSIDs
 1.128  02-May-2001  scw branches: 1.128.2; 1.128.4; 1.128.6;
Add `l_poll' to `struct linesw' and provide an xxxpoll() entry point
in each tty driver to indirect through it.

This allows tty line-disciplines to handle poll(2) system calls.
 1.127  31-Mar-2001  enami Remove unnecessary test of tp->t_linesw against NULL; they are results
of confusion while correcting compilation error after t_line is
replaced with t_linesw.
 1.126  22-Mar-2001  lukem convert to ANSI KNF
 1.125  22-Dec-2000  jdolecek branches: 1.125.2;
split off thread specific stuff from struct sigacts to struct sigctx, leaving
only signal handler array sharable between threads
move other random signal stuff from struct proc to struct sigctx

This addresses kern/10981 by Matthew Orgass.
 1.124  15-Nov-2000  enami Don't allow t_linesw to be NULL.
 1.123  14-Nov-2000  thorpej NBPG -> PAGE_SIZE
 1.122  05-Nov-2000  jdolecek add new function sigismasked(), which checks whether passed signal
is ignored or masked by the process, and use it appropriately
instead of directly checking p->p_sigmask and p->p_sigignore
 1.121  01-Nov-2000  eeh Make line disciplines modular so they can be added or removed dynamically.
 1.120  27-Jun-2000  mrg remove include of <vm/vm.h>
 1.119  26-May-2000  thorpej branches: 1.119.4;
Introduce a new process state distinct from SRUN called SONPROC
which indicates that the process is actually running on a
processor. Test against SONPROC as appropriate rather than
combinations of SRUN and curproc. Update all context switch code
to properly set SONPROC when the process becomes the current
process on the CPU.
 1.118  30-Mar-2000  augustss Get rid of register declarations.
 1.117  28-Mar-2000  kleink Cast timeval members to types we know the printf conversions of.
 1.116  23-Mar-2000  thorpej New callout mechanism with two major improvements over the old
timeout()/untimeout() API:
- Clients supply callout handle storage, thus eliminating problems of
resource allocation.
- Insertion and removal of callouts is constant time, important as
this facility is used quite a lot in the kernel.

The old timeout()/untimeout() API has been removed from the kernel.
 1.115  24-Jul-1999  tron branches: 1.115.2;
Fix NULL pointer access. Patch supplied by Dave Huang in PR kern/8055.
 1.114  22-Jul-1999  thorpej Rework the process exit path, in preparation for making process exit
and PID allocation MP-safe. A new process state is added: SDEAD. This
state indicates that a process is dead, but not yet a zombie (has not
yet been processed by the process reaper).

SDEAD processes exist on both the zombproc list (via p_list) and deadproc
(via p_hash; the proc has been removed from the pidhash earlier in the exit
path). When the reaper deals with a process, it changes the state to
SZOMB, so that wait4 can process it.

Add a P_ZOMBIE() macro, which treats a proc in SZOMB or SDEAD as a zombie,
and update various parts of the kernel to reflect the new state.
 1.113  25-Apr-1999  simonb g/c REAL_CLISTS.
 1.112  11-Sep-1998  mycroft branches: 1.112.8;
Substantial signal handling changes:
* Increase the size of sigset_t to accomodate 128 signals -- adding new
versions of sys_setprocmask(), sys_sigaction(), sys_sigpending() and
sys_sigsuspend() to handle the changed arguments.
* Abstract the guts of sys_sigaltstack(), sys_setprocmask(), sys_sigaction(),
sys_sigpending() and sys_sigsuspend() into separate functions, and call them
from all the emulations rather than hard-coding everything. (Avoids uses
the stackgap crap for these system calls.)
* Add a new flag (p_checksig) to indicate that a process may have signals
pending and userret() needs to do the full (slow) check.
* Eliminate SAS_ALTSTACK; it's exactly the inverse of SS_DISABLE.
* Correct emulation bugs with restoring SS_ONSTACK.
* Make the signal mask in the sigcontext always use the emulated mask format.
* Store signals internally in sigaction structures, rather than maintaining a
bunch of little sigsets for each SA_* bit.
* Keep track of where we put the signal trampoline, rather than figuring it out
in *_sendsig().
* Issue a warning when a non-emulated sigaction bit is observed.
* Add missing emulated signals, and a native SIGPWR (currently not used).
* Implement the `not reset when caught' semantics for relevant signals.

Note: Only code touched by the i386 port has been modified. Other ports and
emulations need to be updated.
 1.111  01-Sep-1998  thorpej Use the pool allocator and the "nointr" pool page allocator for tty
structures.
 1.110  18-Aug-1998  thorpej Add some braces to make egcs happy (ambiguous else warning).
 1.109  04-Aug-1998  perry Abolition of bcopy, ovbcopy, bcmp, and bzero, phase one.
bcopy(x, y, z) -> memcpy(y, x, z)
ovbcopy(x, y, z) -> memmove(y, x, z)
bcmp(x, y, z) -> memcmp(x, y, z)
bzero(x, y) -> memset(x, 0, y)
 1.108  31-Jul-1998  perry fix sizeofs so they comply with the KNF style guide. yes, it is pedantic.
 1.107  22-Mar-1998  mycroft branches: 1.107.2;
Move the code to wait for carrier on a tty into a common function, since it
depends only on device-independent state bits.
Implement SunOS-style `dialout' devices.
 1.106  21-Mar-1998  mycroft Replace TS_WOPEN with t_wopen, per mail on tech-kern.
 1.105  01-Mar-1998  fvdl Merge with Lite2 + local changes
 1.104  14-Feb-1998  thorpej Implement TIOCGSID.
 1.103  13-Feb-1998  kleink Add ONOCR and ONLRET output modes, from XPG4.2.
 1.102  12-Feb-1998  kleink Fix variable declarations: register -> register int.
 1.101  12-Dec-1997  drochner Make ttyblock() work as intended and documented in canonical mode.
(operator precedence problem)
closes PR kern/2131 (Matthias Pfaller)
 1.100  28-Oct-1997  thorpej defopt UCONSOLE
 1.99  19-Oct-1997  mycroft branches: 1.99.2;
Count characters even when !OPOST and FLUSHO.
Don't output the \r for ONLCR if FLUSHO.
 1.98  09-Oct-1997  mycroft Make various standard wmesg strings const.
 1.97  09-Oct-1997  mycroft Make wmesg arguments to various functions const.
 1.96  20-Jun-1997  kleink branches: 1.96.4; 1.96.6;
Add some robustness to ttymodem(), e.g. do not SIGHUP when there hasn't been
an actual carrier transition; from Charles M. Hannum.
 1.95  18-Jun-1997  kleink When a background process attempts to TIOC[CS]BRK (a.k.a. tcsendbreak()) or
TIOCSTART (a.k.a tcflow()), send its process group a SIGTTOU.
 1.94  17-Jun-1997  kleink Rewrote break/parity/framing error handling from spec.
 1.93  22-May-1997  kleink If the pgrp_id argument of TIOCSPGRP (a.k.a. tcsetpgrp()) does not specify
an existing process group, return EINVAL.
 1.92  20-May-1997  kleink When a background process attempts to TIOCDRAIN (a.k.a. tcdrain()), send
its process group a SIGTTOU signal.
 1.91  17-May-1997  thorpej Fix printf format botch.
 1.90  16-May-1997  gwr Eliminate vmspace.vm_pmap and all references to it unless
__VM_PMAP_HACK is defined (for temporary compatibility).
The __VM_PMAP_HACK code should be removed after all the
ports that define it have removed all vm_pmap references.
 1.89  07-Apr-1997  kleink Fix a CRNL/NLCR botch I made after looking this up in the X/Open spec.
Fixes PR 3453; from John Kohl and Enami Tsugutomo.
 1.88  06-Apr-1997  kleink Add some clarification about the TTBREAKC macro's purpose; suggested by
Chris G. Demetriou.
 1.87  06-Apr-1997  cgd fix missing parenthesis in TTBREAKC()
 1.86  05-Apr-1997  kleink If TOSTOP is set, and the process group of the writing process is orphaned,
and the writing process is not ignoring or blocking SIGTTOU, do not signal
the process but return EIO.
 1.85  05-Apr-1997  kleink Recognize EOL2 as a delimiter/"break" character only if IEXTEN is set.
 1.84  04-Apr-1997  mycroft Remove unintended piece of last change.
 1.83  04-Apr-1997  mycroft Fix several bugs related to MDMBUF. Also, remove the partial handling from
ttymodem(); it's not complete, it's better done in the driver, and only the
com driver ever supported it anyway.
 1.82  04-Apr-1997  kleink As specified in POSIX.1 (and termios(4)!), when cc[VMIN]==0 a read() shall
be satisfied by any amount of data actually read.
 1.81  03-Apr-1997  kleink WERASE, REPRINT, STATUS and DSUSP are extensions to the POSIX.1 GTI
set of special characters: recognize them only if IEXTEN is set.
 1.80  02-Apr-1997  kleink KNF glitch in last commit, pointed out by Chris G. Demetriou.
 1.79  02-Apr-1997  kleink Implement OCRNL "\r" -> "\n" tty output translation.
Fixes PR standards/3434.
 1.78  29-Mar-1997  christos PR/3396: Klaus Klein: If CREAD is not set drop incoming data.
 1.77  25-Oct-1996  cgd don't thow away char_type's 'const'ness via a cast when passing it to scanc().
(1) that causes -Wcast-qual to be unhappy, and (2) the cast is unnecessary!
 1.76  13-Oct-1996  christos backout previous kprintf change
 1.75  10-Oct-1996  christos printf -> kprintf, sprintf -> ksprintf
 1.74  07-Sep-1996  mycroft Implement poll(2).
 1.73  06-Jun-1996  mrg don't tty_detach() in ttyfree(). make the user of ttyfree() do
the tty_detach() as not all ttymalloc()'ed ttys are tty_attach()ed.
 1.72  04-Jun-1996  mrg add a comment on how to use tty_attach().
 1.71  30-May-1996  cgd a few minor KNF nits
 1.70  30-May-1996  mrg check tty_count first (from cgd).
 1.69  29-May-1996  mrg impliment ttylist stats based on disk stats.
 1.68  29-Mar-1996  christos branches: 1.68.4;
Fix another printf format warning.
 1.67  16-Mar-1996  christos Fix printf() formats.
 1.66  09-Feb-1996  christos More proto fixes
 1.65  04-Feb-1996  christos First pass at prototyping
 1.64  10-Jan-1996  pk Correct test for ECHONL (from der Mouse; PR#1922).
 1.63  10-Oct-1995  mycroft branches: 1.63.2;
Add hooks for COMPAT_FREEBSD, from Noriyuki Soda.
 1.62  22-Sep-1995  cgd fix annoying but non-critical rounding but in ttyinfo(). (If
microseconds goes over 10^6 when rounding, increment seconds.)
 1.61  02-Jul-1995  mycroft Close routines take file flags, not I/O flags. Fix two incorrect usages.
 1.60  04-Jun-1995  mycroft Only do software flow control if IXOFF is set. Also fix hardware flow control
case in ttyblock().
 1.59  04-Jun-1995  mycroft Use ISSET() and CLR() in two cases.
 1.58  19-Apr-1995  mycroft Change ttselect() to use a callback to get the tty structure.
 1.57  17-Nov-1994  christos Added ifdef COMPAT_SVR4 to the kernel compat code needed.
 1.56  30-Oct-1994  mycroft Change argument list of ttioctl() to match other ioctl functions.
 1.55  30-Oct-1994  cgd be more careful with types, also pull in headers where necessary.
 1.54  24-Oct-1994  mycroft Fix a bug I introduced in the last commit, regarding a VTIME timeout causing
EWOULDBLOCK to be returned rather than looping again to see if any characters
are pending. Also, fix another bug in the original code; if someone changed
VMIN behind our back, last_cc might be uninitialized when we reference it.
 1.53  12-Oct-1994  mycroft Remove the need for some untimeouts.
 1.52  18-Sep-1994  deraadt fix PR#484 relating to backspacing over a tab.
 1.51  30-Aug-1994  mycroft Convert process, file, and namei lists and hash tables to use queue.h.
 1.50  02-Aug-1994  mycroft Clear t_flags on first open.
 1.49  29-Jun-1994  cgd branches: 1.49.2;
New RCS ID's, take two. they're more aesthecially pleasant, and use 'NetBSD'
 1.48  25-May-1994  deraadt use u_char's instead of char's; else the TTY_QUOTE bit can get accidentally
be set.
 1.47  12-May-1994  cgd upgrade to 4.4-Lite's tty code. our bug fixes included, some might need GC.
 1.46  05-May-1994  cgd lots of changes: prototype migration, move lots of variables, definitions,
and structure elements around. kill some unnecessary type and macro
definitions. standardize clock handling. More changes than you'd want.
 1.45  04-May-1994  cgd Rename a lot of process flags.
 1.44  09-Apr-1994  deraadt FIONREAD plays with an int, not an off_t.
 1.43  18-Mar-1994  cgd fix somebody's typo
 1.42  18-Mar-1994  cgd add hw input flow control support
 1.41  05-Mar-1994  mycroft Don't do TIOCHPCL if !COMPAT_43. In the new world, you use termios.
 1.40  20-Feb-1994  mycroft Return a legitimate value from ttylclose().
 1.39  20-Feb-1994  mycroft Don't send SIGINFO if ISIG off.
 1.38  20-Feb-1994  mycroft Some formatting changes.
 1.37  14-Feb-1994  ws (Hopefully) do the right thing with VTIME > 0 and select
 1.36  09-Feb-1994  mycroft All ioctl routines take a struct proc * now.
 1.35  01-Feb-1994  deraadt more untimouts needed, from someone at freebsd
 1.34  28-Jan-1994  deraadt undo totally misguided changes from Andrew Chernov in rev. 1.7:
RTS has nothing to do with ttyblock()
also, close a race.
 1.33  23-Jan-1994  deraadt more COMPAT_SUNOS changes.
 1.32  07-Jan-1994  cgd do the *right* thing with resident set size
 1.31  07-Jan-1994  deraadt really fix the tab code
 1.30  05-Jan-1994  cgd from Mike Karels <karels@bsdi.com>: clear the PENDIN flag if ICANON
is cleared, and retain the PENDIN flag if set when ICANON is set
 1.29  30-Dec-1993  cgd print out what we think is the resident set size. very nasty; the field
in the proc's vmspace struct should be updated, but isn't...
Also, if the process is a zombie or infantile, don't print, because
that could cause a null pointer deref.
 1.28  24-Dec-1993  deraadt OXTABS expansion was putting fewer than the required spaces if the clists
became full. we now retry the tab expansion later.
 1.27  20-Dec-1993  cgd load average changes from magnum
 1.26  18-Dec-1993  mycroft Canonicalize all #includes.
 1.25  16-Dec-1993  deraadt fix from Daniel Harris <daniel@werple.apana.org.au>
VTIME code must untimeout
 1.24  13-Dec-1993  deraadt VMIN/VTIME support from Marc Teitelbaum <marc@vangogh.cs.berkeley.edu>
 1.23  09-Dec-1993  deraadt echo ^V^? correctly as ^?. From Edward Wang <edward@homer.CS.Berkeley.EDU>
 1.22  23-Aug-1993  mycroft branches: 1.22.2;
If ospeed is set to 0, SIGHUP the session leader (if any).
 1.21  01-Aug-1993  mycroft Add RCS identifiers (this time on the correct side of the branch), and
incorporate recent changes in netbsd-0-9 branch.
 1.20  19-Jul-1993  mycroft branches: 1.20.2;
Move flushq() macro into tty.h.
 1.19  19-Jul-1993  mycroft Use flushq() macro instead.
 1.18  19-Jul-1993  mycroft Use ndflush(), not while(getc()).
 1.17  12-Jul-1993  mycroft Change tty code to use clist interface, but with ring buffer implementation.
Also, fix a couple of bugs in tty.c and pccons.c, and some gross kluginess
in the hp300 stuff.
 1.16  11-Jul-1993  cgd re-add two changes which had been deleted by commit of r1.7
 1.15  02-Jul-1993  mycroft Blasted ftpd!
 1.14  02-Jul-1993  mycroft Fix bugs in rb_write and rb_cwrite, and make tab handling use rb_cwrite.
 1.13  01-Jul-1993  mycroft Fix a situation where we might forget to splx().
 1.12  27-Jun-1993  andrew * ansifications
* question about whether the "tp->t_state |= TS_ISOPEN" in ttyopen() should
be shifted to the end of the block in which it appears.
 1.11  20-Jun-1993  andrew Fixed ECHONL.
 1.10  06-Jun-1993  cgd make getc() and ungetc() be rb{un,}getc(), so getc() and ungetc()
don't conflict w/ansi prototypes...
 1.9  26-May-1993  deraadt tty dynamic allocation
 1.8  18-May-1993  cgd make kernel select interface be one-stop shopping & clean it all up.
 1.7  13-May-1993  deraadt various 8-bit patches from Andrew Chernov <ache@astral.msk.su>
tty_compat.c is cleaned up, as is STOP+TIOCSTI in tty.c
 1.6  13-May-1993  cgd from Luke Mewburn <zak@rmit.edu.au>:
add TIOCSTAT ioctl to give load average stats if requested (for tcsh)
 1.5  10-May-1993  deraadt ring buffer now uses rbchar's (shorts) instead of chars.
 1.4  24-Mar-1993  sef Oops. Inserted at the wrong place.
 1.3  24-Mar-1993  sef Handle one-word cases in word-erase.
 1.2  21-Mar-1993  cgd after 0.2.2 "stable" patches applied
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3  01-Mar-1998  fvdl Import 4.4BSD-Lite2
 1.1.1.2  01-Mar-1998  fvdl Import 4.4BSD-Lite for reference
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.20.2.2  31-Jul-1993  cgd give names, err, wmesg's, to my "pain" -- i.e. convert sleep() to tsleep()
 1.20.2.1  19-Jul-1993  cgd file tty.c was added on branch netbsd-0-9 on 1993-07-31 12:17:01 +0000
 1.22.2.6  09-Dec-1993  deraadt update to trunk
 1.22.2.5  14-Nov-1993  mycroft Canonicalize all #includes.
 1.22.2.4  18-Oct-1993  deraadt #ifdef COMPAT_43
->
#if defined(COMPAT_43) || defined(COMPAT_SUNOS)
in a few places
 1.22.2.3  30-Sep-1993  deraadt calcru() calculates times from ticks.
 1.22.2.2  24-Sep-1993  mycroft Make all files using spl*() #include cpu.h. Changes from trunk.
init_main.c: New method of pseudo-device of initialization.
kern_clock.c: hardclock() and softclock() now take a pointer to a clockframe.
softclock() only does callouts.
kern_synch.c: Remove spurious declaration of endtsleep(). Adjust uses of
averunnable for new struct loadav.
subr_prf.c: Allow printf() formats in panic().
tty.c: averunnable changes.
vfs_subr.c: va_size and va_bytes are now quads.
 1.22.2.1  14-Sep-1993  mycroft init_main.c: clock changes from 4.4; initclocks() is called after vfsinit().
No startrtclock() or enablertclock(). Some pseudo-device cruft, but this needs
to be updated.
kern_clock.c: from 4.4: gatherstats() --> statclock(). statclock(),
hardclock(), and softclock() take a `struct clockframe *'. New initclocks(),
harclock(), statclock(), startprofclock(), and stopprofclock().
kern_synch.c: from 4.4: machine-independent swtch(), which is now where
process time is integrated. Calls cpu_swtch() with the current process as an
arg.
subr_autoconf.c: Fix typo.
subr_prf.c: msgbufp and msgbufmapped are define in machdep.c
tty.c: Make TIOCHPCL #ifdef COMPAT_43.
Incorporate changes from main branch.
 1.49.2.2  18-Sep-1994  cgd latest fix, from trunk, per theo.
 1.49.2.1  03-Aug-1994  cgd from trunk
 1.63.2.1  02-Feb-1996  mycroft Bring in changes for mondo patch 2.
 1.68.4.2  06-Jun-1996  thorpej Pull up changes from revision 1.73, per Matt's request.
 1.68.4.1  02-Jun-1996  mrg pull up tty stats "bug fix".
 1.96.6.1  08-Sep-1997  thorpej Significantly restructure the way signal state for a process is stored.
Rather than using bitmasks to redundantly store the information kept
in the process's sigacts (because the sigacts was kept in the u-area),
hang sigacts directly off the process, and access it directly.

Simplify signal setup code tremendously by storing information in
the sigacts as an array of struct sigactions, rather than in a different
format, since userspace uses sigactions.

Make sigacts sharable by adding reference counting.
 1.96.4.1  14-Oct-1997  thorpej Update marc-pcmcia branch from trunk.
 1.99.2.1  28-Oct-1997  thorpej Pull up from trunk: defopt UCONSOLE.
 1.107.2.1  08-Aug-1998  eeh Revert cdevsw mmap routines to return int.
 1.112.8.2  02-Aug-1999  thorpej Update from trunk.
 1.112.8.1  21-Jun-1999  thorpej Sync w/ -current.
 1.115.2.5  21-Apr-2001  bouyer Sync with HEAD
 1.115.2.4  27-Mar-2001  bouyer Sync with HEAD.
 1.115.2.3  05-Jan-2001  bouyer Sync with HEAD
 1.115.2.2  22-Nov-2000  bouyer Sync with HEAD.
 1.115.2.1  20-Nov-2000  bouyer Update thorpej_scsipi to -current as of a month ago
 1.119.4.2  04-Sep-2002  itojun sys/kern/tty.c 1.139 (jdolecek)

Make sure repeated TIOCSCTTY doesn't corrupt session hold count.
Fixes kern/17382 by David Laight.
 1.119.4.1  26-Apr-2002  he Pull up revision 1.136 (requested by christos):
Use SESSHOLD and SESSRELE consistently, and add them to t_session,
so that we do not have dangling references.
 1.125.2.16  11-Dec-2002  thorpej Sync with HEAD.
 1.125.2.15  11-Nov-2002  nathanw Catch up to -current
 1.125.2.14  17-Sep-2002  nathanw Catch up to -current.
 1.125.2.13  27-Aug-2002  nathanw Catch up to -current.
 1.125.2.12  01-Aug-2002  nathanw Catch up to -current.
 1.125.2.11  12-Jul-2002  nathanw No longer need to pull in lwp.h; proc.h pulls it in for us.
 1.125.2.10  24-Jun-2002  nathanw Curproc->curlwp renaming.

Change uses of "curproc->l_proc" back to "curproc", which is more like the
original use. Bare uses of "curproc" are now "curlwp".

"curproc" is now #defined in proc.h as ((curlwp) ? (curlwp)->l_proc) : NULL)
so that it is always safe to reference curproc (*de*referencing curproc
is another story, but that's always been true).
 1.125.2.9  20-Jun-2002  nathanw Catch up to -current.
 1.125.2.8  17-Apr-2002  nathanw Catch up to -current.
 1.125.2.7  01-Apr-2002  nathanw Catch up to -current.
(CVS: It's not just a program. It's an adventure!)
 1.125.2.6  28-Feb-2002  nathanw Catch up to -current.
 1.125.2.5  14-Nov-2001  nathanw Catch up to -current.
 1.125.2.4  22-Aug-2001  nathanw In ttyinfo(), iterate over pick->p_lwps, not p->p_lwps.
 1.125.2.3  21-Jun-2001  nathanw Catch up to -current.
 1.125.2.2  09-Apr-2001  nathanw Catch up with -current.
 1.125.2.1  05-Mar-2001  nathanw Initial commit of scheduler activations and lightweight process support.
 1.128.6.1  12-Nov-2001  thorpej Sync the thorpej-mips-cache branch with -current.
 1.128.4.4  13-Oct-2001  fvdl Revert the t_dev -> t_devvp change in struct tty. The way that tty
structs are currently used (especially by console ttys) aren't
ready for it, and this will require quite a few changes.
 1.128.4.3  26-Sep-2001  fvdl * add a VCLONED vnode flag that indicates a vnode representing a cloned
device.
* rename REVOKEALL to REVOKEALIAS, and add a REVOKECLONE flag, to pass
to VOP_REVOKE
* the revoke system call will revoke all aliases, as before, but not the
clones
* vdevgone is called when detaching a device, so make it use REVOKECLONE
to get rid of all clones as well
* clean up all uses of VOP_OPEN wrt. locking.
* add a few VOPS to spec_vnops that need to do something when it's a
clone vnode (access and getattr)
* add a copy of the vnode vattr structure of the original 'master' vnode
to the specinfo of a cloned vnode. could possibly redirect getattr to
the 'master' vnode, but this has issues with revoke
* add a vdev_reassignvp function that disassociates a vnode from its
original device, and reassociates it with the specified dev_t. to be
used by cloning devices only, in case a new minor is allocated.
* change all direct references in drivers to v_devcookie and v_rdev
to vdev_privdata(vp) and vdev_rdev(vp). for diagnostic purposes
when debugging race conditions that still exist wrt. locking and
revoking vnodes.
* make the locking state of a vnode consistent when passed to
d_open and d_close (unlocked). locked would be better, but has
some deadlock issues
 1.128.4.2  18-Sep-2001  fvdl Various changes to make cloning devices possible:

* Add an extra argument (struct vnode **) to VOP_OPEN. If it is
not NULL, specfs will create a cloned (aliased) vnode during
the call, and return it there. The caller should release and
unlock the original vnode if a new vnode was returned. The
new vnode is returned locked.

* Add a flag field to the cdevsw and bdevsw structures.
DF_CLONING indicates that it wants a new vnode for each
open (XXX is there a better way? devprop?)

* If a device is cloning, always call the close entry
point for a VOP_CLOSE.


Also, rewrite cons.c to do the right thing with vnodes. Use VOPs
rather then direct device entry calls. Suggested by mycroft@

Light to moderate testing done an i386 system (arch doesn't matter
though, these are MI changes).
 1.128.4.1  07-Sep-2001  thorpej Commit my "devvp" changes to the thorpej-devvp branch. This
replaces the use of dev_t in most places with a struct vnode *.

This will form the basic infrastructure for real cloning device
support (besides being architecurally cleaner -- it'll be good
to get away from using numbers to represent objects).
 1.128.2.13  10-Oct-2002  jdolecek sync kqueue with -current; this includes merge of gehenna-devsw branch,
merge of i386 MP branch, and part of autoconf rototil work
 1.128.2.12  29-Sep-2002  jdolecek drop (caddr_t) and (void *) casts for kn_hook
 1.128.2.11  24-Sep-2002  jdolecek filt_ttywrite(): according to EVFILT_WRITE spec, kn_data should contain
'amount of space remaining in the write buffer'. So, do not put
t_outq.c_cc there (which is count of characters in queue), but
't_outq.c_cn - t_outq.cc' (i.e. total ring buffer length without count
if characters in queue)

also shuffle filt_*() functions around to not need forward declaration,
and g/c the prototypes on top
 1.128.2.10  06-Sep-2002  jdolecek sync kqueue branch with HEAD
 1.128.2.9  23-Jun-2002  jdolecek catch up with -current on kqueue branch
 1.128.2.8  16-Mar-2002  jdolecek Catch up with -current.
 1.128.2.7  11-Feb-2002  jdolecek Sync w/ -current.
 1.128.2.6  10-Jan-2002  thorpej Sync kqueue branch with -current.
 1.128.2.5  08-Sep-2001  thorpej Add a selnotify(), which does a selwakeup() + KNOTE(), rather than
requiring all callers to do both.

This may be a transitional step only, or it may stick. I haven't
decided yet.
 1.128.2.4  07-Sep-2001  thorpej More const.
 1.128.2.3  07-Sep-2001  thorpej Stash the tty pointer in kn->kn_hook, not the dev_t.
 1.128.2.2  07-Sep-2001  thorpej Actually activate knotes when appropriate (at the same time
that selwakeup() is performed).
 1.128.2.1  10-Jul-2001  lukem add kqueue methods for filt_tty*
 1.138.4.1  22-Jul-2002  lukem Pull up revision 1.139 (requested by jdolocek in ticket #535):
Make sure repeated TIOCSCTTY doesn't corrupt session hold count.
Fixes kern/17382 by David Laight.
 1.138.2.2  29-Aug-2002  gehenna catch up with -current.
 1.138.2.1  16-May-2002  gehenna Replace the direct-access to devsw table with calling devsw APIs.
 1.154.2.8  11-Dec-2005  christos Sync with head.
 1.154.2.7  10-Nov-2005  skrll Sync with HEAD. Here we go again...
 1.154.2.6  14-Nov-2004  skrll Sync with HEAD.
 1.154.2.5  19-Oct-2004  skrll Sync with HEAD
 1.154.2.4  21-Sep-2004  skrll Fix the sync with head I botched.
 1.154.2.3  18-Sep-2004  skrll Sync with HEAD.
 1.154.2.2  03-Aug-2004  skrll Sync with HEAD
 1.154.2.1  02-Jul-2003  darrenr Apply the aborted ktrace-lwp changes to a specific branch. This is just for
others to review, I'm concerned that patch fuziness may have resulted in some
errant code being generated but I'll look at that later by comparing the diff
from the base to the branch with the file I attempt to apply to it. This will,
at the very least, put the changes in a better context for others to review
them and attempt to tinker with removing passing of 'struct lwp' through
the kernel.
 1.165.2.1  26-May-2004  he Pull up revision 1.168 (requested by atatat in ticket #388):
Add remaining sysctl descriptions under kern subtree.
 1.170.6.1  19-Mar-2005  yamt sync with head. xen and whitespace. xen part is not finished.
 1.170.4.1  29-Apr-2005  kent sync with -current
 1.173.2.10  17-Mar-2008  yamt sync with head.
 1.173.2.9  04-Feb-2008  yamt sync with head.
 1.173.2.8  21-Jan-2008  yamt sync with head
 1.173.2.7  07-Dec-2007  yamt sync with head
 1.173.2.6  15-Nov-2007  yamt sync with head.
 1.173.2.5  27-Oct-2007  yamt sync with head.
 1.173.2.4  03-Sep-2007  yamt sync with head.
 1.173.2.3  26-Feb-2007  yamt sync with head.
 1.173.2.2  30-Dec-2006  yamt sync with head.
 1.173.2.1  21-Jun-2006  yamt sync with head.
 1.176.6.1  29-Nov-2005  yamt sync with head.
 1.179.8.5  14-Sep-2006  yamt sync with head.
 1.179.8.4  11-Aug-2006  yamt sync with head
 1.179.8.3  26-Jun-2006  yamt sync with head.
 1.179.8.2  24-May-2006  yamt sync with head.
 1.179.8.1  13-Mar-2006  yamt sync with head.
 1.179.6.5  07-Jun-2006  kardel Sync with head.
 1.179.6.4  03-Jun-2006  kardel Sync with head.
 1.179.6.3  01-Jun-2006  kardel Sync with head.
 1.179.6.2  22-Apr-2006  simonb Sync with head.
 1.179.6.1  04-Feb-2006  simonb Adapt for timecounters: mostly use get*time() and use "time_second"
instead of "time.tv_sec".
 1.179.4.1  09-Sep-2006  rpaulo sync with head
 1.180.4.1  24-May-2006  tron Merge 2006-05-24 NetBSD-current into the "peter-altq" branch.
 1.180.2.3  11-May-2006  elad sync with head
 1.180.2.2  06-May-2006  christos - Move kauth_cred_t declaration to <sys/types.h>
- Cleanup struct ucred; forward declarations that are unused.
- Don't include <sys/kauth.h> in any header, but include it in the c files
that need it.

Approved by core.
 1.180.2.1  08-Mar-2006  elad Adapt to kernel authorization KPI.
 1.182.2.1  19-Jun-2006  chap Sync with head.
 1.187.4.7  30-Jan-2007  ad Remove support for SA. Ok core@.
 1.187.4.6  12-Jan-2007  ad Sync with head.
 1.187.4.5  29-Dec-2006  ad Checkpoint work in progress.
 1.187.4.4  18-Nov-2006  ad Sync with head.
 1.187.4.3  17-Nov-2006  ad Checkpoint work in progress.
 1.187.4.2  24-Oct-2006  ad - Redo LWP locking slightly and fix some races.
- Fix some locking botches.
- Make signal mask / stack per-proc for SA processes.
- Add _lwp_kill().
 1.187.4.1  20-Oct-2006  ad Acquire proclist_lock / proclist_mutex when sending signals.
 1.187.2.1  14-Sep-2006  riz Pull up following revision(s) (requested by martin in ticket #159):
sys/kern/tty.c: revision 1.188
Avoid NULL deref (this is called with lwp=NULL from ppp interrupt context)
 1.190.2.4  21-Apr-2007  ad Some changes mainly for top/ps:

- Add an optional name field to struct lwp.
- Count the total number of context switches + involuntary,
not voluntary + involuntary.
- Mark the idle threads as LSIDL when not running, otherwise
they show up funny in a top(1) that shows threads.
- Make pctcpu and cpticks per-LWP attributes.
- Add to kinfo_lwp: cpticks, pctcpu, pid, name.
 1.190.2.3  24-Mar-2007  yamt sync with head.
 1.190.2.2  12-Mar-2007  rmind Sync with HEAD.
 1.190.2.1  27-Feb-2007  yamt - sync with head.
- move sched_changepri back to kern_synch.c as it doesn't know PPQ anymore.
 1.193.2.15  05-Nov-2007  ad proc_compare: ignore estcpu, just key on pctcpu.
 1.193.2.14  01-Nov-2007  ad - Fix interactivity problems under high load. Beacuse soft interrupts
are being stacked on top of regular LWPs, more often than not aston()
was being called on a soft interrupt thread instead of a user thread,
meaning that preemption was not happening on EOI.

- Don't use bool in a couple of data structures. Sub-word writes are not
always atomic and may clobber other fields in the containing word.

- For SCHED_4BSD, make p_estcpu per thread (l_estcpu). Rework how the
dynamic priority level is calculated - it's much better behaved now.

- Kill the l_usrpri/l_priority split now that priorities are no longer
directly assigned by tsleep(). There are three fields describing LWP
priority:

l_priority: Dynamic priority calculated by the scheduler.
This does not change for kernel/realtime threads,
and always stays within the correct band. Eg for
timeshared LWPs it never moves out of the user
priority range. This is basically what l_usrpri
was before.

l_inheritedprio: Lent to the LWP due to priority inheritance
(turnstiles).

l_kpriority: A boolean value set true the first time an LWP
sleeps within the kernel. This indicates that the LWP
should get a priority boost as compensation for blocking.
lwp_eprio() now does the equivalent of sched_kpri() if
the flag is set. The flag is cleared in userret().

- Keep track of scheduling class (OTHER, FIFO, RR) in struct lwp, and use
this to make decisions in a few places where we previously tested for a
kernel thread.

- Partially fix itimers and usr/sys/intr time accounting in the presence
of software interrupts.

- Use kthread_create() to create idle LWPs. Move priority definitions
from the various modules into sys/param.h.

- newlwp -> lwp_create
 1.193.2.13  28-Oct-2007  ad Tweak locking / add assertions.
 1.193.2.12  23-Oct-2007  ad Sync with head.
 1.193.2.11  19-Oct-2007  ad In the tty code, defer posting singals to a soft interrupt. Avoids
touching process state from a hardware interrupt, and avoids locking
problems (tty_lock is always held when the signals are sent).
 1.193.2.10  19-Oct-2007  ad Replace the tty locks with a global tty_lock.
 1.193.2.9  09-Oct-2007  ad Sync with head.
 1.193.2.8  28-Aug-2007  ad wakeup -> cv_broadcast
 1.193.2.7  28-Aug-2007  ad Use cdev_stop, cdev_tty.
 1.193.2.6  01-Jul-2007  ad Adapt to callout API change.
 1.193.2.5  08-Jun-2007  ad Sync with head.
 1.193.2.4  05-Apr-2007  ad Compile fixes.
 1.193.2.3  23-Mar-2007  ad Revert accidental change.
 1.193.2.2  21-Mar-2007  ad - Replace more simple_locks, and fix up in a few places.
- Use condition variables.
- LOCK_ASSERT -> KASSERT.
 1.193.2.1  13-Mar-2007  ad Sync with head.
 1.194.2.1  11-Jul-2007  mjf Sync with head.
 1.197.10.1  06-Oct-2007  yamt sync with head.
 1.197.8.4  23-Mar-2008  matt sync with HEAD
 1.197.8.3  09-Jan-2008  matt sync with HEAD
 1.197.8.2  08-Nov-2007  matt sync with -HEAD
 1.197.8.1  06-Nov-2007  matt sync with HEAD
 1.197.6.8  09-Dec-2007  jmcneill Sync with HEAD.
 1.197.6.7  27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.197.6.6  21-Nov-2007  joerg Sync with HEAD.
 1.197.6.5  14-Nov-2007  joerg Sync with HEAD.
 1.197.6.4  11-Nov-2007  joerg Sync with HEAD.
 1.197.6.3  06-Nov-2007  joerg Sync with HEAD.
 1.197.6.2  26-Oct-2007  joerg Sync with HEAD.

Follow the merge of pmap.c on i386 and amd64 and move
pmap_init_tmp_pgtbl into arch/x86/x86/pmap.c. Modify the ACPI wakeup
code to restore CR4 before jumping back into kernel space as the large
page option might cover that.
 1.197.6.1  02-Oct-2007  joerg Sync with HEAD.
 1.198.2.4  21-Nov-2007  bouyer Sync with HEAD
 1.198.2.3  18-Nov-2007  bouyer Sync with HEAD
 1.198.2.2  13-Nov-2007  bouyer Sync with HEAD
 1.198.2.1  25-Oct-2007  bouyer Sync with HEAD.
 1.199.2.4  18-Feb-2008  mjf Sync with HEAD.
 1.199.2.3  27-Dec-2007  mjf Sync with HEAD.
 1.199.2.2  08-Dec-2007  mjf Sync with HEAD.
 1.199.2.1  19-Nov-2007  mjf Sync with HEAD.
 1.206.2.3  26-Dec-2007  ad Sync with head.
 1.206.2.2  21-Dec-2007  ad Protect process groups and sessions with tty_lock.
 1.206.2.1  08-Dec-2007  ad Sync with head.
 1.208.4.2  23-Jan-2008  bouyer Sync with HEAD.
 1.208.4.1  02-Jan-2008  bouyer Sync with HEAD
 1.212.6.5  17-Jan-2009  mjf Sync with HEAD.
 1.212.6.4  28-Sep-2008  mjf Sync with HEAD.
 1.212.6.3  29-Jun-2008  mjf Sync with HEAD.
 1.212.6.2  02-Jun-2008  mjf Sync with HEAD.
 1.212.6.1  03-Apr-2008  mjf Sync with HEAD.
 1.212.2.1  24-Mar-2008  keiichi sync with head.
 1.214.2.3  17-Jun-2008  yamt sync with head.
 1.214.2.2  04-Jun-2008  yamt sync with head
 1.214.2.1  18-May-2008  yamt sync with head.
 1.221.2.6  09-Oct-2010  yamt sync with head
 1.221.2.5  11-Aug-2010  yamt sync with head.
 1.221.2.4  11-Mar-2010  yamt sync with head
 1.221.2.3  19-Aug-2009  yamt sync with head.
 1.221.2.2  04-May-2009  yamt sync with head.
 1.221.2.1  16-May-2008  yamt sync with head.
 1.223.2.2  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.223.2.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.224.2.2  31-Jul-2008  simonb Sync with head.
 1.224.2.1  18-Jun-2008  simonb Sync with head.
 1.225.2.2  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.225.2.1  19-Oct-2008  haad Sync with HEAD.
 1.227.4.2  11-Oct-2009  sborrill Pull up the following revisions(s) (requested by dsl in ticket #1087):
sys/kern/tty.c: revision 1.234

Check for zero length read here - and return zero. Without this there is a
simple local-user panic in ureadc().
 1.227.4.1  06-Feb-2009  snj branches: 1.227.4.1.2; 1.227.4.1.4;
Pull up following revision(s) (requested by drochner in ticket #417):
sys/dev/wscons/wsdisplay.c: revision 1.126
sys/kern/tty.c: revision 1.230
sys/sys/tty.h: revision 1.86
Avoid deadlock in tty code if a terminal emulation responds to
type/status/etc inquiries. (PR kern/37915)
This is clearly a design problem in tty, but we need a cheap fix now.
The problem is that ttyinput() tries to pull a spinlock which
is already held on calls to t_oproc.
The workaround is based on the fact that within wscons code, the
wsdisplay_emulinput() function is only called directly from
wsdisplaystart(). So we can be sure that the tty lock is held,
and use an inofficial entry point in ttc.c which avoids the locking.
These ate certainly more assumptions than needed by the fix
proposed in the PR, but it doesn't affect (and slow down) other
tty drivers.
 1.227.4.1.4.2  25-May-2011  matt Merge in LWP_PC status change from -current. Print PC addr if lwp is
running or runnable.
 1.227.4.1.4.1  21-Apr-2010  matt sync to netbsd-5
 1.227.4.1.2.1  12-Oct-2009  sborrill Pull up the following revisions(s) (requested by dsl in ticket #1087):
sys/kern/tty.c: revision 1.234

Check for zero length read here - and return zero. Without this there is a
simple local-user panic in ureadc().
 1.227.2.3  28-Apr-2009  skrll Sync with HEAD.
 1.227.2.2  03-Mar-2009  skrll Sync with HEAD.
 1.227.2.1  19-Jan-2009  skrll Sync with HEAD.
 1.230.2.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.234.4.5  31-May-2011  rmind sync with head
 1.234.4.4  21-Apr-2011  rmind sync with head
 1.234.4.3  05-Mar-2011  rmind sync with head
 1.234.4.2  03-Jul-2010  rmind sync with head
 1.234.4.1  30-May-2010  rmind sync with head
 1.234.2.2  22-Oct-2010  uebayasi Sync with HEAD (-D20101022).
 1.234.2.1  17-Aug-2010  uebayasi Sync with HEAD.
 1.239.4.1  08-Feb-2011  bouyer Sync with HEAD
 1.239.2.1  06-Jun-2011  jruoho Sync with HEAD.
 1.249.8.2  20-Aug-2012  riz Pull up following revision(s) (requested by christos in ticket #516):
sys/kern/tty.c: revision 1.251
sys/kern/tty.c: revision 1.252
sys/kern/tty.c: revision 1.253
Better (not racy fix) from Paul Goyette.
Use the queue of the tty not garbage from the stack (Paul Goyette)
PR/46780: Dennis Ferguson: Take the easy way out and return EBUSY when changing
the queue size if the output queue is not empty. Other solutions seemed too
complex/fragile.
 1.249.8.1  19-Mar-2012  riz Pull up following revision(s) (requested by dholland in ticket #128):
sys/kern/tty.c: revision 1.250
PR/41673: Stathis Kamperis: tcsetpgrp returns EINVAL, but should return EPERM.
 1.249.6.1  05-Apr-2012  mrg sync to latest -current.
 1.249.2.3  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.249.2.2  30-Oct-2012  yamt sync with head
 1.249.2.1  17-Apr-2012  yamt sync with head
 1.253.2.4  03-Dec-2017  jdolecek update from HEAD
 1.253.2.3  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.253.2.2  25-Feb-2013  tls resync with head
 1.253.2.1  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.257.2.1  18-May-2014  rmind sync with head
 1.259.2.1  10-Aug-2014  tls Rebase.
 1.262.2.4  05-Oct-2016  skrll Sync with HEAD
 1.262.2.3  09-Jul-2016  skrll Sync with HEAD
 1.262.2.2  27-Dec-2015  skrll Sync with HEAD (as of 26th Dec)
 1.262.2.1  22-Sep-2015  skrll Sync with HEAD
 1.271.2.2  04-Nov-2016  pgoyette Sync with HEAD
 1.271.2.1  20-Jul-2016  pgoyette Adapt machine-independant code to the new {b,c}devsw reference-counting
(using localcount(9)). All callers of {b,c}devsw_lookup() now call
{b,c}devsw_lookup_acquire() which retains a reference on the 'struct
{b,c}devsw'. This reference must be released by the caller once it is
finished with the structure's content (or other data that would disappear
if the 'struct {b,c}devsw' were to disappear).
 1.274.6.1  27-Apr-2017  pgoyette Restore all work from the former pgoyette-localcount branch (which is
now abandoned doe to cvs merge botch).

The branch now builds, and installs via anita. There are still some
problems (cgd is non-functional and all atf tests time-out) but they
will get resolved soon.
 1.275.2.9  22-Jan-2019  pgoyette Convert the MODULE_{,VOID_}HOOK_CALL macros to do everything in-line
rather than defining an intermediate hook##call function. Almost
all of the hooks are called only once, and although we lose the
ability of doing things like

if (MODULE_HOOK_CALL(...) == 0) ...

we simplify things quite a bit. With this change, we no longer need
to have both declaration and definition macros, and the definition
no longer needs to have both prototype argument list and a "real"
argument list.

FWIW, the above if now needs to written as

int ret;

MODULE_HOOK_CALL(..., ret);
if (ret == 0) ...

with appropriate use of braces {}.
 1.275.2.8  18-Jan-2019  pgoyette Don't restrict hooks to having only int or void types. Pass the hook's
type to the various macros, as needed.

Allows us to reduce diffs to original in at least one or two places (we
no longer have to provide an additional parameter to the hook routine
for returning a non-int return value).
 1.275.2.7  14-Jan-2019  pgoyette Create a variant of the HOOK macros that handles hook routines of
type void, and use them where appropriate.
 1.275.2.6  13-Jan-2019  pgoyette Remove the HOOK2 versions of the MODULE_HOOK macros. There were
only a few uses, and using them led to some lack of clarity in the
code. Instead, we now use two separate hooks, with names that
make it clear(er) what we're doing.

This also positions us to start unraveling some of the rtsock_50
mess, which will need (at least) five hooks.
 1.275.2.5  15-Oct-2018  pgoyette Convert another hook to the MP-sfe mechanism.

XXX still have three more to convert: openat_10, sysvipc50_sysctl and
XXX compat70_unp_addsockcred
 1.275.2.4  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.275.2.3  04-Sep-2018  pgoyette Separate COMPAT_BSDPTY stuff from tty COMPAT_60 stuff. Enables
building of COMPAT_60 module whether or not COMPAT_BSDPTY is
defined in the kernel.
 1.275.2.2  07-Apr-2018  pgoyette Sync with HEAD. 77 conflicts resolved - all of them $NetBSD$
 1.275.2.1  18-Mar-2018  pgoyette Initial pass at getting the tty stuff properly modularized. Subject
to review and revision.
 1.276.2.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.276.2.1  10-Jun-2019  christos Sync with HEAD
 1.281.4.1  07-Aug-2024  martin Pull up following revision(s) (requested by kre in ticket #1859):

sys/kern/kern_proc.c: revision 1.276 (via patch)
sys/kern/kern_ktrace.c: revision 1.185 (via patch)
sys/kern/sys_sig.c: revision 1.58 (via patch)
sys/kern/kern_descrip.c: revision 1.263 (via patch)
lib/libc/compat-43/killpg.c: revision 1.10
sys/kern/tty.c: revision 1.313 (via patch)
tests/lib/libc/sys/t_kill.c: revision 1.2

PR kern/58425 -- Disallow INT_MIN as a (negative) pid arg.
Since -INT_MIN is undefined, and to point of negative pid args is
to negate them, and use the result as a pgrp id instead, we need
to avoid accidentally negating INT_MIN.

Since pid_t is just an integral type, of unspecified width, when
testing pid_t value test for <= INT_MIN (or > INT_MIN sometimes)
rather than == INT_MIN. When testing int values, just == INT_MIN
is all that is needed, < INT_MIN cannot occur.

tests/lib/libc/sys/t_kill: Test kill(INT_MIN, ...) fails with ESRCH.
PR kern/58425
 1.285.2.1  25-Jan-2020  ad Sync with head.
 1.294.2.1  14-Dec-2020  thorpej Sync w/ HEAD.
 1.307.2.1  07-Aug-2024  martin Pull up following revision(s) (requested by kre in ticket #773):

sys/kern/kern_proc.c: revision 1.276
sys/kern/kern_ktrace.c: revision 1.185
sys/kern/sys_sig.c: revision 1.58
sys/kern/kern_descrip.c: revision 1.263
lib/libc/compat-43/killpg.c: revision 1.10
sys/kern/tty.c: revision 1.313
tests/lib/libc/sys/t_kill.c: revision 1.2

PR kern/58425 -- Disallow INT_MIN as a (negative) pid arg.

Since -INT_MIN is undefined, and to point of negative pid args is
to negate them, and use the result as a pgrp id instead, we need
to avoid accidentally negating INT_MIN.

Since pid_t is just an integral type, of unspecified width, when
testing pid_t value test for <= INT_MIN (or > INT_MIN sometimes)
rather than == INT_MIN. When testing int values, just == INT_MIN
is all that is needed, < INT_MIN cannot occur.

tests/lib/libc/sys/t_kill: Test kill(INT_MIN, ...) fails with ESRCH.
PR kern/58425
 1.312.2.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed