xref: /titanic_50/usr/src/lib/libumem/common/misc.h (revision c5c4113dfcabb1eed3d4bdf7609de5170027a794)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/time.h>
34 #include <thread.h>
35 #include <stdarg.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 extern uint_t umem_abort;		/* abort when errors occur */
42 extern uint_t umem_output;		/* output error messages to stderr */
43 extern caddr_t umem_min_stack;		/* max stack address for audit log */
44 extern caddr_t umem_max_stack;		/* min stack address for audit log */
45 
46 /*
47  * various utility functions
48  * These are globally implemented.
49  */
50 
51 #undef	offsetof
52 #define	offsetof(s, m)	((size_t)(&(((s *)0)->m)))
53 
54 /*
55  * a safe printf  -- do not use for error messages.
56  */
57 void debug_printf(const char *format, ...);
58 
59 /*
60  * adds a message to the log without writing it out.
61  */
62 void log_message(const char *format, ...);
63 
64 /*
65  * returns the index of the (high/low) bit + 1
66  */
67 int highbit(ulong_t);
68 int lowbit(ulong_t);
69 #pragma no_side_effect(highbit, lowbit)
70 
71 /*
72  * Converts a hrtime_t to a timestruc_t
73  */
74 void hrt2ts(hrtime_t hrt, timestruc_t *tsp);
75 
76 /*
77  * tries to print out the symbol and offset of a pointer using umem_error_info
78  */
79 int print_sym(void *pointer);
80 
81 /*
82  * Information about the current error.  Can be called multiple times, should
83  * be followed eventually with a call to umem_err or umem_err_recoverable.
84  */
85 void umem_printf(const char *format, ...);
86 void umem_vprintf(const char *format, va_list);
87 
88 void umem_printf_warn(void *ignored, const char *format, ...);
89 
90 void umem_error_enter(const char *);
91 
92 /*
93  * prints error message and stack trace, then aborts.  Cannot return.
94  */
95 void umem_panic(const char *format, ...) __NORETURN;
96 #pragma does_not_return(umem_panic)
97 #pragma rarely_called(umem_panic)
98 
99 /*
100  * like umem_err, but only aborts if umem_abort > 0
101  */
102 void umem_err_recoverable(const char *format, ...);
103 
104 /*
105  * We define our own assertion handling since libc's assert() calls malloc()
106  */
107 #ifdef NDEBUG
108 #define	ASSERT(assertion) (void)0
109 #else
110 #define	ASSERT(assertion) (void)((assertion) || \
111     __umem_assert_failed(#assertion, __FILE__, __LINE__))
112 #endif
113 
114 int __umem_assert_failed(const char *assertion, const char *file, int line);
115 #pragma does_not_return(__umem_assert_failed)
116 #pragma rarely_called(__umem_assert_failed)
117 /*
118  * These have architecture-specific implementations.
119  */
120 
121 /*
122  * Returns the current function's frame pointer.
123  */
124 extern void *getfp(void);
125 
126 /*
127  * puts a pc-only stack trace of up to pcstack_limit frames into pcstack.
128  * Returns the number of stacks written.
129  *
130  * if check_sighandler != 0, and we are in a signal context, calls
131  * umem_err_recoverable.
132  */
133 extern int getpcstack(uintptr_t *pcstack, int pcstack_limit,
134     int check_sighandler);
135 
136 #ifdef	__cplusplus
137 }
138 #endif
139 
140 #endif /* _MISC_H */
141