umem 1.0.1
misc.h
Go to the documentation of this file.
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-2008 Message Systems, 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
48extern "C" {
49#endif
50
51extern uint_t umem_abort; /* abort when errors occur */
52extern uint_t umem_output; /* output error messages to stderr */
53extern caddr_t umem_min_stack; /* max stack address for audit log */
54extern 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 */
67void debug_printf(const char *format, ...);
68
69/*
70 * adds a message to the log without writing it out.
71 */
72void log_message(const char *format, ...);
73
74/*
75 * returns the index of the (high/low) bit + 1
76 */
77int highbit(ulong_t) __attribute__ ((pure));
78int lowbit(ulong_t) __attribute__ ((pure));
79/* #pragma no_side_effect(highbit, lowbit) */
80
81/*
82 * Converts a hrtime_t to a timestruc_t
83 */
84void 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 */
89int 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 */
95void umem_printf(const char *format, ...);
96void umem_vprintf(const char *format, va_list);
97
98void umem_printf_warn(void *ignored, const char *format, ...);
99
100void umem_error_enter(const char *);
101
102/*
103 * prints error message and stack trace, then aborts. Cannot return.
104 */
105void 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 */
112void 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
124int __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 */
134extern 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 */
143extern int getpcstack(uintptr_t *pcstack, int pcstack_limit,
144 int check_sighandler);
145
146#ifdef __cplusplus
147}
148#endif
149
150#endif /* _MISC_H */
void __attribute__((constructor))
Definition malloc.c:459
void debug_printf(const char *format,...)
Definition misc.c:212
void umem_panic(const char *format,...) __attribute__((noreturn))
Definition umem_fail.c:129
int __umem_assert_failed(const char *assertion, const char *file, int line) __attribute__((noreturn))
Definition umem_fail.c:170
void umem_printf(const char *format,...)
Definition misc.c:237
int highbit(ulong_t) __attribute__((pure))
Definition misc.c:125
void umem_printf_warn(void *ignored, const char *format,...)
Definition misc.c:248
void umem_error_enter(const char *)
Definition misc.c:114
uint_t umem_abort
Definition umem.c:467
void umem_err_recoverable(const char *format,...)
Definition umem_fail.c:152
caddr_t umem_max_stack
Definition umem.c:625
uint_t umem_output
Definition umem.c:468
void log_message(const char *format,...)
Definition misc.c:192
int print_sym(void *pointer)
Definition misc.c:261
int lowbit(ulong_t) __attribute__((pure))
Definition misc.c:155
caddr_t umem_min_stack
Definition umem.c:624
int getpcstack(uintptr_t *pcstack, int pcstack_limit, int check_sighandler)
Definition getpcstack.c:75
void umem_vprintf(const char *format, va_list)
Definition misc.c:227
void * getfp(void)
void hrt2ts(hrtime_t hrt, timestruc_t *tsp)
Definition misc.c:185
uint32_t uint_t
Definition sol_compat.h:48
u_int64_t hrtime_t
Definition sol_compat.h:47
unsigned long ulong_t
Definition sol_compat.h:49
struct timespec timestruc_t
Definition sol_compat.h:50