| @@ -1,715 +1,716 @@ | | | @@ -1,715 +1,716 @@ |
1 | /* $NetBSD: cdefs.h,v 1.149 2019/11/14 16:23:53 maxv Exp $ */ | | 1 | /* $NetBSD: cdefs.h,v 1.150 2019/12/08 11:48:15 maxv Exp $ */ |
2 | | | 2 | |
3 | /* * Copyright (c) 1991, 1993 | | 3 | /* * Copyright (c) 1991, 1993 |
4 | * The Regents of the University of California. All rights reserved. | | 4 | * The Regents of the University of California. All rights reserved. |
5 | * | | 5 | * |
6 | * This code is derived from software contributed to Berkeley by | | 6 | * This code is derived from software contributed to Berkeley by |
7 | * Berkeley Software Design, Inc. | | 7 | * Berkeley Software Design, Inc. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
15 | * notice, this list of conditions and the following disclaimer in the | | 15 | * notice, this list of conditions and the following disclaimer in the |
16 | * documentation and/or other materials provided with the distribution. | | 16 | * documentation and/or other materials provided with the distribution. |
17 | * 3. Neither the name of the University nor the names of its contributors | | 17 | * 3. Neither the name of the University nor the names of its contributors |
18 | * may be used to endorse or promote products derived from this software | | 18 | * may be used to endorse or promote products derived from this software |
19 | * without specific prior written permission. | | 19 | * without specific prior written permission. |
20 | * | | 20 | * |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
31 | * SUCH DAMAGE. | | 31 | * SUCH DAMAGE. |
32 | * | | 32 | * |
33 | * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 | | 33 | * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 |
34 | */ | | 34 | */ |
35 | | | 35 | |
36 | #ifndef _SYS_CDEFS_H_ | | 36 | #ifndef _SYS_CDEFS_H_ |
37 | #define _SYS_CDEFS_H_ | | 37 | #define _SYS_CDEFS_H_ |
38 | | | 38 | |
39 | #ifdef _KERNEL_OPT | | 39 | #ifdef _KERNEL_OPT |
40 | #include "opt_diagnostic.h" | | 40 | #include "opt_diagnostic.h" |
41 | #include "opt_kasan.h" | | 41 | #include "opt_kasan.h" |
42 | #include "opt_kcsan.h" | | 42 | #include "opt_kcsan.h" |
| | | 43 | #include "opt_kmsan.h" |
43 | #endif | | 44 | #endif |
44 | | | 45 | |
45 | /* | | 46 | /* |
46 | * Macro to test if we're using a GNU C compiler of a specific vintage | | 47 | * Macro to test if we're using a GNU C compiler of a specific vintage |
47 | * or later, for e.g. features that appeared in a particular version | | 48 | * or later, for e.g. features that appeared in a particular version |
48 | * of GNU C. Usage: | | 49 | * of GNU C. Usage: |
49 | * | | 50 | * |
50 | * #if __GNUC_PREREQ__(major, minor) | | 51 | * #if __GNUC_PREREQ__(major, minor) |
51 | * ...cool feature... | | 52 | * ...cool feature... |
52 | * #else | | 53 | * #else |
53 | * ...delete feature... | | 54 | * ...delete feature... |
54 | * #endif | | 55 | * #endif |
55 | */ | | 56 | */ |
56 | #ifdef __GNUC__ | | 57 | #ifdef __GNUC__ |
57 | #define __GNUC_PREREQ__(x, y) \ | | 58 | #define __GNUC_PREREQ__(x, y) \ |
58 | ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ | | 59 | ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ |
59 | (__GNUC__ > (x))) | | 60 | (__GNUC__ > (x))) |
60 | #else | | 61 | #else |
61 | #define __GNUC_PREREQ__(x, y) 0 | | 62 | #define __GNUC_PREREQ__(x, y) 0 |
62 | #endif | | 63 | #endif |
63 | | | 64 | |
64 | /* | | 65 | /* |
65 | * Macros to test Clang/LLVM features. | | 66 | * Macros to test Clang/LLVM features. |
66 | * Usage: | | 67 | * Usage: |
67 | * | | 68 | * |
68 | * #if __has_feature(safe_stack) | | 69 | * #if __has_feature(safe_stack) |
69 | * ...SafeStack specific code... | | 70 | * ...SafeStack specific code... |
70 | * #else | | 71 | * #else |
71 | * ..regular code... | | 72 | * ..regular code... |
72 | * #endif | | 73 | * #endif |
73 | */ | | 74 | */ |
74 | #ifndef __has_feature | | 75 | #ifndef __has_feature |
75 | #define __has_feature(x) 0 | | 76 | #define __has_feature(x) 0 |
76 | #endif | | 77 | #endif |
77 | | | 78 | |
78 | #ifndef __has_extension | | 79 | #ifndef __has_extension |
79 | #define __has_extension __has_feature /* Compat with pre-3.0 Clang */ | | 80 | #define __has_extension __has_feature /* Compat with pre-3.0 Clang */ |
80 | #endif | | 81 | #endif |
81 | | | 82 | |
82 | #include <machine/cdefs.h> | | 83 | #include <machine/cdefs.h> |
83 | #ifdef __ELF__ | | 84 | #ifdef __ELF__ |
84 | #include <sys/cdefs_elf.h> | | 85 | #include <sys/cdefs_elf.h> |
85 | #else | | 86 | #else |
86 | #include <sys/cdefs_aout.h> | | 87 | #include <sys/cdefs_aout.h> |
87 | #endif | | 88 | #endif |
88 | | | 89 | |
89 | #ifdef __GNUC__ | | 90 | #ifdef __GNUC__ |
90 | #define __strict_weak_alias(alias,sym) \ | | 91 | #define __strict_weak_alias(alias,sym) \ |
91 | __unused static __typeof__(alias) *__weak_alias_##alias = &sym; \ | | 92 | __unused static __typeof__(alias) *__weak_alias_##alias = &sym; \ |
92 | __weak_alias(alias,sym) | | 93 | __weak_alias(alias,sym) |
93 | #else | | 94 | #else |
94 | #define __strict_weak_alias(alias,sym) __weak_alias(alias,sym) | | 95 | #define __strict_weak_alias(alias,sym) __weak_alias(alias,sym) |
95 | #endif | | 96 | #endif |
96 | | | 97 | |
97 | /* | | 98 | /* |
98 | * Optional marker for size-optimised MD calling convention. | | 99 | * Optional marker for size-optimised MD calling convention. |
99 | */ | | 100 | */ |
100 | #ifndef __compactcall | | 101 | #ifndef __compactcall |
101 | #define __compactcall | | 102 | #define __compactcall |
102 | #endif | | 103 | #endif |
103 | | | 104 | |
104 | /* | | 105 | /* |
105 | * The __CONCAT macro is used to concatenate parts of symbol names, e.g. | | 106 | * The __CONCAT macro is used to concatenate parts of symbol names, e.g. |
106 | * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. | | 107 | * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. |
107 | * The __CONCAT macro is a bit tricky -- make sure you don't put spaces | | 108 | * The __CONCAT macro is a bit tricky -- make sure you don't put spaces |
108 | * in between its arguments. __CONCAT can also concatenate double-quoted | | 109 | * in between its arguments. __CONCAT can also concatenate double-quoted |
109 | * strings produced by the __STRING macro, but this only works with ANSI C. | | 110 | * strings produced by the __STRING macro, but this only works with ANSI C. |
110 | */ | | 111 | */ |
111 | | | 112 | |
112 | #define ___STRING(x) __STRING(x) | | 113 | #define ___STRING(x) __STRING(x) |
113 | #define ___CONCAT(x,y) __CONCAT(x,y) | | 114 | #define ___CONCAT(x,y) __CONCAT(x,y) |
114 | | | 115 | |
115 | #if __STDC__ || defined(__cplusplus) | | 116 | #if __STDC__ || defined(__cplusplus) |
116 | #define __P(protos) protos /* full-blown ANSI C */ | | 117 | #define __P(protos) protos /* full-blown ANSI C */ |
117 | #define __CONCAT(x,y) x ## y | | 118 | #define __CONCAT(x,y) x ## y |
118 | #define __STRING(x) #x | | 119 | #define __STRING(x) #x |
119 | | | 120 | |
120 | #define __const const /* define reserved names to standard */ | | 121 | #define __const const /* define reserved names to standard */ |
121 | #define __signed signed | | 122 | #define __signed signed |
122 | #define __volatile volatile | | 123 | #define __volatile volatile |
123 | #if defined(__cplusplus) || defined(__PCC__) | | 124 | #if defined(__cplusplus) || defined(__PCC__) |
124 | #define __inline inline /* convert to C++/C99 keyword */ | | 125 | #define __inline inline /* convert to C++/C99 keyword */ |
125 | #else | | 126 | #else |
126 | #if !defined(__GNUC__) && !defined(__lint__) | | 127 | #if !defined(__GNUC__) && !defined(__lint__) |
127 | #define __inline /* delete GCC keyword */ | | 128 | #define __inline /* delete GCC keyword */ |
128 | #endif /* !__GNUC__ && !__lint__ */ | | 129 | #endif /* !__GNUC__ && !__lint__ */ |
129 | #endif /* !__cplusplus */ | | 130 | #endif /* !__cplusplus */ |
130 | | | 131 | |
131 | #else /* !(__STDC__ || __cplusplus) */ | | 132 | #else /* !(__STDC__ || __cplusplus) */ |
132 | #define __P(protos) () /* traditional C preprocessor */ | | 133 | #define __P(protos) () /* traditional C preprocessor */ |
133 | #define __CONCAT(x,y) x/**/y | | 134 | #define __CONCAT(x,y) x/**/y |
134 | #define __STRING(x) "x" | | 135 | #define __STRING(x) "x" |
135 | | | 136 | |
136 | #ifndef __GNUC__ | | 137 | #ifndef __GNUC__ |
137 | #define __const /* delete pseudo-ANSI C keywords */ | | 138 | #define __const /* delete pseudo-ANSI C keywords */ |
138 | #define __inline | | 139 | #define __inline |
139 | #define __signed | | 140 | #define __signed |
140 | #define __volatile | | 141 | #define __volatile |
141 | #endif /* !__GNUC__ */ | | 142 | #endif /* !__GNUC__ */ |
142 | | | 143 | |
143 | /* | | 144 | /* |
144 | * In non-ANSI C environments, new programs will want ANSI-only C keywords | | 145 | * In non-ANSI C environments, new programs will want ANSI-only C keywords |
145 | * deleted from the program and old programs will want them left alone. | | 146 | * deleted from the program and old programs will want them left alone. |
146 | * Programs using the ANSI C keywords const, inline etc. as normal | | 147 | * Programs using the ANSI C keywords const, inline etc. as normal |
147 | * identifiers should define -DNO_ANSI_KEYWORDS. | | 148 | * identifiers should define -DNO_ANSI_KEYWORDS. |
148 | */ | | 149 | */ |
149 | #ifndef NO_ANSI_KEYWORDS | | 150 | #ifndef NO_ANSI_KEYWORDS |
150 | #define const __const /* convert ANSI C keywords */ | | 151 | #define const __const /* convert ANSI C keywords */ |
151 | #define inline __inline | | 152 | #define inline __inline |
152 | #define signed __signed | | 153 | #define signed __signed |
153 | #define volatile __volatile | | 154 | #define volatile __volatile |
154 | #endif /* !NO_ANSI_KEYWORDS */ | | 155 | #endif /* !NO_ANSI_KEYWORDS */ |
155 | #endif /* !(__STDC__ || __cplusplus) */ | | 156 | #endif /* !(__STDC__ || __cplusplus) */ |
156 | | | 157 | |
157 | /* | | 158 | /* |
158 | * Used for internal auditing of the NetBSD source tree. | | 159 | * Used for internal auditing of the NetBSD source tree. |
159 | */ | | 160 | */ |
160 | #ifdef __AUDIT__ | | 161 | #ifdef __AUDIT__ |
161 | #define __aconst __const | | 162 | #define __aconst __const |
162 | #else | | 163 | #else |
163 | #define __aconst | | 164 | #define __aconst |
164 | #endif | | 165 | #endif |
165 | | | 166 | |
166 | /* | | 167 | /* |
167 | * Compile Time Assertion. | | 168 | * Compile Time Assertion. |
168 | */ | | 169 | */ |
169 | #ifdef __COUNTER__ | | 170 | #ifdef __COUNTER__ |
170 | #define __CTASSERT(x) __CTASSERT0(x, __ctassert, __COUNTER__) | | 171 | #define __CTASSERT(x) __CTASSERT0(x, __ctassert, __COUNTER__) |
171 | #else | | 172 | #else |
172 | #define __CTASSERT(x) __CTASSERT99(x, __INCLUDE_LEVEL__, __LINE__) | | 173 | #define __CTASSERT(x) __CTASSERT99(x, __INCLUDE_LEVEL__, __LINE__) |
173 | #define __CTASSERT99(x, a, b) __CTASSERT0(x, __CONCAT(__ctassert,a), \ | | 174 | #define __CTASSERT99(x, a, b) __CTASSERT0(x, __CONCAT(__ctassert,a), \ |
174 | __CONCAT(_,b)) | | 175 | __CONCAT(_,b)) |
175 | #endif | | 176 | #endif |
176 | #define __CTASSERT0(x, y, z) __CTASSERT1(x, y, z) | | 177 | #define __CTASSERT0(x, y, z) __CTASSERT1(x, y, z) |
177 | #define __CTASSERT1(x, y, z) \ | | 178 | #define __CTASSERT1(x, y, z) \ |
178 | typedef struct { \ | | 179 | typedef struct { \ |
179 | unsigned int y ## z : /*CONSTCOND*/(x) ? 1 : -1; \ | | 180 | unsigned int y ## z : /*CONSTCOND*/(x) ? 1 : -1; \ |
180 | } y ## z ## _struct __unused | | 181 | } y ## z ## _struct __unused |
181 | | | 182 | |
182 | /* | | 183 | /* |
183 | * The following macro is used to remove const cast-away warnings | | 184 | * The following macro is used to remove const cast-away warnings |
184 | * from gcc -Wcast-qual; it should be used with caution because it | | 185 | * from gcc -Wcast-qual; it should be used with caution because it |
185 | * can hide valid errors; in particular most valid uses are in | | 186 | * can hide valid errors; in particular most valid uses are in |
186 | * situations where the API requires it, not to cast away string | | 187 | * situations where the API requires it, not to cast away string |
187 | * constants. We don't use *intptr_t on purpose here and we are | | 188 | * constants. We don't use *intptr_t on purpose here and we are |
188 | * explicit about unsigned long so that we don't have additional | | 189 | * explicit about unsigned long so that we don't have additional |
189 | * dependencies. | | 190 | * dependencies. |
190 | */ | | 191 | */ |
191 | #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) | | 192 | #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) |
192 | | | 193 | |
193 | /* | | 194 | /* |
194 | * The following macro is used to remove the volatile cast-away warnings | | 195 | * The following macro is used to remove the volatile cast-away warnings |
195 | * from gcc -Wcast-qual; as above it should be used with caution | | 196 | * from gcc -Wcast-qual; as above it should be used with caution |
196 | * because it can hide valid errors or warnings. Valid uses include | | 197 | * because it can hide valid errors or warnings. Valid uses include |
197 | * making it possible to pass a volatile pointer to memset(). | | 198 | * making it possible to pass a volatile pointer to memset(). |
198 | * For the same reasons as above, we use unsigned long and not intptr_t. | | 199 | * For the same reasons as above, we use unsigned long and not intptr_t. |
199 | */ | | 200 | */ |
200 | #define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a)) | | 201 | #define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a)) |
201 | | | 202 | |
202 | /* | | 203 | /* |
203 | * The following macro is used to remove the the function type cast warnings | | 204 | * The following macro is used to remove the the function type cast warnings |
204 | * from gcc -Wcast-function-type and as above should be used with caution. | | 205 | * from gcc -Wcast-function-type and as above should be used with caution. |
205 | */ | | 206 | */ |
206 | #define __FPTRCAST(t, f) ((t)(void *)(f)) | | 207 | #define __FPTRCAST(t, f) ((t)(void *)(f)) |
207 | | | 208 | |
208 | /* | | 209 | /* |
209 | * GCC2 provides __extension__ to suppress warnings for various GNU C | | 210 | * GCC2 provides __extension__ to suppress warnings for various GNU C |
210 | * language extensions under "-ansi -pedantic". | | 211 | * language extensions under "-ansi -pedantic". |
211 | */ | | 212 | */ |
212 | #if !__GNUC_PREREQ__(2, 0) | | 213 | #if !__GNUC_PREREQ__(2, 0) |
213 | #define __extension__ /* delete __extension__ if non-gcc or gcc1 */ | | 214 | #define __extension__ /* delete __extension__ if non-gcc or gcc1 */ |
214 | #endif | | 215 | #endif |
215 | | | 216 | |
216 | /* | | 217 | /* |
217 | * GCC1 and some versions of GCC2 declare dead (non-returning) and | | 218 | * GCC1 and some versions of GCC2 declare dead (non-returning) and |
218 | * pure (no side effects) functions using "volatile" and "const"; | | 219 | * pure (no side effects) functions using "volatile" and "const"; |
219 | * unfortunately, these then cause warnings under "-ansi -pedantic". | | 220 | * unfortunately, these then cause warnings under "-ansi -pedantic". |
220 | * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of | | 221 | * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of |
221 | * these work for GNU C++ (modulo a slight glitch in the C++ grammar | | 222 | * these work for GNU C++ (modulo a slight glitch in the C++ grammar |
222 | * in the distribution version of 2.5.5). | | 223 | * in the distribution version of 2.5.5). |
223 | * | | 224 | * |
224 | * GCC defines a pure function as depending only on its arguments and | | 225 | * GCC defines a pure function as depending only on its arguments and |
225 | * global variables. Typical examples are strlen and sqrt. | | 226 | * global variables. Typical examples are strlen and sqrt. |
226 | * | | 227 | * |
227 | * GCC defines a const function as depending only on its arguments. | | 228 | * GCC defines a const function as depending only on its arguments. |
228 | * Therefore calling a const function again with identical arguments | | 229 | * Therefore calling a const function again with identical arguments |
229 | * will always produce the same result. | | 230 | * will always produce the same result. |
230 | * | | 231 | * |
231 | * Rounding modes for floating point operations are considered global | | 232 | * Rounding modes for floating point operations are considered global |
232 | * variables and prevent sqrt from being a const function. | | 233 | * variables and prevent sqrt from being a const function. |
233 | * | | 234 | * |
234 | * Calls to const functions can be optimised away and moved around | | 235 | * Calls to const functions can be optimised away and moved around |
235 | * without limitations. | | 236 | * without limitations. |
236 | */ | | 237 | */ |
237 | #if !__GNUC_PREREQ__(2, 0) && !defined(__lint__) | | 238 | #if !__GNUC_PREREQ__(2, 0) && !defined(__lint__) |
238 | #define __attribute__(x) | | 239 | #define __attribute__(x) |
239 | #endif | | 240 | #endif |
240 | | | 241 | |
241 | #if __GNUC_PREREQ__(2, 5) || defined(__lint__) | | 242 | #if __GNUC_PREREQ__(2, 5) || defined(__lint__) |
242 | #define __dead __attribute__((__noreturn__)) | | 243 | #define __dead __attribute__((__noreturn__)) |
243 | #elif defined(__GNUC__) | | 244 | #elif defined(__GNUC__) |
244 | #define __dead __volatile | | 245 | #define __dead __volatile |
245 | #else | | 246 | #else |
246 | #define __dead | | 247 | #define __dead |
247 | #endif | | 248 | #endif |
248 | | | 249 | |
249 | #if __GNUC_PREREQ__(2, 96) || defined(__lint__) | | 250 | #if __GNUC_PREREQ__(2, 96) || defined(__lint__) |
250 | #define __pure __attribute__((__pure__)) | | 251 | #define __pure __attribute__((__pure__)) |
251 | #elif defined(__GNUC__) | | 252 | #elif defined(__GNUC__) |
252 | #define __pure __const | | 253 | #define __pure __const |
253 | #else | | 254 | #else |
254 | #define __pure | | 255 | #define __pure |
255 | #endif | | 256 | #endif |
256 | | | 257 | |
257 | #if __GNUC_PREREQ__(2, 5) || defined(__lint__) | | 258 | #if __GNUC_PREREQ__(2, 5) || defined(__lint__) |
258 | #define __constfunc __attribute__((__const__)) | | 259 | #define __constfunc __attribute__((__const__)) |
259 | #else | | 260 | #else |
260 | #define __constfunc | | 261 | #define __constfunc |
261 | #endif | | 262 | #endif |
262 | | | 263 | |
263 | #if __GNUC_PREREQ__(3, 0) || defined(__lint__) | | 264 | #if __GNUC_PREREQ__(3, 0) || defined(__lint__) |
264 | #define __noinline __attribute__((__noinline__)) | | 265 | #define __noinline __attribute__((__noinline__)) |
265 | #else | | 266 | #else |
266 | #define __noinline /* nothing */ | | 267 | #define __noinline /* nothing */ |
267 | #endif | | 268 | #endif |
268 | | | 269 | |
269 | #if __GNUC_PREREQ__(3, 0) || defined(__lint__) | | 270 | #if __GNUC_PREREQ__(3, 0) || defined(__lint__) |
270 | #define __always_inline __attribute__((__always_inline__)) | | 271 | #define __always_inline __attribute__((__always_inline__)) |
271 | #else | | 272 | #else |
272 | #define __always_inline /* nothing */ | | 273 | #define __always_inline /* nothing */ |
273 | #endif | | 274 | #endif |
274 | | | 275 | |
275 | #if __GNUC_PREREQ__(4, 1) || defined(__lint__) | | 276 | #if __GNUC_PREREQ__(4, 1) || defined(__lint__) |
276 | #define __returns_twice __attribute__((__returns_twice__)) | | 277 | #define __returns_twice __attribute__((__returns_twice__)) |
277 | #else | | 278 | #else |
278 | #define __returns_twice /* nothing */ | | 279 | #define __returns_twice /* nothing */ |
279 | #endif | | 280 | #endif |
280 | | | 281 | |
281 | #if __GNUC_PREREQ__(4, 5) || defined(__lint__) | | 282 | #if __GNUC_PREREQ__(4, 5) || defined(__lint__) |
282 | #define __noclone __attribute__((__noclone__)) | | 283 | #define __noclone __attribute__((__noclone__)) |
283 | #else | | 284 | #else |
284 | #define __noclone /* nothing */ | | 285 | #define __noclone /* nothing */ |
285 | #endif | | 286 | #endif |
286 | | | 287 | |
287 | /* | | 288 | /* |
288 | * __unused: Note that item or function might be unused. | | 289 | * __unused: Note that item or function might be unused. |
289 | */ | | 290 | */ |
290 | #if __GNUC_PREREQ__(2, 7) || defined(__lint__) | | 291 | #if __GNUC_PREREQ__(2, 7) || defined(__lint__) |
291 | #define __unused __attribute__((__unused__)) | | 292 | #define __unused __attribute__((__unused__)) |
292 | #else | | 293 | #else |
293 | #define __unused /* delete */ | | 294 | #define __unused /* delete */ |
294 | #endif | | 295 | #endif |
295 | | | 296 | |
296 | /* | | 297 | /* |
297 | * __used: Note that item is needed, even if it appears to be unused. | | 298 | * __used: Note that item is needed, even if it appears to be unused. |
298 | */ | | 299 | */ |
299 | #if __GNUC_PREREQ__(3, 1) || defined(__lint__) | | 300 | #if __GNUC_PREREQ__(3, 1) || defined(__lint__) |
300 | #define __used __attribute__((__used__)) | | 301 | #define __used __attribute__((__used__)) |
301 | #else | | 302 | #else |
302 | #define __used __unused | | 303 | #define __used __unused |
303 | #endif | | 304 | #endif |
304 | | | 305 | |
305 | /* | | 306 | /* |
306 | * __diagused: Note that item is used in diagnostic code, but may be | | 307 | * __diagused: Note that item is used in diagnostic code, but may be |
307 | * unused in non-diagnostic code. | | 308 | * unused in non-diagnostic code. |
308 | */ | | 309 | */ |
309 | #if (defined(_KERNEL) && defined(DIAGNOSTIC)) \ | | 310 | #if (defined(_KERNEL) && defined(DIAGNOSTIC)) \ |
310 | || (!defined(_KERNEL) && !defined(NDEBUG)) | | 311 | || (!defined(_KERNEL) && !defined(NDEBUG)) |
311 | #define __diagused /* empty */ | | 312 | #define __diagused /* empty */ |
312 | #else | | 313 | #else |
313 | #define __diagused __unused | | 314 | #define __diagused __unused |
314 | #endif | | 315 | #endif |
315 | | | 316 | |
316 | /* | | 317 | /* |
317 | * __debugused: Note that item is used in debug code, but may be | | 318 | * __debugused: Note that item is used in debug code, but may be |
318 | * unused in non-debug code. | | 319 | * unused in non-debug code. |
319 | */ | | 320 | */ |
320 | #if defined(DEBUG) | | 321 | #if defined(DEBUG) |
321 | #define __debugused /* empty */ | | 322 | #define __debugused /* empty */ |
322 | #else | | 323 | #else |
323 | #define __debugused __unused | | 324 | #define __debugused __unused |
324 | #endif | | 325 | #endif |
325 | | | 326 | |
326 | #if __GNUC_PREREQ__(3, 1) || defined(__lint__) | | 327 | #if __GNUC_PREREQ__(3, 1) || defined(__lint__) |
327 | #define __noprofile __attribute__((__no_instrument_function__)) | | 328 | #define __noprofile __attribute__((__no_instrument_function__)) |
328 | #else | | 329 | #else |
329 | #define __noprofile /* nothing */ | | 330 | #define __noprofile /* nothing */ |
330 | #endif | | 331 | #endif |
331 | | | 332 | |
332 | #if __GNUC_PREREQ__(4, 6) || defined(__clang__) || defined(__lint__) | | 333 | #if __GNUC_PREREQ__(4, 6) || defined(__clang__) || defined(__lint__) |
333 | #define __unreachable() __builtin_unreachable() | | 334 | #define __unreachable() __builtin_unreachable() |
334 | #else | | 335 | #else |
335 | #define __unreachable() do {} while (/*CONSTCOND*/0) | | 336 | #define __unreachable() do {} while (/*CONSTCOND*/0) |
336 | #endif | | 337 | #endif |
337 | | | 338 | |
338 | #if defined(_KERNEL) | | 339 | #if defined(_KERNEL) |
339 | #if __GNUC_PREREQ__(4, 9) && defined(KASAN) | | 340 | #if __GNUC_PREREQ__(4, 9) && defined(KASAN) |
340 | #define __noasan __attribute__((no_sanitize_address)) | | 341 | #define __noasan __attribute__((no_sanitize_address)) |
341 | #else | | 342 | #else |
342 | #define __noasan /* nothing */ | | 343 | #define __noasan /* nothing */ |
343 | #endif | | 344 | #endif |
344 | | | 345 | |
345 | #if __GNUC_PREREQ__(4, 9) && defined(KCSAN) | | 346 | #if __GNUC_PREREQ__(4, 9) && defined(KCSAN) |
346 | #define __nocsan __attribute__((no_sanitize_thread)) | | 347 | #define __nocsan __attribute__((no_sanitize_thread)) |
347 | #else | | 348 | #else |
348 | #define __nocsan /* nothing */ | | 349 | #define __nocsan /* nothing */ |
349 | #endif | | 350 | #endif |
350 | | | 351 | |
351 | #if defined(__clang__) && defined(KMSAN) | | 352 | #if defined(__clang__) && defined(KMSAN) |
352 | #define __nomsan __attribute__((no_sanitize("memory"))) | | 353 | #define __nomsan __attribute__((no_sanitize("kernel-memory"))) |
353 | #else | | 354 | #else |
354 | #define __nomsan /* nothing */ | | 355 | #define __nomsan /* nothing */ |
355 | #endif | | 356 | #endif |
356 | | | 357 | |
357 | #if defined(__clang__) | | 358 | #if defined(__clang__) |
358 | #define __noubsan __attribute__((no_sanitize("undefined"))) | | 359 | #define __noubsan __attribute__((no_sanitize("undefined"))) |
359 | #elif __GNUC_PREREQ__(4, 9) | | 360 | #elif __GNUC_PREREQ__(4, 9) |
360 | #define __noubsan __attribute__((no_sanitize_undefined)) | | 361 | #define __noubsan __attribute__((no_sanitize_undefined)) |
361 | #else | | 362 | #else |
362 | #define __noubsan /* nothing */ | | 363 | #define __noubsan /* nothing */ |
363 | #endif | | 364 | #endif |
364 | #endif | | 365 | #endif |
365 | | | 366 | |
366 | #if defined(__COVERITY__) || \ | | 367 | #if defined(__COVERITY__) || \ |
367 | __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) ||\ | | 368 | __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) ||\ |
368 | __has_feature(leak_sanitizer) || defined(__SANITIZE_LEAK__) | | 369 | __has_feature(leak_sanitizer) || defined(__SANITIZE_LEAK__) |
369 | #define __NO_LEAKS | | 370 | #define __NO_LEAKS |
370 | #endif | | 371 | #endif |
371 | | | 372 | |
372 | /* | | 373 | /* |
373 | * To be used when an empty body is required like: | | 374 | * To be used when an empty body is required like: |
374 | * | | 375 | * |
375 | * #ifdef DEBUG | | 376 | * #ifdef DEBUG |
376 | * # define dprintf(a) printf(a) | | 377 | * # define dprintf(a) printf(a) |
377 | * #else | | 378 | * #else |
378 | * # define dprintf(a) __nothing | | 379 | * # define dprintf(a) __nothing |
379 | * #endif | | 380 | * #endif |
380 | * | | 381 | * |
381 | * We use ((void)0) instead of do {} while (0) so that it | | 382 | * We use ((void)0) instead of do {} while (0) so that it |
382 | * works on , expressions. | | 383 | * works on , expressions. |
383 | */ | | 384 | */ |
384 | #define __nothing (/*LINTED*/(void)0) | | 385 | #define __nothing (/*LINTED*/(void)0) |
385 | | | 386 | |
386 | #if defined(__cplusplus) | | 387 | #if defined(__cplusplus) |
387 | #define __BEGIN_EXTERN_C extern "C" { | | 388 | #define __BEGIN_EXTERN_C extern "C" { |
388 | #define __END_EXTERN_C } | | 389 | #define __END_EXTERN_C } |
389 | #define __static_cast(x,y) static_cast<x>(y) | | 390 | #define __static_cast(x,y) static_cast<x>(y) |
390 | #else | | 391 | #else |
391 | #define __BEGIN_EXTERN_C | | 392 | #define __BEGIN_EXTERN_C |
392 | #define __END_EXTERN_C | | 393 | #define __END_EXTERN_C |
393 | #define __static_cast(x,y) (x)y | | 394 | #define __static_cast(x,y) (x)y |
394 | #endif | | 395 | #endif |
395 | | | 396 | |
396 | #if __GNUC_PREREQ__(4, 0) || defined(__lint__) | | 397 | #if __GNUC_PREREQ__(4, 0) || defined(__lint__) |
397 | # define __dso_public __attribute__((__visibility__("default"))) | | 398 | # define __dso_public __attribute__((__visibility__("default"))) |
398 | # define __dso_hidden __attribute__((__visibility__("hidden"))) | | 399 | # define __dso_hidden __attribute__((__visibility__("hidden"))) |
399 | # define __BEGIN_PUBLIC_DECLS \ | | 400 | # define __BEGIN_PUBLIC_DECLS \ |
400 | _Pragma("GCC visibility push(default)") __BEGIN_EXTERN_C | | 401 | _Pragma("GCC visibility push(default)") __BEGIN_EXTERN_C |
401 | # define __END_PUBLIC_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") | | 402 | # define __END_PUBLIC_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") |
402 | # define __BEGIN_HIDDEN_DECLS \ | | 403 | # define __BEGIN_HIDDEN_DECLS \ |
403 | _Pragma("GCC visibility push(hidden)") __BEGIN_EXTERN_C | | 404 | _Pragma("GCC visibility push(hidden)") __BEGIN_EXTERN_C |
404 | # define __END_HIDDEN_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") | | 405 | # define __END_HIDDEN_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") |
405 | #else | | 406 | #else |
406 | # define __dso_public | | 407 | # define __dso_public |
407 | # define __dso_hidden | | 408 | # define __dso_hidden |
408 | # define __BEGIN_PUBLIC_DECLS __BEGIN_EXTERN_C | | 409 | # define __BEGIN_PUBLIC_DECLS __BEGIN_EXTERN_C |
409 | # define __END_PUBLIC_DECLS __END_EXTERN_C | | 410 | # define __END_PUBLIC_DECLS __END_EXTERN_C |
410 | # define __BEGIN_HIDDEN_DECLS __BEGIN_EXTERN_C | | 411 | # define __BEGIN_HIDDEN_DECLS __BEGIN_EXTERN_C |
411 | # define __END_HIDDEN_DECLS __END_EXTERN_C | | 412 | # define __END_HIDDEN_DECLS __END_EXTERN_C |
412 | #endif | | 413 | #endif |
413 | #if __GNUC_PREREQ__(4, 2) || defined(__lint__) | | 414 | #if __GNUC_PREREQ__(4, 2) || defined(__lint__) |
414 | # define __dso_protected __attribute__((__visibility__("protected"))) | | 415 | # define __dso_protected __attribute__((__visibility__("protected"))) |
415 | #else | | 416 | #else |
416 | # define __dso_protected | | 417 | # define __dso_protected |
417 | #endif | | 418 | #endif |
418 | | | 419 | |
419 | #define __BEGIN_DECLS __BEGIN_PUBLIC_DECLS | | 420 | #define __BEGIN_DECLS __BEGIN_PUBLIC_DECLS |
420 | #define __END_DECLS __END_PUBLIC_DECLS | | 421 | #define __END_DECLS __END_PUBLIC_DECLS |
421 | | | 422 | |
422 | /* | | 423 | /* |
423 | * Non-static C99 inline functions are optional bodies. They don't | | 424 | * Non-static C99 inline functions are optional bodies. They don't |
424 | * create global symbols if not used, but can be replaced if desirable. | | 425 | * create global symbols if not used, but can be replaced if desirable. |
425 | * This differs from the behavior of GCC before version 4.3. The nearest | | 426 | * This differs from the behavior of GCC before version 4.3. The nearest |
426 | * equivalent for older GCC is `extern inline'. For newer GCC, use the | | 427 | * equivalent for older GCC is `extern inline'. For newer GCC, use the |
427 | * gnu_inline attribute additionally to get the old behavior. | | 428 | * gnu_inline attribute additionally to get the old behavior. |
428 | * | | 429 | * |
429 | * For C99 compilers other than GCC, the C99 behavior is expected. | | 430 | * For C99 compilers other than GCC, the C99 behavior is expected. |
430 | */ | | 431 | */ |
431 | #if defined(__GNUC__) && defined(__GNUC_STDC_INLINE__) | | 432 | #if defined(__GNUC__) && defined(__GNUC_STDC_INLINE__) |
432 | #define __c99inline extern __attribute__((__gnu_inline__)) __inline | | 433 | #define __c99inline extern __attribute__((__gnu_inline__)) __inline |
433 | #elif defined(__GNUC__) | | 434 | #elif defined(__GNUC__) |
434 | #define __c99inline extern __inline | | 435 | #define __c99inline extern __inline |
435 | #elif defined(__STDC_VERSION__) || defined(__lint__) | | 436 | #elif defined(__STDC_VERSION__) || defined(__lint__) |
436 | #define __c99inline __inline | | 437 | #define __c99inline __inline |
437 | #endif | | 438 | #endif |
438 | | | 439 | |
439 | #if defined(__lint__) | | 440 | #if defined(__lint__) |
440 | #define __thread /* delete */ | | 441 | #define __thread /* delete */ |
441 | #define __packed __packed | | 442 | #define __packed __packed |
442 | #define __aligned(x) /* delete */ | | 443 | #define __aligned(x) /* delete */ |
443 | #define __section(x) /* delete */ | | 444 | #define __section(x) /* delete */ |
444 | #elif __GNUC_PREREQ__(2, 7) || defined(__PCC__) || defined(__lint__) | | 445 | #elif __GNUC_PREREQ__(2, 7) || defined(__PCC__) || defined(__lint__) |
445 | #define __packed __attribute__((__packed__)) | | 446 | #define __packed __attribute__((__packed__)) |
446 | #define __aligned(x) __attribute__((__aligned__(x))) | | 447 | #define __aligned(x) __attribute__((__aligned__(x))) |
447 | #define __section(x) __attribute__((__section__(x))) | | 448 | #define __section(x) __attribute__((__section__(x))) |
448 | #elif defined(_MSC_VER) | | 449 | #elif defined(_MSC_VER) |
449 | #define __packed /* ignore */ | | 450 | #define __packed /* ignore */ |
450 | #else | | 451 | #else |
451 | #define __packed error: no __packed for this compiler | | 452 | #define __packed error: no __packed for this compiler |
452 | #define __aligned(x) error: no __aligned for this compiler | | 453 | #define __aligned(x) error: no __aligned for this compiler |
453 | #define __section(x) error: no __section for this compiler | | 454 | #define __section(x) error: no __section for this compiler |
454 | #endif | | 455 | #endif |
455 | | | 456 | |
456 | /* | | 457 | /* |
457 | * C99 defines the restrict type qualifier keyword, which was made available | | 458 | * C99 defines the restrict type qualifier keyword, which was made available |
458 | * in GCC 2.92. | | 459 | * in GCC 2.92. |
459 | */ | | 460 | */ |
460 | #if defined(__lint__) | | 461 | #if defined(__lint__) |
461 | #define __restrict /* delete __restrict when not supported */ | | 462 | #define __restrict /* delete __restrict when not supported */ |
462 | #elif __STDC_VERSION__ >= 199901L | | 463 | #elif __STDC_VERSION__ >= 199901L |
463 | #define __restrict restrict | | 464 | #define __restrict restrict |
464 | #elif __GNUC_PREREQ__(2, 92) || defined(__lint__) | | 465 | #elif __GNUC_PREREQ__(2, 92) || defined(__lint__) |
465 | #define __restrict __restrict__ | | 466 | #define __restrict __restrict__ |
466 | #else | | 467 | #else |
467 | #define __restrict /* delete __restrict when not supported */ | | 468 | #define __restrict /* delete __restrict when not supported */ |
468 | #endif | | 469 | #endif |
469 | | | 470 | |
470 | /* | | 471 | /* |
471 | * C99 and C++11 define __func__ predefined identifier, which was made | | 472 | * C99 and C++11 define __func__ predefined identifier, which was made |
472 | * available in GCC 2.95. | | 473 | * available in GCC 2.95. |
473 | */ | | 474 | */ |
474 | #if !(__STDC_VERSION__ >= 199901L) && !(__cplusplus - 0 >= 201103L) | | 475 | #if !(__STDC_VERSION__ >= 199901L) && !(__cplusplus - 0 >= 201103L) |
475 | #if __GNUC_PREREQ__(2, 4) || defined(__lint__) | | 476 | #if __GNUC_PREREQ__(2, 4) || defined(__lint__) |
476 | #define __func__ __FUNCTION__ | | 477 | #define __func__ __FUNCTION__ |
477 | #else | | 478 | #else |
478 | #define __func__ "" | | 479 | #define __func__ "" |
479 | #endif | | 480 | #endif |
480 | #endif /* !(__STDC_VERSION__ >= 199901L) && !(__cplusplus - 0 >= 201103L) */ | | 481 | #endif /* !(__STDC_VERSION__ >= 199901L) && !(__cplusplus - 0 >= 201103L) */ |
481 | | | 482 | |
482 | #if defined(_KERNEL) | | 483 | #if defined(_KERNEL) |
483 | #if defined(NO_KERNEL_RCSIDS) | | 484 | #if defined(NO_KERNEL_RCSIDS) |
484 | #undef __KERNEL_RCSID | | 485 | #undef __KERNEL_RCSID |
485 | #define __KERNEL_RCSID(_n, _s) /* nothing */ | | 486 | #define __KERNEL_RCSID(_n, _s) /* nothing */ |
486 | #endif /* NO_KERNEL_RCSIDS */ | | 487 | #endif /* NO_KERNEL_RCSIDS */ |
487 | #endif /* _KERNEL */ | | 488 | #endif /* _KERNEL */ |
488 | | | 489 | |
489 | #if !defined(_STANDALONE) && !defined(_KERNEL) | | 490 | #if !defined(_STANDALONE) && !defined(_KERNEL) |
490 | #if defined(__GNUC__) || defined(__PCC__) | | 491 | #if defined(__GNUC__) || defined(__PCC__) |
491 | #define __RENAME(x) ___RENAME(x) | | 492 | #define __RENAME(x) ___RENAME(x) |
492 | #elif defined(__lint__) | | 493 | #elif defined(__lint__) |
493 | #define __RENAME(x) __symbolrename(x) | | 494 | #define __RENAME(x) __symbolrename(x) |
494 | #else | | 495 | #else |
495 | #error "No function renaming possible" | | 496 | #error "No function renaming possible" |
496 | #endif /* __GNUC__ */ | | 497 | #endif /* __GNUC__ */ |
497 | #else /* _STANDALONE || _KERNEL */ | | 498 | #else /* _STANDALONE || _KERNEL */ |
498 | #define __RENAME(x) no renaming in kernel/standalone environment | | 499 | #define __RENAME(x) no renaming in kernel/standalone environment |
499 | #endif | | 500 | #endif |
500 | | | 501 | |
501 | /* | | 502 | /* |
502 | * A barrier to stop the optimizer from moving code or assume live | | 503 | * A barrier to stop the optimizer from moving code or assume live |
503 | * register values. This is gcc specific, the version is more or less | | 504 | * register values. This is gcc specific, the version is more or less |
504 | * arbitrary, might work with older compilers. | | 505 | * arbitrary, might work with older compilers. |
505 | */ | | 506 | */ |
506 | #if __GNUC_PREREQ__(2, 95) || defined(__lint__) | | 507 | #if __GNUC_PREREQ__(2, 95) || defined(__lint__) |
507 | #define __insn_barrier() __asm __volatile("":::"memory") | | 508 | #define __insn_barrier() __asm __volatile("":::"memory") |
508 | #else | | 509 | #else |
509 | #define __insn_barrier() /* */ | | 510 | #define __insn_barrier() /* */ |
510 | #endif | | 511 | #endif |
511 | | | 512 | |
512 | /* | | 513 | /* |
513 | * GNU C version 2.96 adds explicit branch prediction so that | | 514 | * GNU C version 2.96 adds explicit branch prediction so that |
514 | * the CPU back-end can hint the processor and also so that | | 515 | * the CPU back-end can hint the processor and also so that |
515 | * code blocks can be reordered such that the predicted path | | 516 | * code blocks can be reordered such that the predicted path |
516 | * sees a more linear flow, thus improving cache behavior, etc. | | 517 | * sees a more linear flow, thus improving cache behavior, etc. |
517 | * | | 518 | * |
518 | * The following two macros provide us with a way to use this | | 519 | * The following two macros provide us with a way to use this |
519 | * compiler feature. Use __predict_true() if you expect the expression | | 520 | * compiler feature. Use __predict_true() if you expect the expression |
520 | * to evaluate to true, and __predict_false() if you expect the | | 521 | * to evaluate to true, and __predict_false() if you expect the |
521 | * expression to evaluate to false. | | 522 | * expression to evaluate to false. |
522 | * | | 523 | * |
523 | * A few notes about usage: | | 524 | * A few notes about usage: |
524 | * | | 525 | * |
525 | * * Generally, __predict_false() error condition checks (unless | | 526 | * * Generally, __predict_false() error condition checks (unless |
526 | * you have some _strong_ reason to do otherwise, in which case | | 527 | * you have some _strong_ reason to do otherwise, in which case |
527 | * document it), and/or __predict_true() `no-error' condition | | 528 | * document it), and/or __predict_true() `no-error' condition |
528 | * checks, assuming you want to optimize for the no-error case. | | 529 | * checks, assuming you want to optimize for the no-error case. |
529 | * | | 530 | * |
530 | * * Other than that, if you don't know the likelihood of a test | | 531 | * * Other than that, if you don't know the likelihood of a test |
531 | * succeeding from empirical or other `hard' evidence, don't | | 532 | * succeeding from empirical or other `hard' evidence, don't |
532 | * make predictions. | | 533 | * make predictions. |
533 | * | | 534 | * |
534 | * * These are meant to be used in places that are run `a lot'. | | 535 | * * These are meant to be used in places that are run `a lot'. |
535 | * It is wasteful to make predictions in code that is run | | 536 | * It is wasteful to make predictions in code that is run |
536 | * seldomly (e.g. at subsystem initialization time) as the | | 537 | * seldomly (e.g. at subsystem initialization time) as the |
537 | * basic block reordering that this affects can often generate | | 538 | * basic block reordering that this affects can often generate |
538 | * larger code. | | 539 | * larger code. |
539 | */ | | 540 | */ |
540 | #if __GNUC_PREREQ__(2, 96) || defined(__lint__) | | 541 | #if __GNUC_PREREQ__(2, 96) || defined(__lint__) |
541 | #define __predict_true(exp) __builtin_expect((exp) != 0, 1) | | 542 | #define __predict_true(exp) __builtin_expect((exp) != 0, 1) |
542 | #define __predict_false(exp) __builtin_expect((exp) != 0, 0) | | 543 | #define __predict_false(exp) __builtin_expect((exp) != 0, 0) |
543 | #else | | 544 | #else |
544 | #define __predict_true(exp) (exp) | | 545 | #define __predict_true(exp) (exp) |
545 | #define __predict_false(exp) (exp) | | 546 | #define __predict_false(exp) (exp) |
546 | #endif | | 547 | #endif |
547 | | | 548 | |
548 | /* | | 549 | /* |
549 | * Compiler-dependent macros to declare that functions take printf-like | | 550 | * Compiler-dependent macros to declare that functions take printf-like |
550 | * or scanf-like arguments. They are null except for versions of gcc | | 551 | * or scanf-like arguments. They are null except for versions of gcc |
551 | * that are known to support the features properly (old versions of gcc-2 | | 552 | * that are known to support the features properly (old versions of gcc-2 |
552 | * didn't permit keeping the keywords out of the application namespace). | | 553 | * didn't permit keeping the keywords out of the application namespace). |
553 | */ | | 554 | */ |
554 | #if __GNUC_PREREQ__(2, 7) || defined(__lint__) | | 555 | #if __GNUC_PREREQ__(2, 7) || defined(__lint__) |
555 | #define __printflike(fmtarg, firstvararg) \ | | 556 | #define __printflike(fmtarg, firstvararg) \ |
556 | __attribute__((__format__ (__printf__, fmtarg, firstvararg))) | | 557 | __attribute__((__format__ (__printf__, fmtarg, firstvararg))) |
557 | #ifndef __syslog_attribute__ | | 558 | #ifndef __syslog_attribute__ |
558 | #define __syslog__ __printf__ | | 559 | #define __syslog__ __printf__ |
559 | #endif | | 560 | #endif |
560 | #define __sysloglike(fmtarg, firstvararg) \ | | 561 | #define __sysloglike(fmtarg, firstvararg) \ |
561 | __attribute__((__format__ (__syslog__, fmtarg, firstvararg))) | | 562 | __attribute__((__format__ (__syslog__, fmtarg, firstvararg))) |
562 | #define __scanflike(fmtarg, firstvararg) \ | | 563 | #define __scanflike(fmtarg, firstvararg) \ |
563 | __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) | | 564 | __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) |
564 | #define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) | | 565 | #define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) |
565 | #else | | 566 | #else |
566 | #define __printflike(fmtarg, firstvararg) /* nothing */ | | 567 | #define __printflike(fmtarg, firstvararg) /* nothing */ |
567 | #define __scanflike(fmtarg, firstvararg) /* nothing */ | | 568 | #define __scanflike(fmtarg, firstvararg) /* nothing */ |
568 | #define __sysloglike(fmtarg, firstvararg) /* nothing */ | | 569 | #define __sysloglike(fmtarg, firstvararg) /* nothing */ |
569 | #define __format_arg(fmtarg) /* nothing */ | | 570 | #define __format_arg(fmtarg) /* nothing */ |
570 | #endif | | 571 | #endif |
571 | | | 572 | |
572 | /* | | 573 | /* |
573 | * Macros for manipulating "link sets". Link sets are arrays of pointers | | 574 | * Macros for manipulating "link sets". Link sets are arrays of pointers |
574 | * to objects, which are gathered up by the linker. | | 575 | * to objects, which are gathered up by the linker. |
575 | * | | 576 | * |
576 | * Object format-specific code has provided us with the following macros: | | 577 | * Object format-specific code has provided us with the following macros: |
577 | * | | 578 | * |
578 | * __link_set_add_text(set, sym) | | 579 | * __link_set_add_text(set, sym) |
579 | * Add a reference to the .text symbol `sym' to `set'. | | 580 | * Add a reference to the .text symbol `sym' to `set'. |
580 | * | | 581 | * |
581 | * __link_set_add_rodata(set, sym) | | 582 | * __link_set_add_rodata(set, sym) |
582 | * Add a reference to the .rodata symbol `sym' to `set'. | | 583 | * Add a reference to the .rodata symbol `sym' to `set'. |
583 | * | | 584 | * |
584 | * __link_set_add_data(set, sym) | | 585 | * __link_set_add_data(set, sym) |
585 | * Add a reference to the .data symbol `sym' to `set'. | | 586 | * Add a reference to the .data symbol `sym' to `set'. |
586 | * | | 587 | * |
587 | * __link_set_add_bss(set, sym) | | 588 | * __link_set_add_bss(set, sym) |
588 | * Add a reference to the .bss symbol `sym' to `set'. | | 589 | * Add a reference to the .bss symbol `sym' to `set'. |
589 | * | | 590 | * |
590 | * __link_set_decl(set, ptype) | | 591 | * __link_set_decl(set, ptype) |
591 | * Provide an extern declaration of the set `set', which | | 592 | * Provide an extern declaration of the set `set', which |
592 | * contains an array of pointers to type `ptype'. This | | 593 | * contains an array of pointers to type `ptype'. This |
593 | * macro must be used by any code which wishes to reference | | 594 | * macro must be used by any code which wishes to reference |
594 | * the elements of a link set. | | 595 | * the elements of a link set. |
595 | * | | 596 | * |
596 | * __link_set_start(set) | | 597 | * __link_set_start(set) |
597 | * This points to the first slot in the link set. | | 598 | * This points to the first slot in the link set. |
598 | * | | 599 | * |
599 | * __link_set_end(set) | | 600 | * __link_set_end(set) |
600 | * This points to the (non-existent) slot after the last | | 601 | * This points to the (non-existent) slot after the last |
601 | * entry in the link set. | | 602 | * entry in the link set. |
602 | * | | 603 | * |
603 | * __link_set_count(set) | | 604 | * __link_set_count(set) |
604 | * Count the number of entries in link set `set'. | | 605 | * Count the number of entries in link set `set'. |
605 | * | | 606 | * |
606 | * In addition, we provide the following macros for accessing link sets: | | 607 | * In addition, we provide the following macros for accessing link sets: |
607 | * | | 608 | * |
608 | * __link_set_foreach(pvar, set) | | 609 | * __link_set_foreach(pvar, set) |
609 | * Iterate over the link set `set'. Because a link set is | | 610 | * Iterate over the link set `set'. Because a link set is |
610 | * an array of pointers, pvar must be declared as "type **pvar", | | 611 | * an array of pointers, pvar must be declared as "type **pvar", |
611 | * and the actual entry accessed as "*pvar". | | 612 | * and the actual entry accessed as "*pvar". |
612 | * | | 613 | * |
613 | * __link_set_entry(set, idx) | | 614 | * __link_set_entry(set, idx) |
614 | * Access the link set entry at index `idx' from set `set'. | | 615 | * Access the link set entry at index `idx' from set `set'. |
615 | */ | | 616 | */ |
616 | #define __link_set_foreach(pvar, set) \ | | 617 | #define __link_set_foreach(pvar, set) \ |
617 | for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) | | 618 | for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) |
618 | | | 619 | |
619 | #define __link_set_entry(set, idx) (__link_set_start(set)[idx]) | | 620 | #define __link_set_entry(set, idx) (__link_set_start(set)[idx]) |
620 | | | 621 | |
621 | /* | | 622 | /* |
622 | * Return the natural alignment in bytes for the given type | | 623 | * Return the natural alignment in bytes for the given type |
623 | */ | | 624 | */ |
624 | #if __GNUC_PREREQ__(4, 1) || defined(__lint__) | | 625 | #if __GNUC_PREREQ__(4, 1) || defined(__lint__) |
625 | #define __alignof(__t) __alignof__(__t) | | 626 | #define __alignof(__t) __alignof__(__t) |
626 | #else | | 627 | #else |
627 | #define __alignof(__t) (sizeof(struct { char __x; __t __y; }) - sizeof(__t)) | | 628 | #define __alignof(__t) (sizeof(struct { char __x; __t __y; }) - sizeof(__t)) |
628 | #endif | | 629 | #endif |
629 | | | 630 | |
630 | /* | | 631 | /* |
631 | * Return the number of elements in a statically-allocated array, | | 632 | * Return the number of elements in a statically-allocated array, |
632 | * __x. | | 633 | * __x. |
633 | */ | | 634 | */ |
634 | #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) | | 635 | #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) |
635 | | | 636 | |
636 | #ifndef __ASSEMBLER__ | | 637 | #ifndef __ASSEMBLER__ |
637 | /* __BIT(n): nth bit, where __BIT(0) == 0x1. */ | | 638 | /* __BIT(n): nth bit, where __BIT(0) == 0x1. */ |
638 | #define __BIT(__n) \ | | 639 | #define __BIT(__n) \ |
639 | (((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : \ | | 640 | (((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : \ |
640 | ((uintmax_t)1 << (uintmax_t)((__n) & (NBBY * sizeof(uintmax_t) - 1)))) | | 641 | ((uintmax_t)1 << (uintmax_t)((__n) & (NBBY * sizeof(uintmax_t) - 1)))) |
641 | | | 642 | |
642 | /* Macros for min/max. */ | | 643 | /* Macros for min/max. */ |
643 | #define __MIN(a,b) ((/*CONSTCOND*/(a)<=(b))?(a):(b)) | | 644 | #define __MIN(a,b) ((/*CONSTCOND*/(a)<=(b))?(a):(b)) |
644 | #define __MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b)) | | 645 | #define __MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b)) |
645 | | | 646 | |
646 | /* __BITS(m, n): bits m through n, m < n. */ | | 647 | /* __BITS(m, n): bits m through n, m < n. */ |
647 | #define __BITS(__m, __n) \ | | 648 | #define __BITS(__m, __n) \ |
648 | ((__BIT(__MAX((__m), (__n)) + 1) - 1) ^ (__BIT(__MIN((__m), (__n))) - 1)) | | 649 | ((__BIT(__MAX((__m), (__n)) + 1) - 1) ^ (__BIT(__MIN((__m), (__n))) - 1)) |
649 | #endif /* !__ASSEMBLER__ */ | | 650 | #endif /* !__ASSEMBLER__ */ |
650 | | | 651 | |
651 | /* find least significant bit that is set */ | | 652 | /* find least significant bit that is set */ |
652 | #define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask)) | | 653 | #define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask)) |
653 | | | 654 | |
654 | #define __PRIuBIT PRIuMAX | | 655 | #define __PRIuBIT PRIuMAX |
655 | #define __PRIuBITS __PRIuBIT | | 656 | #define __PRIuBITS __PRIuBIT |
656 | | | 657 | |
657 | #define __PRIxBIT PRIxMAX | | 658 | #define __PRIxBIT PRIxMAX |
658 | #define __PRIxBITS __PRIxBIT | | 659 | #define __PRIxBITS __PRIxBIT |
659 | | | 660 | |
660 | #define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask)) | | 661 | #define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask)) |
661 | #define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask)) | | 662 | #define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask)) |
662 | #define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask)) | | 663 | #define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask)) |
663 | | | 664 | |
664 | /* | | 665 | /* |
665 | * Only to be used in other headers that are included from both c or c++ | | 666 | * Only to be used in other headers that are included from both c or c++ |
666 | * NOT to be used in code. | | 667 | * NOT to be used in code. |
667 | */ | | 668 | */ |
668 | #ifdef __cplusplus | | 669 | #ifdef __cplusplus |
669 | #define __CAST(__dt, __st) static_cast<__dt>(__st) | | 670 | #define __CAST(__dt, __st) static_cast<__dt>(__st) |
670 | #else | | 671 | #else |
671 | #define __CAST(__dt, __st) ((__dt)(__st)) | | 672 | #define __CAST(__dt, __st) ((__dt)(__st)) |
672 | #endif | | 673 | #endif |
673 | | | 674 | |
674 | #define __CASTV(__dt, __st) __CAST(__dt, __CAST(void *, __st)) | | 675 | #define __CASTV(__dt, __st) __CAST(__dt, __CAST(void *, __st)) |
675 | #define __CASTCV(__dt, __st) __CAST(__dt, __CAST(const void *, __st)) | | 676 | #define __CASTCV(__dt, __st) __CAST(__dt, __CAST(const void *, __st)) |
676 | | | 677 | |
677 | #define __USE(a) (/*LINTED*/(void)(a)) | | 678 | #define __USE(a) (/*LINTED*/(void)(a)) |
678 | | | 679 | |
679 | #define __type_mask(t) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \ | | 680 | #define __type_mask(t) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \ |
680 | (~((1ULL << (sizeof(t) * NBBY)) - 1)) : 0ULL) | | 681 | (~((1ULL << (sizeof(t) * NBBY)) - 1)) : 0ULL) |
681 | | | 682 | |
682 | #ifndef __ASSEMBLER__ | | 683 | #ifndef __ASSEMBLER__ |
683 | static __inline long long __zeroll(void) { return 0; } | | 684 | static __inline long long __zeroll(void) { return 0; } |
684 | static __inline unsigned long long __zeroull(void) { return 0; } | | 685 | static __inline unsigned long long __zeroull(void) { return 0; } |
685 | #else | | 686 | #else |
686 | #define __zeroll() (0LL) | | 687 | #define __zeroll() (0LL) |
687 | #define __zeroull() (0ULL) | | 688 | #define __zeroull() (0ULL) |
688 | #endif | | 689 | #endif |
689 | | | 690 | |
690 | #define __negative_p(x) (!((x) > 0) && ((x) != 0)) | | 691 | #define __negative_p(x) (!((x) > 0) && ((x) != 0)) |
691 | | | 692 | |
692 | #define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1)))) | | 693 | #define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1)))) |
693 | #define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1)))) | | 694 | #define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1)))) |
694 | #define __type_min_u(t) ((t)0ULL) | | 695 | #define __type_min_u(t) ((t)0ULL) |
695 | #define __type_max_u(t) ((t)~0ULL) | | 696 | #define __type_max_u(t) ((t)~0ULL) |
696 | #define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1) | | 697 | #define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1) |
697 | #define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t)) | | 698 | #define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t)) |
698 | #define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t)) | | 699 | #define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t)) |
699 | | | 700 | |
700 | | | 701 | |
701 | #define __type_fit_u(t, a) (/*LINTED*/!__negative_p(a) && \ | | 702 | #define __type_fit_u(t, a) (/*LINTED*/!__negative_p(a) && \ |
702 | (uintmax_t)((a) + __zeroull()) <= (uintmax_t)__type_max_u(t)) | | 703 | (uintmax_t)((a) + __zeroull()) <= (uintmax_t)__type_max_u(t)) |
703 | | | 704 | |
704 | #define __type_fit_s(t, a) (/*LINTED*/__negative_p(a) ? \ | | 705 | #define __type_fit_s(t, a) (/*LINTED*/__negative_p(a) ? \ |
705 | ((intmax_t)((a) + __zeroll()) >= (intmax_t)__type_min_s(t)) : \ | | 706 | ((intmax_t)((a) + __zeroll()) >= (intmax_t)__type_min_s(t)) : \ |
706 | ((intmax_t)((a) + __zeroll()) >= (intmax_t)0 && \ | | 707 | ((intmax_t)((a) + __zeroll()) >= (intmax_t)0 && \ |
707 | (intmax_t)((a) + __zeroll()) <= (intmax_t)__type_max_s(t))) | | 708 | (intmax_t)((a) + __zeroll()) <= (intmax_t)__type_max_s(t))) |
708 | | | 709 | |
709 | /* | | 710 | /* |
710 | * return true if value 'a' fits in type 't' | | 711 | * return true if value 'a' fits in type 't' |
711 | */ | | 712 | */ |
712 | #define __type_fit(t, a) (__type_is_signed(t) ? \ | | 713 | #define __type_fit(t, a) (__type_is_signed(t) ? \ |
713 | __type_fit_s(t, a) : __type_fit_u(t, a)) | | 714 | __type_fit_s(t, a) : __type_fit_u(t, a)) |
714 | | | 715 | |
715 | #endif /* !_SYS_CDEFS_H_ */ | | 716 | #endif /* !_SYS_CDEFS_H_ */ |