History log of /openbsd-current/sys/kern/subr_prf.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.106 14-Aug-2022 jsg

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


Revision tags: OPENBSD_7_1_BASE
# 1.105 20-Jan-2022 bluhm

snprintf(9) allows NULL string if size is 0. But doing NULL pointer
arithmetic is undefined behavior. Check that size is positive
before adding to pointer. While there, use NUL char for string
termination.
found by kubsan; joint work with tobhe@; OK millert@


Revision tags: OPENBSD_7_0_BASE
# 1.104 02-Jun-2021 cheloha

kernel: introduce per-CPU panic(9) message buffers

Add a 512-byte buffer (ci_panicbuf) to each cpu_info struct on each
platform for use by panic(9). The first panic on a given CPU writes
its message to this buffer. Subsequent panics on a given CPU print
the panic message to the console but do not modify the buffer. This
aids debugging in two cases:

- If 2+ CPUs panic simultaneously there is no risk of garbled messages
in the panic buffer.

- If a CPU panics and then the operator causes a second panic while
using ddb(4), the operator can still recall the first failure on
a particular CPU.

Misc. changes to support this bigger change:

- Set panicstr atomically to identify the first CPU to reach panic().

- Tweak db_show_panic_cmd() to print all panic messages across all
CPUs. Prefix the first panic with an asterisk ('*').

- Prefer db_printf() to printf() during a panic if we have it.
Apparently it disturbs less global state.

- On amd64, tweak fault() to write the local panic buffer. This needs
more work.

Prompted by bluhm@ and deraadt@. Mostly written by deraadt@.
Discussed with bluhm@, deraadt@ and kettenis@.

Borne from a discussion on tech@ about making panic(9) more MP-safe:

https://marc.info/?l=openbsd-tech&m=162086462316143&w=2

ok kettenis@, visa@, bluhm@, deraadt@


# 1.103 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_9_BASE
# 1.102 28-Nov-2020 deraadt

Rather than skipping %[sizearg]n in the kernel, panic when it is encountered.
printf(9) already lacked documentation and needs no change.


Revision tags: OPENBSD_6_8_BASE
# 1.101 24-Jul-2020 kettenis

Implement BOOT_QUIET option that supresses kernel printf output to the
console. When the kernel panics, print console output is enabled such
that we see those messages. Use this option for the powerpc64 boot
kernel.

ok visa@, deraadt@


# 1.100 20-Jul-2020 deraadt

fix macro indent


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.99 20-Jul-2019 mpi

Get rid of `ddb_is_active' instead use `db_active'.

From Christian Ludwig <christian_ludwig at genua dot de>

ok visa@


# 1.98 08-May-2019 anton

Add a compile-time option called SPLASSERT_WATCH which changes the
default value of kern.splassert to 3, i.e. enter ddb on splassert()
failure. Will be used during fuzzing.

ok mpi@ visa@


Revision tags: OPENBSD_6_5_BASE
# 1.97 29-Oct-2018 deraadt

irrelevant part snuck into previous commit; from semarie


# 1.96 28-Oct-2018 beck

Correctly deal with upper level unveil's by keeping track of the covering
unveil for each unveil in the process at unveil() time, and refactoring the
handling of current directory and ISDOTDOT to be much more sensible.
Worked out at ns2k18 with guenther@.
ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.95 10-Apr-2018 mpi

Do not call logwakeup(), ending in wakeup_n(), while holding a mutex.

Prevents a lock ordering issue between SCHED_LOCK() and printf(9)'s
mutex. While here protect all kprintf() calls ending on the console
with the mutex.

ok kettenis@, visa@


Revision tags: OPENBSD_6_3_BASE
# 1.94 20-Mar-2018 mpi

Do not panic from ddb(4) when a lock requirement isn't fulfilled.

Extend the logic already present for panic() to any DDB-related
operation such that if ddb(4) is entered because of a fault or
other trap it is still possible to call 'boot reboot'.

While here stop printing splassert() messages as well, to not fill
the buffer.

ok visa@, deraadt@


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.105 20-Jan-2022 bluhm

snprintf(9) allows NULL string if size is 0. But doing NULL pointer
arithmetic is undefined behavior. Check that size is positive
before adding to pointer. While there, use NUL char for string
termination.
found by kubsan; joint work with tobhe@; OK millert@


Revision tags: OPENBSD_7_0_BASE
# 1.104 02-Jun-2021 cheloha

kernel: introduce per-CPU panic(9) message buffers

Add a 512-byte buffer (ci_panicbuf) to each cpu_info struct on each
platform for use by panic(9). The first panic on a given CPU writes
its message to this buffer. Subsequent panics on a given CPU print
the panic message to the console but do not modify the buffer. This
aids debugging in two cases:

- If 2+ CPUs panic simultaneously there is no risk of garbled messages
in the panic buffer.

- If a CPU panics and then the operator causes a second panic while
using ddb(4), the operator can still recall the first failure on
a particular CPU.

Misc. changes to support this bigger change:

- Set panicstr atomically to identify the first CPU to reach panic().

- Tweak db_show_panic_cmd() to print all panic messages across all
CPUs. Prefix the first panic with an asterisk ('*').

- Prefer db_printf() to printf() during a panic if we have it.
Apparently it disturbs less global state.

- On amd64, tweak fault() to write the local panic buffer. This needs
more work.

Prompted by bluhm@ and deraadt@. Mostly written by deraadt@.
Discussed with bluhm@, deraadt@ and kettenis@.

Borne from a discussion on tech@ about making panic(9) more MP-safe:

https://marc.info/?l=openbsd-tech&m=162086462316143&w=2

ok kettenis@, visa@, bluhm@, deraadt@


# 1.103 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_9_BASE
# 1.102 28-Nov-2020 deraadt

Rather than skipping %[sizearg]n in the kernel, panic when it is encountered.
printf(9) already lacked documentation and needs no change.


Revision tags: OPENBSD_6_8_BASE
# 1.101 24-Jul-2020 kettenis

Implement BOOT_QUIET option that supresses kernel printf output to the
console. When the kernel panics, print console output is enabled such
that we see those messages. Use this option for the powerpc64 boot
kernel.

ok visa@, deraadt@


# 1.100 20-Jul-2020 deraadt

fix macro indent


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.99 20-Jul-2019 mpi

Get rid of `ddb_is_active' instead use `db_active'.

From Christian Ludwig <christian_ludwig at genua dot de>

ok visa@


# 1.98 08-May-2019 anton

Add a compile-time option called SPLASSERT_WATCH which changes the
default value of kern.splassert to 3, i.e. enter ddb on splassert()
failure. Will be used during fuzzing.

ok mpi@ visa@


Revision tags: OPENBSD_6_5_BASE
# 1.97 29-Oct-2018 deraadt

irrelevant part snuck into previous commit; from semarie


# 1.96 28-Oct-2018 beck

Correctly deal with upper level unveil's by keeping track of the covering
unveil for each unveil in the process at unveil() time, and refactoring the
handling of current directory and ISDOTDOT to be much more sensible.
Worked out at ns2k18 with guenther@.
ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.95 10-Apr-2018 mpi

Do not call logwakeup(), ending in wakeup_n(), while holding a mutex.

Prevents a lock ordering issue between SCHED_LOCK() and printf(9)'s
mutex. While here protect all kprintf() calls ending on the console
with the mutex.

ok kettenis@, visa@


Revision tags: OPENBSD_6_3_BASE
# 1.94 20-Mar-2018 mpi

Do not panic from ddb(4) when a lock requirement isn't fulfilled.

Extend the logic already present for panic() to any DDB-related
operation such that if ddb(4) is entered because of a fault or
other trap it is still possible to call 'boot reboot'.

While here stop printing splassert() messages as well, to not fill
the buffer.

ok visa@, deraadt@


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.104 02-Jun-2021 cheloha

kernel: introduce per-CPU panic(9) message buffers

Add a 512-byte buffer (ci_panicbuf) to each cpu_info struct on each
platform for use by panic(9). The first panic on a given CPU writes
its message to this buffer. Subsequent panics on a given CPU print
the panic message to the console but do not modify the buffer. This
aids debugging in two cases:

- If 2+ CPUs panic simultaneously there is no risk of garbled messages
in the panic buffer.

- If a CPU panics and then the operator causes a second panic while
using ddb(4), the operator can still recall the first failure on
a particular CPU.

Misc. changes to support this bigger change:

- Set panicstr atomically to identify the first CPU to reach panic().

- Tweak db_show_panic_cmd() to print all panic messages across all
CPUs. Prefix the first panic with an asterisk ('*').

- Prefer db_printf() to printf() during a panic if we have it.
Apparently it disturbs less global state.

- On amd64, tweak fault() to write the local panic buffer. This needs
more work.

Prompted by bluhm@ and deraadt@. Mostly written by deraadt@.
Discussed with bluhm@, deraadt@ and kettenis@.

Borne from a discussion on tech@ about making panic(9) more MP-safe:

https://marc.info/?l=openbsd-tech&m=162086462316143&w=2

ok kettenis@, visa@, bluhm@, deraadt@


# 1.103 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_9_BASE
# 1.102 28-Nov-2020 deraadt

Rather than skipping %[sizearg]n in the kernel, panic when it is encountered.
printf(9) already lacked documentation and needs no change.


Revision tags: OPENBSD_6_8_BASE
# 1.101 24-Jul-2020 kettenis

Implement BOOT_QUIET option that supresses kernel printf output to the
console. When the kernel panics, print console output is enabled such
that we see those messages. Use this option for the powerpc64 boot
kernel.

ok visa@, deraadt@


# 1.100 20-Jul-2020 deraadt

fix macro indent


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.99 20-Jul-2019 mpi

Get rid of `ddb_is_active' instead use `db_active'.

From Christian Ludwig <christian_ludwig at genua dot de>

ok visa@


# 1.98 08-May-2019 anton

Add a compile-time option called SPLASSERT_WATCH which changes the
default value of kern.splassert to 3, i.e. enter ddb on splassert()
failure. Will be used during fuzzing.

