root/trunk/misc.h

Revision 2, 3.9 kB (checked in by wez, 8 years ago)

Initial revision

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