Print this page
10099 libfakekernel vpanic() should cast away assfail()
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libfakekernel/common/printf.c
+++ new/usr/src/lib/libfakekernel/common/printf.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 24 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
25 25 * Copyright 2017 RackTop Systems.
26 + * Copyright (c) 2018, Joyent, Inc.
26 27 */
27 28
28 29 #include <sys/param.h>
29 30 #include <sys/types.h>
30 31 #include <sys/varargs.h>
31 32 #include <sys/systm.h>
32 33 #include <sys/cmn_err.h>
33 34 #include <sys/log.h>
34 35
35 36 #include <fakekernel.h>
36 37
37 38 void abort(void) __NORETURN;
38 39
39 40 char *volatile panicstr;
40 41 va_list panicargs;
41 42 char panicbuf[512];
42 43
43 44 volatile int aok;
44 45
45 46 static const int
46 47 ce_flags[CE_IGNORE] = { SL_NOTE, SL_NOTE, SL_WARN, SL_FATAL };
47 48 static const char
48 49 ce_prefix[CE_IGNORE][10] = { "", "NOTICE: ", "WARNING: ", "" };
49 50 static const char
50 51 ce_suffix[CE_IGNORE][2] = { "", "\n", "\n", "" };
51 52
52 53
53 54 /*
54 55 * This function is just a stub, exported NODIRECT so that
55 56 * comsumers like fksmbd can provide their own.
56 57 * (One that actually prints the messages.)
57 58 *
58 59 * It's used by fakekernel_cprintf() below.
59 60 * The flags are SL_... from strlog.h
60 61 */
61 62 /* ARGSUSED */
62 63 void
63 64 fakekernel_putlog(char *msg, size_t len, int flags)
64 65 {
65 66 }
66 67
67 68 /*
68 69 * fakekernel_cprintf() corresponds to os/printf.c:cprintf()
69 70 * This formats the message and calls fakekernel_putlog().
70 71 * It's exported NODIRECT to allow replacment.
71 72 * The flags are SL_... from strlog.h
72 73 */
73 74 void
74 75 fakekernel_cprintf(const char *fmt, va_list adx, int flags,
75 76 const char *prefix, const char *suffix)
76 77 {
77 78 size_t bufsize = LOG_MSGSIZE;
78 79 char buf[LOG_MSGSIZE];
79 80 char *bufp = buf;
80 81 char *msgp, *bufend;
81 82 size_t len;
82 83
83 84 if (strchr("^!?", fmt[0]) != NULL) {
84 85 if (fmt[0] == '^')
85 86 flags |= SL_CONSONLY;
86 87 else if (fmt[0] == '!')
87 88 flags |= SL_LOGONLY;
88 89 fmt++;
89 90 }
90 91
91 92 bufend = bufp + bufsize;
92 93 msgp = bufp;
93 94 msgp += snprintf(msgp, bufend - msgp, "[fake_kernel] ");
94 95 msgp += snprintf(msgp, bufend - msgp, prefix);
95 96 msgp += vsnprintf(msgp, bufend - msgp, fmt, adx);
96 97 msgp += snprintf(msgp, bufend - msgp, suffix);
97 98 len = msgp - bufp;
98 99
99 100 fakekernel_putlog(bufp, len, flags);
100 101 }
101 102
102 103 /*
103 104 * "User-level crash dump", if you will.
104 105 */
105 106 void
106 107 vpanic(const char *fmt, va_list adx)
107 108 {
↓ open down ↓ |
72 lines elided |
↑ open up ↑ |
108 109 va_list tmpargs;
109 110
110 111 panicstr = (char *)fmt;
111 112 va_copy(panicargs, adx);
112 113
113 114 va_copy(tmpargs, adx);
114 115 fakekernel_cprintf(fmt, tmpargs, SL_FATAL, "fatal: ", "\n");
115 116
116 117 /* Call libc`assfail() so that mdb ::status works */
117 118 (void) vsnprintf(panicbuf, sizeof (panicbuf), fmt, adx);
118 - assfail(panicbuf, "(panic)", 0);
119 + (void) assfail(panicbuf, "(panic)", 0);
119 120
120 121 abort(); /* avoid "noreturn" warnings */
121 122 }
122 123
123 124 void
124 125 panic(const char *fmt, ...)
125 126 {
126 127 va_list adx;
127 128
128 129 va_start(adx, fmt);
129 130 vpanic(fmt, adx);
130 131 va_end(adx);
131 132 }
132 133
133 134 void
134 135 fm_panic(const char *fmt, ...)
135 136 {
136 137 va_list adx;
137 138
138 139 va_start(adx, fmt);
139 140 vpanic(fmt, adx);
140 141 va_end(adx);
141 142 }
142 143
143 144 void
144 145 vcmn_err(int ce, const char *fmt, va_list adx)
145 146 {
146 147
147 148 if (ce == CE_PANIC)
148 149 vpanic(fmt, adx);
149 150 if (ce >= CE_IGNORE)
150 151 return;
151 152
152 153 fakekernel_cprintf(fmt, adx, ce_flags[ce] | SL_CONSOLE,
153 154 ce_prefix[ce], ce_suffix[ce]);
154 155 }
155 156
156 157 /*PRINTFLIKE2*/
157 158 void
158 159 cmn_err(int ce, const char *fmt, ...)
159 160 {
160 161 va_list adx;
161 162
162 163 va_start(adx, fmt);
163 164 vcmn_err(ce, fmt, adx);
164 165 va_end(adx);
165 166 }
↓ open down ↓ |
37 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX