FreeBSD/Linux Kernel Cross Reference
sys/sys/cdefs.h
1 /* $NetBSD: cdefs.h,v 1.51 2004/01/07 19:38:10 martin Exp $ */
2
3 /*
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Berkeley Software Design, Inc.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
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
20 * without specific prior written permission.
21 *
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
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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
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
32 * SUCH DAMAGE.
33 *
34 * @(#)cdefs.h 8.8 (Berkeley) 1/9/95
35 */
36
37 #ifndef _SYS_CDEFS_H_
38 #define _SYS_CDEFS_H_
39
40 /*
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
43 * of GNU C. Usage:
44 *
45 * #if __GNUC_PREREQ__(major, minor)
46 * ...cool feature...
47 * #else
48 * ...delete feature...
49 * #endif
50 */
51 #ifdef __GNUC__
52 #define __GNUC_PREREQ__(x, y) \
53 ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
54 (__GNUC__ > (x)))
55 #else
56 #define __GNUC_PREREQ__(x, y) 0
57 #endif
58
59 #include <machine/cdefs.h>
60 #ifdef __ELF__
61 #include <sys/cdefs_elf.h>
62 #else
63 #include <sys/cdefs_aout.h>
64 #endif
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 /*
77 * 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.
79 * 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
81 * strings produced by the __STRING macro, but this only works with ANSI C.
82 */
83
84 #define ___STRING(x) __STRING(x)
85 #define ___CONCAT(x,y) __CONCAT(x,y)
86
87 #if __STDC__ || defined(__cplusplus)
88 #define __P(protos) protos /* full-blown ANSI C */
89 #define __CONCAT(x,y) x ## y
90 #define __STRING(x) #x
91
92 #define __const const /* define reserved names to standard */
93 #define __signed signed
94 #define __volatile volatile
95 #if defined(__cplusplus)
96 #define __inline inline /* convert to C++ keyword */
97 #else
98 #if !defined(__GNUC__) && !defined(__lint__)
99 #define __inline /* delete GCC keyword */
100 #endif /* !__GNUC__ && !__lint__ */
101 #endif /* !__cplusplus */
102
103 #else /* !(__STDC__ || __cplusplus) */
104 #define __P(protos) () /* traditional C preprocessor */
105 #define __CONCAT(x,y) x/**/y
106 #define __STRING(x) "x"
107
108 #ifndef __GNUC__
109 #define __const /* delete pseudo-ANSI C keywords */
110 #define __inline
111 #define __signed
112 #define __volatile
113 #endif /* !__GNUC__ */
114
115 /*
116 * 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.
118 * Programs using the ANSI C keywords const, inline etc. as normal
119 * identifiers should define -DNO_ANSI_KEYWORDS.
120 */
121 #ifndef NO_ANSI_KEYWORDS
122 #define const __const /* convert ANSI C keywords */
123 #define inline __inline
124 #define signed __signed
125 #define volatile __volatile
126 #endif /* !NO_ANSI_KEYWORDS */
127 #endif /* !(__STDC__ || __cplusplus) */
128
129 /*
130 * Used for internal auditing of the NetBSD source tree.
131 */
132 #ifdef __AUDIT__
133 #define __aconst __const
134 #else
135 #define __aconst
136 #endif
137
138 /*
139 * GCC2 provides __extension__ to suppress warnings for various GNU C
140 * language extensions under "-ansi -pedantic".
141 */
142 #if !__GNUC_PREREQ__(2, 0)
143 #define __extension__ /* delete __extension__ if non-gcc or gcc1 */
144 #endif
145
146 /*
147 * GCC1 and some versions of GCC2 declare dead (non-returning) and
148 * pure (no side effects) functions using "volatile" and "const";
149 * unfortunately, these then cause warnings under "-ansi -pedantic".
150 * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of
151 * these work for GNU C++ (modulo a slight glitch in the C++ grammar
152 * in the distribution version of 2.5.5).
153 */
154 #if !__GNUC_PREREQ__(2, 5)
155 #define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */
156 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
157 #define __dead __volatile
158 #define __pure __const
159 #endif
160 #endif
161
162 /* Delete pseudo-keywords wherever they are not available or needed. */
163 #ifndef __dead
164 #define __dead
165 #define __pure
166 #endif
167
168 #if __GNUC_PREREQ__(2, 7)
169 #define __unused __attribute__((__unused__))
170 #else
171 #define __unused /* delete */
172 #endif
173
174 #if __GNUC_PREREQ__(2, 7)
175 #define __packed __attribute__((__packed__))
176 #define __aligned(x) __attribute__((__aligned__(x)))
177 #define __section(x) __attribute__((__section__(x)))
178 #elif defined(__lint__)
179 #define __packed /* delete */
180 #define __aligned(x) /* delete */
181 #define __section(x) /* delete */
182 #else
183 #define __packed error: no __packed for this compiler
184 #define __aligned(x) error: no __aligned for this compiler
185 #define __section(x) error: no __section for this compiler
186 #endif
187
188 /*
189 * C99 defines the restrict type qualifier keyword, which was made available
190 * in GCC 2.92.
191 */
192 #if __STDC_VERSION__ >= 199901L
193 #define __restrict restrict
194 #else
195 #if !__GNUC_PREREQ__(2, 92)
196 #define __restrict /* delete __restrict when not supported */
197 #endif
198 #endif
199
200 /*
201 * C99 defines __func__ predefined identifier, which was made available
202 * in GCC 2.95.
203 */
204 #if !(__STDC_VERSION__ >= 199901L)
205 #if __GNUC_PREREQ__(2, 6)
206 #define __func__ __PRETTY_FUNCTION__
207 #elif __GNUC_PREREQ__(2, 4)
208 #define __func__ __FUNCTION__
209 #else
210 #define __func__ ""
211 #endif
212 #endif /* !(__STDC_VERSION__ >= 199901L) */
213
214 #if defined(_KERNEL)
215 #if defined(NO_KERNEL_RCSIDS)
216 #undef __KERNEL_RCSID
217 #define __KERNEL_RCSID(_n, _s) /* nothing */
218 #endif /* NO_KERNEL_RCSIDS */
219 #endif /* _KERNEL */
220
221 #if !defined(_STANDALONE) && !defined(_KERNEL)
222 #ifdef __GNUC__
223 #define __RENAME(x) ___RENAME(x)
224 #else
225 #ifdef __lint__
226 #define __RENAME(x) __symbolrename(x)
227 #else
228 #error "No function renaming possible"
229 #endif /* __lint__ */
230 #endif /* __GNUC__ */
231 #else /* _STANDALONE || _KERNEL */
232 #define __RENAME(x) no renaming in kernel or standalone environment
233 #endif
234
235 /*
236 * A barrier to stop the optimizer from moving code or assume live
237 * register values. This is gcc specific, the version is more or less
238 * arbitrary, might work with older compilers.
239 */
240 #if __GNUC_PREREQ__(2, 95)
241 #define __insn_barrier() __asm __volatile("":::"memory")
242 #else
243 #define __insn_barrier() /* */
244 #endif
245
246 /*
247 * GNU C version 2.96 adds explicit branch prediction so that
248 * the CPU back-end can hint the processor and also so that
249 * code blocks can be reordered such that the predicted path
250 * sees a more linear flow, thus improving cache behavior, etc.
251 *
252 * The following two macros provide us with a way to use this
253 * compiler feature. Use __predict_true() if you expect the expression
254 * to evaluate to true, and __predict_false() if you expect the
255 * expression to evaluate to false.
256 *
257 * A few notes about usage:
258 *
259 * * Generally, __predict_false() error condition checks (unless
260 * you have some _strong_ reason to do otherwise, in which case
261 * document it), and/or __predict_true() `no-error' condition
262 * checks, assuming you want to optimize for the no-error case.
263 *
264 * * Other than that, if you don't know the likelihood of a test
265 * succeeding from empirical or other `hard' evidence, don't
266 * make predictions.
267 *
268 * * These are meant to be used in places that are run `a lot'.
269 * It is wasteful to make predictions in code that is run
270 * seldomly (e.g. at subsystem initialization time) as the
271 * basic block reordering that this affects can often generate
272 * larger code.
273 */
274 #if __GNUC_PREREQ__(2, 96)
275 #define __predict_true(exp) __builtin_expect((exp) != 0, 1)
276 #define __predict_false(exp) __builtin_expect((exp) != 0, 0)
277 #else
278 #define __predict_true(exp) (exp)
279 #define __predict_false(exp) (exp)
280 #endif
281
282 /*
283 * Macros for manipulating "link sets". Link sets are arrays of pointers
284 * to objects, which are gathered up by the linker.
285 *
286 * Object format-specific code has provided us with the following macros:
287 *
288 * __link_set_add_text(set, sym)
289 * Add a reference to the .text symbol `sym' to `set'.
290 *
291 * __link_set_add_rodata(set, sym)
292 * Add a reference to the .rodata symbol `sym' to `set'.
293 *
294 * __link_set_add_data(set, sym)
295 * Add a reference to the .data symbol `sym' to `set'.
296 *
297 * __link_set_add_bss(set, sym)
298 * Add a reference to the .bss symbol `sym' to `set'.
299 *
300 * __link_set_decl(set, ptype)
301 * Provide an extern declaration of the set `set', which
302 * contains an array of the pointer type `ptype'. This
303 * macro must be used by any code which wishes to reference
304 * the elements of a link set.
305 *
306 * __link_set_start(set)
307 * This points to the first slot in the link set.
308 *
309 * __link_set_end(set)
310 * This points to the (non-existent) slot after the last
311 * entry in the link set.
312 *
313 * __link_set_count(set)
314 * Count the number of entries in link set `set'.
315 *
316 * In addition, we provide the following macros for accessing link sets:
317 *
318 * __link_set_foreach(pvar, set)
319 * Iterate over the link set `set'. Because a link set is
320 * an array of pointers, pvar must be declared as "type **pvar",
321 * and the actual entry accessed as "*pvar".
322 *
323 * __link_set_entry(set, idx)
324 * Access the link set entry at index `idx' from set `set'.
325 */
326 #define __link_set_foreach(pvar, set) \
327 for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++)
328
329 #define __link_set_entry(set, idx) (__link_set_begin(set)[idx])
330
331 #endif /* !_SYS_CDEFS_H_ */
Cache object: 630b0053eeb02eb3fac7f47675156e77
|