-# $OpenBSD: Makefile,v 1.216 2014/07/13 09:37:22 mpi Exp $
+# $OpenBSD: Makefile,v 1.217 2014/07/13 23:49:40 uebayasi Exp $
# $NetBSD: Makefile,v 1.4 1996/01/09 03:23:01 thorpej Exp $
# Makefile for section 9 (kernel function and variable) manual pages.
MLINKS+=kern.9 imax.9 kern.9 imin.9 kern.9 lmax.9 kern.9 lmin.9 \
kern.9 max.9 kern.9 min.9 kern.9 ulmax.9 kern.9 ulmin.9 kern.9 abs.9 \
kern.9 assert.9 kern.9 KASSERT.9 kern.9 KDASSERT.9 \
+ kern.9 KASSERTMSG.9 kern.9 KDASSERTMSG.9 \
kern.9 skpc.9 kern.9 scanc.9 kern.9 bcmp.9 \
kern.9 memchr.9 kern.9 memcmp.9 kern.9 ffs.9 kern.9 fls.9 kern.9 flsl.9 \
kern.9 strlen.9 kern.9 strncpy.9 kern.9 strlcpy.9 kern.9 strlcat.9 \
-.\" $OpenBSD: kern.9,v 1.18 2013/07/11 01:24:12 jsg Exp $
+.\" $OpenBSD: kern.9,v 1.19 2014/07/13 23:49:40 uebayasi Exp $
.\"
.\" Copyright (c) 2002, 2003 CubeSoft Communications, Inc.
.\" <http://www.csoft.org>
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: July 11 2013 $
+.Dd $Mdocdate: July 13 2014 $
.Dt KERN 9
.Os
.Sh NAME
.Fn KASSERT "CONDITION"
.Ft "void"
.Fn KDASSERT "CONDITION"
+.Ft "void"
+.Fn KASSERTMSG "CONDITION" "fmt" "..."
+.Ft "void"
+.Fn KDASSERTMSG "CONDITION" "fmt" "..."
.nr nS 0
.Pp
These macros cause kernel
.Fn assert
tests are always compiled in.
.Fn KASSERT
+and
+.Fn KASSERTMSG
tests are only included if the kernel has
.Dv DIAGNOSTIC
enabled.
.Fn KDASSERT
+and
+.Fn KDASSERTMSG
tests are only included if the kernel has
.Dv DEBUG
enabled.
+The
+.Fn KASSERTMSG
+and
+.Fn KDASSERTMSG
+macros append
+to the
+.Xr panic 9
+format string the message specified by
+.Fa format
+and its subsequent arguments, similar to
+.Xr printf 9
+functions.
.Pp
.nr nS 1
.Fn CTASSERT "CONDITION"
and
.Fn scanc
functions are based on vax instructions of the same name.
+The
+.Fn KASSERTMSG
+and
+.Fn KDASSERTMSG
+macros are taken from NetBSD.
-/* $OpenBSD: kern_physio.c,v 1.39 2011/07/18 02:49:20 matthew Exp $ */
+/* $OpenBSD: kern_physio.c,v 1.40 2014/07/13 23:49:40 uebayasi Exp $ */
/* $NetBSD: kern_physio.c,v 1.28 1997/05/19 10:43:28 pk Exp $ */
/*-
*/
(*minphys)(bp);
todo = bp->b_bcount;
-#ifdef DIAGNOSTIC
- if (todo < 0)
- panic("todo < 0; minphys broken");
- if (todo > MAXPHYS)
- panic("todo > MAXPHYS; minphys broken");
-#endif
+ KASSERTMSG(todo >= 0, "minphys broken");
+ KASSERTMSG(todo <= MAXPHYS, "minphys broken");
/*
* [lock the part of the user address space involved
* of data to transfer]
*/
done = bp->b_bcount - bp->b_resid;
-#ifdef DIAGNOSTIC
- if (done < 0)
- panic("done < 0; strategy broken");
- if (done > todo)
- panic("done > todo; strategy broken");
-#endif
+ KASSERTMSG(done >= 0, "strategy broken");
+ KASSERTMSG(done <= todo, "strategy broken");
iovp->iov_len -= done;
iovp->iov_base = (caddr_t)iovp->iov_base + done;
uio->uio_offset += done;
-/* $OpenBSD: subr_prf.c,v 1.82 2014/07/11 14:36:44 uebayasi Exp $ */
+/* $OpenBSD: subr_prf.c,v 1.83 2014/07/13 23:49:40 uebayasi Exp $ */
/* $NetBSD: subr_prf.c,v 1.45 1997/10/24 18:14:25 chuck Exp $ */
/*-
__assert(const char *t, const char *f, int l, const char *e)
{
- panic("kernel %sassertion \"%s\" failed: file \"%s\", line %d",
- t, e, f, l);
+ panic(__KASSERTSTR, t, e, f, l);
}
/*
-/* $OpenBSD: libkern.h,v 1.33 2014/06/10 04:16:57 deraadt Exp $ */
+/* $OpenBSD: libkern.h,v 1.34 2014/07/13 23:49:40 uebayasi Exp $ */
/* $NetBSD: libkern.h,v 1.7 1996/03/14 18:52:08 christos Exp $ */
/*-
#endif
#endif
+#define __KASSERTSTR "kernel %sassertion \"%s\" failed: file \"%s\", line %d"
+
#ifndef DIAGNOSTIC
+#define KASSERTMSG(e, msg, ...) ((void)0)
#define KASSERT(e) ((void)0)
#else
#ifdef __STDC__
+#define KASSERTMSG(e, msg, ...) ((e) ? (void)0 : \
+ panic(__KASSERTSTR " " msg, "diagnostic ", #e, \
+ __FILE__, __LINE__, ## __VA_ARGS__))
#define KASSERT(e) ((e) ? (void)0 : \
__assert("diagnostic ", __FILE__, __LINE__, #e))
#else
+#define KASSERTMSG(e, msg, ...) ((e) ? (void)0 : \
+ panic(__KASSERTSTR " " msg, "diagnostic ", "e", \
+ __FILE__, __LINE__, ## __VA_ARGS__))
#define KASSERT(e) ((e) ? (void)0 : \
__assert("diagnostic ", __FILE__, __LINE__, "e"))
#endif
#endif
#ifndef DEBUG
+#define KDASSERTMSG(e, msg, ...) ((void)0)
#define KDASSERT(e) ((void)0)
#else
#ifdef __STDC__
+#define KDASSERTMSG(e, msg, ...) ((e) ? (void)0 : \
+ panic(__KASSERTSTR " " msg, "debugging ", #e, \
+ __FILE__, __LINE__, ## __VA_ARGS__))
#define KDASSERT(e) ((e) ? (void)0 : \
__assert("debugging ", __FILE__, __LINE__, #e))
#else
+#define KDASSERTMSG(e, msg, ...) ((e) ? (void)0 : \
+ panic(__KASSERTSTR " " msg, "debugging ", "e", \
+ __FILE__, __LINE__, ## __VA_ARGS__))
#define KDASSERT(e) ((e) ? (void)0 : \
__assert("debugging ", __FILE__, __LINE__, "e"))
#endif