4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Copyright (c) 2012 by Delphix. All rights reserved.
28 * Copyright 2013 Saso Kiselkov. All rights reserved.
31 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
32 /* All Rights Reserved */
37 #include <sys/types.h>
45 * ASSERT(ex) causes a panic or debugger entry if expression ex is not
46 * true. ASSERT() is included only for debugging, and is a no-op in
47 * production kernels. VERIFY(ex), on the other hand, behaves like
48 * ASSERT and is evaluated on both debug and non-debug kernels.
52 extern int assfail(const char *, const char *, int);
53 #define VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
55 #define ASSERT(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
57 #define ASSERT(x) ((void)0)
59 #else /* defined(__STDC__) */
61 #define VERIFY(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__)))
63 #define ASSERT(EX) ((void)((EX) || assfail("EX", __FILE__, __LINE__)))
65 #define ASSERT(x) ((void)0)
67 #endif /* defined(__STDC__) */
70 * Assertion variants sensitive to the compilation data model
73 #define ASSERT64(x) ASSERT(x)
77 #define ASSERT32(x) ASSERT(x)
81 * IMPLY and EQUIV are assertions of the form:
85 * if (a) then (b) *AND* if (b) then (a)
89 ((void)(((!(A)) || (B)) || \
90 assfail("(" #A ") implies (" #B ")", __FILE__, __LINE__)))
92 ((void)((!!(A) == !!(B)) || \
93 assfail("(" #A ") is equivalent to (" #B ")", __FILE__, __LINE__)))
95 #define IMPLY(A, B) ((void)0)
96 #define EQUIV(A, B) ((void)0)
100 * ASSERT3() behaves like ASSERT() except that it is an explicit conditional,
101 * and prints out the values of the left and right hand expressions as part of
102 * the panic message to ease debugging. The three variants imply the type
103 * of their arguments. ASSERT3S() is for signed data types, ASSERT3U() is
104 * for unsigned, and ASSERT3P() is for pointers. The VERIFY3*() macros
105 * have the same relationship as above.
107 extern void assfail3(const char *, uintmax_t, const char *, uintmax_t,
109 #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
110 const TYPE __left = (TYPE)(LEFT); \
111 const TYPE __right = (TYPE)(RIGHT); \
112 if (!(__left OP __right)) \
113 assfail3(#LEFT " " #OP " " #RIGHT, \
114 (uintmax_t)__left, #OP, (uintmax_t)__right, \
115 __FILE__, __LINE__); \
116 _NOTE(CONSTCOND) } while (0)
118 #define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t)
119 #define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t)
120 #define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t)
121 #define VERIFY0(x) VERIFY3_IMPL(x, ==, 0, uintmax_t)
124 #define ASSERT3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t)
125 #define ASSERT3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t)
126 #define ASSERT3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t)
127 #define ASSERT0(x) VERIFY3_IMPL(x, ==, 0, uintmax_t)
129 #define ASSERT3S(x, y, z) ((void)0)
130 #define ASSERT3U(x, y, z) ((void)0)
131 #define ASSERT3P(x, y, z) ((void)0)
132 #define ASSERT0(x) ((void)0)
136 * Compile-time assertion. The condition 'x' must be constant.
139 #define CTASSERT(x) _CTASSERT(x, __LINE__)
140 #define _CTASSERT(x, y) __CTASSERT(x, y)
141 #define __CTASSERT(x, y) \
142 typedef char __compile_time_assertion__ ## y [(x) ? 1 : -1]
147 extern void abort_sequence_enter(char *);
148 extern void debug_enter(char *);
152 #if defined(DEBUG) && !defined(__sun)
157 #define STATIC static
164 #endif /* _SYS_DEBUG_H */