xref: /illumos-gate/usr/src/boot/sys/sys/cdefs.h (revision 199767f8)
1*199767f8SToomas Soome /*-
2*199767f8SToomas Soome  * Copyright (c) 1991, 1993
3*199767f8SToomas Soome  *	The Regents of the University of California.  All rights reserved.
4*199767f8SToomas Soome  *
5*199767f8SToomas Soome  * This code is derived from software contributed to Berkeley by
6*199767f8SToomas Soome  * Berkeley Software Design, Inc.
7*199767f8SToomas Soome  *
8*199767f8SToomas Soome  * Redistribution and use in source and binary forms, with or without
9*199767f8SToomas Soome  * modification, are permitted provided that the following conditions
10*199767f8SToomas Soome  * are met:
11*199767f8SToomas Soome  * 1. Redistributions of source code must retain the above copyright
12*199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer.
13*199767f8SToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
14*199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer in the
15*199767f8SToomas Soome  *    documentation and/or other materials provided with the distribution.
16*199767f8SToomas Soome  * 4. Neither the name of the University nor the names of its contributors
17*199767f8SToomas Soome  *    may be used to endorse or promote products derived from this software
18*199767f8SToomas Soome  *    without specific prior written permission.
19*199767f8SToomas Soome  *
20*199767f8SToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21*199767f8SToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*199767f8SToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*199767f8SToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24*199767f8SToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25*199767f8SToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26*199767f8SToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*199767f8SToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28*199767f8SToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29*199767f8SToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30*199767f8SToomas Soome  * SUCH DAMAGE.
31*199767f8SToomas Soome  *
32*199767f8SToomas Soome  *	@(#)cdefs.h	8.8 (Berkeley) 1/9/95
33*199767f8SToomas Soome  * $FreeBSD$
34*199767f8SToomas Soome  */
35*199767f8SToomas Soome 
36*199767f8SToomas Soome #ifndef	_SYS_CDEFS_H_
37*199767f8SToomas Soome #define	_SYS_CDEFS_H_
38*199767f8SToomas Soome 
39*199767f8SToomas Soome /*
40*199767f8SToomas Soome  * Testing against Clang-specific extensions.
41*199767f8SToomas Soome  */
42*199767f8SToomas Soome #ifndef	__has_attribute
43*199767f8SToomas Soome #define	__has_attribute(x)	0
44*199767f8SToomas Soome #endif
45*199767f8SToomas Soome #ifndef	__has_extension
46*199767f8SToomas Soome #define	__has_extension		__has_feature
47*199767f8SToomas Soome #endif
48*199767f8SToomas Soome #ifndef	__has_feature
49*199767f8SToomas Soome #define	__has_feature(x)	0
50*199767f8SToomas Soome #endif
51*199767f8SToomas Soome #ifndef	__has_include
52*199767f8SToomas Soome #define	__has_include(x)	0
53*199767f8SToomas Soome #endif
54*199767f8SToomas Soome #ifndef	__has_builtin
55*199767f8SToomas Soome #define	__has_builtin(x)	0
56*199767f8SToomas Soome #endif
57*199767f8SToomas Soome 
58*199767f8SToomas Soome #if defined(__cplusplus)
59*199767f8SToomas Soome #define	__BEGIN_DECLS	extern "C" {
60*199767f8SToomas Soome #define	__END_DECLS	}
61*199767f8SToomas Soome #else
62*199767f8SToomas Soome #define	__BEGIN_DECLS
63*199767f8SToomas Soome #define	__END_DECLS
64*199767f8SToomas Soome #endif
65*199767f8SToomas Soome 
66*199767f8SToomas Soome /*
67*199767f8SToomas Soome  * This code has been put in place to help reduce the addition of
68*199767f8SToomas Soome  * compiler specific defines in FreeBSD code.  It helps to aid in
69*199767f8SToomas Soome  * having a compiler-agnostic source tree.
70*199767f8SToomas Soome  */
71*199767f8SToomas Soome 
72*199767f8SToomas Soome #if defined(__GNUC__) || defined(__INTEL_COMPILER)
73*199767f8SToomas Soome 
74*199767f8SToomas Soome #if __GNUC__ >= 3 || defined(__INTEL_COMPILER)
75*199767f8SToomas Soome #define	__GNUCLIKE_ASM 3
76*199767f8SToomas Soome #define	__GNUCLIKE_MATH_BUILTIN_CONSTANTS
77*199767f8SToomas Soome #else
78*199767f8SToomas Soome #define	__GNUCLIKE_ASM 2
79*199767f8SToomas Soome #endif
80*199767f8SToomas Soome #define	__GNUCLIKE___TYPEOF 1
81*199767f8SToomas Soome #define	__GNUCLIKE___OFFSETOF 1
82*199767f8SToomas Soome #define	__GNUCLIKE___SECTION 1
83*199767f8SToomas Soome 
84*199767f8SToomas Soome #ifndef __INTEL_COMPILER
85*199767f8SToomas Soome #define	__GNUCLIKE_CTOR_SECTION_HANDLING 1
86*199767f8SToomas Soome #endif
87*199767f8SToomas Soome 
88*199767f8SToomas Soome #define	__GNUCLIKE_BUILTIN_CONSTANT_P 1
89*199767f8SToomas Soome #if defined(__INTEL_COMPILER) && defined(__cplusplus) && \
90*199767f8SToomas Soome    __INTEL_COMPILER < 800
91*199767f8SToomas Soome #undef __GNUCLIKE_BUILTIN_CONSTANT_P
92*199767f8SToomas Soome #endif
93*199767f8SToomas Soome 
94*199767f8SToomas Soome #if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3)
95*199767f8SToomas Soome #define	__GNUCLIKE_BUILTIN_VARARGS 1
96*199767f8SToomas Soome #define	__GNUCLIKE_BUILTIN_STDARG 1
97*199767f8SToomas Soome #define	__GNUCLIKE_BUILTIN_VAALIST 1
98*199767f8SToomas Soome #endif
99*199767f8SToomas Soome 
100*199767f8SToomas Soome #if defined(__GNUC__)
101*199767f8SToomas Soome #define	__GNUC_VA_LIST_COMPATIBILITY 1
102*199767f8SToomas Soome #endif
103*199767f8SToomas Soome 
104*199767f8SToomas Soome /*
105*199767f8SToomas Soome  * Compiler memory barriers, specific to gcc and clang.
106*199767f8SToomas Soome  */
107*199767f8SToomas Soome #if defined(__GNUC__)
108*199767f8SToomas Soome #define	__compiler_membar()	__asm __volatile(" " : : : "memory")
109*199767f8SToomas Soome #endif
110*199767f8SToomas Soome 
111*199767f8SToomas Soome #ifndef __INTEL_COMPILER
112*199767f8SToomas Soome #define	__GNUCLIKE_BUILTIN_NEXT_ARG 1
113*199767f8SToomas Soome #define	__GNUCLIKE_MATH_BUILTIN_RELOPS
114*199767f8SToomas Soome #endif
115*199767f8SToomas Soome 
116*199767f8SToomas Soome #define	__GNUCLIKE_BUILTIN_MEMCPY 1
117*199767f8SToomas Soome 
118*199767f8SToomas Soome /* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */
119*199767f8SToomas Soome #define	__CC_SUPPORTS_INLINE 1
120*199767f8SToomas Soome #define	__CC_SUPPORTS___INLINE 1
121*199767f8SToomas Soome #define	__CC_SUPPORTS___INLINE__ 1
122*199767f8SToomas Soome 
123*199767f8SToomas Soome #define	__CC_SUPPORTS___FUNC__ 1
124*199767f8SToomas Soome #define	__CC_SUPPORTS_WARNING 1
125*199767f8SToomas Soome 
126*199767f8SToomas Soome #define	__CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */
127*199767f8SToomas Soome 
128*199767f8SToomas Soome #define	__CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1
129*199767f8SToomas Soome 
130*199767f8SToomas Soome #endif /* __GNUC__ || __INTEL_COMPILER */
131*199767f8SToomas Soome 
132*199767f8SToomas Soome /*
133*199767f8SToomas Soome  * Macro to test if we're using a specific version of gcc or later.
134*199767f8SToomas Soome  */
135*199767f8SToomas Soome #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
136*199767f8SToomas Soome #define	__GNUC_PREREQ__(ma, mi)	\
137*199767f8SToomas Soome 	(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
138*199767f8SToomas Soome #else
139*199767f8SToomas Soome #define	__GNUC_PREREQ__(ma, mi)	0
140*199767f8SToomas Soome #endif
141*199767f8SToomas Soome 
142*199767f8SToomas Soome /*
143*199767f8SToomas Soome  * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
144*199767f8SToomas Soome  * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
145*199767f8SToomas Soome  * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
146*199767f8SToomas Soome  * mode -- there must be no spaces between its arguments, and for nested
147*199767f8SToomas Soome  * __CONCAT's, all the __CONCAT's must be at the left.  __CONCAT can also
148*199767f8SToomas Soome  * concatenate double-quoted strings produced by the __STRING macro, but
149*199767f8SToomas Soome  * this only works with ANSI C.
150*199767f8SToomas Soome  *
151*199767f8SToomas Soome  * __XSTRING is like __STRING, but it expands any macros in its argument
152*199767f8SToomas Soome  * first.  It is only available with ANSI C.
153*199767f8SToomas Soome  */
154*199767f8SToomas Soome #if defined(__STDC__) || defined(__cplusplus)
155*199767f8SToomas Soome #define	__P(protos)	protos		/* full-blown ANSI C */
156*199767f8SToomas Soome #define	__CONCAT1(x,y)	x ## y
157*199767f8SToomas Soome #define	__CONCAT(x,y)	__CONCAT1(x,y)
158*199767f8SToomas Soome #define	__STRING(x)	#x		/* stringify without expanding x */
159*199767f8SToomas Soome #define	__XSTRING(x)	__STRING(x)	/* expand x, then stringify */
160*199767f8SToomas Soome 
161*199767f8SToomas Soome #define	__const		const		/* define reserved names to standard */
162*199767f8SToomas Soome #define	__signed	signed
163*199767f8SToomas Soome #define	__volatile	volatile
164*199767f8SToomas Soome #if defined(__cplusplus)
165*199767f8SToomas Soome #define	__inline	inline		/* convert to C++ keyword */
166*199767f8SToomas Soome #else
167*199767f8SToomas Soome #if !(defined(__CC_SUPPORTS___INLINE))
168*199767f8SToomas Soome #define	__inline			/* delete GCC keyword */
169*199767f8SToomas Soome #endif /* ! __CC_SUPPORTS___INLINE */
170*199767f8SToomas Soome #endif /* !__cplusplus */
171*199767f8SToomas Soome 
172*199767f8SToomas Soome #else	/* !(__STDC__ || __cplusplus) */
173*199767f8SToomas Soome #define	__P(protos)	()		/* traditional C preprocessor */
174*199767f8SToomas Soome #define	__CONCAT(x,y)	x/**/y
175*199767f8SToomas Soome #define	__STRING(x)	"x"
176*199767f8SToomas Soome 
177*199767f8SToomas Soome #if !defined(__CC_SUPPORTS___INLINE)
178*199767f8SToomas Soome #define	__const				/* delete pseudo-ANSI C keywords */
179*199767f8SToomas Soome #define	__inline
180*199767f8SToomas Soome #define	__signed
181*199767f8SToomas Soome #define	__volatile
182*199767f8SToomas Soome /*
183*199767f8SToomas Soome  * In non-ANSI C environments, new programs will want ANSI-only C keywords
184*199767f8SToomas Soome  * deleted from the program and old programs will want them left alone.
185*199767f8SToomas Soome  * When using a compiler other than gcc, programs using the ANSI C keywords
186*199767f8SToomas Soome  * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
187*199767f8SToomas Soome  * When using "gcc -traditional", we assume that this is the intent; if
188*199767f8SToomas Soome  * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
189*199767f8SToomas Soome  */
190*199767f8SToomas Soome #ifndef	NO_ANSI_KEYWORDS
191*199767f8SToomas Soome #define	const				/* delete ANSI C keywords */
192*199767f8SToomas Soome #define	inline
193*199767f8SToomas Soome #define	signed
194*199767f8SToomas Soome #define	volatile
195*199767f8SToomas Soome #endif	/* !NO_ANSI_KEYWORDS */
196*199767f8SToomas Soome #endif	/* !__CC_SUPPORTS___INLINE */
197*199767f8SToomas Soome #endif	/* !(__STDC__ || __cplusplus) */
198*199767f8SToomas Soome 
199*199767f8SToomas Soome /*
200*199767f8SToomas Soome  * Compiler-dependent macros to help declare dead (non-returning) and
201*199767f8SToomas Soome  * pure (no side effects) functions, and unused variables.  They are
202*199767f8SToomas Soome  * null except for versions of gcc that are known to support the features
203*199767f8SToomas Soome  * properly (old versions of gcc-2 supported the dead and pure features
204*199767f8SToomas Soome  * in a different (wrong) way).  If we do not provide an implementation
205*199767f8SToomas Soome  * for a given compiler, let the compile fail if it is told to use
206*199767f8SToomas Soome  * a feature that we cannot live without.
207*199767f8SToomas Soome  */
208*199767f8SToomas Soome #ifdef lint
209*199767f8SToomas Soome #define	__dead2
210*199767f8SToomas Soome #define	__pure2
211*199767f8SToomas Soome #define	__unused
212*199767f8SToomas Soome #define	__packed
213*199767f8SToomas Soome #define	__aligned(x)
214*199767f8SToomas Soome #define	__alloc_align(x)
215*199767f8SToomas Soome #define	__alloc_size(x)
216*199767f8SToomas Soome #define	__section(x)
217*199767f8SToomas Soome #define	__weak_symbol
218*199767f8SToomas Soome #else
219*199767f8SToomas Soome #define	__weak_symbol	__attribute__((__weak__))
220*199767f8SToomas Soome #if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER)
221*199767f8SToomas Soome #define	__dead2
222*199767f8SToomas Soome #define	__pure2
223*199767f8SToomas Soome #define	__unused
224*199767f8SToomas Soome #endif
225*199767f8SToomas Soome #if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER)
226*199767f8SToomas Soome #define	__dead2		__attribute__((__noreturn__))
227*199767f8SToomas Soome #define	__pure2		__attribute__((__const__))
228*199767f8SToomas Soome #define	__unused
229*199767f8SToomas Soome /* XXX Find out what to do for __packed, __aligned and __section */
230*199767f8SToomas Soome #endif
231*199767f8SToomas Soome #if __GNUC_PREREQ__(2, 7) || defined(__INTEL_COMPILER)
232*199767f8SToomas Soome #define	__dead2		__attribute__((__noreturn__))
233*199767f8SToomas Soome #define	__pure2		__attribute__((__const__))
234*199767f8SToomas Soome #define	__unused	__attribute__((__unused__))
235*199767f8SToomas Soome #define	__used		__attribute__((__used__))
236*199767f8SToomas Soome #define	__packed	__attribute__((__packed__))
237*199767f8SToomas Soome #define	__aligned(x)	__attribute__((__aligned__(x)))
238*199767f8SToomas Soome #define	__section(x)	__attribute__((__section__(x)))
239*199767f8SToomas Soome #endif
240*199767f8SToomas Soome #if __GNUC_PREREQ__(4, 3) || __has_attribute(__alloc_size__)
241*199767f8SToomas Soome #define	__alloc_size(x)	__attribute__((__alloc_size__(x)))
242*199767f8SToomas Soome #else
243*199767f8SToomas Soome #define	__alloc_size(x)
244*199767f8SToomas Soome #endif
245*199767f8SToomas Soome #if __GNUC_PREREQ__(4, 9) || __has_attribute(__alloc_align__)
246*199767f8SToomas Soome #define	__alloc_align(x)	__attribute__((__alloc_align__(x)))
247*199767f8SToomas Soome #else
248*199767f8SToomas Soome #define	__alloc_align(x)
249*199767f8SToomas Soome #endif
250*199767f8SToomas Soome #endif /* lint */
251*199767f8SToomas Soome 
252*199767f8SToomas Soome #if !__GNUC_PREREQ__(2, 95)
253*199767f8SToomas Soome #define	__alignof(x)	__offsetof(struct { char __a; x __b; }, __b)
254*199767f8SToomas Soome #endif
255*199767f8SToomas Soome 
256*199767f8SToomas Soome /*
257*199767f8SToomas Soome  * Keywords added in C11.
258*199767f8SToomas Soome  */
259*199767f8SToomas Soome 
260*199767f8SToomas Soome #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint)
261*199767f8SToomas Soome 
262*199767f8SToomas Soome #if !__has_extension(c_alignas)
263*199767f8SToomas Soome #if (defined(__cplusplus) && __cplusplus >= 201103L) || \
264*199767f8SToomas Soome     __has_extension(cxx_alignas)
265*199767f8SToomas Soome #define	_Alignas(x)		alignas(x)
266*199767f8SToomas Soome #else
267*199767f8SToomas Soome /* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */
268*199767f8SToomas Soome #define	_Alignas(x)		__aligned(x)
269*199767f8SToomas Soome #endif
270*199767f8SToomas Soome #endif
271*199767f8SToomas Soome 
272*199767f8SToomas Soome #if defined(__cplusplus) && __cplusplus >= 201103L
273*199767f8SToomas Soome #define	_Alignof(x)		alignof(x)
274*199767f8SToomas Soome #else
275*199767f8SToomas Soome #define	_Alignof(x)		__alignof(x)
276*199767f8SToomas Soome #endif
277*199767f8SToomas Soome 
278*199767f8SToomas Soome #if !__has_extension(c_atomic) && !__has_extension(cxx_atomic)
279*199767f8SToomas Soome /*
280*199767f8SToomas Soome  * No native support for _Atomic(). Place object in structure to prevent
281*199767f8SToomas Soome  * most forms of direct non-atomic access.
282*199767f8SToomas Soome  */
283*199767f8SToomas Soome #define	_Atomic(T)		struct { T volatile __val; }
284*199767f8SToomas Soome #endif
285*199767f8SToomas Soome 
286*199767f8SToomas Soome #if defined(__cplusplus) && __cplusplus >= 201103L
287*199767f8SToomas Soome #define	_Noreturn		[[noreturn]]
288*199767f8SToomas Soome #else
289*199767f8SToomas Soome #define	_Noreturn		__dead2
290*199767f8SToomas Soome #endif
291*199767f8SToomas Soome 
292*199767f8SToomas Soome #if !__has_extension(c_static_assert)
293*199767f8SToomas Soome #if (defined(__cplusplus) && __cplusplus >= 201103L) || \
294*199767f8SToomas Soome     __has_extension(cxx_static_assert)
295*199767f8SToomas Soome #define	_Static_assert(x, y)	static_assert(x, y)
296*199767f8SToomas Soome #elif __GNUC_PREREQ__(4,6)
297*199767f8SToomas Soome /* Nothing, gcc 4.6 and higher has _Static_assert built-in */
298*199767f8SToomas Soome #elif defined(__COUNTER__)
299*199767f8SToomas Soome #define	_Static_assert(x, y)	__Static_assert(x, __COUNTER__)
300*199767f8SToomas Soome #define	__Static_assert(x, y)	___Static_assert(x, y)
301*199767f8SToomas Soome #define	___Static_assert(x, y)	typedef char __assert_ ## y[(x) ? 1 : -1] \
302*199767f8SToomas Soome 				__unused
303*199767f8SToomas Soome #else
304*199767f8SToomas Soome #define	_Static_assert(x, y)	struct __hack
305*199767f8SToomas Soome #endif
306*199767f8SToomas Soome #endif
307*199767f8SToomas Soome 
308*199767f8SToomas Soome #if !__has_extension(c_thread_local)
309*199767f8SToomas Soome /*
310*199767f8SToomas Soome  * XXX: Some compilers (Clang 3.3, GCC 4.7) falsely announce C++11 mode
311*199767f8SToomas Soome  * without actually supporting the thread_local keyword. Don't check for
312*199767f8SToomas Soome  * the presence of C++11 when defining _Thread_local.
313*199767f8SToomas Soome  */
314*199767f8SToomas Soome #if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \
315*199767f8SToomas Soome     __has_extension(cxx_thread_local)
316*199767f8SToomas Soome #define	_Thread_local		thread_local
317*199767f8SToomas Soome #else
318*199767f8SToomas Soome #define	_Thread_local		__thread
319*199767f8SToomas Soome #endif
320*199767f8SToomas Soome #endif
321*199767f8SToomas Soome 
322*199767f8SToomas Soome #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */
323*199767f8SToomas Soome 
324*199767f8SToomas Soome /*
325*199767f8SToomas Soome  * Emulation of C11 _Generic().  Unlike the previously defined C11
326*199767f8SToomas Soome  * keywords, it is not possible to implement this using exactly the same
327*199767f8SToomas Soome  * syntax.  Therefore implement something similar under the name
328*199767f8SToomas Soome  * __generic().  Unlike _Generic(), this macro can only distinguish
329*199767f8SToomas Soome  * between a single type, so it requires nested invocations to
330*199767f8SToomas Soome  * distinguish multiple cases.
331*199767f8SToomas Soome  */
332*199767f8SToomas Soome 
333*199767f8SToomas Soome #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
334*199767f8SToomas Soome     __has_extension(c_generic_selections)
335*199767f8SToomas Soome #define	__generic(expr, t, yes, no)					\
336*199767f8SToomas Soome 	_Generic(expr, t: yes, default: no)
337*199767f8SToomas Soome #elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus)
338*199767f8SToomas Soome #define	__generic(expr, t, yes, no)					\
339*199767f8SToomas Soome 	__builtin_choose_expr(						\
340*199767f8SToomas Soome 	    __builtin_types_compatible_p(__typeof(expr), t), yes, no)
341*199767f8SToomas Soome #endif
342*199767f8SToomas Soome 
343*199767f8SToomas Soome #if __GNUC_PREREQ__(2, 96)
344*199767f8SToomas Soome #define	__malloc_like	__attribute__((__malloc__))
345*199767f8SToomas Soome #define	__pure		__attribute__((__pure__))
346*199767f8SToomas Soome #else
347*199767f8SToomas Soome #define	__malloc_like
348*199767f8SToomas Soome #define	__pure
349*199767f8SToomas Soome #endif
350*199767f8SToomas Soome 
351*199767f8SToomas Soome #if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
352*199767f8SToomas Soome #define	__always_inline	__attribute__((__always_inline__))
353*199767f8SToomas Soome #else
354*199767f8SToomas Soome #define	__always_inline
355*199767f8SToomas Soome #endif
356*199767f8SToomas Soome 
357*199767f8SToomas Soome #if __GNUC_PREREQ__(3, 1)
358*199767f8SToomas Soome #define	__noinline	__attribute__ ((__noinline__))
359*199767f8SToomas Soome #else
360*199767f8SToomas Soome #define	__noinline
361*199767f8SToomas Soome #endif
362*199767f8SToomas Soome 
363*199767f8SToomas Soome #if __GNUC_PREREQ__(3, 3)
364*199767f8SToomas Soome #define	__nonnull(x)	__attribute__((__nonnull__(x)))
365*199767f8SToomas Soome #define	__nonnull_all	__attribute__((__nonnull__))
366*199767f8SToomas Soome #else
367*199767f8SToomas Soome #define	__nonnull(x)
368*199767f8SToomas Soome #define	__nonnull_all
369*199767f8SToomas Soome #endif
370*199767f8SToomas Soome 
371*199767f8SToomas Soome #if __GNUC_PREREQ__(3, 4)
372*199767f8SToomas Soome #define	__fastcall	__attribute__((__fastcall__))
373*199767f8SToomas Soome #define	__result_use_check	__attribute__((__warn_unused_result__))
374*199767f8SToomas Soome #else
375*199767f8SToomas Soome #define	__fastcall
376*199767f8SToomas Soome #define	__result_use_check
377*199767f8SToomas Soome #endif
378*199767f8SToomas Soome 
379*199767f8SToomas Soome #if __GNUC_PREREQ__(4, 1)
380*199767f8SToomas Soome #define	__returns_twice	__attribute__((__returns_twice__))
381*199767f8SToomas Soome #else
382*199767f8SToomas Soome #define	__returns_twice
383*199767f8SToomas Soome #endif
384*199767f8SToomas Soome 
385*199767f8SToomas Soome #if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable)
386*199767f8SToomas Soome #define	__unreachable()	__builtin_unreachable()
387*199767f8SToomas Soome #else
388*199767f8SToomas Soome #define	__unreachable()	((void)0)
389*199767f8SToomas Soome #endif
390*199767f8SToomas Soome 
391*199767f8SToomas Soome /* XXX: should use `#if __STDC_VERSION__ < 199901'. */
392*199767f8SToomas Soome #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
393*199767f8SToomas Soome #define	__func__	NULL
394*199767f8SToomas Soome #endif
395*199767f8SToomas Soome 
396*199767f8SToomas Soome #if (defined(__INTEL_COMPILER) || (defined(__GNUC__) && __GNUC__ >= 2)) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901
397*199767f8SToomas Soome #define	__LONG_LONG_SUPPORTED
398*199767f8SToomas Soome #endif
399*199767f8SToomas Soome 
400*199767f8SToomas Soome /* C++11 exposes a load of C99 stuff */
401*199767f8SToomas Soome #if defined(__cplusplus) && __cplusplus >= 201103L
402*199767f8SToomas Soome #define	__LONG_LONG_SUPPORTED
403*199767f8SToomas Soome #ifndef	__STDC_LIMIT_MACROS
404*199767f8SToomas Soome #define	__STDC_LIMIT_MACROS
405*199767f8SToomas Soome #endif
406*199767f8SToomas Soome #ifndef	__STDC_CONSTANT_MACROS
407*199767f8SToomas Soome #define	__STDC_CONSTANT_MACROS
408*199767f8SToomas Soome #endif
409*199767f8SToomas Soome #endif
410*199767f8SToomas Soome 
411*199767f8SToomas Soome /*
412*199767f8SToomas Soome  * GCC 2.95 provides `__restrict' as an extension to C90 to support the
413*199767f8SToomas Soome  * C99-specific `restrict' type qualifier.  We happen to use `__restrict' as
414*199767f8SToomas Soome  * a way to define the `restrict' type qualifier without disturbing older
415*199767f8SToomas Soome  * software that is unaware of C99 keywords.
416*199767f8SToomas Soome  */
417*199767f8SToomas Soome #if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
418*199767f8SToomas Soome #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 || defined(lint)
419*199767f8SToomas Soome #define	__restrict
420*199767f8SToomas Soome #else
421*199767f8SToomas Soome #define	__restrict	restrict
422*199767f8SToomas Soome #endif
423*199767f8SToomas Soome #endif
424*199767f8SToomas Soome 
425*199767f8SToomas Soome /*
426*199767f8SToomas Soome  * GNU C version 2.96 adds explicit branch prediction so that
427*199767f8SToomas Soome  * the CPU back-end can hint the processor and also so that
428*199767f8SToomas Soome  * code blocks can be reordered such that the predicted path
429*199767f8SToomas Soome  * sees a more linear flow, thus improving cache behavior, etc.
430*199767f8SToomas Soome  *
431*199767f8SToomas Soome  * The following two macros provide us with a way to utilize this
432*199767f8SToomas Soome  * compiler feature.  Use __predict_true() if you expect the expression
433*199767f8SToomas Soome  * to evaluate to true, and __predict_false() if you expect the
434*199767f8SToomas Soome  * expression to evaluate to false.
435*199767f8SToomas Soome  *
436*199767f8SToomas Soome  * A few notes about usage:
437*199767f8SToomas Soome  *
438*199767f8SToomas Soome  *	* Generally, __predict_false() error condition checks (unless
439*199767f8SToomas Soome  *	  you have some _strong_ reason to do otherwise, in which case
440*199767f8SToomas Soome  *	  document it), and/or __predict_true() `no-error' condition
441*199767f8SToomas Soome  *	  checks, assuming you want to optimize for the no-error case.
442*199767f8SToomas Soome  *
443*199767f8SToomas Soome  *	* Other than that, if you don't know the likelihood of a test
444*199767f8SToomas Soome  *	  succeeding from empirical or other `hard' evidence, don't
445*199767f8SToomas Soome  *	  make predictions.
446*199767f8SToomas Soome  *
447*199767f8SToomas Soome  *	* These are meant to be used in places that are run `a lot'.
448*199767f8SToomas Soome  *	  It is wasteful to make predictions in code that is run
449*199767f8SToomas Soome  *	  seldomly (e.g. at subsystem initialization time) as the
450*199767f8SToomas Soome  *	  basic block reordering that this affects can often generate
451*199767f8SToomas Soome  *	  larger code.
452*199767f8SToomas Soome  */
453*199767f8SToomas Soome #if __GNUC_PREREQ__(2, 96)
454*199767f8SToomas Soome #define	__predict_true(exp)     __builtin_expect((exp), 1)
455*199767f8SToomas Soome #define	__predict_false(exp)    __builtin_expect((exp), 0)
456*199767f8SToomas Soome #else
457*199767f8SToomas Soome #define	__predict_true(exp)     (exp)
458*199767f8SToomas Soome #define	__predict_false(exp)    (exp)
459*199767f8SToomas Soome #endif
460*199767f8SToomas Soome 
461*199767f8SToomas Soome #if __GNUC_PREREQ__(4, 0)
462*199767f8SToomas Soome #define	__null_sentinel	__attribute__((__sentinel__))
463*199767f8SToomas Soome #define	__exported	__attribute__((__visibility__("default")))
464*199767f8SToomas Soome #define	__hidden	__attribute__((__visibility__("hidden")))
465*199767f8SToomas Soome #else
466*199767f8SToomas Soome #define	__null_sentinel
467*199767f8SToomas Soome #define	__exported
468*199767f8SToomas Soome #define	__hidden
469*199767f8SToomas Soome #endif
470*199767f8SToomas Soome 
471*199767f8SToomas Soome /*
472*199767f8SToomas Soome  * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
473*199767f8SToomas Soome  * require it.
474*199767f8SToomas Soome  */
475*199767f8SToomas Soome #if __GNUC_PREREQ__(4, 1)
476*199767f8SToomas Soome #define	__offsetof(type, field)	 __builtin_offsetof(type, field)
477*199767f8SToomas Soome #else
478*199767f8SToomas Soome #ifndef __cplusplus
479*199767f8SToomas Soome #define	__offsetof(type, field) \
480*199767f8SToomas Soome 	((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field))
481*199767f8SToomas Soome #else
482*199767f8SToomas Soome #define	__offsetof(type, field)					\
483*199767f8SToomas Soome   (__offsetof__ (reinterpret_cast <__size_t>			\
484*199767f8SToomas Soome                  (&reinterpret_cast <const volatile char &>	\
485*199767f8SToomas Soome                   (static_cast<type *> (0)->field))))
486*199767f8SToomas Soome #endif
487*199767f8SToomas Soome #endif
488*199767f8SToomas Soome #define	__rangeof(type, start, end) \
489*199767f8SToomas Soome 	(__offsetof(type, end) - __offsetof(type, start))
490*199767f8SToomas Soome 
491*199767f8SToomas Soome /*
492*199767f8SToomas Soome  * Given the pointer x to the member m of the struct s, return
493*199767f8SToomas Soome  * a pointer to the containing structure.  When using GCC, we first
494*199767f8SToomas Soome  * assign pointer x to a local variable, to check that its type is
495*199767f8SToomas Soome  * compatible with member m.
496*199767f8SToomas Soome  */
497*199767f8SToomas Soome #if __GNUC_PREREQ__(3, 1)
498*199767f8SToomas Soome #define	__containerof(x, s, m) ({					\
499*199767f8SToomas Soome 	const volatile __typeof(((s *)0)->m) *__x = (x);		\
500*199767f8SToomas Soome 	__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\
501*199767f8SToomas Soome })
502*199767f8SToomas Soome #else
503*199767f8SToomas Soome #define	__containerof(x, s, m)						\
504*199767f8SToomas Soome 	__DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m))
505*199767f8SToomas Soome #endif
506*199767f8SToomas Soome 
507*199767f8SToomas Soome /*
508*199767f8SToomas Soome  * Compiler-dependent macros to declare that functions take printf-like
509*199767f8SToomas Soome  * or scanf-like arguments.  They are null except for versions of gcc
510*199767f8SToomas Soome  * that are known to support the features properly (old versions of gcc-2
511*199767f8SToomas Soome  * didn't permit keeping the keywords out of the application namespace).
512*199767f8SToomas Soome  */
513*199767f8SToomas Soome #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
514*199767f8SToomas Soome #define	__printflike(fmtarg, firstvararg)
515*199767f8SToomas Soome #define	__scanflike(fmtarg, firstvararg)
516*199767f8SToomas Soome #define	__format_arg(fmtarg)
517*199767f8SToomas Soome #define	__strfmonlike(fmtarg, firstvararg)
518*199767f8SToomas Soome #define	__strftimelike(fmtarg, firstvararg)
519*199767f8SToomas Soome #else
520*199767f8SToomas Soome #define	__printflike(fmtarg, firstvararg) \
521*199767f8SToomas Soome 	    __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
522*199767f8SToomas Soome #define	__scanflike(fmtarg, firstvararg) \
523*199767f8SToomas Soome 	    __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
524*199767f8SToomas Soome #define	__format_arg(fmtarg)	__attribute__((__format_arg__ (fmtarg)))
525*199767f8SToomas Soome #define	__strfmonlike(fmtarg, firstvararg) \
526*199767f8SToomas Soome 	    __attribute__((__format__ (__strfmon__, fmtarg, firstvararg)))
527*199767f8SToomas Soome #define	__strftimelike(fmtarg, firstvararg) \
528*199767f8SToomas Soome 	    __attribute__((__format__ (__strftime__, fmtarg, firstvararg)))
529*199767f8SToomas Soome #endif
530*199767f8SToomas Soome 
531*199767f8SToomas Soome /*
532*199767f8SToomas Soome  * FORTIFY_SOURCE, and perhaps other compiler-specific features, require
533*199767f8SToomas Soome  * the use of non-standard inlining.  In general we should try to avoid
534*199767f8SToomas Soome  * using these but GCC-compatible compilers tend to support the extensions
535*199767f8SToomas Soome  * well enough to use them in limited cases.
536*199767f8SToomas Soome  */
537*199767f8SToomas Soome #if defined(__GNUC_GNU_INLINE__) || defined(__GNUC_STDC_INLINE__)
538*199767f8SToomas Soome #if __GNUC_PREREQ__(4, 3) || __has_attribute(__artificial__)
539*199767f8SToomas Soome #define	__gnu_inline	__attribute__((__gnu_inline__, __artificial__))
540*199767f8SToomas Soome #else
541*199767f8SToomas Soome #define	__gnu_inline	__attribute__((__gnu_inline__))
542*199767f8SToomas Soome #endif /* artificial */
543*199767f8SToomas Soome #else
544*199767f8SToomas Soome #define	__gnu_inline
545*199767f8SToomas Soome #endif
546*199767f8SToomas Soome 
547*199767f8SToomas Soome /* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
548*199767f8SToomas Soome #if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \
549*199767f8SToomas Soome     defined(__GNUC__) && !defined(__INTEL_COMPILER)
550*199767f8SToomas Soome #define	__printf0like(fmtarg, firstvararg) \
551*199767f8SToomas Soome 	    __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
552*199767f8SToomas Soome #else
553*199767f8SToomas Soome #define	__printf0like(fmtarg, firstvararg)
554*199767f8SToomas Soome #endif
555*199767f8SToomas Soome 
556*199767f8SToomas Soome #if defined(__GNUC__) || defined(__INTEL_COMPILER)
557*199767f8SToomas Soome #ifndef __INTEL_COMPILER
558*199767f8SToomas Soome #define	__strong_reference(sym,aliassym)	\
559*199767f8SToomas Soome 	extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
560*199767f8SToomas Soome #endif
561*199767f8SToomas Soome #ifdef __STDC__
562*199767f8SToomas Soome #define	__weak_reference(sym,alias)	\
563*199767f8SToomas Soome 	__asm__(".weak " #alias);	\
564*199767f8SToomas Soome 	__asm__(".equ "  #alias ", " #sym)
565*199767f8SToomas Soome #define	__warn_references(sym,msg)	\
566*199767f8SToomas Soome 	__asm__(".section .gnu.warning." #sym);	\
567*199767f8SToomas Soome 	__asm__(".asciz \"" msg "\"");	\
568*199767f8SToomas Soome 	__asm__(".previous")
569*199767f8SToomas Soome #define	__sym_compat(sym,impl,verid)	\
570*199767f8SToomas Soome 	__asm__(".symver " #impl ", " #sym "@" #verid)
571*199767f8SToomas Soome #define	__sym_default(sym,impl,verid)	\
572*199767f8SToomas Soome 	__asm__(".symver " #impl ", " #sym "@@" #verid)
573*199767f8SToomas Soome #else
574*199767f8SToomas Soome #define	__weak_reference(sym,alias)	\
575*199767f8SToomas Soome 	__asm__(".weak alias");		\
576*199767f8SToomas Soome 	__asm__(".equ alias, sym")
577*199767f8SToomas Soome #define	__warn_references(sym,msg)	\
578*199767f8SToomas Soome 	__asm__(".section .gnu.warning.sym"); \
579*199767f8SToomas Soome 	__asm__(".asciz \"msg\"");	\
580*199767f8SToomas Soome 	__asm__(".previous")
581*199767f8SToomas Soome #define	__sym_compat(sym,impl,verid)	\
582*199767f8SToomas Soome 	__asm__(".symver impl, sym@verid")
583*199767f8SToomas Soome #define	__sym_default(impl,sym,verid)	\
584*199767f8SToomas Soome 	__asm__(".symver impl, sym@@verid")
585*199767f8SToomas Soome #endif	/* __STDC__ */
586*199767f8SToomas Soome #endif	/* __GNUC__ || __INTEL_COMPILER */
587*199767f8SToomas Soome 
588*199767f8SToomas Soome #define	__GLOBL1(sym)	__asm__(".globl " #sym)
589*199767f8SToomas Soome #define	__GLOBL(sym)	__GLOBL1(sym)
590*199767f8SToomas Soome 
591*199767f8SToomas Soome #if defined(__GNUC__) || defined(__INTEL_COMPILER)
592*199767f8SToomas Soome #define	__IDSTRING(name,string)	__asm__(".ident\t\"" string "\"")
593*199767f8SToomas Soome #else
594*199767f8SToomas Soome /*
595*199767f8SToomas Soome  * The following definition might not work well if used in header files,
596*199767f8SToomas Soome  * but it should be better than nothing.  If you want a "do nothing"
597*199767f8SToomas Soome  * version, then it should generate some harmless declaration, such as:
598*199767f8SToomas Soome  *    #define	__IDSTRING(name,string)	struct __hack
599*199767f8SToomas Soome  */
600*199767f8SToomas Soome #define	__IDSTRING(name,string)	static const char name[] __unused = string
601*199767f8SToomas Soome #endif
602*199767f8SToomas Soome 
603*199767f8SToomas Soome /*
604*199767f8SToomas Soome  * Embed the rcs id of a source file in the resulting library.  Note that in
605*199767f8SToomas Soome  * more recent ELF binutils, we use .ident allowing the ID to be stripped.
606*199767f8SToomas Soome  * Usage:
607*199767f8SToomas Soome  *	__FBSDID("$FreeBSD$");
608*199767f8SToomas Soome  */
609*199767f8SToomas Soome #ifndef	__FBSDID
610*199767f8SToomas Soome #if !defined(lint) && !defined(STRIP_FBSDID)
611*199767f8SToomas Soome #define	__FBSDID(s)	__IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
612*199767f8SToomas Soome #else
613*199767f8SToomas Soome #define	__FBSDID(s)	struct __hack
614*199767f8SToomas Soome #endif
615*199767f8SToomas Soome #endif
616*199767f8SToomas Soome 
617*199767f8SToomas Soome #ifndef	__RCSID
618*199767f8SToomas Soome #ifndef	NO__RCSID
619*199767f8SToomas Soome #define	__RCSID(s)	__IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
620*199767f8SToomas Soome #else
621*199767f8SToomas Soome #define	__RCSID(s)	struct __hack
622*199767f8SToomas Soome #endif
623*199767f8SToomas Soome #endif
624*199767f8SToomas Soome 
625*199767f8SToomas Soome #ifndef	__RCSID_SOURCE
626*199767f8SToomas Soome #ifndef	NO__RCSID_SOURCE
627*199767f8SToomas Soome #define	__RCSID_SOURCE(s)	__IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s)
628*199767f8SToomas Soome #else
629*199767f8SToomas Soome #define	__RCSID_SOURCE(s)	struct __hack
630*199767f8SToomas Soome #endif
631*199767f8SToomas Soome #endif
632*199767f8SToomas Soome 
633*199767f8SToomas Soome #ifndef	__SCCSID
634*199767f8SToomas Soome #ifndef	NO__SCCSID
635*199767f8SToomas Soome #define	__SCCSID(s)	__IDSTRING(__CONCAT(__sccsid_,__LINE__),s)
636*199767f8SToomas Soome #else
637*199767f8SToomas Soome #define	__SCCSID(s)	struct __hack
638*199767f8SToomas Soome #endif
639*199767f8SToomas Soome #endif
640*199767f8SToomas Soome 
641*199767f8SToomas Soome #ifndef	__COPYRIGHT
642*199767f8SToomas Soome #ifndef	NO__COPYRIGHT
643*199767f8SToomas Soome #define	__COPYRIGHT(s)	__IDSTRING(__CONCAT(__copyright_,__LINE__),s)
644*199767f8SToomas Soome #else
645*199767f8SToomas Soome #define	__COPYRIGHT(s)	struct __hack
646*199767f8SToomas Soome #endif
647*199767f8SToomas Soome #endif
648*199767f8SToomas Soome 
649*199767f8SToomas Soome #ifndef	__DECONST
650*199767f8SToomas Soome #define	__DECONST(type, var)	((type)(__uintptr_t)(const void *)(var))
651*199767f8SToomas Soome #endif
652*199767f8SToomas Soome 
653*199767f8SToomas Soome #ifndef	__DEVOLATILE
654*199767f8SToomas Soome #define	__DEVOLATILE(type, var)	((type)(__uintptr_t)(volatile void *)(var))
655*199767f8SToomas Soome #endif
656*199767f8SToomas Soome 
657*199767f8SToomas Soome #ifndef	__DEQUALIFY
658*199767f8SToomas Soome #define	__DEQUALIFY(type, var)	((type)(__uintptr_t)(const volatile void *)(var))
659*199767f8SToomas Soome #endif
660*199767f8SToomas Soome 
661*199767f8SToomas Soome /*-
662*199767f8SToomas Soome  * The following definitions are an extension of the behavior originally
663*199767f8SToomas Soome  * implemented in <sys/_posix.h>, but with a different level of granularity.
664*199767f8SToomas Soome  * POSIX.1 requires that the macros we test be defined before any standard
665*199767f8SToomas Soome  * header file is included.
666*199767f8SToomas Soome  *
667*199767f8SToomas Soome  * Here's a quick run-down of the versions:
668*199767f8SToomas Soome  *  defined(_POSIX_SOURCE)		1003.1-1988
669*199767f8SToomas Soome  *  _POSIX_C_SOURCE == 1		1003.1-1990
670*199767f8SToomas Soome  *  _POSIX_C_SOURCE == 2		1003.2-1992 C Language Binding Option
671*199767f8SToomas Soome  *  _POSIX_C_SOURCE == 199309		1003.1b-1993
672*199767f8SToomas Soome  *  _POSIX_C_SOURCE == 199506		1003.1c-1995, 1003.1i-1995,
673*199767f8SToomas Soome  *					and the omnibus ISO/IEC 9945-1: 1996
674*199767f8SToomas Soome  *  _POSIX_C_SOURCE == 200112		1003.1-2001
675*199767f8SToomas Soome  *  _POSIX_C_SOURCE == 200809		1003.1-2008
676*199767f8SToomas Soome  *
677*199767f8SToomas Soome  * In addition, the X/Open Portability Guide, which is now the Single UNIX
678*199767f8SToomas Soome  * Specification, defines a feature-test macro which indicates the version of
679*199767f8SToomas Soome  * that specification, and which subsumes _POSIX_C_SOURCE.
680*199767f8SToomas Soome  *
681*199767f8SToomas Soome  * Our macros begin with two underscores to avoid namespace screwage.
682*199767f8SToomas Soome  */
683*199767f8SToomas Soome 
684*199767f8SToomas Soome /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
685*199767f8SToomas Soome #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
686*199767f8SToomas Soome #undef _POSIX_C_SOURCE		/* Probably illegal, but beyond caring now. */
687*199767f8SToomas Soome #define	_POSIX_C_SOURCE		199009
688*199767f8SToomas Soome #endif
689*199767f8SToomas Soome 
690*199767f8SToomas Soome /* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
691*199767f8SToomas Soome #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2
692*199767f8SToomas Soome #undef _POSIX_C_SOURCE
693*199767f8SToomas Soome #define	_POSIX_C_SOURCE		199209
694*199767f8SToomas Soome #endif
695*199767f8SToomas Soome 
696*199767f8SToomas Soome /* Deal with various X/Open Portability Guides and Single UNIX Spec. */
697*199767f8SToomas Soome #ifdef _XOPEN_SOURCE
698*199767f8SToomas Soome #if _XOPEN_SOURCE - 0 >= 700
699*199767f8SToomas Soome #define	__XSI_VISIBLE		700
700*199767f8SToomas Soome #undef _POSIX_C_SOURCE
701*199767f8SToomas Soome #define	_POSIX_C_SOURCE		200809
702*199767f8SToomas Soome #elif _XOPEN_SOURCE - 0 >= 600
703*199767f8SToomas Soome #define	__XSI_VISIBLE		600
704*199767f8SToomas Soome #undef _POSIX_C_SOURCE
705*199767f8SToomas Soome #define	_POSIX_C_SOURCE		200112
706*199767f8SToomas Soome #elif _XOPEN_SOURCE - 0 >= 500
707*199767f8SToomas Soome #define	__XSI_VISIBLE		500
708*199767f8SToomas Soome #undef _POSIX_C_SOURCE
709*199767f8SToomas Soome #define	_POSIX_C_SOURCE		199506
710*199767f8SToomas Soome #endif
711*199767f8SToomas Soome #endif
712*199767f8SToomas Soome 
713*199767f8SToomas Soome /*
714*199767f8SToomas Soome  * Deal with all versions of POSIX.  The ordering relative to the tests above is
715*199767f8SToomas Soome  * important.
716*199767f8SToomas Soome  */
717*199767f8SToomas Soome #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
718*199767f8SToomas Soome #define	_POSIX_C_SOURCE		198808
719*199767f8SToomas Soome #endif
720*199767f8SToomas Soome #ifdef _POSIX_C_SOURCE
721*199767f8SToomas Soome #if _POSIX_C_SOURCE >= 200809
722*199767f8SToomas Soome #define	__POSIX_VISIBLE		200809
723*199767f8SToomas Soome #define	__ISO_C_VISIBLE		1999
724*199767f8SToomas Soome #elif _POSIX_C_SOURCE >= 200112
725*199767f8SToomas Soome #define	__POSIX_VISIBLE		200112
726*199767f8SToomas Soome #define	__ISO_C_VISIBLE		1999
727*199767f8SToomas Soome #elif _POSIX_C_SOURCE >= 199506
728*199767f8SToomas Soome #define	__POSIX_VISIBLE		199506
729*199767f8SToomas Soome #define	__ISO_C_VISIBLE		1990
730*199767f8SToomas Soome #elif _POSIX_C_SOURCE >= 199309
731*199767f8SToomas Soome #define	__POSIX_VISIBLE		199309
732*199767f8SToomas Soome #define	__ISO_C_VISIBLE		1990
733*199767f8SToomas Soome #elif _POSIX_C_SOURCE >= 199209
734*199767f8SToomas Soome #define	__POSIX_VISIBLE		199209
735*199767f8SToomas Soome #define	__ISO_C_VISIBLE		1990
736*199767f8SToomas Soome #elif _POSIX_C_SOURCE >= 199009
737*199767f8SToomas Soome #define	__POSIX_VISIBLE		199009
738*199767f8SToomas Soome #define	__ISO_C_VISIBLE		1990
739*199767f8SToomas Soome #else
740*199767f8SToomas Soome #define	__POSIX_VISIBLE		198808
741*199767f8SToomas Soome #define	__ISO_C_VISIBLE		0
742*199767f8SToomas Soome #endif /* _POSIX_C_SOURCE */
743*199767f8SToomas Soome #else
744*199767f8SToomas Soome /*-
745*199767f8SToomas Soome  * Deal with _ANSI_SOURCE:
746*199767f8SToomas Soome  * If it is defined, and no other compilation environment is explicitly
747*199767f8SToomas Soome  * requested, then define our internal feature-test macros to zero.  This
748*199767f8SToomas Soome  * makes no difference to the preprocessor (undefined symbols in preprocessing
749*199767f8SToomas Soome  * expressions are defined to have value zero), but makes it more convenient for
750*199767f8SToomas Soome  * a test program to print out the values.
751*199767f8SToomas Soome  *
752*199767f8SToomas Soome  * If a program mistakenly defines _ANSI_SOURCE and some other macro such as
753*199767f8SToomas Soome  * _POSIX_C_SOURCE, we will assume that it wants the broader compilation
754*199767f8SToomas Soome  * environment (and in fact we will never get here).
755*199767f8SToomas Soome  */
756*199767f8SToomas Soome #if defined(_ANSI_SOURCE)	/* Hide almost everything. */
757*199767f8SToomas Soome #define	__POSIX_VISIBLE		0
758*199767f8SToomas Soome #define	__XSI_VISIBLE		0
759*199767f8SToomas Soome #define	__BSD_VISIBLE		0
760*199767f8SToomas Soome #define	__ISO_C_VISIBLE		1990
761*199767f8SToomas Soome #elif defined(_C99_SOURCE)	/* Localism to specify strict C99 env. */
762*199767f8SToomas Soome #define	__POSIX_VISIBLE		0
763*199767f8SToomas Soome #define	__XSI_VISIBLE		0
764*199767f8SToomas Soome #define	__BSD_VISIBLE		0
765*199767f8SToomas Soome #define	__ISO_C_VISIBLE		1999
766*199767f8SToomas Soome #elif defined(_C11_SOURCE)	/* Localism to specify strict C11 env. */
767*199767f8SToomas Soome #define	__POSIX_VISIBLE		0
768*199767f8SToomas Soome #define	__XSI_VISIBLE		0
769*199767f8SToomas Soome #define	__BSD_VISIBLE		0
770*199767f8SToomas Soome #define	__ISO_C_VISIBLE		2011
771*199767f8SToomas Soome #else				/* Default environment: show everything. */
772*199767f8SToomas Soome #define	__POSIX_VISIBLE		200809
773*199767f8SToomas Soome #define	__XSI_VISIBLE		700
774*199767f8SToomas Soome #define	__BSD_VISIBLE		1
775*199767f8SToomas Soome #define	__ISO_C_VISIBLE		2011
776*199767f8SToomas Soome #endif
777*199767f8SToomas Soome #endif
778*199767f8SToomas Soome 
779*199767f8SToomas Soome #if defined(__mips) || defined(__powerpc64__) || defined(__riscv__)
780*199767f8SToomas Soome #define	__NO_TLS 1
781*199767f8SToomas Soome #endif
782*199767f8SToomas Soome 
783*199767f8SToomas Soome /*
784*199767f8SToomas Soome  * Type Safety Checking
785*199767f8SToomas Soome  *
786*199767f8SToomas Soome  * Clang provides additional attributes to enable checking type safety
787*199767f8SToomas Soome  * properties that cannot be enforced by the C type system.
788*199767f8SToomas Soome  */
789*199767f8SToomas Soome 
790*199767f8SToomas Soome #if __has_attribute(__argument_with_type_tag__) && \
791*199767f8SToomas Soome     __has_attribute(__type_tag_for_datatype__) && !defined(lint)
792*199767f8SToomas Soome #define	__arg_type_tag(arg_kind, arg_idx, type_tag_idx) \
793*199767f8SToomas Soome 	    __attribute__((__argument_with_type_tag__(arg_kind, arg_idx, type_tag_idx)))
794*199767f8SToomas Soome #define	__datatype_type_tag(kind, type) \
795*199767f8SToomas Soome 	    __attribute__((__type_tag_for_datatype__(kind, type)))
796*199767f8SToomas Soome #else
797*199767f8SToomas Soome #define	__arg_type_tag(arg_kind, arg_idx, type_tag_idx)
798*199767f8SToomas Soome #define	__datatype_type_tag(kind, type)
799*199767f8SToomas Soome #endif
800*199767f8SToomas Soome 
801*199767f8SToomas Soome /*
802*199767f8SToomas Soome  * Lock annotations.
803*199767f8SToomas Soome  *
804*199767f8SToomas Soome  * Clang provides support for doing basic thread-safety tests at
805*199767f8SToomas Soome  * compile-time, by marking which locks will/should be held when
806*199767f8SToomas Soome  * entering/leaving a functions.
807*199767f8SToomas Soome  *
808*199767f8SToomas Soome  * Furthermore, it is also possible to annotate variables and structure
809*199767f8SToomas Soome  * members to enforce that they are only accessed when certain locks are
810*199767f8SToomas Soome  * held.
811*199767f8SToomas Soome  */
812*199767f8SToomas Soome 
813*199767f8SToomas Soome #if __has_extension(c_thread_safety_attributes)
814*199767f8SToomas Soome #define	__lock_annotate(x)	__attribute__((x))
815*199767f8SToomas Soome #else
816*199767f8SToomas Soome #define	__lock_annotate(x)
817*199767f8SToomas Soome #endif
818*199767f8SToomas Soome 
819*199767f8SToomas Soome /* Structure implements a lock. */
820*199767f8SToomas Soome #define	__lockable		__lock_annotate(lockable)
821*199767f8SToomas Soome 
822*199767f8SToomas Soome /* Function acquires an exclusive or shared lock. */
823*199767f8SToomas Soome #define	__locks_exclusive(...) \
824*199767f8SToomas Soome 	__lock_annotate(exclusive_lock_function(__VA_ARGS__))
825*199767f8SToomas Soome #define	__locks_shared(...) \
826*199767f8SToomas Soome 	__lock_annotate(shared_lock_function(__VA_ARGS__))
827*199767f8SToomas Soome 
828*199767f8SToomas Soome /* Function attempts to acquire an exclusive or shared lock. */
829*199767f8SToomas Soome #define	__trylocks_exclusive(...) \
830*199767f8SToomas Soome 	__lock_annotate(exclusive_trylock_function(__VA_ARGS__))
831*199767f8SToomas Soome #define	__trylocks_shared(...) \
832*199767f8SToomas Soome 	__lock_annotate(shared_trylock_function(__VA_ARGS__))
833*199767f8SToomas Soome 
834*199767f8SToomas Soome /* Function releases a lock. */
835*199767f8SToomas Soome #define	__unlocks(...)		__lock_annotate(unlock_function(__VA_ARGS__))
836*199767f8SToomas Soome 
837*199767f8SToomas Soome /* Function asserts that an exclusive or shared lock is held. */
838*199767f8SToomas Soome #define	__asserts_exclusive(...) \
839*199767f8SToomas Soome 	__lock_annotate(assert_exclusive_lock(__VA_ARGS__))
840*199767f8SToomas Soome #define	__asserts_shared(...) \
841*199767f8SToomas Soome 	__lock_annotate(assert_shared_lock(__VA_ARGS__))
842*199767f8SToomas Soome 
843*199767f8SToomas Soome /* Function requires that an exclusive or shared lock is or is not held. */
844*199767f8SToomas Soome #define	__requires_exclusive(...) \
845*199767f8SToomas Soome 	__lock_annotate(exclusive_locks_required(__VA_ARGS__))
846*199767f8SToomas Soome #define	__requires_shared(...) \
847*199767f8SToomas Soome 	__lock_annotate(shared_locks_required(__VA_ARGS__))
848*199767f8SToomas Soome #define	__requires_unlocked(...) \
849*199767f8SToomas Soome 	__lock_annotate(locks_excluded(__VA_ARGS__))
850*199767f8SToomas Soome 
851*199767f8SToomas Soome /* Function should not be analyzed. */
852*199767f8SToomas Soome #define	__no_lock_analysis	__lock_annotate(no_thread_safety_analysis)
853*199767f8SToomas Soome 
854*199767f8SToomas Soome /* Guard variables and structure members by lock. */
855*199767f8SToomas Soome #define	__guarded_by(x)		__lock_annotate(guarded_by(x))
856*199767f8SToomas Soome #define	__pt_guarded_by(x)	__lock_annotate(pt_guarded_by(x))
857*199767f8SToomas Soome 
858*199767f8SToomas Soome #endif /* !_SYS_CDEFS_H_ */
859