ok mpi@ visa@


Revision tags: OPENBSD_6_5_BASE
# 1.97 29-Oct-2018 deraadt

irrelevant part snuck into previous commit; from semarie


# 1.96 28-Oct-2018 beck

Correctly deal with upper level unveil's by keeping track of the covering
unveil for each unveil in the process at unveil() time, and refactoring the
handling of current directory and ISDOTDOT to be much more sensible.
Worked out at ns2k18 with guenther@.
ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.95 10-Apr-2018 mpi

Do not call logwakeup(), ending in wakeup_n(), while holding a mutex.

Prevents a lock ordering issue between SCHED_LOCK() and printf(9)'s
mutex. While here protect all kprintf() calls ending on the console
with the mutex.

ok kettenis@, visa@


Revision tags: OPENBSD_6_3_BASE
# 1.94 20-Mar-2018 mpi

Do not panic from ddb(4) when a lock requirement isn't fulfilled.

Extend the logic already present for panic() to any DDB-related
operation such that if ddb(4) is entered because of a fault or
other trap it is still possible to call 'boot reboot'.

While here stop printing splassert() messages as well, to not fill
the buffer.

ok visa@, deraadt@


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.103 16-May-2021 deraadt

panic does not require a \n at the end. When one is provided, it looks wrong.


Revision tags: OPENBSD_6_9_BASE
# 1.102 28-Nov-2020 deraadt

Rather than skipping %[sizearg]n in the kernel, panic when it is encountered.
printf(9) already lacked documentation and needs no change.


Revision tags: OPENBSD_6_8_BASE
# 1.101 24-Jul-2020 kettenis

Implement BOOT_QUIET option that supresses kernel printf output to the
console. When the kernel panics, print console output is enabled such
that we see those messages. Use this option for the powerpc64 boot
kernel.

ok visa@, deraadt@


# 1.100 20-Jul-2020 deraadt

fix macro indent


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.99 20-Jul-2019 mpi

Get rid of `ddb_is_active' instead use `db_active'.

From Christian Ludwig <christian_ludwig at genua dot de>

ok visa@


# 1.98 08-May-2019 anton

Add a compile-time option called SPLASSERT_WATCH which changes the
default value of kern.splassert to 3, i.e. enter ddb on splassert()
failure. Will be used during fuzzing.

ok mpi@ visa@


Revision tags: OPENBSD_6_5_BASE
# 1.97 29-Oct-2018 deraadt

irrelevant part snuck into previous commit; from semarie


# 1.96 28-Oct-2018 beck

Correctly deal with upper level unveil's by keeping track of the covering
unveil for each unveil in the process at unveil() time, and refactoring the
handling of current directory and ISDOTDOT to be much more sensible.
Worked out at ns2k18 with guenther@.
ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.95 10-Apr-2018 mpi

Do not call logwakeup(), ending in wakeup_n(), while holding a mutex.

Prevents a lock ordering issue between SCHED_LOCK() and printf(9)'s
mutex. While here protect all kprintf() calls ending on the console
with the mutex.

ok kettenis@, visa@


Revision tags: OPENBSD_6_3_BASE
# 1.94 20-Mar-2018 mpi

Do not panic from ddb(4) when a lock requirement isn't fulfilled.

Extend the logic already present for panic() to any DDB-related
operation such that if ddb(4) is entered because of a fault or
other trap it is still possible to call 'boot reboot'.

While here stop printing splassert() messages as well, to not fill
the buffer.

ok visa@, deraadt@


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.102 28-Nov-2020 deraadt

Rather than skipping %[sizearg]n in the kernel, panic when it is encountered.
printf(9) already lacked documentation and needs no change.


Revision tags: OPENBSD_6_8_BASE
# 1.101 24-Jul-2020 kettenis

Implement BOOT_QUIET option that supresses kernel printf output to the
console. When the kernel panics, print console output is enabled such
that we see those messages. Use this option for the powerpc64 boot
kernel.

ok visa@, deraadt@


# 1.100 20-Jul-2020 deraadt

fix macro indent


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.99 20-Jul-2019 mpi

Get rid of `ddb_is_active' instead use `db_active'.

From Christian Ludwig <christian_ludwig at genua dot de>

ok visa@


# 1.98 08-May-2019 anton

Add a compile-time option called SPLASSERT_WATCH which changes the
default value of kern.splassert to 3, i.e. enter ddb on splassert()
failure. Will be used during fuzzing.

ok mpi@ visa@


Revision tags: OPENBSD_6_5_BASE
# 1.97 29-Oct-2018 deraadt

irrelevant part snuck into previous commit; from semarie


# 1.96 28-Oct-2018 beck

Correctly deal with upper level unveil's by keeping track of the covering
unveil for each unveil in the process at unveil() time, and refactoring the
handling of current directory and ISDOTDOT to be much more sensible.
Worked out at ns2k18 with guenther@.
ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.95 10-Apr-2018 mpi

Do not call logwakeup(), ending in wakeup_n(), while holding a mutex.

Prevents a lock ordering issue between SCHED_LOCK() and printf(9)'s
mutex. While here protect all kprintf() calls ending on the console
with the mutex.

ok kettenis@, visa@


Revision tags: OPENBSD_6_3_BASE
# 1.94 20-Mar-2018 mpi

Do not panic from ddb(4) when a lock requirement isn't fulfilled.

Extend the logic already present for panic() to any DDB-related
operation such that if ddb(4) is entered because of a fault or
other trap it is still possible to call 'boot reboot'.

While here stop printing splassert() messages as well, to not fill
the buffer.

ok visa@, deraadt@


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.101 24-Jul-2020 kettenis

Implement BOOT_QUIET option that supresses kernel printf output to the
console. When the kernel panics, print console output is enabled such
that we see those messages. Use this option for the powerpc64 boot
kernel.

ok visa@, deraadt@


# 1.100 20-Jul-2020 deraadt

fix macro indent


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.99 20-Jul-2019 mpi

Get rid of `ddb_is_active' instead use `db_active'.

From Christian Ludwig <christian_ludwig at genua dot de>

ok visa@


# 1.98 08-May-2019 anton

Add a compile-time option called SPLASSERT_WATCH which changes the
default value of kern.splassert to 3, i.e. enter ddb on splassert()
failure. Will be used during fuzzing.

ok mpi@ visa@


Revision tags: OPENBSD_6_5_BASE
# 1.97 29-Oct-2018 deraadt

irrelevant part snuck into previous commit; from semarie


# 1.96 28-Oct-2018 beck

Correctly deal with upper level unveil's by keeping track of the covering
unveil for each unveil in the process at unveil() time, and refactoring the
handling of current directory and ISDOTDOT to be much more sensible.
Worked out at ns2k18 with guenther@.
ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.95 10-Apr-2018 mpi

Do not call logwakeup(), ending in wakeup_n(), while holding a mutex.

Prevents a lock ordering issue between SCHED_LOCK() and printf(9)'s
mutex. While here protect all kprintf() calls ending on the console
with the mutex.

ok kettenis@, visa@


Revision tags: OPENBSD_6_3_BASE
# 1.94 20-Mar-2018 mpi

Do not panic from ddb(4) when a lock requirement isn't fulfilled.

Extend the logic already present for panic() to any DDB-related
operation such that if ddb(4) is entered because of a fault or
other trap it is still possible to call 'boot reboot'.

While here stop printing splassert() messages as well, to not fill
the buffer.

ok visa@, deraadt@


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.100 20-Jul-2020 deraadt

fix macro indent


Revision tags: OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.99 20-Jul-2019 mpi

Get rid of `ddb_is_active' instead use `db_active'.

From Christian Ludwig <christian_ludwig at genua dot de>

ok visa@


# 1.98 08-May-2019 anton

Add a compile-time option called SPLASSERT_WATCH which changes the
default value of kern.splassert to 3, i.e. enter ddb on splassert()
failure. Will be used during fuzzing.

ok mpi@ visa@


Revision tags: OPENBSD_6_5_BASE
# 1.97 29-Oct-2018 deraadt

irrelevant part snuck into previous commit; from semarie


# 1.96 28-Oct-2018 beck

Correctly deal with upper level unveil's by keeping track of the covering
unveil for each unveil in the process at unveil() time, and refactoring the
handling of current directory and ISDOTDOT to be much more sensible.
Worked out at ns2k18 with guenther@.
ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.95 10-Apr-2018 mpi

Do not call logwakeup(), ending in wakeup_n(), while holding a mutex.

Prevents a lock ordering issue between SCHED_LOCK() and printf(9)'s
mutex. While here protect all kprintf() calls ending on the console
with the mutex.

ok kettenis@, visa@


Revision tags: OPENBSD_6_3_BASE
# 1.94 20-Mar-2018 mpi

Do not panic from ddb(4) when a lock requirement isn't fulfilled.

Extend the logic already present for panic() to any DDB-related
operation such that if ddb(4) is entered because of a fault or
other trap it is still possible to call 'boot reboot'.

While here stop printing splassert() messages as well, to not fill
the buffer.

ok visa@, deraadt@


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.99 20-Jul-2019 mpi

Get rid of `ddb_is_active' instead use `db_active'.

From Christian Ludwig <christian_ludwig at genua dot de>

ok visa@


# 1.98 08-May-2019 anton

Add a compile-time option called SPLASSERT_WATCH which changes the
default value of kern.splassert to 3, i.e. enter ddb on splassert()
failure. Will be used during fuzzing.

ok mpi@ visa@


Revision tags: OPENBSD_6_5_BASE
# 1.97 29-Oct-2018 deraadt

irrelevant part snuck into previous commit; from semarie


# 1.96 28-Oct-2018 beck

Correctly deal with upper level unveil's by keeping track of the covering
unveil for each unveil in the process at unveil() time, and refactoring the
handling of current directory and ISDOTDOT to be much more sensible.
Worked out at ns2k18 with guenther@.
ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.95 10-Apr-2018 mpi

