Subversion Repositories Kolibri OS

Rev

Rev 6109 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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