|
|
1.1 root 1: #define _DDI_DKI 1
2: #define _SYSV4 1
3:
4: /*
5: * This file contains the definition for the kernel assertion helper function
6: * __assert_fail (), and a manual page for ASSERT ().
7: */
8:
9: /*
10: *-IMPORTS:
11: * <common/ccompat.h>
12: * __USE_PROTO__
13: * __ARGS ()
14: * <sys/cmn_err.h>
15: * CE_PANIC
16: * cmn_err ()
17: */
18:
19: #include <common/ccompat.h>
20: #include <sys/cmn_err.h>
21: #include <stddef.h>
22:
23: #include <sys/debug.h>
24:
25:
26: /*
27: *-STATUS:
28: * DDI/DKI.
29: *
30: *-NAME:
31: * ASSERT () Verify assertion.
32: *
33: *-SYNOPSIS:
34: * #include <sys/debug.h>
35: *
36: * void ASSERT (int expression);
37: *
38: *-ARGUMENTS:
39: * expression Expression to be evaluated.
40: *
41: *-DESCRIPTION:
42: * ASSERT () is a debugging interface for verifying program invariants
43: * within code that is compiled with the DEBUG compilation option
44: * defined. "expression" is a boolean expression that the caller expects
45: * to evaluate to non-zero (that is, the caller is asserting that the
46: * expression has a non-zero value). If "expression" evaluates to non-
47: * zero, the ASSERT () call has no effect. If "expression" evaluates to
48: * zero, ASSERT () causes the system to panic with a message identifying
49: * the expression, the name of the source file containing the assertion,
50: * and the line number within the source file where the assertion is
51: * made.
52: *
53: * When the DEBUG compilation option is not defined, ASSERT () calls are
54: * not compiled into the code, and therefore have no effect.
55: *
56: *-RETURN VALUE:
57: * If "expression" evaluates to non-zero, ASSERT () returns no value. If
58: * "expression" evaluates to zero, ASSERT () panics the system.
59: *
60: *-LEVEL:
61: * Base or interrupt.
62: *
63: *-NOTES:
64: * Does not sleep.
65: *
66: * Driver-defined basic locks, read/write locks and sleep locks may be
67: * held across calls to this function.
68: *
69: *-SEE ALSO:
70: * cmn_err ()
71: */
72:
73: /*
74: *-STATUS:
75: * Internal helper for ASSERT ().
76: *
77: *-NAME:
78: * __assert_fail () Report an assertion failure.
79: *
80: *-ARGUMENTS:
81: * exp The text of the source code for the expression that ASSERT ()
82: * evaluated and found to be false.
83: *
84: *-DESCRIPTION:
85: * Like assert () in C programs, the ASSERT () macro within the kernel
86: * provides a simple debugging mechanism. It is good software engineering
87: * practice to check even those situations that "cannot happen", at least
88: * during the development phase(s) of a section of code. The assertion
89: * mechanisms provide a simple and inexpensive way of performing those
90: * checks that if they fail indicate some condition that indicates a
91: * bug in some code. Normally, the debugging statements are compiled to
92: * check the assertions, but at the developer's option all calls to the
93: * ASSERT () macro will instead expand to no code.
94: *
95: * When the ASSERT () macro detects that an assertion condition did not
96: * evaluate to a logically true value (which in C is anything non-zero)
97: * then this helper function is called to halt the kernel with an
98: * appropriate error message.
99: *
100: *-RETURNS:
101: * Does not return.
102: *
103: *-LEVEL:
104: * Base or Interrupt.
105: *
106: *-NOTES:
107: * This function calls cmn_err () to panic the kernel on the CPU where
108: * the fault was detected (and to print the assertion failure message).
109: */
110:
111: #if __USE_PROTO__
112: int (__assert_fail) (__CONST__ char * exp)
113: #else
114: int
115: __assert_fail __ARGS ((exp))
116: __CONST__ char * exp;
117: #endif
118: {
119: cmn_err (CE_PANIC, "Assertion \"%s\" failed", exp);
120: return 0;
121: }
122:
123:
124: /*
125: *-STATUS:
126: * Internal helper for ASSERT ().
127: *
128: *-NAME:
129: * __assert_fail2 () Verbose form of __assert_fail ()
130: *
131: *-ARGUMENTS:
132: * exp The text of the source code for the expression that ASSERT ()
133: * evaluated and found to be false.
134: *
135: * info Location information that aids in locating the source code
136: * which failed the assertion. There are various levels of
137: * detail that may be desired; see <common/xdebug.h> for more on
138: * selecting the contents of the __FILE_INFO__ macro.
139: *
140: * lineno Optional line number in the source file.
141: *
142: *-DESCRIPTION:
143: * Like assert () in C programs, the ASSERT () macro within the kernel
144: * provides a simple debugging mechanism. It is good software engineering
145: * practice to check even those situations that "cannot happen", at least
146: * during the development phase(s) of a section of code. The assertion
147: * mechanisms provide a simple and inexpensive way of performing those
148: * checks that if they fail indicate some condition that indicates a
149: * bug in some code. Normally, the debugging statements are compiled to
150: * check the assertions, but at the developer's option all calls to the
151: * ASSERT () macro will instead expand to no code.
152: *
153: * When the ASSERT () macro detects that an assertion condition did not
154: * evaluate to a logically true value (which in C is anything non-zero)
155: * then this helper function is called to halt the kernel with an
156: * appropriate error message.
157: *
158: *-RETURNS:
159: * Does not return.
160: *
161: *-LEVEL:
162: * Base or Interrupt.
163: *
164: *-NOTES:
165: * This function calls cmn_err () to panic the kernel on the CPU where
166: * the fault was detected (and to print the assertion failure message).
167: */
168:
169: #if __USE_PROTO__
170: int (__assert_fail2) (__CONST__ char * exp, __CONST__ char * info,
171: int lineno)
172: #else
173: int
174: __assert_fail2 __ARGS ((exp, info, lineno))
175: __CONST__ char * exp;
176: __CONST__ char * info;
177: int lineno;
178: #endif
179: {
180: cmn_err (CE_PANIC,
181: lineno == 0 ? "Assertion \"%s\" failed in %s" :
182: "Assertion \"%s\" failed in %s at line %d",
183: exp, info, lineno);
184: return 0;
185: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.