Do not call logwakeup(), ending in wakeup_n(), while holding a mutex.

Prevents a lock ordering issue between SCHED_LOCK() and printf(9)'s
mutex. While here protect all kprintf() calls ending on the console
with the mutex.

ok kettenis@, visa@


Revision tags: OPENBSD_6_3_BASE
# 1.94 20-Mar-2018 mpi

Do not panic from ddb(4) when a lock requirement isn't fulfilled.

Extend the logic already present for panic() to any DDB-related
operation such that if ddb(4) is entered because of a fault or
other trap it is still possible to call 'boot reboot'.

While here stop printing splassert() messages as well, to not fill
the buffer.

ok visa@, deraadt@


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.98 08-May-2019 anton

Add a compile-time option called SPLASSERT_WATCH which changes the
default value of kern.splassert to 3, i.e. enter ddb on splassert()
failure. Will be used during fuzzing.

ok mpi@ visa@


Revision tags: OPENBSD_6_5_BASE
# 1.97 29-Oct-2018 deraadt

irrelevant part snuck into previous commit; from semarie


# 1.96 28-Oct-2018 beck

Correctly deal with upper level unveil's by keeping track of the covering
unveil for each unveil in the process at unveil() time, and refactoring the
handling of current directory and ISDOTDOT to be much more sensible.
Worked out at ns2k18 with guenther@.
ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.95 10-Apr-2018 mpi

Do not call logwakeup(), ending in wakeup_n(), while holding a mutex.

Prevents a lock ordering issue between SCHED_LOCK() and printf(9)'s
mutex. While here protect all kprintf() calls ending on the console
with the mutex.

ok kettenis@, visa@


Revision tags: OPENBSD_6_3_BASE
# 1.94 20-Mar-2018 mpi

Do not panic from ddb(4) when a lock requirement isn't fulfilled.

Extend the logic already present for panic() to any DDB-related
operation such that if ddb(4) is entered because of a fault or
other trap it is still possible to call 'boot reboot'.

While here stop printing splassert() messages as well, to not fill
the buffer.

ok visa@, deraadt@


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.97 29-Oct-2018 deraadt

irrelevant part snuck into previous commit; from semarie


# 1.96 28-Oct-2018 beck

Correctly deal with upper level unveil's by keeping track of the covering
unveil for each unveil in the process at unveil() time, and refactoring the
handling of current directory and ISDOTDOT to be much more sensible.
Worked out at ns2k18 with guenther@.
ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.95 10-Apr-2018 mpi

Do not call logwakeup(), ending in wakeup_n(), while holding a mutex.

Prevents a lock ordering issue between SCHED_LOCK() and printf(9)'s
mutex. While here protect all kprintf() calls ending on the console
with the mutex.

ok kettenis@, visa@


Revision tags: OPENBSD_6_3_BASE
# 1.94 20-Mar-2018 mpi

Do not panic from ddb(4) when a lock requirement isn't fulfilled.

Extend the logic already present for panic() to any DDB-related
operation such that if ddb(4) is entered because of a fault or
other trap it is still possible to call 'boot reboot'.

While here stop printing splassert() messages as well, to not fill
the buffer.

ok visa@, deraadt@


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.96 28-Oct-2018 beck

Correctly deal with upper level unveil's by keeping track of the covering
unveil for each unveil in the process at unveil() time, and refactoring the
handling of current directory and ISDOTDOT to be much more sensible.
Worked out at ns2k18 with guenther@.
ok deraadt@


Revision tags: OPENBSD_6_4_BASE
# 1.95 10-Apr-2018 mpi

Do not call logwakeup(), ending in wakeup_n(), while holding a mutex.

Prevents a lock ordering issue between SCHED_LOCK() and printf(9)'s
mutex. While here protect all kprintf() calls ending on the console
with the mutex.

ok kettenis@, visa@


Revision tags: OPENBSD_6_3_BASE
# 1.94 20-Mar-2018 mpi

Do not panic from ddb(4) when a lock requirement isn't fulfilled.

Extend the logic already present for panic() to any DDB-related
operation such that if ddb(4) is entered because of a fault or
other trap it is still possible to call 'boot reboot'.

While here stop printing splassert() messages as well, to not fill
the buffer.

ok visa@, deraadt@


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.95 10-Apr-2018 mpi

Do not call logwakeup(), ending in wakeup_n(), while holding a mutex.

Prevents a lock ordering issue between SCHED_LOCK() and printf(9)'s
mutex. While here protect all kprintf() calls ending on the console
with the mutex.

ok kettenis@, visa@


Revision tags: OPENBSD_6_3_BASE
# 1.94 20-Mar-2018 mpi

Do not panic from ddb(4) when a lock requirement isn't fulfilled.

Extend the logic already present for panic() to any DDB-related
operation such that if ddb(4) is entered because of a fault or
other trap it is still possible to call 'boot reboot'.

While here stop printing splassert() messages as well, to not fill
the buffer.

ok visa@, deraadt@


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


Revision tags: OPENBSD_6_3_BASE
# 1.94 20-Mar-2018 mpi

Do not panic from ddb(4) when a lock requirement isn't fulfilled.

Extend the logic already present for panic() to any DDB-related
operation such that if ddb(4) is entered because of a fault or
other trap it is still possible to call 'boot reboot'.

While here stop printing splassert() messages as well, to not fill
the buffer.

ok visa@, deraadt@


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.93 05-Jan-2018 pirofti

Show uvm_fault and trace when typing show panic on a page fault'd kernel

Currently there is only support for amd64, if this change settles
I will add support for the rest of the architectures.

OK kettenis@.


# 1.92 30-Dec-2017 guenther

Delete unnecessary <sys/file.h> includes

ok millert@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.91 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.90 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


# 1.89 27-Apr-2017 mpi

Unifdef KADB.

ok deraadt@


# 1.88 20-Apr-2017 visa

Tweak lock inits to make the system runnable with witness(4)
on amd64 and i386.


Revision tags: OPENBSD_6_0_BASE OPENBSD_6_1_BASE
# 1.87 17-May-2016 bluhm

Allow sendsyslog(2) with LOG_CONS even when /dev/console has not
been opened during init(8). Only log with cnwrite() if cn_devvp
exists, otherwise use cnputc() as fallback. While there move extern
declarations to dev/cons.h.
input and OK deraadt@


Revision tags: OPENBSD_5_9_BASE
# 1.86 29-Sep-2015 guenther

Delete the final, inscrutable NOSTRICT and VARARGS lint comments

ok millert@


Revision tags: OPENBSD_5_8_BASE
# 1.85 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.84 13-Jan-2015 mpf

Add dmesg -s support, to view the output of rc(8) system startup messages.
Help and feedback by Theo and Miod.
OK deraadt@, manpage-ok jmc@


Revision tags: OPENBSD_5_6_BASE
# 1.83 13-Jul-2014 uebayasi

KASSERTMSG(9): New kernel assertion with message

KASSERT() is annoying as it only prints the expression as a string. If you
(developers) want to know a little more information, you have to do:

#ifdef DIAGNOSTIC
if (bad)
panic(...);
#endif

KASSERTMSG() replaces it into a single line:

KASSERTMSG(!bad, ...);

Taken from NetBSD.

(There is a concern that KASSERT() messages are too long; consume more memory,
and not friendly for small monitors. This have to be considered & revisited
later.)

"Like" from henning@
Man page review & advices from jmc@ and schwarze@


# 1.82 11-Jul-2014 uebayasi

reboot(9): Add MI reboot entry function

Now, for kernel to "reboot" (reboot, halt, or shutdown), MD boot(9) is called
in some places. This change introduces a new MI function reboot(9) which is
simply a wrapper to call MD boot(9).

OK kettenis@ deraadt@


Revision tags: OPENBSD_5_5_BASE
# 1.81 12-Dec-2013 guenther

Add db_vprintf(), and then use it in ACPI's db_disprint() instead of
formatting into a local buffer.

ok miod@


# 1.80 25-Nov-2013 djm

disable %n in printf(9); there is no need for it in the kernel besides
making format-string vulnerabilities exploitable; inspired by similar
change made by Kees Cook to Linux; ok deraadt@


# 1.79 07-Aug-2013 bluhm

After a panic, do not fill up the dmesg with splassert messages.
They scroll away the important information. Disable splassert in
panic().
OK deraadt@ uebayasi@ sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.78 03-Jul-2013 sf

add support for %td for ptrdiff_t in kernel printf

this also adds support in gcc 4.x kprintf format checks

ok kettenis@


# 1.77 28-Mar-2013 deraadt

do not include machine/cpu.h from a .c file; it is the responsibility of
.h files to pull it in, if needed
ok tedu


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.76 03-Apr-2011 drahn

Allow kernel printfs to go to console if in ddb instead of being redirected
to xconsole. ok deraadt@ guenther@


Revision tags: OPENBSD_4_8_BASE OPENBSD_4_9_BASE
# 1.75 26-Jul-2010 guenther

Correct the links between threads, processes, pgrps, and sessions,
so that the process-level stuff is to/from struct process and not
struct proc. This fixes a bunch of problem cases in rthreads.
Based on earlier work by blambert and myself, but mostly written
at c2k10.

Tested by many: deraadt, sthen, krw, ray, and in snapshots


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.74 27-Jun-2008 miod

Do not disallow kernel crash dumps on panic if swap encryption is enabled,
as dumpsys() will now clear the sensitive information.

ok djm@ (and dumpsys changes too)


Revision tags: OPENBSD_4_3_BASE
# 1.73 30-Dec-2007 bluhm

Remove unused variable consintr. ok mbalmer


# 1.72 08-Oct-2007 ray

Introduce %z for printf(9), like %z for printf(3). Used to print
size_t and ssize_t variables.

OK miod and cthulhu.


# 1.71 01-Sep-2007 miod

Remove support for ddb-only %r, %z, and the ddb-specific handling of %n from
the kernel printf. This will allow support for the real %z in the near future.


Revision tags: OPENBSD_4_2_BASE
# 1.70 26-Apr-2007 deraadt

