1.\" $NetBSD: KASSERT.9,v 1.12 2011/04/06 05:40:19 jruoho 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 April 6, 2011 28.Dt KASSERT 9 29.Os 30.Sh NAME 31.Nm KASSERT , 32.Nm KASSERTMSG , 33.Nm KDASSERT 34.Nd kernel expression verification macros 35.Sh SYNOPSIS 36.Ft void 37.Fn KASSERT expression 38.Ft void 39.Fn KASSERTMSG expression message 40.Ft void 41.Fn KDASSERT expression 42.Sh DESCRIPTION 43These machine independent assertion-checking macros cause a kernel 44.Xr panic 9 45if the given 46.Ar expression 47evaluates to false. 48Two compile-time 49.Xr options 4 50define the behavior of the checks. 51.Bl -enum -offset 2n 52.It 53The 54.Fn KASSERT 55and 56.Fn KASSERTMSG 57tests are included only in kernels compiled with the 58.Dv DIAGNOSTIC 59configuration option. 60In a kernel that does not have this configuration option, 61the macros are defined to be no-ops. 62.It 63The 64.Fn KDASSERT 65tests are included only in kernels compiled with the 66.Dv DEBUG 67configuration option. 68The 69.Fn KDASSERT 70and 71.Fn KASSERT 72macros are identical except for the controlling option 73.Pf ( Dv DEBUG 74vs 75.Dv DIAGNOSTIC ) . 76Basically, 77.Fn KASSERT 78should be used for light-weight checks and 79.Fn KDASSERT 80should be used for heavier ones. 81.El 82.Pp 83Callers should not rely on the side effects of 84.Ar expression 85because, depending on the kernel compile options mentioned above, 86.Ar expression 87might not be evaluated at all. 88.Pp 89The panic message will display the style of assertion (debugging 90vs. diagnostic), the expression that failed and the filename, and line 91number the failure happened on. 92The 93.Fn KASSERTMSG 94macro appends additional 95.Fa message 96to the 97.Xr panic 9 98format string. 99.Sh SEE ALSO 100.Xr config 1 , 101.Xr options 4 , 102.Xr CTASSERT 9 , 103.Xr panic 9 , 104.Xr printf 9 105.Sh AUTHORS 106These macros were written by 107.An Chris G. Demetriou 108.Aq cgd@netbsd.org . 109