aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2025-01-13 00:41:25 +0000
committerKyle Evans <kevans@FreeBSD.org>2025-01-13 00:41:37 +0000
commit712f81feea416e9f8aaf040173883876a50a7d34 (patch)
treeed67a41735d2d1a72a8d265fb5289fdcea351d1f
parentdf48361e7792f9a9e6371f95c1228d4af2808d2a (diff)
include: add a userland version of __assert_unreachable
The kernel has had a version of this since c79cee71363d ("kernel: provide panicky version of __unreachable"), and userland can benefit from the same. __unreachable is largely inadequate because it's *not* an assertion of any sort, so we're not really alerted to a problem that we could've anticipated. Reviewed by: emaste, imp, jhb, olce Differential Revision: https://reviews.freebsd.org/D48077
-rw-r--r--include/assert.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/include/assert.h b/include/assert.h
index cc2a5f8b9e64..a3dbe933e18f 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -43,15 +43,22 @@
#undef assert
#undef _assert
+#undef __assert_unreachable
#ifdef NDEBUG
#define assert(e) ((void)0)
#define _assert(e) ((void)0)
+#if __BSD_VISIBLE
+#define __assert_unreachable() __unreachable()
+#endif /* __BSD_VISIBLE */
#else
#define _assert(e) assert(e)
#define assert(e) ((e) ? (void)0 : __assert(__func__, __FILE__, \
__LINE__, #e))
+#if __BSD_VISIBLE
+#define __assert_unreachable() assert(0 && "unreachable segment reached")
+#endif /* __BSD_VISIBLE */
#endif /* NDEBUG */
#ifndef _ASSERT_H_