| @@ -1,464 +1,481 @@ | | | @@ -1,464 +1,481 @@ |
1 | /* $NetBSD: cdefs.h,v 1.79 2010/07/31 00:04:43 joerg Exp $ */ | | 1 | /* $NetBSD: cdefs.h,v 1.80 2010/08/07 21:03:18 joerg Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1991, 1993 | | 4 | * Copyright (c) 1991, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Berkeley Software Design, Inc. | | 8 | * Berkeley Software Design, Inc. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * 3. Neither the name of the University nor the names of its contributors | | 18 | * 3. Neither the name of the University nor the names of its contributors |
19 | * may be used to endorse or promote products derived from this software | | 19 | * may be used to endorse or promote products derived from this software |
20 | * without specific prior written permission. | | 20 | * without specific prior written permission. |
21 | * | | 21 | * |
22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | * SUCH DAMAGE. | | 32 | * SUCH DAMAGE. |
33 | * | | 33 | * |
34 | * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 | | 34 | * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 |
35 | */ | | 35 | */ |
36 | | | 36 | |
37 | #ifndef _SYS_CDEFS_H_ | | 37 | #ifndef _SYS_CDEFS_H_ |
38 | #define _SYS_CDEFS_H_ | | 38 | #define _SYS_CDEFS_H_ |
39 | | | 39 | |
40 | /* | | 40 | /* |
41 | * Macro to test if we're using a GNU C compiler of a specific vintage | | 41 | * Macro to test if we're using a GNU C compiler of a specific vintage |
42 | * or later, for e.g. features that appeared in a particular version | | 42 | * or later, for e.g. features that appeared in a particular version |
43 | * of GNU C. Usage: | | 43 | * of GNU C. Usage: |
44 | * | | 44 | * |
45 | * #if __GNUC_PREREQ__(major, minor) | | 45 | * #if __GNUC_PREREQ__(major, minor) |
46 | * ...cool feature... | | 46 | * ...cool feature... |
47 | * #else | | 47 | * #else |
48 | * ...delete feature... | | 48 | * ...delete feature... |
49 | * #endif | | 49 | * #endif |
50 | */ | | 50 | */ |
51 | #ifdef __GNUC__ | | 51 | #ifdef __GNUC__ |
52 | #define __GNUC_PREREQ__(x, y) \ | | 52 | #define __GNUC_PREREQ__(x, y) \ |
53 | ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ | | 53 | ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ |
54 | (__GNUC__ > (x))) | | 54 | (__GNUC__ > (x))) |
55 | #else | | 55 | #else |
56 | #define __GNUC_PREREQ__(x, y) 0 | | 56 | #define __GNUC_PREREQ__(x, y) 0 |
57 | #endif | | 57 | #endif |
58 | | | 58 | |
59 | #include <machine/cdefs.h> | | 59 | #include <machine/cdefs.h> |
60 | #ifdef __ELF__ | | 60 | #ifdef __ELF__ |
61 | #include <sys/cdefs_elf.h> | | 61 | #include <sys/cdefs_elf.h> |
62 | #else | | 62 | #else |
63 | #include <sys/cdefs_aout.h> | | 63 | #include <sys/cdefs_aout.h> |
64 | #endif | | 64 | #endif |
65 | | | 65 | |
66 | #if defined(__cplusplus) | | | |
67 | #define __BEGIN_DECLS extern "C" { | | | |
68 | #define __END_DECLS } | | | |
69 | #define __static_cast(x,y) static_cast<x>(y) | | | |
70 | #else | | | |
71 | #define __BEGIN_DECLS | | | |
72 | #define __END_DECLS | | | |
73 | #define __static_cast(x,y) (x)y | | | |
74 | #endif | | | |
75 | | | | |
76 | /* | | 66 | /* |
77 | * The __CONCAT macro is used to concatenate parts of symbol names, e.g. | | 67 | * The __CONCAT macro is used to concatenate parts of symbol names, e.g. |
78 | * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. | | 68 | * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. |
79 | * The __CONCAT macro is a bit tricky -- make sure you don't put spaces | | 69 | * The __CONCAT macro is a bit tricky -- make sure you don't put spaces |
80 | * in between its arguments. __CONCAT can also concatenate double-quoted | | 70 | * in between its arguments. __CONCAT can also concatenate double-quoted |
81 | * strings produced by the __STRING macro, but this only works with ANSI C. | | 71 | * strings produced by the __STRING macro, but this only works with ANSI C. |
82 | */ | | 72 | */ |
83 | | | 73 | |
84 | #define ___STRING(x) __STRING(x) | | 74 | #define ___STRING(x) __STRING(x) |
85 | #define ___CONCAT(x,y) __CONCAT(x,y) | | 75 | #define ___CONCAT(x,y) __CONCAT(x,y) |
86 | | | 76 | |
87 | #if __STDC__ || defined(__cplusplus) | | 77 | #if __STDC__ || defined(__cplusplus) |
88 | #define __P(protos) protos /* full-blown ANSI C */ | | 78 | #define __P(protos) protos /* full-blown ANSI C */ |
89 | #define __CONCAT(x,y) x ## y | | 79 | #define __CONCAT(x,y) x ## y |
90 | #define __STRING(x) #x | | 80 | #define __STRING(x) #x |
91 | | | 81 | |
92 | #define __const const /* define reserved names to standard */ | | 82 | #define __const const /* define reserved names to standard */ |
93 | #define __signed signed | | 83 | #define __signed signed |
94 | #define __volatile volatile | | 84 | #define __volatile volatile |
95 | #if defined(__cplusplus) || defined(__PCC__) | | 85 | #if defined(__cplusplus) || defined(__PCC__) |
96 | #define __inline inline /* convert to C++/C99 keyword */ | | 86 | #define __inline inline /* convert to C++/C99 keyword */ |
97 | #else | | 87 | #else |
98 | #if !defined(__GNUC__) && !defined(__lint__) | | 88 | #if !defined(__GNUC__) && !defined(__lint__) |
99 | #define __inline /* delete GCC keyword */ | | 89 | #define __inline /* delete GCC keyword */ |
100 | #endif /* !__GNUC__ && !__lint__ */ | | 90 | #endif /* !__GNUC__ && !__lint__ */ |
101 | #endif /* !__cplusplus */ | | 91 | #endif /* !__cplusplus */ |
102 | | | 92 | |
103 | #else /* !(__STDC__ || __cplusplus) */ | | 93 | #else /* !(__STDC__ || __cplusplus) */ |
104 | #define __P(protos) () /* traditional C preprocessor */ | | 94 | #define __P(protos) () /* traditional C preprocessor */ |
105 | #define __CONCAT(x,y) x/**/y | | 95 | #define __CONCAT(x,y) x/**/y |
106 | #define __STRING(x) "x" | | 96 | #define __STRING(x) "x" |
107 | | | 97 | |
108 | #ifndef __GNUC__ | | 98 | #ifndef __GNUC__ |
109 | #define __const /* delete pseudo-ANSI C keywords */ | | 99 | #define __const /* delete pseudo-ANSI C keywords */ |
110 | #define __inline | | 100 | #define __inline |
111 | #define __signed | | 101 | #define __signed |
112 | #define __volatile | | 102 | #define __volatile |
113 | #endif /* !__GNUC__ */ | | 103 | #endif /* !__GNUC__ */ |
114 | | | 104 | |
115 | /* | | 105 | /* |
116 | * In non-ANSI C environments, new programs will want ANSI-only C keywords | | 106 | * In non-ANSI C environments, new programs will want ANSI-only C keywords |
117 | * deleted from the program and old programs will want them left alone. | | 107 | * deleted from the program and old programs will want them left alone. |
118 | * Programs using the ANSI C keywords const, inline etc. as normal | | 108 | * Programs using the ANSI C keywords const, inline etc. as normal |
119 | * identifiers should define -DNO_ANSI_KEYWORDS. | | 109 | * identifiers should define -DNO_ANSI_KEYWORDS. |
120 | */ | | 110 | */ |
121 | #ifndef NO_ANSI_KEYWORDS | | 111 | #ifndef NO_ANSI_KEYWORDS |
122 | #define const __const /* convert ANSI C keywords */ | | 112 | #define const __const /* convert ANSI C keywords */ |
123 | #define inline __inline | | 113 | #define inline __inline |
124 | #define signed __signed | | 114 | #define signed __signed |
125 | #define volatile __volatile | | 115 | #define volatile __volatile |
126 | #endif /* !NO_ANSI_KEYWORDS */ | | 116 | #endif /* !NO_ANSI_KEYWORDS */ |
127 | #endif /* !(__STDC__ || __cplusplus) */ | | 117 | #endif /* !(__STDC__ || __cplusplus) */ |
128 | | | 118 | |
129 | /* | | 119 | /* |
130 | * Used for internal auditing of the NetBSD source tree. | | 120 | * Used for internal auditing of the NetBSD source tree. |
131 | */ | | 121 | */ |
132 | #ifdef __AUDIT__ | | 122 | #ifdef __AUDIT__ |
133 | #define __aconst __const | | 123 | #define __aconst __const |
134 | #else | | 124 | #else |
135 | #define __aconst | | 125 | #define __aconst |
136 | #endif | | 126 | #endif |
137 | | | 127 | |
138 | /* | | 128 | /* |
139 | * The following macro is used to remove const cast-away warnings | | 129 | * The following macro is used to remove const cast-away warnings |
140 | * from gcc -Wcast-qual; it should be used with caution because it | | 130 | * from gcc -Wcast-qual; it should be used with caution because it |
141 | * can hide valid errors; in particular most valid uses are in | | 131 | * can hide valid errors; in particular most valid uses are in |
142 | * situations where the API requires it, not to cast away string | | 132 | * situations where the API requires it, not to cast away string |
143 | * constants. We don't use *intptr_t on purpose here and we are | | 133 | * constants. We don't use *intptr_t on purpose here and we are |
144 | * explicit about unsigned long so that we don't have additional | | 134 | * explicit about unsigned long so that we don't have additional |
145 | * dependencies. | | 135 | * dependencies. |
146 | */ | | 136 | */ |
147 | #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) | | 137 | #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) |
148 | | | 138 | |
149 | /* | | 139 | /* |
150 | * The following macro is used to remove the volatile cast-away warnings | | 140 | * The following macro is used to remove the volatile cast-away warnings |
151 | * from gcc -Wcast-qual; as above it should be used with caution | | 141 | * from gcc -Wcast-qual; as above it should be used with caution |
152 | * because it can hide valid errors or warnings. Valid uses include | | 142 | * because it can hide valid errors or warnings. Valid uses include |
153 | * making it possible to pass a volatile pointer to memset(). | | 143 | * making it possible to pass a volatile pointer to memset(). |
154 | * For the same reasons as above, we use unsigned long and not intptr_t. | | 144 | * For the same reasons as above, we use unsigned long and not intptr_t. |
155 | */ | | 145 | */ |
156 | #define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a)) | | 146 | #define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a)) |
157 | | | 147 | |
158 | /* | | 148 | /* |
159 | * GCC2 provides __extension__ to suppress warnings for various GNU C | | 149 | * GCC2 provides __extension__ to suppress warnings for various GNU C |
160 | * language extensions under "-ansi -pedantic". | | 150 | * language extensions under "-ansi -pedantic". |
161 | */ | | 151 | */ |
162 | #if !__GNUC_PREREQ__(2, 0) | | 152 | #if !__GNUC_PREREQ__(2, 0) |
163 | #define __extension__ /* delete __extension__ if non-gcc or gcc1 */ | | 153 | #define __extension__ /* delete __extension__ if non-gcc or gcc1 */ |
164 | #endif | | 154 | #endif |
165 | | | 155 | |
166 | /* | | 156 | /* |
167 | * GCC1 and some versions of GCC2 declare dead (non-returning) and | | 157 | * GCC1 and some versions of GCC2 declare dead (non-returning) and |
168 | * pure (no side effects) functions using "volatile" and "const"; | | 158 | * pure (no side effects) functions using "volatile" and "const"; |
169 | * unfortunately, these then cause warnings under "-ansi -pedantic". | | 159 | * unfortunately, these then cause warnings under "-ansi -pedantic". |
170 | * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of | | 160 | * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of |
171 | * these work for GNU C++ (modulo a slight glitch in the C++ grammar | | 161 | * these work for GNU C++ (modulo a slight glitch in the C++ grammar |
172 | * in the distribution version of 2.5.5). | | 162 | * in the distribution version of 2.5.5). |
173 | * | | 163 | * |
174 | * GCC defines a pure function as depending only on its arguments and | | 164 | * GCC defines a pure function as depending only on its arguments and |
175 | * global variables. Typical examples are strlen and sqrt. | | 165 | * global variables. Typical examples are strlen and sqrt. |
176 | * | | 166 | * |
177 | * GCC defines a const function as depending only on its arguments. | | 167 | * GCC defines a const function as depending only on its arguments. |
178 | * Therefore calling a const function again with identical arguments | | 168 | * Therefore calling a const function again with identical arguments |
179 | * will always produce the same result. | | 169 | * will always produce the same result. |
180 | * | | 170 | * |
181 | * Rounding modes for floating point operations are considered global | | 171 | * Rounding modes for floating point operations are considered global |
182 | * variables and prevent sqrt from being a const function. | | 172 | * variables and prevent sqrt from being a const function. |
183 | * | | 173 | * |
184 | * Calls to const functions can be optimised away and moved around | | 174 | * Calls to const functions can be optimised away and moved around |
185 | * without limitations. | | 175 | * without limitations. |
186 | */ | | 176 | */ |
187 | #if !__GNUC_PREREQ__(2, 0) | | 177 | #if !__GNUC_PREREQ__(2, 0) |
188 | #define __attribute__(x) | | 178 | #define __attribute__(x) |
189 | #endif | | 179 | #endif |
190 | | | 180 | |
191 | #if __GNUC_PREREQ__(2, 5) | | 181 | #if __GNUC_PREREQ__(2, 5) |
192 | #define __dead __attribute__((__noreturn__)) | | 182 | #define __dead __attribute__((__noreturn__)) |
193 | #elif defined(__GNUC__) | | 183 | #elif defined(__GNUC__) |
194 | #define __dead __volatile | | 184 | #define __dead __volatile |
195 | #else | | 185 | #else |
196 | #define __dead | | 186 | #define __dead |
197 | #endif | | 187 | #endif |
198 | | | 188 | |
199 | #if __GNUC_PREREQ__(2, 96) | | 189 | #if __GNUC_PREREQ__(2, 96) |
200 | #define __pure __attribute__((__pure__)) | | 190 | #define __pure __attribute__((__pure__)) |
201 | #elif defined(__GNUC__) | | 191 | #elif defined(__GNUC__) |
202 | #define __pure __const | | 192 | #define __pure __const |
203 | #else | | 193 | #else |
204 | #define __pure | | 194 | #define __pure |
205 | #endif | | 195 | #endif |
206 | | | 196 | |
207 | #if __GNUC_PREREQ__(2, 5) | | 197 | #if __GNUC_PREREQ__(2, 5) |
208 | #define __constfunc __attribute__((__const__)) | | 198 | #define __constfunc __attribute__((__const__)) |
209 | #else | | 199 | #else |
210 | #define __constfunc | | 200 | #define __constfunc |
211 | #endif | | 201 | #endif |
212 | | | 202 | |
213 | #if __GNUC_PREREQ__(3, 0) | | 203 | #if __GNUC_PREREQ__(3, 0) |
214 | #define __noinline __attribute__((__noinline__)) | | 204 | #define __noinline __attribute__((__noinline__)) |
215 | #else | | 205 | #else |
216 | #define __noinline /* nothing */ | | 206 | #define __noinline /* nothing */ |
217 | #endif | | 207 | #endif |
218 | | | 208 | |
219 | #if __GNUC_PREREQ__(2, 7) | | 209 | #if __GNUC_PREREQ__(2, 7) |
220 | #define __unused __attribute__((__unused__)) | | 210 | #define __unused __attribute__((__unused__)) |
221 | #else | | 211 | #else |
222 | #define __unused /* delete */ | | 212 | #define __unused /* delete */ |
223 | #endif | | 213 | #endif |
224 | | | 214 | |
225 | #if __GNUC_PREREQ__(3, 1) | | 215 | #if __GNUC_PREREQ__(3, 1) |
226 | #define __used __attribute__((__used__)) | | 216 | #define __used __attribute__((__used__)) |
227 | #else | | 217 | #else |
228 | #define __used __unused | | 218 | #define __used __unused |
229 | #endif | | 219 | #endif |
230 | | | 220 | |
| | | 221 | #if __GNUC_PREREQ__(4, 0) |
| | | 222 | # define __dso_public __attribute__((__visibility__("default"))) |
| | | 223 | # define __dso_hidden __attribute__((__visibility__("hidden"))) |
| | | 224 | # define __BEGIN_PUBLIC _Pragma("GCC visibility push(default)") |
| | | 225 | # define __END_PUBLIC _Pragma("GCC visibility pop") |
| | | 226 | # define __BEGIN_HIDDEN _Pragma("GCC visibility push(hidden)") |
| | | 227 | # define __END_HIDDEN _Pragma("GCC visibility pop") |
| | | 228 | #else |
| | | 229 | # define __dso_public |
| | | 230 | # define __dso_hidden |
| | | 231 | # define __BEGIN_PUBLIC |
| | | 232 | # define __END_PUBLIC |
| | | 233 | # define __BEGIN_HIDDEN |
| | | 234 | # define __END_HIDDEN |
| | | 235 | #endif |
| | | 236 | |
| | | 237 | |
| | | 238 | #if defined(__cplusplus) |
| | | 239 | #define __BEGIN_DECLS __BEGIN_PUBLIC extern "C" { |
| | | 240 | #define __END_DECLS } __END_PUBLIC |
| | | 241 | #define __static_cast(x,y) static_cast<x>(y) |
| | | 242 | #else |
| | | 243 | #define __BEGIN_DECLS __BEGIN_PUBLIC |
| | | 244 | #define __END_DECLS __END_PUBLIC |
| | | 245 | #define __static_cast(x,y) (x)y |
| | | 246 | #endif |
| | | 247 | |
231 | /* | | 248 | /* |
232 | * Non-static C99 inline functions are optional bodies. They don't | | 249 | * Non-static C99 inline functions are optional bodies. They don't |
233 | * create global symbols if not used, but can be replaced if desirable. | | 250 | * create global symbols if not used, but can be replaced if desirable. |
234 | * This differs from the behavior of GCC before version 4.3. The nearest | | 251 | * This differs from the behavior of GCC before version 4.3. The nearest |
235 | * equivalent for older GCC is `extern inline'. For newer GCC, use the | | 252 | * equivalent for older GCC is `extern inline'. For newer GCC, use the |
236 | * gnu_inline attribute additionally to get the old behavior. | | 253 | * gnu_inline attribute additionally to get the old behavior. |
237 | * | | 254 | * |
238 | * For C99 compilers other than GCC, the C99 behavior is expected. | | 255 | * For C99 compilers other than GCC, the C99 behavior is expected. |
239 | */ | | 256 | */ |
240 | #if defined(__GNUC__) && defined(__GNUC_STDC_INLINE__) | | 257 | #if defined(__GNUC__) && defined(__GNUC_STDC_INLINE__) |
241 | #define __c99inline extern __attribute__((__gnu_inline__)) __inline | | 258 | #define __c99inline extern __attribute__((__gnu_inline__)) __inline |
242 | #elif defined(__GNUC__) | | 259 | #elif defined(__GNUC__) |
243 | #define __c99inline extern __inline | | 260 | #define __c99inline extern __inline |
244 | #elif defined(__STDC_VERSION__) | | 261 | #elif defined(__STDC_VERSION__) |
245 | #define __c99inline __inline | | 262 | #define __c99inline __inline |
246 | #endif | | 263 | #endif |
247 | | | 264 | |
248 | #if defined(__lint__) | | 265 | #if defined(__lint__) |
249 | #define __packed __packed | | 266 | #define __packed __packed |
250 | #define __aligned(x) /* delete */ | | 267 | #define __aligned(x) /* delete */ |
251 | #define __section(x) /* delete */ | | 268 | #define __section(x) /* delete */ |
252 | #elif __GNUC_PREREQ__(2, 7) | | 269 | #elif __GNUC_PREREQ__(2, 7) |
253 | #define __packed __attribute__((__packed__)) | | 270 | #define __packed __attribute__((__packed__)) |
254 | #define __aligned(x) __attribute__((__aligned__(x))) | | 271 | #define __aligned(x) __attribute__((__aligned__(x))) |
255 | #define __section(x) __attribute__((__section__(x))) | | 272 | #define __section(x) __attribute__((__section__(x))) |
256 | #elif defined(__PCC__) | | 273 | #elif defined(__PCC__) |
257 | #define __packed _Pragma("packed 1") | | 274 | #define __packed _Pragma("packed 1") |
258 | #define __aligned(x) _Pragma("aligned " __STRING(x)) | | 275 | #define __aligned(x) _Pragma("aligned " __STRING(x)) |
259 | #define __section(x) _Pragma("section " ## x) | | 276 | #define __section(x) _Pragma("section " ## x) |
260 | #else | | 277 | #else |
261 | #define __packed error: no __packed for this compiler | | 278 | #define __packed error: no __packed for this compiler |
262 | #define __aligned(x) error: no __aligned for this compiler | | 279 | #define __aligned(x) error: no __aligned for this compiler |
263 | #define __section(x) error: no __section for this compiler | | 280 | #define __section(x) error: no __section for this compiler |
264 | #endif | | 281 | #endif |
265 | | | 282 | |
266 | /* | | 283 | /* |
267 | * C99 defines the restrict type qualifier keyword, which was made available | | 284 | * C99 defines the restrict type qualifier keyword, which was made available |
268 | * in GCC 2.92. | | 285 | * in GCC 2.92. |
269 | */ | | 286 | */ |
270 | #if defined(__lint__) | | 287 | #if defined(__lint__) |
271 | #define __restrict /* delete __restrict when not supported */ | | 288 | #define __restrict /* delete __restrict when not supported */ |
272 | #elif __STDC_VERSION__ >= 199901L | | 289 | #elif __STDC_VERSION__ >= 199901L |
273 | #define __restrict restrict | | 290 | #define __restrict restrict |
274 | #elif !__GNUC_PREREQ__(2, 92) | | 291 | #elif !__GNUC_PREREQ__(2, 92) |
275 | #define __restrict /* delete __restrict when not supported */ | | 292 | #define __restrict /* delete __restrict when not supported */ |
276 | #endif | | 293 | #endif |
277 | | | 294 | |
278 | /* | | 295 | /* |
279 | * C99 defines __func__ predefined identifier, which was made available | | 296 | * C99 defines __func__ predefined identifier, which was made available |
280 | * in GCC 2.95. | | 297 | * in GCC 2.95. |
281 | */ | | 298 | */ |
282 | #if !(__STDC_VERSION__ >= 199901L) | | 299 | #if !(__STDC_VERSION__ >= 199901L) |
283 | #if __GNUC_PREREQ__(2, 6) | | 300 | #if __GNUC_PREREQ__(2, 6) |
284 | #define __func__ __PRETTY_FUNCTION__ | | 301 | #define __func__ __PRETTY_FUNCTION__ |
285 | #elif __GNUC_PREREQ__(2, 4) | | 302 | #elif __GNUC_PREREQ__(2, 4) |
286 | #define __func__ __FUNCTION__ | | 303 | #define __func__ __FUNCTION__ |
287 | #else | | 304 | #else |
288 | #define __func__ "" | | 305 | #define __func__ "" |
289 | #endif | | 306 | #endif |
290 | #endif /* !(__STDC_VERSION__ >= 199901L) */ | | 307 | #endif /* !(__STDC_VERSION__ >= 199901L) */ |
291 | | | 308 | |
292 | #if defined(_KERNEL) | | 309 | #if defined(_KERNEL) |
293 | #if defined(NO_KERNEL_RCSIDS) | | 310 | #if defined(NO_KERNEL_RCSIDS) |
294 | #undef __KERNEL_RCSID | | 311 | #undef __KERNEL_RCSID |
295 | #define __KERNEL_RCSID(_n, _s) /* nothing */ | | 312 | #define __KERNEL_RCSID(_n, _s) /* nothing */ |
296 | #endif /* NO_KERNEL_RCSIDS */ | | 313 | #endif /* NO_KERNEL_RCSIDS */ |
297 | #endif /* _KERNEL */ | | 314 | #endif /* _KERNEL */ |
298 | | | 315 | |
299 | #if !defined(_STANDALONE) && !defined(_KERNEL) | | 316 | #if !defined(_STANDALONE) && !defined(_KERNEL) |
300 | #if defined(__GNUC__) || defined(__PCC__) | | 317 | #if defined(__GNUC__) || defined(__PCC__) |
301 | #define __RENAME(x) ___RENAME(x) | | 318 | #define __RENAME(x) ___RENAME(x) |
302 | #else | | 319 | #else |
303 | #ifdef __lint__ | | 320 | #ifdef __lint__ |
304 | #define __RENAME(x) __symbolrename(x) | | 321 | #define __RENAME(x) __symbolrename(x) |
305 | #else | | 322 | #else |
306 | #error "No function renaming possible" | | 323 | #error "No function renaming possible" |
307 | #endif /* __lint__ */ | | 324 | #endif /* __lint__ */ |
308 | #endif /* __GNUC__ */ | | 325 | #endif /* __GNUC__ */ |
309 | #else /* _STANDALONE || _KERNEL */ | | 326 | #else /* _STANDALONE || _KERNEL */ |
310 | #define __RENAME(x) no renaming in kernel or standalone environment | | 327 | #define __RENAME(x) no renaming in kernel or standalone environment |
311 | #endif | | 328 | #endif |
312 | | | 329 | |
313 | /* | | 330 | /* |
314 | * A barrier to stop the optimizer from moving code or assume live | | 331 | * A barrier to stop the optimizer from moving code or assume live |
315 | * register values. This is gcc specific, the version is more or less | | 332 | * register values. This is gcc specific, the version is more or less |
316 | * arbitrary, might work with older compilers. | | 333 | * arbitrary, might work with older compilers. |
317 | */ | | 334 | */ |
318 | #if __GNUC_PREREQ__(2, 95) | | 335 | #if __GNUC_PREREQ__(2, 95) |
319 | #define __insn_barrier() __asm __volatile("":::"memory") | | 336 | #define __insn_barrier() __asm __volatile("":::"memory") |
320 | #else | | 337 | #else |
321 | #define __insn_barrier() /* */ | | 338 | #define __insn_barrier() /* */ |
322 | #endif | | 339 | #endif |
323 | | | 340 | |
324 | /* | | 341 | /* |
325 | * GNU C version 2.96 adds explicit branch prediction so that | | 342 | * GNU C version 2.96 adds explicit branch prediction so that |
326 | * the CPU back-end can hint the processor and also so that | | 343 | * the CPU back-end can hint the processor and also so that |
327 | * code blocks can be reordered such that the predicted path | | 344 | * code blocks can be reordered such that the predicted path |
328 | * sees a more linear flow, thus improving cache behavior, etc. | | 345 | * sees a more linear flow, thus improving cache behavior, etc. |
329 | * | | 346 | * |
330 | * The following two macros provide us with a way to use this | | 347 | * The following two macros provide us with a way to use this |
331 | * compiler feature. Use __predict_true() if you expect the expression | | 348 | * compiler feature. Use __predict_true() if you expect the expression |
332 | * to evaluate to true, and __predict_false() if you expect the | | 349 | * to evaluate to true, and __predict_false() if you expect the |
333 | * expression to evaluate to false. | | 350 | * expression to evaluate to false. |
334 | * | | 351 | * |
335 | * A few notes about usage: | | 352 | * A few notes about usage: |
336 | * | | 353 | * |
337 | * * Generally, __predict_false() error condition checks (unless | | 354 | * * Generally, __predict_false() error condition checks (unless |
338 | * you have some _strong_ reason to do otherwise, in which case | | 355 | * you have some _strong_ reason to do otherwise, in which case |
339 | * document it), and/or __predict_true() `no-error' condition | | 356 | * document it), and/or __predict_true() `no-error' condition |
340 | * checks, assuming you want to optimize for the no-error case. | | 357 | * checks, assuming you want to optimize for the no-error case. |
341 | * | | 358 | * |
342 | * * Other than that, if you don't know the likelihood of a test | | 359 | * * Other than that, if you don't know the likelihood of a test |
343 | * succeeding from empirical or other `hard' evidence, don't | | 360 | * succeeding from empirical or other `hard' evidence, don't |
344 | * make predictions. | | 361 | * make predictions. |
345 | * | | 362 | * |
346 | * * These are meant to be used in places that are run `a lot'. | | 363 | * * These are meant to be used in places that are run `a lot'. |
347 | * It is wasteful to make predictions in code that is run | | 364 | * It is wasteful to make predictions in code that is run |
348 | * seldomly (e.g. at subsystem initialization time) as the | | 365 | * seldomly (e.g. at subsystem initialization time) as the |
349 | * basic block reordering that this affects can often generate | | 366 | * basic block reordering that this affects can often generate |
350 | * larger code. | | 367 | * larger code. |
351 | */ | | 368 | */ |
352 | #if __GNUC_PREREQ__(2, 96) | | 369 | #if __GNUC_PREREQ__(2, 96) |
353 | #define __predict_true(exp) __builtin_expect((exp) != 0, 1) | | 370 | #define __predict_true(exp) __builtin_expect((exp) != 0, 1) |
354 | #define __predict_false(exp) __builtin_expect((exp) != 0, 0) | | 371 | #define __predict_false(exp) __builtin_expect((exp) != 0, 0) |
355 | #else | | 372 | #else |
356 | #define __predict_true(exp) (exp) | | 373 | #define __predict_true(exp) (exp) |
357 | #define __predict_false(exp) (exp) | | 374 | #define __predict_false(exp) (exp) |
358 | #endif | | 375 | #endif |
359 | | | 376 | |
360 | /* | | 377 | /* |
361 | * Compiler-dependent macros to declare that functions take printf-like | | 378 | * Compiler-dependent macros to declare that functions take printf-like |
362 | * or scanf-like arguments. They are null except for versions of gcc | | 379 | * or scanf-like arguments. They are null except for versions of gcc |
363 | * that are known to support the features properly (old versions of gcc-2 | | 380 | * that are known to support the features properly (old versions of gcc-2 |
364 | * didn't permit keeping the keywords out of the application namespace). | | 381 | * didn't permit keeping the keywords out of the application namespace). |
365 | */ | | 382 | */ |
366 | #if __GNUC_PREREQ__(2, 7) | | 383 | #if __GNUC_PREREQ__(2, 7) |
367 | #define __printflike(fmtarg, firstvararg) \ | | 384 | #define __printflike(fmtarg, firstvararg) \ |
368 | __attribute__((__format__ (__printf__, fmtarg, firstvararg))) | | 385 | __attribute__((__format__ (__printf__, fmtarg, firstvararg))) |
369 | #define __scanflike(fmtarg, firstvararg) \ | | 386 | #define __scanflike(fmtarg, firstvararg) \ |
370 | __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) | | 387 | __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) |
371 | #define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) | | 388 | #define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) |
372 | #else | | 389 | #else |
373 | #define __printflike(fmtarg, firstvararg) /* nothing */ | | 390 | #define __printflike(fmtarg, firstvararg) /* nothing */ |
374 | #define __scanflike(fmtarg, firstvararg) /* nothing */ | | 391 | #define __scanflike(fmtarg, firstvararg) /* nothing */ |
375 | #define __format_arg(fmtarg) /* nothing */ | | 392 | #define __format_arg(fmtarg) /* nothing */ |
376 | #endif | | 393 | #endif |
377 | | | 394 | |
378 | /* | | 395 | /* |
379 | * Macros for manipulating "link sets". Link sets are arrays of pointers | | 396 | * Macros for manipulating "link sets". Link sets are arrays of pointers |
380 | * to objects, which are gathered up by the linker. | | 397 | * to objects, which are gathered up by the linker. |
381 | * | | 398 | * |
382 | * Object format-specific code has provided us with the following macros: | | 399 | * Object format-specific code has provided us with the following macros: |
383 | * | | 400 | * |
384 | * __link_set_add_text(set, sym) | | 401 | * __link_set_add_text(set, sym) |
385 | * Add a reference to the .text symbol `sym' to `set'. | | 402 | * Add a reference to the .text symbol `sym' to `set'. |
386 | * | | 403 | * |
387 | * __link_set_add_rodata(set, sym) | | 404 | * __link_set_add_rodata(set, sym) |
388 | * Add a reference to the .rodata symbol `sym' to `set'. | | 405 | * Add a reference to the .rodata symbol `sym' to `set'. |
389 | * | | 406 | * |
390 | * __link_set_add_data(set, sym) | | 407 | * __link_set_add_data(set, sym) |
391 | * Add a reference to the .data symbol `sym' to `set'. | | 408 | * Add a reference to the .data symbol `sym' to `set'. |
392 | * | | 409 | * |
393 | * __link_set_add_bss(set, sym) | | 410 | * __link_set_add_bss(set, sym) |
394 | * Add a reference to the .bss symbol `sym' to `set'. | | 411 | * Add a reference to the .bss symbol `sym' to `set'. |
395 | * | | 412 | * |
396 | * __link_set_decl(set, ptype) | | 413 | * __link_set_decl(set, ptype) |
397 | * Provide an extern declaration of the set `set', which | | 414 | * Provide an extern declaration of the set `set', which |
398 | * contains an array of the pointer type `ptype'. This | | 415 | * contains an array of the pointer type `ptype'. This |
399 | * macro must be used by any code which wishes to reference | | 416 | * macro must be used by any code which wishes to reference |
400 | * the elements of a link set. | | 417 | * the elements of a link set. |
401 | * | | 418 | * |
402 | * __link_set_start(set) | | 419 | * __link_set_start(set) |
403 | * This points to the first slot in the link set. | | 420 | * This points to the first slot in the link set. |
404 | * | | 421 | * |
405 | * __link_set_end(set) | | 422 | * __link_set_end(set) |
406 | * This points to the (non-existent) slot after the last | | 423 | * This points to the (non-existent) slot after the last |
407 | * entry in the link set. | | 424 | * entry in the link set. |
408 | * | | 425 | * |
409 | * __link_set_count(set) | | 426 | * __link_set_count(set) |
410 | * Count the number of entries in link set `set'. | | 427 | * Count the number of entries in link set `set'. |
411 | * | | 428 | * |
412 | * In addition, we provide the following macros for accessing link sets: | | 429 | * In addition, we provide the following macros for accessing link sets: |
413 | * | | 430 | * |
414 | * __link_set_foreach(pvar, set) | | 431 | * __link_set_foreach(pvar, set) |
415 | * Iterate over the link set `set'. Because a link set is | | 432 | * Iterate over the link set `set'. Because a link set is |
416 | * an array of pointers, pvar must be declared as "type **pvar", | | 433 | * an array of pointers, pvar must be declared as "type **pvar", |
417 | * and the actual entry accessed as "*pvar". | | 434 | * and the actual entry accessed as "*pvar". |
418 | * | | 435 | * |
419 | * __link_set_entry(set, idx) | | 436 | * __link_set_entry(set, idx) |
420 | * Access the link set entry at index `idx' from set `set'. | | 437 | * Access the link set entry at index `idx' from set `set'. |
421 | */ | | 438 | */ |
422 | #define __link_set_foreach(pvar, set) \ | | 439 | #define __link_set_foreach(pvar, set) \ |
423 | for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) | | 440 | for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) |
424 | | | 441 | |
425 | #define __link_set_entry(set, idx) (__link_set_begin(set)[idx]) | | 442 | #define __link_set_entry(set, idx) (__link_set_begin(set)[idx]) |
426 | | | 443 | |
427 | /* | | 444 | /* |
428 | * Return the number of elements in a statically-allocated array, | | 445 | * Return the number of elements in a statically-allocated array, |
429 | * __x. | | 446 | * __x. |
430 | */ | | 447 | */ |
431 | #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) | | 448 | #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) |
432 | | | 449 | |
433 | /* __BIT(n): nth bit, where __BIT(0) == 0x1. */ | | 450 | /* __BIT(n): nth bit, where __BIT(0) == 0x1. */ |
434 | #define __BIT(__n) \ | | 451 | #define __BIT(__n) \ |
435 | (((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : ((uintmax_t)1 << (uintmax_t)(__n))) | | 452 | (((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : ((uintmax_t)1 << (uintmax_t)(__n))) |
436 | | | 453 | |
437 | /* __BITS(m, n): bits m through n, m < n. */ | | 454 | /* __BITS(m, n): bits m through n, m < n. */ |
438 | #define __BITS(__m, __n) \ | | 455 | #define __BITS(__m, __n) \ |
439 | ((__BIT(MAX((__m), (__n)) + 1) - 1) ^ (__BIT(MIN((__m), (__n))) - 1)) | | 456 | ((__BIT(MAX((__m), (__n)) + 1) - 1) ^ (__BIT(MIN((__m), (__n))) - 1)) |
440 | | | 457 | |
441 | /* find least significant bit that is set */ | | 458 | /* find least significant bit that is set */ |
442 | #define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask)) | | 459 | #define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask)) |
443 | | | 460 | |
444 | #define __PRIuBIT PRIuMAX | | 461 | #define __PRIuBIT PRIuMAX |
445 | #define __PRIuBITS __PRIuBIT | | 462 | #define __PRIuBITS __PRIuBIT |
446 | | | 463 | |
447 | #define __PRIxBIT PRIxMAX | | 464 | #define __PRIxBIT PRIxMAX |
448 | #define __PRIxBITS __PRIxBIT | | 465 | #define __PRIxBITS __PRIxBIT |
449 | | | 466 | |
450 | #define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask)) | | 467 | #define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask)) |
451 | #define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask)) | | 468 | #define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask)) |
452 | #define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask)) | | 469 | #define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask)) |
453 | | | 470 | |
454 | /* | | 471 | /* |
455 | * Only to be used in other headers that are included from both c or c++ | | 472 | * Only to be used in other headers that are included from both c or c++ |
456 | * NOT to be used in code. | | 473 | * NOT to be used in code. |
457 | */ | | 474 | */ |
458 | #ifdef __cplusplus | | 475 | #ifdef __cplusplus |
459 | #define __CAST(__dt, __st) static_cast<__dt>(__st) | | 476 | #define __CAST(__dt, __st) static_cast<__dt>(__st) |
460 | #else | | 477 | #else |
461 | #define __CAST(__dt, __st) ((__dt)(__st)) | | 478 | #define __CAST(__dt, __st) ((__dt)(__st)) |
462 | #endif | | 479 | #endif |
463 | | | 480 | |
464 | #endif /* !_SYS_CDEFS_H_ */ | | 481 | #endif /* !_SYS_CDEFS_H_ */ |