summaryrefslogtreecommitdiffstats
path: root/sys/lib/libkern/libkern.h
diff options
context:
space:
mode:
authoruebayasi <uebayasi@openbsd.org>2014-07-13 23:49:40 +0000
committeruebayasi <uebayasi@openbsd.org>2014-07-13 23:49:40 +0000
commita972b4a4eb1466195f36d2e762d5d43d5e152e6c (patch)
tree22e17e4064f54adc8445ba74e5b28bc38feec087 /sys/lib/libkern/libkern.h
parentAdd stubs for the proposed server API. (diff)
downloadwireguard-openbsd-a972b4a4eb1466195f36d2e762d5d43d5e152e6c.tar.xz
wireguard-openbsd-a972b4a4eb1466195f36d2e762d5d43d5e152e6c.zip
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@
Diffstat (limited to 'sys/lib/libkern/libkern.h')
-rw-r--r--sys/lib/libkern/libkern.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/sys/lib/libkern/libkern.h b/sys/lib/libkern/libkern.h
index 4e53f92fbc2..d743920ea0b 100644
--- a/sys/lib/libkern/libkern.h
+++ b/sys/lib/libkern/libkern.h
@@ -1,4 +1,4 @@
-/* $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 $ */
/*-
@@ -114,25 +114,41 @@ abs(int j)
#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