History log of /openbsd-current/sys/kern/kern_subr.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.52 31-Jan-2023 deraadt

On systems without xonly mmu hardware-enforcement, we can still mitigate
against classic BROP with a range-checking wrapper in front of copyin() and
copyinstr() which ensures the userland source doesn't overlap the main program
text, ld.so text, signal tramp text (it's mapping is hard to distinguish
so it comes along for the ride), or libc.so text. ld.so tells the kernel
libc.so text range with msyscall(2). The range checking for 2-4 elements is
done without locking (because all 4 ranges are immutable!) and is inexpensive.

write(sock, &open, 400) now fails with EFAULT. No programs have been
discovered which require reading their own text segments with a system call.

On a machine without mmu enforcement, a test program reports the following:
userland kernel
ld.so readable unreadable
mmap xz unreadable unreadable
mmap x readable readable
mmap nrx readable readable
mmap nwx readable readable
mmap xnwx readable readable
main readable unreadable
libc unmapped? readable unreadable
libc mapped readable unreadable

ok kettenis, additional help from miod


Revision tags: OPENBSD_7_2_BASE
# 1.51 14-Aug-2022 jsg

remove unneeded includes in sys/kern
ok mpi@ miod@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.50 29-Apr-2018 anton

In hash{free,init}(), there's no need to calculate the size of the hash table if
the given number of elements already is a power of 2.

ok visa@, "seems like a good plan" deraadt@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.49 14-Feb-2017 mpi

Convert most of the manual checks for CPU hogging to sched_pause().

The distinction between preempt() and yield() stays as it is usueful
to know if a thread decided to yield by itself or if the kernel told
him to go away.

ok tedu@, guenther@


# 1.48 24-Sep-2016 tedu

introduce hashfree() function to free hash tables, with sizes.
ok guenther


Revision tags: OPENBSD_6_0_BASE
# 1.47 15-Mar-2016 stefan

Remove now unused legacy uiomovei() function.

All its callers got reviewed and converted to
use uiomove() properly.

ok deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.46 11-Feb-2016 stefan

Make sure uiomove does not copy more than uio_resid bytes, as the manual
says. Move code belonging to diagnostics in the #ifdef DIAGNOSTIC part
and add a KASSERT that makes sure that we do not run beyond uio_iov.
Diff from Martin Natano.


# 1.45 11-Dec-2015 mpi

Replace mountroothook_establish(9) by config_mountroot(9) a narrower API
similar to config_defer(9).

ok mikeb@, deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.44 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.43 10-Feb-2015 miod

First step towards making uiomove() take a size_t size argument:
- rename uiomove() to uiomovei() and update all its users.
- introduce uiomove(), which is similar to uiomovei() but with a size_t.
- rewrite uiomovei() as an uiomove() wrapper.
ok kettenis@


# 1.42 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.41 01-Nov-2014 tedu

add a few sizes to free


Revision tags: OPENBSD_5_6_BASE
# 1.40 13-Jul-2014 tedu

trim some casts


# 1.39 13-Jul-2014 tedu

use mallocarray where arguments are multipled. ok deraadt


# 1.38 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_5_BASE
# 1.37 19-Oct-2013 reyk

When hooks are called, allow them to disestablish themselves by using
the safe version to traverse the TAILQ list.

ok deraadt@


# 1.36 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


# 1.35 13-Aug-2013 guenther

Switch time_t, ino_t, clock_t, and struct kevent's ident and data
members to 64bit types. Assign new syscall numbers for (almost
all) the syscalls that involve the affected types, including anything
with time_t, timeval, itimerval, timespec, rusage, dirent, stat,
or kevent arguments. Add a d_off member to struct dirent and replace
getdirentries() with getdents(), thus immensely simplifying and
accelerating telldir/seekdir. Build perl with -DBIG_TIME.

Bump the major on every single base library: the compat bits included
here are only good enough to make the transition; the T32 compat
option will be burned as soon as we've reached the new world are
are happy with the snapshots for all architectures.

DANGER: ABI incompatibility. Updating to this kernel requires extra
work or you won't be able to login: install a snapshot instead.

Much assistance in fixing userland issues from deraadt@ and tedu@
and build assistance from todd@ and otto@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.33 06-Sep-2010 deraadt

All PWR_{SUSPEND,RESUME} can now be replaced by DVACT_{SUSPEND,RESUME}


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.32 12-Jun-2008 marco

Remove silly panic when disestablish cookie doesnt exist

ok art


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.31 16-May-2007 art

The world of __HAVEs and __HAVE_NOTs is reducing. All architectures
have cpu_info now, so kill the option.

eyeballed by jsg@ and grange@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.30 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.29 28-Nov-2004 deraadt

mountroothooks are called after the root filesystem is mounted.


Revision tags: OPENBSD_3_6_BASE
# 1.28 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.27 09-Jun-2004 art

Merge in a piece of the SMP branch into HEAD.

Introduce the cpu_info structure, p_cpu field in struct proc and global
scheduling context and various changed code to deal with this. At the
moment no architecture uses this stuff yet, but it will allow us slow and
controlled migration to the new APIs.

All new code is ifdef:ed out.

ok deraadt@ niklas@


Revision tags: OPENBSD_3_5_BASE
# 1.26 31-Oct-2003 markus

allocate at least as much elements as requested in hashinit
fixes pr 3537, based on patch from daniel@nofsk.nofsk.au.eu.org
ok millert@, deraadt@, tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.25 21-Jul-2003 tedu

remove caddr_t casts. it's just silly to cast something when the function
takes a void *. convert uiomove to take a void * as well. ok deraadt@


# 1.24 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.23 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.22 12-Jul-2002 art

- Add a flags argument to dohooks.
The flag can be either HOOK_REMOVE or HOOK_REMOVE|HOOK_FREE.
o HOOK_REMOVE removes the hook from the list before executing it.
o HOOK_FREE frees the hook after that.

- Let dostartuphooks use HOOK_REMOVE|HOOK_FREE so we can reclaim the memory.

- Let doshutdownhooks use HOOK_REMOVE so that when some shutdown hook
panics (they do that all the #@$%! time these days) we don't loop
for ever. Don't HOOK_FREE, it doesn't matter and I don't want to add
another possible panic condition for shutdown hooks.

- Actually free the pointer we're throwing away in hook_disestablish (I wonder
how much memory this has leaked over the years).


Revision tags: OPENBSD_3_1_BASE
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.20 27-Jul-2001 niklas

branches: 1.20.4;
Startup hooks. Can be used for providing root/swap devices from device
systems which want configuration to finish late, like I2O. Implemented via
a general hooks mechanism which the shutdown hooks have been converted to
use as well. It even has manpages!


# 1.19 27-Jun-2001 art

remove old vm


# 1.18 26-Jun-2001 aaron

Appease gcc by not using void pointers in arithmetic operations; art@ ok


# 1.17 23-Jun-2001 art

Since malloc in hashinit can get M_NOWAIT flags, we should
check the return value.


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 07-Sep-2000 art

On resume run the powerhook in installation order.
(the powerhooks were always run in reverse order).


# 1.15 07-Sep-2000 art

Put powerhooks on a CIRCLEQ instead of LIST.
Use FOREACH macros instead of walking the list manually.


# 1.14 07-Sep-2000 art

Run powerhooks at splhigh.


# 1.13 05-Sep-2000 aaron

Wrap power hooks in splimp(), fixes WaveLAN suspend problem; thanks art@


Revision tags: OPENBSD_2_7_BASE
# 1.12 19-Apr-2000 art

Remove the roundrobin_attempts hack and replace it with per-process scheduling
flags (much nicer for future smp work).
Add two generic functions yield() and preempt(). Use preepmt() in uio when
we are told to yield.
Based on my idea, code written by Jason Thorpe from NetBSD.


# 1.11 03-Mar-2000 art

If we attempted reschedule two times without suceeding, uiomove will yield,
giving other processes a chance to run.

A process feeding a huge buffer to {read,write}{,v} on a file that doesn't
need to wait for I/O, could have hogged a lot of cpu in the kernel, blocking
all userland activity.

Based on a similiar fix in FreeBSD.


Revision tags: SMP_BASE kame_19991208
# 1.10 07-Nov-1999 provos

branches: 1.10.2;
add APM powerhooks.
from NetBSD, Sat Jun 26 08:25:25 1999 UTC by augustss:

Add powerhooks, i.e., the ability to register a function that will be
called when the machine does a suspend or resume.
XXX Will go away when Jason's kevents come to life.


Revision tags: OPENBSD_2_6_BASE
# 1.9 28-Apr-1999 art

zap the newhashinit hack.
Add an extra flag to hashinit telling if it should wait in malloc.
update all calls to hashinit.


Revision tags: OPENBSD_2_5_BASE
# 1.8 26-Feb-1999 art

uvm uses kcopy when uiomoving from sysspace


# 1.7 26-Feb-1999 millert

Add newhashinit(), which is identical to hashinit() except it takes a flags
arg for passing to malloc() (hashinit always uses M_WAITOK which is not
always what you want). Everything that uses hashinit should really
get converted to newhashinit and then newhashinit can be renamed.


Revision tags: OPENBSD_2_4_BASE
# 1.6 28-Jul-1998 millert

Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.5 11-May-1998 deraadt

