1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _MISC_H 28 #define _MISC_H 29 30 #include <sys/types.h> 31 #include <sys/time.h> 32 #include <thread.h> 33 #include <pthread.h> 34 #include <stdarg.h> 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 extern uint_t umem_abort; /* abort when errors occur */ 41 extern uint_t umem_output; /* output error messages to stderr */ 42 extern caddr_t umem_min_stack; /* max stack address for audit log */ 43 extern caddr_t umem_max_stack; /* min stack address for audit log */ 44 45 /* 46 * various utility functions 47 * These are globally implemented. 48 */ 49 50 #undef offsetof 51 #if defined(__GNUC__) 52 #define offsetof(s, m) __builtin_offsetof(s, m) 53 #else 54 #define offsetof(s, m) ((size_t)(&(((s *)0)->m))) 55 #endif 56 57 /* 58 * a safe printf -- do not use for error messages. 59 */ 60 void debug_printf(const char *format, ...); 61 62 /* 63 * adds a message to the log without writing it out. 64 */ 65 void log_message(const char *format, ...); 66 67 /* 68 * returns the index of the (high/low) bit + 1 69 */ 70 int highbit(ulong_t); 71 int lowbit(ulong_t); 72 #pragma no_side_effect(highbit, lowbit) 73 74 /* 75 * Converts a hrtime_t to a timestruc_t 76 */ 77 void hrt2ts(hrtime_t hrt, timestruc_t *tsp); 78 79 /* 80 * tries to print out the symbol and offset of a pointer using umem_error_info 81 */ 82 int print_sym(void *pointer); 83 84 /* 85 * Information about the current error. Can be called multiple times, should 86 * be followed eventually with a call to umem_err or umem_err_recoverable. 87 */ 88 void umem_printf(const char *format, ...); 89 void umem_vprintf(const char *format, va_list); 90 91 void umem_printf_warn(void *ignored, const char *format, ...); 92 93 void umem_error_enter(const char *); 94 95 /* 96 * prints error message and stack trace, then aborts. Cannot return. 97 */ 98 void umem_panic(const char *format, ...) __NORETURN; 99 #pragma does_not_return(umem_panic) 100 #pragma rarely_called(umem_panic) 101 102 /* 103 * like umem_err, but only aborts if umem_abort > 0 104 */ 105 void umem_err_recoverable(const char *format, ...); 106 107 /* 108 * We define our own assertion handling since libc's assert() calls malloc() 109 */ 110 #ifdef NDEBUG 111 #define ASSERT(assertion) (void)0 112 #else 113 #define ASSERT(assertion) (void)((assertion) || \ 114 __umem_assert_failed(#assertion, __FILE__, __LINE__)) 115 #endif 116 117 int __umem_assert_failed(const char *assertion, const char *file, int line); 118 #pragma does_not_return(__umem_assert_failed) 119 #pragma rarely_called(__umem_assert_failed) 120 /* 121 * These have architecture-specific implementations. 122 */ 123 124 /* 125 * Returns the current function's frame pointer. 126 */ 127 extern void *getfp(void); 128 129 /* 130 * puts a pc-only stack trace of up to pcstack_limit frames into pcstack. 131 * Returns the number of stacks written. 132 * 133 * if check_sighandler != 0, and we are in a signal context, calls 134 * umem_err_recoverable. 135 */ 136 extern int getpcstack(uintptr_t *pcstack, int pcstack_limit, 137 int check_sighandler); 138 139 #ifdef __cplusplus 140 } 141 #endif 142 143 #endif /* _MISC_H */