misc.h

Go to the documentation of this file.
00001 /*
00002  * CDDL HEADER START
00003  *
00004  * The contents of this file are subject to the terms of the
00005  * Common Development and Distribution License, Version 1.0 only
00006  * (the "License").  You may not use this file except in compliance
00007  * with the License.
00008  *
00009  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
00010  * or http://www.opensolaris.org/os/licensing.
00011  * See the License for the specific language governing permissions
00012  * and limitations under the License.
00013  *
00014  * When distributing Covered Code, include this CDDL HEADER in each
00015  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
00016  * If applicable, add the following below this CDDL HEADER, with the
00017  * fields enclosed by brackets "[]" replaced with your own identifying
00018  * information: Portions Copyright [yyyy] [name of copyright owner]
00019  *
00020  * CDDL HEADER END
00021  */
00022 /*
00023  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
00024  * Use is subject to license terms.
00025  */
00026 /*
00027  * Portions Copyright 2006 OmniTI, Inc.
00028  */
00029 
00030 #ifndef _MISC_H
00031 #define _MISC_H
00032 
00033 /* #pragma ident        "@(#)misc.h     1.6     05/06/08 SMI" */
00034 
00035 #include "config.h"
00036 #include <sys/types.h>
00037 #ifndef _WIN32
00038 #include <sys/time.h>
00039 #endif
00040 #ifdef HAVE_THREAD_H
00041 # include <thread.h>
00042 #else
00043 # include "sol_compat.h"
00044 #endif
00045 #include <stdarg.h>
00046 
00047 #ifdef  __cplusplus
00048 extern "C" {
00049 #endif
00050 
00051 extern uint_t umem_abort;               /* abort when errors occur */
00052 extern uint_t umem_output;              /* output error messages to stderr */
00053 extern caddr_t umem_min_stack;          /* max stack address for audit log */
00054 extern caddr_t umem_max_stack;          /* min stack address for audit log */
00055 
00056 /*
00057  * various utility functions
00058  * These are globally implemented.
00059  */
00060 
00061 #undef  offsetof
00062 #define offsetof(s, m)  ((size_t)(&(((s *)0)->m)))
00063 
00064 /*
00065  * a safe printf  -- do not use for error messages.
00066  */
00067 void debug_printf(const char *format, ...);
00068 
00069 /*
00070  * adds a message to the log without writing it out.
00071  */
00072 void log_message(const char *format, ...);
00073 
00074 /*
00075  * returns the index of the (high/low) bit + 1
00076  */
00077 int highbit(ulong_t) __attribute__ ((pure));
00078 int lowbit(ulong_t) __attribute__ ((pure));
00079 /* #pragma no_side_effect(highbit, lowbit) */
00080 
00081 /*
00082  * Converts a hrtime_t to a timestruc_t
00083  */
00084 void hrt2ts(hrtime_t hrt, timestruc_t *tsp);
00085 
00086 /*
00087  * tries to print out the symbol and offset of a pointer using umem_error_info
00088  */
00089 int print_sym(void *pointer);
00090 
00091 /*
00092  * Information about the current error.  Can be called multiple times, should
00093  * be followed eventually with a call to umem_err or umem_err_recoverable.
00094  */
00095 void umem_printf(const char *format, ...);
00096 void umem_vprintf(const char *format, va_list);
00097 
00098 void umem_printf_warn(void *ignored, const char *format, ...);
00099 
00100 void umem_error_enter(const char *);
00101 
00102 /*
00103  * prints error message and stack trace, then aborts.  Cannot return.
00104  */
00105 void umem_panic(const char *format, ...) __attribute__((noreturn));
00106 /* #pragma does_not_return(umem_panic) */
00107 /* #pragma rarely_called(umem_panic) */
00108 
00109 /*
00110  * like umem_err, but only aborts if umem_abort > 0
00111  */
00112 void umem_err_recoverable(const char *format, ...);
00113 
00114 /*
00115  * We define our own assertion handling since libc's assert() calls malloc()
00116  */
00117 #ifdef NDEBUG
00118 #define ASSERT(assertion) (void)0
00119 #else
00120 #define ASSERT(assertion) (void)((assertion) || \
00121     __umem_assert_failed(#assertion, __FILE__, __LINE__))
00122 #endif
00123 
00124 int __umem_assert_failed(const char *assertion, const char *file, int line) __attribute__ ((noreturn));
00125 /* #pragma does_not_return(__umem_assert_failed) */
00126 /* #pragma rarely_called(__umem_assert_failed) */
00127 /*
00128  * These have architecture-specific implementations.
00129  */
00130 
00131 /*
00132  * Returns the current function's frame pointer.
00133  */
00134 extern void *getfp(void);
00135 
00136 /*
00137  * puts a pc-only stack trace of up to pcstack_limit frames into pcstack.
00138  * Returns the number of stacks written.
00139  *
00140  * if check_sighandler != 0, and we are in a signal context, calls
00141  * umem_err_recoverable.
00142  */
00143 extern int getpcstack(uintptr_t *pcstack, int pcstack_limit,
00144     int check_sighandler);
00145 
00146 #ifdef  __cplusplus
00147 }
00148 #endif
00149 
00150 #endif /* _MISC_H */

Generated on Thu Feb 7 05:40:23 2008 for umem by  doxygen 1.5.4