|
|
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: void (__assert_fail) (__CONST__ char * exp) ! 113: #else ! 114: void ! 115: __assert_fail __ARGS ((exp)) ! 116: __CONST__ char * exp; ! 117: #endif ! 118: { ! 119: cmn_err (CE_PANIC, "Assertion \"%s\" failed", exp); ! 120: } ! 121: ! 122: ! 123: /* ! 124: *-STATUS: ! 125: * Internal helper for ASSERT (). ! 126: * ! 127: *-NAME: ! 128: * __assert_fail2 () Verbose form of __assert_fail () ! 129: * ! 130: *-ARGUMENTS: ! 131: * exp The text of the source code for the expression that ASSERT () ! 132: * evaluated and found to be false. ! 133: * ! 134: * info Location information that aids in locating the source code ! 135: * which failed the assertion. There are various levels of ! 136: * detail that may be desired; see <common/xdebug.h> for more on ! 137: * selecting the contents of the __FILE_INFO__ macro. ! 138: * ! 139: * lineno Optional line number in the source file. ! 140: * ! 141: *-DESCRIPTION: ! 142: * Like assert () in C programs, the ASSERT () macro within the kernel ! 143: * provides a simple debugging mechanism. It is good software engineering ! 144: * practice to check even those situations that "cannot happen", at least ! 145: * during the development phase(s) of a section of code. The assertion ! 146: * mechanisms provide a simple and inexpensive way of performing those ! 147: * checks that if they fail indicate some condition that indicates a ! 148: * bug in some code. Normally, the debugging statements are compiled to ! 149: * check the assertions, but at the developer's option all calls to the ! 150: * ASSERT () macro will instead expand to no code. ! 151: * ! 152: * When the ASSERT () macro detects that an assertion condition did not ! 153: * evaluate to a logically true value (which in C is anything non-zero) ! 154: * then this helper function is called to halt the kernel with an ! 155: * appropriate error message. ! 156: * ! 157: *-RETURNS: ! 158: * Does not return. ! 159: * ! 160: *-LEVEL: ! 161: * Base or Interrupt. ! 162: * ! 163: *-NOTES: ! 164: * This function calls cmn_err () to panic the kernel on the CPU where ! 165: * the fault was detected (and to print the assertion failure message). ! 166: */ ! 167: ! 168: #if __USE_PROTO__ ! 169: void (__assert_fail2) (__CONST__ char * exp, __CONST__ char * info, ! 170: int lineno) ! 171: #else ! 172: void ! 173: __assert_fail2 __ARGS ((exp, info, lineno)) ! 174: __CONST__ char * exp; ! 175: __CONST__ char * info; ! 176: int lineno; ! 177: #endif ! 178: { ! 179: cmn_err (CE_PANIC, ! 180: lineno == 0 ? "Assertion \"%s\" failed in %s" : ! 181: "Assertion \"%s\" failed in %s at line %d", ! 182: exp, info, lineno); ! 183: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.