enable splassert (1) by default; requested and ok many


Revision tags: OPENBSD_4_1_BASE
# 1.69 11-Dec-2006 deraadt

allow bit 32 to be printed; bug spotted and fix tested by dlg


# 1.68 17-Nov-2006 jmc

missing punctuation in comments; from bret lambert


Revision tags: OPENBSD_4_0_BASE
# 1.67 06-Jul-2006 miod

Make the ddb.log sysctl available as an in-ddb variable, $log, for consistency.


# 1.66 01-Jun-2006 jason

the bit shifted should be a type at least as wide as the comparison (u_quad_t)


# 1.65 29-May-2006 jason

extend %b support so that it will allow for arguments with more than 32 bits.


Revision tags: OPENBSD_3_9_BASE
# 1.64 27-Dec-2005 miod

tprintf() is now only necessary for NFS, so do not compile it for kernels
which like NFSSERVER and NFSCLIENT.


# 1.63 09-Dec-2005 jsg

ansi and deregister. No binary change.


# 1.62 27-Sep-2005 grunk

typo in comment: sprintf -> snprintf, ok markus@


Revision tags: OPENBSD_3_8_BASE
# 1.61 14-Apr-2005 krw

Try to start log message buffer on a new line. Helps install scripts avoid
detecting phantom devices when scanning dmesg output.

Suggested by miod@, ok deraadt@.


Revision tags: OPENBSD_3_6_BASE OPENBSD_3_7_BASE
# 1.60 20-Jul-2004 art

protect printf with a mutex instead of SIMPLELOCK.


# 1.59 13-Jun-2004 niklas

debranch SMP, have fun


Revision tags: OPENBSD_3_5_BASE SMP_SYNC_A SMP_SYNC_B
# 1.58 03-Jan-2004 espie

put an mi wrapper around stdarg.h/varargs.h. gcc3 moved stdarg/varargs macros
to built-ins, so eventually we will have one version of these files.
Special adjustments for the kernel to cope: machine/stdarg.h -> sys/stdarg.h
and machine/ansi.h needs to have a _BSD_VA_LIST_ for syslog* prototypes.
okay millert@, drahn@, miod@.


# 1.57 21-Dec-2003 miod

Kill non-standard kernel printf %: braindead extension for good.
ok markus@ drahn@


Revision tags: OPENBSD_3_4_BASE
# 1.56 28-Jun-2003 tedu

option to log ddb output to kernel message buffer, via sysctl ddb.log
ok deraadt@ henric@ djm@


# 1.55 02-Jun-2003 millert

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


# 1.54 29-May-2003 ho

Add kern.splassert=3. deraadt@ ok.


# 1.53 27-May-2003 henning

typos in comments; From: Bengt Wessling <bengt@lemuria.org>, 10x


# 1.52 22-May-2003 deraadt

remove sprintf() and vsprintf(). nothing in the kernel needs it. if
some module does -- tough -- they can rewrite it using the safer versions.


# 1.51 21-May-2003 art

Match vprintf prototype to userland and standards.

deraadt@ ok


# 1.50 20-May-2003 jason

ansi and de-register; ok millert


Revision tags: UBC_SYNC_A
# 1.49 13-May-2003 jason

Kill a bunch more commons (very few left =)


# 1.48 10-May-2003 deraadt

warn for strcpy|strcat|sprintf|vsprintf; ok art dhartmei pval, and either henning or pb, i cannot tell which it was


# 1.47 06-May-2003 deraadt

use snprintf


Revision tags: OPENBSD_3_3_BASE
# 1.46 13-Jan-2003 weingart

Fix kernel snprintf function(s) to be like
userland in return values.

deraadt@ ok.


Revision tags: UBC_SYNC_B
# 1.45 14-Oct-2002 art

Stuff needed for gcc 3.X.

gcc has the nice feature of optimizing various common constructs into
more optimal ones, inlining various calls, etc. The problem with that
is that it assumes that we have a proper libc backing us. We really
don't want to loose all those features by defining -ffreestanding and
right now there is no way to just disable some of them, so we have to
make the kernel more libc-like in some aspects to make it work with
newer gcc.

rename putchar to kputchar because it was nothing like libc putchar (and
only internal to this function). Implement dummy putchar and puts (not
prototyped outside this file).


Revision tags: OPENBSD_3_2_BASE
# 1.44 20-May-2002 art

Add one more level to the kern.splassert sysctl.
0 - do nothing.
1 - small message on error (function name and the levels).
2 - big message on error (function name, levels and traceback (if possible)).
3 - panic.
After suggestion from deraadt@.


# 1.43 18-May-2002 art

dump the stack on splassert failure (XXX - need some kind of
rate limiting).


# 1.42 18-May-2002 art

If ddb.panic is disabled, print the stack trace before dumping.


# 1.41 15-May-2002 art

Implement splassert() for sparc - a tool for finding problems related to
spl handling (already found 3 problems).

Man page in a few seconds.
deraadt@ ok.


Revision tags: OPENBSD_3_1_BASE
# 1.40 15-Mar-2002 millert

Kill #if __STDC__ used to do K&R vs. ANSI varargs/stdarg; just do things
the ANSI way.


# 1.39 14-Mar-2002 millert

First round of __P removal in sys


# 1.38 23-Jan-2002 art

Allocate rusage, pgrp, ucred and session with pool.


Revision tags: UBC_BASE
# 1.37 02-Dec-2001 deraadt

branches: 1.37.2;
remove some XXX comments


# 1.36 15-Nov-2001 niklas

remove statics


Revision tags: OPENBSD_3_0_BASE
# 1.35 05-Sep-2001 deraadt

make sure that va_start() has matching va_end()


# 1.34 05-Sep-2001 deraadt

use %ll instead of %q


# 1.33 27-Jun-2001 art

remove old vm


# 1.32 22-Jun-2001 deraadt

KNF


Revision tags: OPENBSD_2_9_BASE
# 1.31 22-Feb-2001 mickey

avoid sign extension for %b


Revision tags: OPENBSD_2_8_BASE
# 1.30 25-Jun-2000 provos

disable automatic crashdump when swap encryption is on


Revision tags: OPENBSD_2_7_BASE
# 1.29 13-Mar-2000 millert

Get rid of leading NULs in /kern/msgbuf. If the msgbuf modified in between
reads at just the right time is is possible to get duplicate output but
in practice this is extremely rare. Joint effort with Theo.


# 1.28 02-Mar-2000 art

Add an option DDB_SAFE_CONSOLE that defaults db_console to 1.
In many cases, setting db_console in /etc/rc is too late.


# 1.27 22-Feb-2000 deraadt

enlarge msgbuf, somewhat line netbsd did


Revision tags: SMP_BASE kame_19991208
# 1.26 02-Dec-1999 deraadt

branches: 1.26.2;
snprintf in kernel; assar@stacken.kth.se


Revision tags: OPENBSD_2_5_BASE OPENBSD_2_6_BASE
# 1.25 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


# 1.24 10-Jan-1999 niklas

NUL terminate the buffer in vsprintf


Revision tags: OPENBSD_2_3_BASE OPENBSD_2_4_BASE
# 1.23 04-Apr-1998 deraadt

default to console ddb off


# 1.22 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


# 1.21 24-Jan-1998 niklas

NULL deref


# 1.20 21-Jan-1998 deraadt

support expanded panicstr; and add vsprintf back


# 1.19 29-Dec-1997 deraadt

sysctl ddb.panic_ddb; felix@mamba.pond.sub.org


# 1.18 28-Dec-1997 niklas

Do not lose the first char in msgbuf


# 1.17 04-Nov-1997 chuck

import torek's vfprintf() from libc [renamed to kprintf and all
floating point stuff removed].

the new kprintf replaces the 3 different (and buggy) versions of
printf that were in the kernel before (kprintf, sprintf, and db_printf),
thus reducing duplicated code by 2/3's. this fixes (or adds) several
printf formats.

XXX: new kprintf still supports several non-standard '%' formats:
%: - passes an additional format string and argument list recursively
%b - used to decode error registers
%r - int, but print in radix "db_radix" [DDB only]
%z - 'signed hex' [DDB only]
%n - unsigned int, but print in radix "db_radix" [DDB only]

note that DDB's "%n" conflicts with standard "%n" which takes the
number of characters written so far and stores it into the integer
indicated by the "int *" pointer arg. yuck!

while here, add comments for each function explaining what it is
supposed to do.


Revision tags: OPENBSD_2_2_BASE
# 1.16 01-Oct-1997 angelos

added 'q' modifier (64-bit integers) in kernel vsprintf/kprintf


Revision tags: OPENBSD_2_1_BASE
# 1.15 06-Dec-1996 niklas

-Wcast-qual cleanup


# 1.14 29-Nov-1996 kstailey

back out bitmask_snprintf()


# 1.13 24-Nov-1996 niklas

Commented out a def, only referenced in out-commented code


# 1.12 24-Nov-1996 kstailey

added bitmap_snprintf


# 1.11 19-Oct-1996 niklas

__assert added, impl from netbsd, however put elsewhere. use it instead
of private versions (one even using the userland header) in if_sn.c


Revision tags: OPENBSD_2_0_BASE
# 1.10 28-Jul-1996 deraadt

fix vsnprintf return val


# 1.9 23-Jul-1996 deraadt

make printf/addlog return 0, for compat to userland


# 1.8 19-Jul-1996 dm

Fixed NetBSD pr #2633 (douzzer@mit.edu)--Be slightly more reasonable
about something like printf ("bogus format %l");


# 1.7 02-Jul-1996 niklas

-Wall & -Wstrict-prototype fixes


# 1.6 26-Jun-1996 dm

expand %d is panicstr


# 1.5 02-May-1996 deraadt

sync syscalls, no sys/cpu.h


# 1.4 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.3 19-Apr-1996 niklas

NetBSD 960317 merge


# 1.2 29-Feb-1996 niklas

From NetBSD: Merge with NetBSD 960217


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision