10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*5891Sraf * Common Development and Distribution License (the "License"). 6*5891Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*5891Sraf 220Sstevel@tonic-gate /* 23*5891Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _MISC_H 280Sstevel@tonic-gate #define _MISC_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/time.h> 340Sstevel@tonic-gate #include <thread.h> 35*5891Sraf #include <pthread.h> 360Sstevel@tonic-gate #include <stdarg.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #ifdef __cplusplus 390Sstevel@tonic-gate extern "C" { 400Sstevel@tonic-gate #endif 410Sstevel@tonic-gate 420Sstevel@tonic-gate extern uint_t umem_abort; /* abort when errors occur */ 430Sstevel@tonic-gate extern uint_t umem_output; /* output error messages to stderr */ 440Sstevel@tonic-gate extern caddr_t umem_min_stack; /* max stack address for audit log */ 450Sstevel@tonic-gate extern caddr_t umem_max_stack; /* min stack address for audit log */ 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* 480Sstevel@tonic-gate * various utility functions 490Sstevel@tonic-gate * These are globally implemented. 500Sstevel@tonic-gate */ 510Sstevel@tonic-gate 520Sstevel@tonic-gate #undef offsetof 530Sstevel@tonic-gate #define offsetof(s, m) ((size_t)(&(((s *)0)->m))) 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* 560Sstevel@tonic-gate * a safe printf -- do not use for error messages. 570Sstevel@tonic-gate */ 580Sstevel@tonic-gate void debug_printf(const char *format, ...); 590Sstevel@tonic-gate 600Sstevel@tonic-gate /* 610Sstevel@tonic-gate * adds a message to the log without writing it out. 620Sstevel@tonic-gate */ 630Sstevel@tonic-gate void log_message(const char *format, ...); 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* 660Sstevel@tonic-gate * returns the index of the (high/low) bit + 1 670Sstevel@tonic-gate */ 680Sstevel@tonic-gate int highbit(ulong_t); 690Sstevel@tonic-gate int lowbit(ulong_t); 700Sstevel@tonic-gate #pragma no_side_effect(highbit, lowbit) 710Sstevel@tonic-gate 720Sstevel@tonic-gate /* 730Sstevel@tonic-gate * Converts a hrtime_t to a timestruc_t 740Sstevel@tonic-gate */ 750Sstevel@tonic-gate void hrt2ts(hrtime_t hrt, timestruc_t *tsp); 760Sstevel@tonic-gate 770Sstevel@tonic-gate /* 780Sstevel@tonic-gate * tries to print out the symbol and offset of a pointer using umem_error_info 790Sstevel@tonic-gate */ 800Sstevel@tonic-gate int print_sym(void *pointer); 810Sstevel@tonic-gate 820Sstevel@tonic-gate /* 830Sstevel@tonic-gate * Information about the current error. Can be called multiple times, should 840Sstevel@tonic-gate * be followed eventually with a call to umem_err or umem_err_recoverable. 850Sstevel@tonic-gate */ 860Sstevel@tonic-gate void umem_printf(const char *format, ...); 870Sstevel@tonic-gate void umem_vprintf(const char *format, va_list); 880Sstevel@tonic-gate 890Sstevel@tonic-gate void umem_printf_warn(void *ignored, const char *format, ...); 900Sstevel@tonic-gate 910Sstevel@tonic-gate void umem_error_enter(const char *); 920Sstevel@tonic-gate 930Sstevel@tonic-gate /* 940Sstevel@tonic-gate * prints error message and stack trace, then aborts. Cannot return. 950Sstevel@tonic-gate */ 960Sstevel@tonic-gate void umem_panic(const char *format, ...) __NORETURN; 970Sstevel@tonic-gate #pragma does_not_return(umem_panic) 980Sstevel@tonic-gate #pragma rarely_called(umem_panic) 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* 1010Sstevel@tonic-gate * like umem_err, but only aborts if umem_abort > 0 1020Sstevel@tonic-gate */ 1030Sstevel@tonic-gate void umem_err_recoverable(const char *format, ...); 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate /* 1060Sstevel@tonic-gate * We define our own assertion handling since libc's assert() calls malloc() 1070Sstevel@tonic-gate */ 1080Sstevel@tonic-gate #ifdef NDEBUG 1090Sstevel@tonic-gate #define ASSERT(assertion) (void)0 1100Sstevel@tonic-gate #else 1110Sstevel@tonic-gate #define ASSERT(assertion) (void)((assertion) || \ 1120Sstevel@tonic-gate __umem_assert_failed(#assertion, __FILE__, __LINE__)) 1130Sstevel@tonic-gate #endif 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate int __umem_assert_failed(const char *assertion, const char *file, int line); 1160Sstevel@tonic-gate #pragma does_not_return(__umem_assert_failed) 1170Sstevel@tonic-gate #pragma rarely_called(__umem_assert_failed) 1180Sstevel@tonic-gate /* 1190Sstevel@tonic-gate * These have architecture-specific implementations. 1200Sstevel@tonic-gate */ 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate /* 1230Sstevel@tonic-gate * Returns the current function's frame pointer. 1240Sstevel@tonic-gate */ 1250Sstevel@tonic-gate extern void *getfp(void); 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate /* 1280Sstevel@tonic-gate * puts a pc-only stack trace of up to pcstack_limit frames into pcstack. 1290Sstevel@tonic-gate * Returns the number of stacks written. 1300Sstevel@tonic-gate * 1310Sstevel@tonic-gate * if check_sighandler != 0, and we are in a signal context, calls 1320Sstevel@tonic-gate * umem_err_recoverable. 1330Sstevel@tonic-gate */ 1340Sstevel@tonic-gate extern int getpcstack(uintptr_t *pcstack, int pcstack_limit, 1350Sstevel@tonic-gate int check_sighandler); 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate #ifdef __cplusplus 1380Sstevel@tonic-gate } 1390Sstevel@tonic-gate #endif 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate #endif /* _MISC_H */ 142