xref: /illumos-gate/usr/src/lib/libumem/common/misc.h (revision fcdb3229a31dd4ff700c69238814e326aad49098)
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 #include <stddef.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  * a safe printf  -- do not use for error messages.
48  */
49 void debug_printf(const char *format, ...);
50 
51 /*
52  * adds a message to the log without writing it out.
53  */
54 void log_message(const char *format, ...);
55 
56 /*
57  * returns the index of the (high/low) bit + 1
58  */
59 int highbit(ulong_t);
60 int lowbit(ulong_t);
61 
62 /*
63  * Converts a hrtime_t to a timestruc_t
64  */
65 void hrt2ts(hrtime_t hrt, timestruc_t *tsp);
66 
67 /*
68  * tries to print out the symbol and offset of a pointer using umem_error_info
69  */
70 int print_sym(void *pointer);
71 
72 /*
73  * Information about the current error.  Can be called multiple times, should
74  * be followed eventually with a call to umem_err or umem_err_recoverable.
75  */
76 void umem_printf(const char *format, ...);
77 void umem_vprintf(const char *format, va_list);
78 
79 void umem_printf_warn(void *ignored, const char *format, ...);
80 
81 void umem_error_enter(const char *);
82 
83 /*
84  * prints error message and stack trace, then aborts.  Cannot return.
85  */
86 void umem_panic(const char *format, ...) __NORETURN;
87 
88 /*
89  * like umem_err, but only aborts if umem_abort > 0
90  */
91 void umem_err_recoverable(const char *format, ...);
92 
93 /*
94  * We define our own assertion handling since libc's assert() calls malloc()
95  */
96 #ifdef NDEBUG
97 #define	ASSERT(assertion) (void)0
98 #else
99 #define	ASSERT(assertion) (void)((assertion) || \
100     __umem_assert_failed(#assertion, __FILE__, __LINE__))
101 #endif
102 
103 int __umem_assert_failed(const char *assertion, const char *file, int line);
104 /*
105  * These have architecture-specific implementations.
106  */
107 
108 /*
109  * Returns the current function's frame pointer.
110  */
111 extern void *getfp(void);
112 
113 /*
114  * puts a pc-only stack trace of up to pcstack_limit frames into pcstack.
115  * Returns the number of stacks written.
116  *
117  * if check_sighandler != 0, and we are in a signal context, calls
118  * umem_err_recoverable.
119  */
120 extern int getpcstack(uintptr_t *pcstack, int pcstack_limit,
121     int check_sighandler);
122 
123 #ifdef	__cplusplus
124 }
125 #endif
126 
127 #endif /* _MISC_H */
128