1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #ifndef _SYS_CMN_ERR_H
32 #define	_SYS_CMN_ERR_H
33 
34 #if !defined(_ASM)
35 #include <sys/_stdarg.h>
36 #include <sys/atomic.h>
37 #endif
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /* Common error handling severity levels */
44 
45 #define	CE_CONT		0	/* continuation		*/
46 #define	CE_NOTE		1	/* notice		*/
47 #define	CE_WARN		2	/* warning		*/
48 #define	CE_PANIC	3	/* panic		*/
49 #define	CE_IGNORE	4	/* print nothing	*/
50 
51 #ifndef _ASM
52 
53 extern void cmn_err(int, const char *, ...)
54     __attribute__((format(printf, 2, 3)));
55 
56 extern void vzcmn_err(zoneid_t, int, const char *, __va_list)
57     __attribute__((format(printf, 3, 0)));
58 
59 extern void vcmn_err(int, const char *, __va_list)
60     __attribute__((format(printf, 2, 0)));
61 
62 extern void zcmn_err(zoneid_t, int, const char *, ...)
63     __attribute__((format(printf, 3, 4)));
64 
65 extern void vzprintf(zoneid_t, const char *, __va_list)
66     __attribute__((format(printf, 2, 0)));
67 
68 extern void zprintf(zoneid_t, const char *, ...)
69     __attribute__((format(printf, 2, 3)));
70 
71 extern void vuprintf(const char *, __va_list)
72     __attribute__((format(printf, 1, 0)));
73 
74 extern void panic(const char *, ...)
75     __attribute__((format(printf, 1, 2), __noreturn__));
76 
77 #define	cmn_err_once(ce, ...)				\
78 do {							\
79 	static volatile uint32_t printed = 0;		\
80 	if (atomic_cas_32(&printed, 0, 1) == 0) {	\
81 		cmn_err(ce, __VA_ARGS__);		\
82 	}						\
83 } while (0)
84 
85 #define	vcmn_err_once(ce, fmt, ap)			\
86 do {							\
87 	static volatile uint32_t printed = 0;		\
88 	if (atomic_cas_32(&printed, 0, 1) == 0) {	\
89 		vcmn_err(ce, fmt, ap);			\
90 	}						\
91 } while (0)
92 
93 #define	zcmn_err_once(zone, ce, ...)			\
94 do {							\
95 	static volatile uint32_t printed = 0;		\
96 	if (atomic_cas_32(&printed, 0, 1) == 0) {	\
97 		zcmn_err(zone, ce, __VA_ARGS__);	\
98 	}						\
99 } while (0)
100 
101 #define	vzcmn_err_once(zone, ce, fmt, ap)		\
102 do {							\
103 	static volatile uint32_t printed = 0;		\
104 	if (atomic_cas_32(&printed, 0, 1) == 0) {	\
105 		vzcmn_err(zone, ce, fmt, ap);		\
106 	}						\
107 } while (0)
108 
109 #endif /* !_ASM */
110 
111 #ifdef	__cplusplus
112 }
113 #endif
114 
115 #endif	/* _SYS_CMN_ERR_H */
116