xref: /netbsd-src/share/man/man9/KASSERT.9 (revision 586001f7c7e9a7926e015290e223dac8f8f4cda2)
1.\"     $NetBSD: KASSERT.9,v 1.13 2011/09/27 00:36:51 jym Exp $
2.\"
3.\" Copyright (c) 2006 Igor Sobrado
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25.\" POSSIBILITY OF SUCH DAMAGE.
26.\"
27.Dd September 27, 2011
28.Dt KASSERT 9
29.Os
30.Sh NAME
31.Nm KASSERT ,
32.Nm KASSERTMSG ,
33.Nm KDASSERT ,
34.Nm KDASSERTMSG
35.Nd kernel expression verification macros
36.Sh SYNOPSIS
37.Ft void
38.Fn KASSERT expression
39.Ft void
40.Fn KASSERTMSG expression format ...
41.Ft void
42.Fn KDASSERT expression
43.Ft void
44.Fn KDASSERTMSG expression format ...
45.Sh DESCRIPTION
46These machine independent assertion-checking macros cause a kernel
47.Xr panic 9
48if the given
49.Ar expression
50evaluates to false.
51Two compile-time
52.Xr options 4
53define the behavior of the checks.
54.Bl -enum -offset 2n
55.It
56The
57.Fn KASSERT
58and
59.Fn KASSERTMSG
60tests are included only in kernels compiled with the
61.Dv DIAGNOSTIC
62configuration option.
63In a kernel that does not have this configuration option,
64the macros are defined to be no-ops.
65.It
66The
67.Fn KDASSERT
68and
69.Fn KDASSERTMSG
70tests are included only in kernels compiled with the
71.Dv DEBUG
72configuration option.
73The
74.Fn KDASSERT
75and
76.Fn KASSERT
77macros are identical except for the controlling option
78.Pf ( Dv DEBUG
79vs
80.Dv DIAGNOSTIC ) .
81Basically,
82.Fn KASSERT
83should be used for light-weight checks and
84.Fn KDASSERT
85should be used for heavier ones.
86.El
87.Pp
88Callers should not rely on the side effects of
89.Ar expression
90because, depending on the kernel compile options mentioned above,
91.Ar expression
92might not be evaluated at all.
93.Pp
94The panic message will display the style of assertion (debugging
95vs. diagnostic), the expression that failed and the filename, and line
96number the failure happened on.
97The
98.Fn KASSERTMSG
99and
100.Fn KDASSERTMSG
101macros append
102to the
103.Xr panic 9
104format string the message specified by
105.Fa format
106and its subsequent arguments, similar to
107.Xr printf 9
108functions.
109.Sh SEE ALSO
110.Xr config 1 ,
111.Xr options 4 ,
112.Xr CTASSERT 9 ,
113.Xr panic 9 ,
114.Xr printf 9
115.Sh AUTHORS
116These macros were written by
117.An Chris G. Demetriou
118.Aq cgd@netbsd.org .
119