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