compile if iov_base is void *


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.4 24-Feb-1997 niklas

OpenBSD tags


Revision tags: OPENBSD_2_0_BASE
# 1.3 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.2 17-Apr-1996 mickey

Removed vax ifdefed function from kern_subr.c (from NetBSD).
Do sync in the order of umount (vfs_syscals.c), as it was pointed
by someone in NetBSD's lists.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.51 14-Aug-2022 jsg

remove unneeded includes in sys/kern
ok mpi@ miod@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE OPENBSD_7_1_BASE
# 1.50 29-Apr-2018 anton

In hash{free,init}(), there's no need to calculate the size of the hash table if
the given number of elements already is a power of 2.

ok visa@, "seems like a good plan" deraadt@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.49 14-Feb-2017 mpi

Convert most of the manual checks for CPU hogging to sched_pause().

The distinction between preempt() and yield() stays as it is usueful
to know if a thread decided to yield by itself or if the kernel told
him to go away.

ok tedu@, guenther@


# 1.48 24-Sep-2016 tedu

introduce hashfree() function to free hash tables, with sizes.
ok guenther


Revision tags: OPENBSD_6_0_BASE
# 1.47 15-Mar-2016 stefan

Remove now unused legacy uiomovei() function.

All its callers got reviewed and converted to
use uiomove() properly.

ok deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.46 11-Feb-2016 stefan

Make sure uiomove does not copy more than uio_resid bytes, as the manual
says. Move code belonging to diagnostics in the #ifdef DIAGNOSTIC part
and add a KASSERT that makes sure that we do not run beyond uio_iov.
Diff from Martin Natano.


# 1.45 11-Dec-2015 mpi

Replace mountroothook_establish(9) by config_mountroot(9) a narrower API
similar to config_defer(9).

ok mikeb@, deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.44 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.43 10-Feb-2015 miod

First step towards making uiomove() take a size_t size argument:
- rename uiomove() to uiomovei() and update all its users.
- introduce uiomove(), which is similar to uiomovei() but with a size_t.
- rewrite uiomovei() as an uiomove() wrapper.
ok kettenis@


# 1.42 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.41 01-Nov-2014 tedu

add a few sizes to free


Revision tags: OPENBSD_5_6_BASE
# 1.40 13-Jul-2014 tedu

trim some casts


# 1.39 13-Jul-2014 tedu

use mallocarray where arguments are multipled. ok deraadt


# 1.38 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_5_BASE
# 1.37 19-Oct-2013 reyk

When hooks are called, allow them to disestablish themselves by using
the safe version to traverse the TAILQ list.

ok deraadt@


# 1.36 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


# 1.35 13-Aug-2013 guenther

Switch time_t, ino_t, clock_t, and struct kevent's ident and data
members to 64bit types. Assign new syscall numbers for (almost
all) the syscalls that involve the affected types, including anything
with time_t, timeval, itimerval, timespec, rusage, dirent, stat,
or kevent arguments. Add a d_off member to struct dirent and replace
getdirentries() with getdents(), thus immensely simplifying and
accelerating telldir/seekdir. Build perl with -DBIG_TIME.

Bump the major on every single base library: the compat bits included
here are only good enough to make the transition; the T32 compat
option will be burned as soon as we've reached the new world are
are happy with the snapshots for all architectures.

DANGER: ABI incompatibility. Updating to this kernel requires extra
work or you won't be able to login: install a snapshot instead.

Much assistance in fixing userland issues from deraadt@ and tedu@
and build assistance from todd@ and otto@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.33 06-Sep-2010 deraadt

All PWR_{SUSPEND,RESUME} can now be replaced by DVACT_{SUSPEND,RESUME}


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.32 12-Jun-2008 marco

Remove silly panic when disestablish cookie doesnt exist

ok art


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.31 16-May-2007 art

The world of __HAVEs and __HAVE_NOTs is reducing. All architectures
have cpu_info now, so kill the option.

eyeballed by jsg@ and grange@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.30 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.29 28-Nov-2004 deraadt

mountroothooks are called after the root filesystem is mounted.


Revision tags: OPENBSD_3_6_BASE
# 1.28 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.27 09-Jun-2004 art

Merge in a piece of the SMP branch into HEAD.

Introduce the cpu_info structure, p_cpu field in struct proc and global
scheduling context and various changed code to deal with this. At the
moment no architecture uses this stuff yet, but it will allow us slow and
controlled migration to the new APIs.

All new code is ifdef:ed out.

ok deraadt@ niklas@


Revision tags: OPENBSD_3_5_BASE
# 1.26 31-Oct-2003 markus

