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]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
27 #include <sys/param.h>
28 #include <sys/types.h>
29 #include <sys/varargs.h>
30 #include <sys/systm.h>
31 #include <sys/cmn_err.h>
34 #include <fakekernel.h>
36 void abort(void) __NORETURN
;
38 char *volatile panicstr
;
45 ce_flags
[CE_IGNORE
] = { SL_NOTE
, SL_NOTE
, SL_WARN
, SL_FATAL
};
47 ce_prefix
[CE_IGNORE
][10] = { "", "NOTICE: ", "WARNING: ", "" };
49 ce_suffix
[CE_IGNORE
][2] = { "", "\n", "\n", "" };
53 * This function is just a stub, exported NODIRECT so that
54 * comsumers like fksmbd can provide their own.
55 * (One that actually prints the messages.)
57 * It's used by fakekernel_cprintf() below.
58 * The flags are SL_... from strlog.h
62 fakekernel_putlog(char *msg
, size_t len
, int flags
)
67 * fakekernel_cprintf() corresponds to os/printf.c:cprintf()
68 * This formats the message and calls fakekernel_putlog().
69 * It's exported NODIRECT to allow replacment.
70 * The flags are SL_... from strlog.h
73 fakekernel_cprintf(const char *fmt
, va_list adx
, int flags
,
74 const char *prefix
, const char *suffix
)
76 size_t bufsize
= LOG_MSGSIZE
;
77 char buf
[LOG_MSGSIZE
];
82 if (strchr("^!?", fmt
[0]) != NULL
) {
85 else if (fmt
[0] == '!')
90 bufend
= bufp
+ bufsize
;
92 msgp
+= snprintf(msgp
, bufend
- msgp
, "[fake_kernel] ");
93 msgp
+= snprintf(msgp
, bufend
- msgp
, prefix
);
94 msgp
+= vsnprintf(msgp
, bufend
- msgp
, fmt
, adx
);
95 msgp
+= snprintf(msgp
, bufend
- msgp
, suffix
);
98 fakekernel_putlog(bufp
, len
, flags
);
102 * "User-level crash dump", if you will.
105 vpanic(const char *fmt
, va_list adx
)
109 panicstr
= (char *)fmt
;
110 va_copy(panicargs
, adx
);
112 va_copy(tmpargs
, adx
);
113 fakekernel_cprintf(fmt
, tmpargs
, SL_FATAL
, "fatal: ", "\n");
115 /* Call libc`assfail() so that mdb ::status works */
116 (void) vsnprintf(panicbuf
, sizeof (panicbuf
), fmt
, adx
);
117 assfail(panicbuf
, "(panic)", 0);
119 abort(); /* avoid "noreturn" warnings */
123 panic(const char *fmt
, ...)
133 vcmn_err(int ce
, const char *fmt
, va_list adx
)
141 fakekernel_cprintf(fmt
, adx
, ce_flags
[ce
] | SL_CONSOLE
,
142 ce_prefix
[ce
], ce_suffix
[ce
]);
147 cmn_err(int ce
, const char *fmt
, ...)
152 vcmn_err(ce
, fmt
, adx
);