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
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.
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]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 * Portions Copyright 2006 OmniTI, Inc.
30 /* #pragma ident "@(#)umem_fail.c 1.4 05/06/08 SMI" */
33 * Failure routines for libumem (not standalone)
37 #include <sys/types.h>
45 static volatile int umem_exiting = 0;
46 #define UMEM_EXIT_ABORT 1
48 static mutex_t umem_exit_lock = DEFAULTMUTEX; /* protects umem_exiting */
56 (void) mutex_lock(&umem_exit_lock);
58 (void) mutex_unlock(&umem_exit_lock);
62 (void) mutex_unlock(&umem_exit_lock);
68 * We can't use abort(3C), since it closes all of the standard library
69 * FILEs, which can call free().
71 * In addition, we can't just raise(SIGABRT), since the current handler
72 * might do allocation. We give them once chance, though.
74 static void __NORETURN
80 if (firstexit(UMEM_EXIT_ABORT)) {
81 (void) raise(SIGABRT);
85 #if defined(__FreeBSD__)
89 sa.sa_handler = SIG_DFL;
90 (void) sigaction(SIGABRT, &sa, NULL);
91 (void) sigemptyset (&set);
92 (void) sigaddset (&set, SIGABRT);
93 (void) sigprocmask (SIG_UNBLOCK, &set, NULL);
94 (void) raise (SIGABRT);
96 (void) signal(SIGABRT, SIG_DFL);
97 (void) sigrelse(SIGABRT);
98 (void) raise(SIGABRT);
104 #define SKIP_FRAMES 1 /* skip the panic frame */
105 #define ERR_STACK_FRAMES 128
108 print_stacktrace(void)
110 uintptr_t cur_stack[ERR_STACK_FRAMES];
113 * if we are in a signal context, checking for it will recurse
115 uint_t nframes = getpcstack(cur_stack, ERR_STACK_FRAMES, 0);
118 if (nframes > SKIP_FRAMES) {
119 umem_printf("stack trace:\n");
121 for (idx = SKIP_FRAMES; idx < nframes; idx++) {
122 (void) print_sym((void *)cur_stack[idx]);
129 umem_panic(const char *format, ...)
133 va_start(va, format);
134 umem_vprintf(format, va);
137 if (format[strlen(format)-1] != '\n')
138 umem_error_enter("\n");
141 va_start(va, format);
142 ec_debug_vprintf(DCRITICAL, DMEM, format, va);
152 umem_err_recoverable(const char *format, ...)
156 va_start(va, format);
157 umem_vprintf(format, va);
160 if (format[strlen(format)-1] != '\n')
161 umem_error_enter("\n");
170 __umem_assert_failed(const char *assertion, const char *file, int line)
172 umem_panic("Assertion failed: %s, file %s, line %d\n",
173 assertion, file, line);