allocate at least as much elements as requested in hashinit
fixes pr 3537, based on patch from daniel@nofsk.nofsk.au.eu.org
ok millert@, deraadt@, tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.25 21-Jul-2003 tedu

remove caddr_t casts. it's just silly to cast something when the function
takes a void *. convert uiomove to take a void * as well. ok deraadt@


# 1.24 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.23 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.22 12-Jul-2002 art

- Add a flags argument to dohooks.
The flag can be either HOOK_REMOVE or HOOK_REMOVE|HOOK_FREE.
o HOOK_REMOVE removes the hook from the list before executing it.
o HOOK_FREE frees the hook after that.

- Let dostartuphooks use HOOK_REMOVE|HOOK_FREE so we can reclaim the memory.

- Let doshutdownhooks use HOOK_REMOVE so that when some shutdown hook
panics (they do that all the #@$%! time these days) we don't loop
for ever. Don't HOOK_FREE, it doesn't matter and I don't want to add
another possible panic condition for shutdown hooks.

- Actually free the pointer we're throwing away in hook_disestablish (I wonder
how much memory this has leaked over the years).


Revision tags: OPENBSD_3_1_BASE
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.20 27-Jul-2001 niklas

branches: 1.20.4;
Startup hooks. Can be used for providing root/swap devices from device
systems which want configuration to finish late, like I2O. Implemented via
a general hooks mechanism which the shutdown hooks have been converted to
use as well. It even has manpages!


# 1.19 27-Jun-2001 art

remove old vm


# 1.18 26-Jun-2001 aaron

Appease gcc by not using void pointers in arithmetic operations; art@ ok


# 1.17 23-Jun-2001 art

Since malloc in hashinit can get M_NOWAIT flags, we should
check the return value.


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 07-Sep-2000 art

On resume run the powerhook in installation order.
(the powerhooks were always run in reverse order).


# 1.15 07-Sep-2000 art

Put powerhooks on a CIRCLEQ instead of LIST.
Use FOREACH macros instead of walking the list manually.


# 1.14 07-Sep-2000 art

Run powerhooks at splhigh.


# 1.13 05-Sep-2000 aaron

Wrap power hooks in splimp(), fixes WaveLAN suspend problem; thanks art@


Revision tags: OPENBSD_2_7_BASE
# 1.12 19-Apr-2000 art

Remove the roundrobin_attempts hack and replace it with per-process scheduling
flags (much nicer for future smp work).
Add two generic functions yield() and preempt(). Use preepmt() in uio when
we are told to yield.
Based on my idea, code written by Jason Thorpe from NetBSD.


# 1.11 03-Mar-2000 art

If we attempted reschedule two times without suceeding, uiomove will yield,
giving other processes a chance to run.

A process feeding a huge buffer to {read,write}{,v} on a file that doesn't
need to wait for I/O, could have hogged a lot of cpu in the kernel, blocking
all userland activity.

Based on a similiar fix in FreeBSD.


Revision tags: SMP_BASE kame_19991208
# 1.10 07-Nov-1999 provos

branches: 1.10.2;
add APM powerhooks.
from NetBSD, Sat Jun 26 08:25:25 1999 UTC by augustss:

Add powerhooks, i.e., the ability to register a function that will be
called when the machine does a suspend or resume.
XXX Will go away when Jason's kevents come to life.


Revision tags: OPENBSD_2_6_BASE
# 1.9 28-Apr-1999 art

zap the newhashinit hack.
Add an extra flag to hashinit telling if it should wait in malloc.
update all calls to hashinit.


Revision tags: OPENBSD_2_5_BASE
# 1.8 26-Feb-1999 art

uvm uses kcopy when uiomoving from sysspace


# 1.7 26-Feb-1999 millert

Add newhashinit(), which is identical to hashinit() except it takes a flags
arg for passing to malloc() (hashinit always uses M_WAITOK which is not
always what you want). Everything that uses hashinit should really
get converted to newhashinit and then newhashinit can be renamed.


Revision tags: OPENBSD_2_4_BASE
# 1.6 28-Jul-1998 millert

Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.5 11-May-1998 deraadt

compile if iov_base is void *


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.4 24-Feb-1997 niklas

OpenBSD tags


Revision tags: OPENBSD_2_0_BASE
# 1.3 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.2 17-Apr-1996 mickey

Removed vax ifdefed function from kern_subr.c (from NetBSD).
Do sync in the order of umount (vfs_syscals.c), as it was pointed
by someone in NetBSD's lists.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.50 29-Apr-2018 anton

In hash{free,init}(), there's no need to calculate the size of the hash table if
the given number of elements already is a power of 2.

ok visa@, "seems like a good plan" deraadt@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.49 14-Feb-2017 mpi

