4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Failure routines for libumem (not standalone)
31 #include <sys/types.h>
38 static volatile int umem_exiting
= 0;
39 #define UMEM_EXIT_ABORT 1
41 static mutex_t umem_exit_lock
= DEFAULTMUTEX
; /* protects umem_exiting */
49 (void) mutex_lock(&umem_exit_lock
);
51 (void) mutex_unlock(&umem_exit_lock
);
55 (void) mutex_unlock(&umem_exit_lock
);
61 * We can't use abort(3C), since it closes all of the standard library
62 * FILEs, which can call free().
64 * In addition, we can't just raise(SIGABRT), since the current handler
65 * might do allocation. We give them once chance, though.
67 static void __NORETURN
70 if (firstexit(UMEM_EXIT_ABORT
))
71 (void) raise(SIGABRT
);
74 (void) signal(SIGABRT
, SIG_DFL
);
75 (void) sigrelse(SIGABRT
);
76 (void) raise(SIGABRT
);
80 #define SKIP_FRAMES 1 /* skip the panic frame */
81 #define ERR_STACK_FRAMES 128
84 print_stacktrace(void)
86 uintptr_t cur_stack
[ERR_STACK_FRAMES
];
89 * if we are in a signal context, checking for it will recurse
91 uint_t nframes
= getpcstack(cur_stack
, ERR_STACK_FRAMES
, 0);
94 if (nframes
> SKIP_FRAMES
) {
95 umem_printf("stack trace:\n");
97 for (idx
= SKIP_FRAMES
; idx
< nframes
; idx
++) {
98 (void) print_sym((void *)cur_stack
[idx
]);
105 umem_panic(const char *format
, ...)
109 va_start(va
, format
);
110 umem_vprintf(format
, va
);
113 if (format
[strlen(format
)-1] != '\n')
114 umem_error_enter("\n");
122 umem_err_recoverable(const char *format
, ...)
126 va_start(va
, format
);
127 umem_vprintf(format
, va
);
130 if (format
[strlen(format
)-1] != '\n')
131 umem_error_enter("\n");
140 __umem_assert_failed(const char *assertion
, const char *file
, int line
)
142 umem_panic("Assertion failed: %s, file %s, line %d\n",
143 assertion
, file
, line
);