1.\" $OpenBSD: KASSERT.9,v 1.2 2019/05/10 14:36:21 mpi Exp $ 2.\" 3.\" Copyright (c) 2002, 2003 CubeSoft Communications, Inc. 4.\" <http://www.csoft.org> 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 AUTHOR ``AS IS'' AND ANY EXPRESS OR 16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 19.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20.\" (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 23.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 24.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE 25.\" POSSIBILITY OF SUCH DAMAGE. 26.\" 27.Dd $Mdocdate: May 10 2019 $ 28.Dt KASSERT 9 29.Os 30.Sh NAME 31.Nm assert , 32.Nm KASSERT , 33.Nm KDASSERT , 34.Nm KASSERTMSG , 35.Nm KDASSERTMSG , 36.Nm CTASSERT 37.Nd kernel assert library routines 38.Sh SYNOPSIS 39.In sys/systm.h 40.Ft "void" 41.Fn assert "CONDITION" 42.Ft "void" 43.Fn KASSERT "CONDITION" 44.Ft "void" 45.Fn KDASSERT "CONDITION" 46.Ft "void" 47.Fn KASSERTMSG "CONDITION" "fmt" "..." 48.Ft "void" 49.Fn KDASSERTMSG "CONDITION" "fmt" "..." 50.Ft "void" 51.Fn CTASSERT "CONDITION" 52.Sh DESCRIPTION 53The 54kernel 55library implements a set of useful functions and macros implementing 56expression verification. 57.Pp 58These macros cause kernel 59.Xr panic 9 60if the given condition evaluates to false. 61.Fn assert 62tests are always compiled in. 63.Fn KASSERT 64and 65.Fn KASSERTMSG 66tests are only included if the kernel has 67.Dv DIAGNOSTIC 68enabled. 69.Fn KDASSERT 70and 71.Fn KDASSERTMSG 72tests are only included if the kernel has 73.Dv DEBUG 74enabled. 75The 76.Fn KASSERTMSG 77and 78.Fn KDASSERTMSG 79macros append 80to the 81.Xr panic 9 82format string the message specified by 83.Fa format 84and its subsequent arguments, similar to 85.Xr printf 9 86functions. 87.Pp 88.Fn CTASSERT 89causes a compile time error if the given condition evaluates to 90false. 91Its main purpose is to verify assertions about type and struct sizes that 92would otherwise make the code fail at run time. 93.Fn CTASSERT 94can be used in global scope or at the start of blocks, where variable 95declarations are allowed. 96.Sh SEE ALSO 97.Xr assert 3 , 98.Xr panic 9 99.Sh HISTORY 100The 101.Fn KASSERTMSG 102and 103.Fn KDASSERTMSG 104macros are taken from 105.Nx . 106