Convert most of the manual checks for CPU hogging to sched_pause().

The distinction between preempt() and yield() stays as it is usueful
to know if a thread decided to yield by itself or if the kernel told
him to go away.

ok tedu@, guenther@


# 1.48 24-Sep-2016 tedu

introduce hashfree() function to free hash tables, with sizes.
ok guenther


Revision tags: OPENBSD_6_0_BASE
# 1.47 15-Mar-2016 stefan

Remove now unused legacy uiomovei() function.

All its callers got reviewed and converted to
use uiomove() properly.

ok deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.46 11-Feb-2016 stefan

Make sure uiomove does not copy more than uio_resid bytes, as the manual
says. Move code belonging to diagnostics in the #ifdef DIAGNOSTIC part
and add a KASSERT that makes sure that we do not run beyond uio_iov.
Diff from Martin Natano.


# 1.45 11-Dec-2015 mpi

Replace mountroothook_establish(9) by config_mountroot(9) a narrower API
similar to config_defer(9).

ok mikeb@, deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.44 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.43 10-Feb-2015 miod

First step towards making uiomove() take a size_t size argument:
- rename uiomove() to uiomovei() and update all its users.
- introduce uiomove(), which is similar to uiomovei() but with a size_t.
- rewrite uiomovei() as an uiomove() wrapper.
ok kettenis@


# 1.42 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.41 01-Nov-2014 tedu

add a few sizes to free


Revision tags: OPENBSD_5_6_BASE
# 1.40 13-Jul-2014 tedu

trim some casts


# 1.39 13-Jul-2014 tedu

use mallocarray where arguments are multipled. ok deraadt


# 1.38 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_5_BASE
# 1.37 19-Oct-2013 reyk

When hooks are called, allow them to disestablish themselves by using
the safe version to traverse the TAILQ list.

ok deraadt@


# 1.36 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


# 1.35 13-Aug-2013 guenther

Switch time_t, ino_t, clock_t, and struct kevent's ident and data
members to 64bit types. Assign new syscall numbers for (almost
all) the syscalls that involve the affected types, including anything
with time_t, timeval, itimerval, timespec, rusage, dirent, stat,
or kevent arguments. Add a d_off member to struct dirent and replace
getdirentries() with getdents(), thus immensely simplifying and
accelerating telldir/seekdir. Build perl with -DBIG_TIME.

Bump the major on every single base library: the compat bits included
here are only good enough to make the transition; the T32 compat
option will be burned as soon as we've reached the new world are
are happy with the snapshots for all architectures.

DANGER: ABI incompatibility. Updating to this kernel requires extra
work or you won't be able to login: install a snapshot instead.

Much assistance in fixing userland issues from deraadt@ and tedu@
and build assistance from todd@ and otto@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.33 06-Sep-2010 deraadt

All PWR_{SUSPEND,RESUME} can now be replaced by DVACT_{SUSPEND,RESUME}


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.32 12-Jun-2008 marco

Remove silly panic when disestablish cookie doesnt exist

ok art


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.31 16-May-2007 art

The world of __HAVEs and __HAVE_NOTs is reducing. All architectures
have cpu_info now, so kill the option.

eyeballed by jsg@ and grange@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.30 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.29 28-Nov-2004 deraadt

mountroothooks are called after the root filesystem is mounted.


Revision tags: OPENBSD_3_6_BASE
# 1.28 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.27 09-Jun-2004 art

Merge in a piece of the SMP branch into HEAD.

Introduce the cpu_info structure, p_cpu field in struct proc and global
scheduling context and various changed code to deal with this. At the
moment no architecture uses this stuff yet, but it will allow us slow and
controlled migration to the new APIs.

All new code is ifdef:ed out.

ok deraadt@ niklas@


Revision tags: OPENBSD_3_5_BASE
# 1.26 31-Oct-2003 markus

allocate at least as much elements as requested in hashinit
fixes pr 3537, based on patch from daniel@nofsk.nofsk.au.eu.org
ok millert@, deraadt@, tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.25 21-Jul-2003 tedu

remove caddr_t casts. it's just silly to cast something when the function
takes a void *. convert uiomove to take a void * as well. ok deraadt@


# 1.24 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.23 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.22 12-Jul-2002 art

- Add a flags argument to dohooks.
The flag can be either HOOK_REMOVE or HOOK_REMOVE|HOOK_FREE.
o HOOK_REMOVE removes the hook from the list before executing it.
o HOOK_FREE frees the hook after that.

- Let dostartuphooks use HOOK_REMOVE|HOOK_FREE so we can reclaim the memory.

- Let doshutdownhooks use HOOK_REMOVE so that when some shutdown hook
panics (they do that all the #@$%! time these days) we don't loop
for ever. Don't HOOK_FREE, it doesn't matter and I don't want to add
another possible panic condition for shutdown hooks.

- Actually free the pointer we're throwing away in hook_disestablish (I wonder
how much memory this has leaked over the years).


Revision tags: OPENBSD_3_1_BASE
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.20 27-Jul-2001 niklas

branches: 1.20.4;
Startup hooks. Can be used for providing root/swap devices from device
systems which want configuration to finish late, like I2O. Implemented via
a general hooks mechanism which the shutdown hooks have been converted to
use as well. It even has manpages!


# 1.19 27-Jun-2001 art

remove old vm


# 1.18 26-Jun-2001 aaron

Appease gcc by not using void pointers in arithmetic operations; art@ ok


# 1.17 23-Jun-2001 art

Since malloc in hashinit can get M_NOWAIT flags, we should
check the return value.


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 07-Sep-2000 art

On resume run the powerhook in installation order.
(the powerhooks were always run in reverse order).


# 1.15 07-Sep-2000 art

Put powerhooks on a CIRCLEQ instead of LIST.
Use FOREACH macros instead of walking the list manually.


# 1.14 07-Sep-2000 art

Run powerhooks at splhigh.


# 1.13 05-Sep-2000 aaron

Wrap power hooks in splimp(), fixes WaveLAN suspend problem; thanks art@


Revision tags: OPENBSD_2_7_BASE
# 1.12 19-Apr-2000 art

Remove the roundrobin_attempts hack and replace it with per-process scheduling
flags (much nicer for future smp work).
Add two generic functions yield() and preempt(). Use preepmt() in uio when
we are told to yield.
Based on my idea, code written by Jason Thorpe from NetBSD.


# 1.11 03-Mar-2000 art

If we attempted reschedule two times without suceeding, uiomove will yield,
giving other processes a chance to run.

A process feeding a huge buffer to {read,write}{,v} on a file that doesn't
need to wait for I/O, could have hogged a lot of cpu in the kernel, blocking
all userland activity.

Based on a similiar fix in FreeBSD.


Revision tags: SMP_BASE kame_19991208
# 1.10 07-Nov-1999 provos

branches: 1.10.2;
add APM powerhooks.
from NetBSD, Sat Jun 26 08:25:25 1999 UTC by augustss:

Add powerhooks, i.e., the ability to register a function that will be
called when the machine does a suspend or resume.
XXX Will go away when Jason's kevents come to life.


Revision tags: OPENBSD_2_6_BASE
# 1.9 28-Apr-1999 art

zap the newhashinit hack.
Add an extra flag to hashinit telling if it should wait in malloc.
update all calls to hashinit.


Revision tags: OPENBSD_2_5_BASE
# 1.8 26-Feb-1999 art

uvm uses kcopy when uiomoving from sysspace


# 1.7 26-Feb-1999 millert

Add newhashinit(), which is identical to hashinit() except it takes a flags
arg for passing to malloc() (hashinit always uses M_WAITOK which is not
always what you want). Everything that uses hashinit should really
get converted to newhashinit and then newhashinit can be renamed.


Revision tags: OPENBSD_2_4_BASE
# 1.6 28-Jul-1998 millert

Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.5 11-May-1998 deraadt

compile if iov_base is void *


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.4 24-Feb-1997 niklas

OpenBSD tags


Revision tags: OPENBSD_2_0_BASE
# 1.3 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.2 17-Apr-1996 mickey

Removed vax ifdefed function from kern_subr.c (from NetBSD).
Do sync in the order of umount (vfs_syscals.c), as it was pointed
by someone in NetBSD's lists.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.49 14-Feb-2017 mpi

Convert most of the manual checks for CPU hogging to sched_pause().

The distinction between preempt() and yield() stays as it is usueful
to know if a thread decided to yield by itself or if the kernel told
him to go away.

ok tedu@, guenther@


# 1.48 24-Sep-2016 tedu

introduce hashfree() function to free hash tables, with sizes.
ok guenther


Revision tags: OPENBSD_6_0_BASE
# 1.47 15-Mar-2016 stefan

Remove now unused legacy uiomovei() function.

All its callers got reviewed and converted to
use uiomove() properly.

ok deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.46 11-Feb-2016 stefan

Make sure uiomove does not copy more than uio_resid bytes, as the manual
says. Move code belonging to diagnostics in the #ifdef DIAGNOSTIC part
and add a KASSERT that makes sure that we do not run beyond uio_iov.
Diff from Martin Natano.


# 1.45 11-Dec-2015 mpi

Replace mountroothook_establish(9) by config_mountroot(9) a narrower API
similar to config_defer(9).

ok mikeb@, deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.44 14-Mar-2015 jsg

Remove some includes include-what-you-use claims don't
have any direct symbols used. Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@


Revision tags: OPENBSD_5_7_BASE
# 1.43 10-Feb-2015 miod

First step towards making uiomove() take a size_t size argument:
- rename uiomove() to uiomovei() and update all its users.
- introduce uiomove(), which is similar to uiomovei() but with a size_t.
- rewrite uiomovei() as an uiomove() wrapper.
ok kettenis@


# 1.42 10-Dec-2014 mikeb

retire shutdown hooks; ok deraadt, krw


# 1.41 01-Nov-2014 tedu

add a few sizes to free


Revision tags: OPENBSD_5_6_BASE
# 1.40 13-Jul-2014 tedu

trim some casts


# 1.39 13-Jul-2014 tedu

use mallocarray where arguments are multipled. ok deraadt


# 1.38 12-Jul-2014 tedu

add a size argument to free. will be used soon, but for now default to 0.
after discussions with beck deraadt kettenis.


Revision tags: OPENBSD_5_5_BASE
# 1.37 19-Oct-2013 reyk

When hooks are called, allow them to disestablish themselves by using
the safe version to traverse the TAILQ list.

ok deraadt@


# 1.36 14-Sep-2013 guenther

Correct the handling of I/O of >=2^32 bytes and the ktracing there of
by using size_t/ssize_t instead of int/u_int to handle I/O lengths in
uiomove(), vn_fsizechk(), and ktrgenio(). Eliminate the always-zero
'error' argument to ktrgenio() at the same time.


# 1.35 13-Aug-2013 guenther

Switch time_t, ino_t, clock_t, and struct kevent's ident and data
members to 64bit types. Assign new syscall numbers for (almost
all) the syscalls that involve the affected types, including anything
with time_t, timeval, itimerval, timespec, rusage, dirent, stat,
or kevent arguments. Add a d_off member to struct dirent and replace
getdirentries() with getdents(), thus immensely simplifying and
accelerating telldir/seekdir. Build perl with -DBIG_TIME.

Bump the major on every single base library: the compat bits included
here are only good enough to make the transition; the T32 compat
option will be burned as soon as we've reached the new world are
are happy with the snapshots for all architectures.

DANGER: ABI incompatibility. Updating to this kernel requires extra
work or you won't be able to login: install a snapshot instead.

Much assistance in fixing userland issues from deraadt@ and tedu@
and build assistance from todd@ and otto@


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.34 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.33 06-Sep-2010 deraadt

All PWR_{SUSPEND,RESUME} can now be replaced by DVACT_{SUSPEND,RESUME}


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.32 12-Jun-2008 marco

Remove silly panic when disestablish cookie doesnt exist

ok art


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.31 16-May-2007 art

The world of __HAVEs and __HAVE_NOTs is reducing. All architectures
have cpu_info now, so kill the option.

eyeballed by jsg@ and grange@


Revision tags: OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.30 28-Nov-2005 jsg

ansi/deregister.
'go for it' deraadt@


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE
# 1.29 28-Nov-2004 deraadt

mountroothooks are called after the root filesystem is mounted.


Revision tags: OPENBSD_3_6_BASE
# 1.28 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.27 09-Jun-2004 art

Merge in a piece of the SMP branch into HEAD.

Introduce the cpu_info structure, p_cpu field in struct proc and global
scheduling context and various changed code to deal with this. At the
moment no architecture uses this stuff yet, but it will allow us slow and
controlled migration to the new APIs.

All new code is ifdef:ed out.

ok deraadt@ niklas@


Revision tags: OPENBSD_3_5_BASE
# 1.26 31-Oct-2003 markus

allocate at least as much elements as requested in hashinit
fixes pr 3537, based on patch from daniel@nofsk.nofsk.au.eu.org
ok millert@, deraadt@, tedu@


Revision tags: OPENBSD_3_4_BASE
# 1.25 21-Jul-2003 tedu

remove caddr_t casts. it's just silly to cast something when the function
takes a void *. convert uiomove to take a void * as well. ok deraadt@


# 1.24 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.23 09-Jan-2003 miod

Remove fetch(9) and store(9) functions from the kernel, and replace the few
remaining instances of them with appropriate copy(9) usage.

ok art@, tested on all arches unless my memory is non-ECC


Revision tags: OPENBSD_3_2_BASE UBC_SYNC_B
# 1.22 12-Jul-2002 art

- Add a flags argument to dohooks.
The flag can be either HOOK_REMOVE or HOOK_REMOVE|HOOK_FREE.
o HOOK_REMOVE removes the hook from the list before executing it.
o HOOK_FREE frees the hook after that.

- Let dostartuphooks use HOOK_REMOVE|HOOK_FREE so we can reclaim the memory.

- Let doshutdownhooks use HOOK_REMOVE so that when some shutdown hook
panics (they do that all the #@$%! time these days) we don't loop
for ever. Don't HOOK_FREE, it doesn't matter and I don't want to add
another possible panic condition for shutdown hooks.

- Actually free the pointer we're throwing away in hook_disestablish (I wonder
how much memory this has leaked over the years).


Revision tags: OPENBSD_3_1_BASE
# 1.21 14-Mar-2002 millert

First round of __P removal in sys


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.20 27-Jul-2001 niklas

branches: 1.20.4;
Startup hooks. Can be used for providing root/swap devices from device
systems which want configuration to finish late, like I2O. Implemented via
a general hooks mechanism which the shutdown hooks have been converted to
use as well. It even has manpages!


# 1.19 27-Jun-2001 art

remove old vm


# 1.18 26-Jun-2001 aaron

Appease gcc by not using void pointers in arithmetic operations; art@ ok


# 1.17 23-Jun-2001 art

Since malloc in hashinit can get M_NOWAIT flags, we should
check the return value.


Revision tags: OPENBSD_2_8_BASE OPENBSD_2_9_BASE
# 1.16 07-Sep-2000 art

On resume run the powerhook in installation order.
(the powerhooks were always run in reverse order).


# 1.15 07-Sep-2000 art

Put powerhooks on a CIRCLEQ instead of LIST.
Use FOREACH macros instead of walking the list manually.


# 1.14 07-Sep-2000 art

Run powerhooks at splhigh.


# 1.13 05-Sep-2000 aaron

Wrap power hooks in splimp(), fixes WaveLAN suspend problem; thanks art@


Revision tags: OPENBSD_2_7_BASE
# 1.12 19-Apr-2000 art

Remove the roundrobin_attempts hack and replace it with per-process scheduling
flags (much nicer for future smp work).
Add two generic functions yield() and preempt(). Use preepmt() in uio when
we are told to yield.
Based on my idea, code written by Jason Thorpe from NetBSD.


# 1.11 03-Mar-2000 art

If we attempted reschedule two times without suceeding, uiomove will yield,
giving other processes a chance to run.

A process feeding a huge buffer to {read,write}{,v} on a file that doesn't
need to wait for I/O, could have hogged a lot of cpu in the kernel, blocking
all userland activity.

Based on a similiar fix in FreeBSD.


Revision tags: SMP_BASE kame_19991208
# 1.10 07-Nov-1999 provos

branches: 1.10.2;
add APM powerhooks.
from NetBSD, Sat Jun 26 08:25:25 1999 UTC by augustss:

Add powerhooks, i.e., the ability to register a function that will be
called when the machine does a suspend or resume.
XXX Will go away when Jason's kevents come to life.


Revision tags: OPENBSD_2_6_BASE
# 1.9 28-Apr-1999 art

zap the newhashinit hack.
Add an extra flag to hashinit telling if it should wait in malloc.
update all calls to hashinit.


Revision tags: OPENBSD_2_5_BASE
# 1.8 26-Feb-1999 art

uvm uses kcopy when uiomoving from sysspace


# 1.7 26-Feb-1999 millert

Add newhashinit(), which is identical to hashinit() except it takes a flags
arg for passing to malloc() (hashinit always uses M_WAITOK which is not
always what you want). Everything that uses hashinit should really
get converted to newhashinit and then newhashinit can be renamed.


Revision tags: OPENBSD_2_4_BASE
# 1.6 28-Jul-1998 millert

Return EINVAL when msg_iovlen or iovcnt <= 0; Make uio_resid unsigned (size_t) and don't return EINVAL if it is < 0 in sys_{read,write}. Remove check for uio_resid < 0 uiomove() now that uio_resid is unsigned and brack remaining panics with #ifdef DIAGNOSTIC. vn_rdwr() must now take a size_t * as its 9th argument so change that and clean up uses of vn_rdwr(). Fixes 549 + more


# 1.5 11-May-1998 deraadt

compile if iov_base is void *


Revision tags: OPENBSD_2_1_BASE OPENBSD_2_2_BASE OPENBSD_2_3_BASE
# 1.4 24-Feb-1997 niklas

OpenBSD tags


Revision tags: OPENBSD_2_0_BASE
# 1.3 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.2 17-Apr-1996 mickey

Removed vax ifdefed function from kern_subr.c (from NetBSD).
Do sync in the order of umount (vfs_syscals.c), as it was pointed
by someone in NetBSD's lists.


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision