1 /* $NetBSD: cdefs.h,v 1.58 2004/12/11 05:59:00 christos Exp $ */
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Berkeley Software Design, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
34 * @(#)cdefs.h 8.8 (Berkeley) 1/9/95
41 /* our implementation of wchar_t is only 8-bit - die die non-portable code */
43 #define __WCHAR_TYPE__ unsigned char
47 * Macro to test if we're using a GNU C compiler of a specific vintage
48 * or later, for e.g. features that appeared in a particular version
51 * #if __GNUC_PREREQ__(major, minor)
54 * ...delete feature...
58 #define __GNUC_PREREQ__(x, y) \
59 ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \
62 #define __GNUC_PREREQ__(x, y) 0
65 //XXX #include <machine/cdefs.h>
67 /* BIONIC: simpler definition */
68 #define __BSD_VISIBLE 1
70 #include <sys/cdefs_elf.h>
72 #if defined(__cplusplus)
73 #define __BEGIN_DECLS extern "C" {
75 #define __static_cast(x,y) static_cast<x>(y)
79 #define __static_cast(x,y) (x)y
83 * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
84 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
85 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
86 * in between its arguments. __CONCAT can also concatenate double-quoted
87 * strings produced by the __STRING macro, but this only works with ANSI C.
90 #define ___STRING(x) __STRING(x)
91 #define ___CONCAT(x,y) __CONCAT(x,y)
93 #if __STDC__ || defined(__cplusplus)
94 #define __P(protos) protos /* full-blown ANSI C */
95 #define __CONCAT(x,y) x ## y
96 #define __STRING(x) #x
98 #define __const const /* define reserved names to standard */
99 #define __signed signed
100 #define __volatile volatile
101 #if defined(__cplusplus)
102 #define __inline inline /* convert to C++ keyword */
104 #if !defined(__GNUC__) && !defined(__lint__)
105 #define __inline /* delete GCC keyword */
106 #endif /* !__GNUC__ && !__lint__ */
107 #endif /* !__cplusplus */
109 #else /* !(__STDC__ || __cplusplus) */
110 #define __P(protos) () /* traditional C preprocessor */
111 #define __CONCAT(x,y) x/**/y
112 #define __STRING(x) "x"
115 #define __const /* delete pseudo-ANSI C keywords */
119 #endif /* !__GNUC__ */
122 * In non-ANSI C environments, new programs will want ANSI-only C keywords
123 * deleted from the program and old programs will want them left alone.
124 * Programs using the ANSI C keywords const, inline etc. as normal
125 * identifiers should define -DNO_ANSI_KEYWORDS.
127 #ifndef NO_ANSI_KEYWORDS
128 #define const __const /* convert ANSI C keywords */
129 #define inline __inline
130 #define signed __signed
131 #define volatile __volatile
132 #endif /* !NO_ANSI_KEYWORDS */
133 #endif /* !(__STDC__ || __cplusplus) */
136 * Used for internal auditing of the NetBSD source tree.
139 #define __aconst __const
145 * The following macro is used to remove const cast-away warnings
146 * from gcc -Wcast-qual; it should be used with caution because it
147 * can hide valid errors; in particular most valid uses are in
148 * situations where the API requires it, not to cast away string
149 * constants. We don't use *intptr_t on purpose here and we are
150 * explicit about unsigned long so that we don't have additional
153 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
156 * GCC2 provides __extension__ to suppress warnings for various GNU C
157 * language extensions under "-ansi -pedantic".
159 #if !__GNUC_PREREQ__(2, 0)
160 #define __extension__ /* delete __extension__ if non-gcc or gcc1 */
164 * GCC1 and some versions of GCC2 declare dead (non-returning) and
165 * pure (no side effects) functions using "volatile" and "const";
166 * unfortunately, these then cause warnings under "-ansi -pedantic".
167 * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of
168 * these work for GNU C++ (modulo a slight glitch in the C++ grammar
169 * in the distribution version of 2.5.5).
171 #if !__GNUC_PREREQ__(2, 5)
172 #define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */
173 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
174 #define __dead __volatile
175 #define __pure __const
179 /* Delete pseudo-keywords wherever they are not available or needed. */
185 #if __GNUC_PREREQ__(2, 7)
186 #define __unused __attribute__((__unused__))
188 #define __unused /* delete */
191 #if __GNUC_PREREQ__(3, 1)
192 #define __used __attribute__((__used__))
194 #define __used /* delete */
197 #if __GNUC_PREREQ__(2, 7)
198 #define __packed __attribute__((__packed__))
199 #define __aligned(x) __attribute__((__aligned__(x)))
200 #define __section(x) __attribute__((__section__(x)))
201 #elif defined(__lint__)
202 #define __packed /* delete */
203 #define __aligned(x) /* delete */
204 #define __section(x) /* delete */
206 #define __packed error: no __packed for this compiler
207 #define __aligned(x) error: no __aligned for this compiler
208 #define __section(x) error: no __section for this compiler
211 #if !__GNUC_PREREQ__(2, 8)
212 #define __extension__
215 #if __GNUC_PREREQ__(2, 8)
216 #define __statement(x) __extension__(x)
218 #define __statement(x) (0)
220 #define __statement(x) (x)
224 * C99 defines the restrict type qualifier keyword, which was made available
227 #if __STDC_VERSION__ >= 199901L
228 #define __restrict restrict
230 #if !__GNUC_PREREQ__(2, 92)
231 #define __restrict /* delete __restrict when not supported */
236 * C99 defines __func__ predefined identifier, which was made available
239 #if !(__STDC_VERSION__ >= 199901L)
240 #if __GNUC_PREREQ__(2, 6)
241 #define __func__ __PRETTY_FUNCTION__
242 #elif __GNUC_PREREQ__(2, 4)
243 #define __func__ __FUNCTION__
247 #endif /* !(__STDC_VERSION__ >= 199901L) */
250 #if defined(NO_KERNEL_RCSIDS)
251 #undef __KERNEL_RCSID
252 #define __KERNEL_RCSID(_n, _s) /* nothing */
253 #endif /* NO_KERNEL_RCSIDS */
256 #if !defined(_STANDALONE) && !defined(_KERNEL)
258 #define __RENAME(x) ___RENAME(x)
261 #define __RENAME(x) __symbolrename(x)
263 #error "No function renaming possible"
264 #endif /* __lint__ */
265 #endif /* __GNUC__ */
266 #else /* _STANDALONE || _KERNEL */
267 #define __RENAME(x) no renaming in kernel or standalone environment
271 * A barrier to stop the optimizer from moving code or assume live
272 * register values. This is gcc specific, the version is more or less
273 * arbitrary, might work with older compilers.
275 #if __GNUC_PREREQ__(2, 95)
276 #define __insn_barrier() __asm __volatile("":::"memory")
278 #define __insn_barrier() /* */
282 * GNU C version 2.96 adds explicit branch prediction so that
283 * the CPU back-end can hint the processor and also so that
284 * code blocks can be reordered such that the predicted path
285 * sees a more linear flow, thus improving cache behavior, etc.
287 * The following two macros provide us with a way to use this
288 * compiler feature. Use __predict_true() if you expect the expression
289 * to evaluate to true, and __predict_false() if you expect the
290 * expression to evaluate to false.
292 * A few notes about usage:
294 * * Generally, __predict_false() error condition checks (unless
295 * you have some _strong_ reason to do otherwise, in which case
296 * document it), and/or __predict_true() `no-error' condition
297 * checks, assuming you want to optimize for the no-error case.
299 * * Other than that, if you don't know the likelihood of a test
300 * succeeding from empirical or other `hard' evidence, don't
303 * * These are meant to be used in places that are run `a lot'.
304 * It is wasteful to make predictions in code that is run
305 * seldomly (e.g. at subsystem initialization time) as the
306 * basic block reordering that this affects can often generate
309 #if __GNUC_PREREQ__(2, 96)
310 #define __predict_true(exp) __builtin_expect((exp) != 0, 1)
311 #define __predict_false(exp) __builtin_expect((exp) != 0, 0)
313 #define __predict_true(exp) (exp)
314 #define __predict_false(exp) (exp)
317 #if __GNUC_PREREQ__(2, 96)
318 #define __noreturn __attribute__((__noreturn__))
319 #define __mallocfunc __attribute__((malloc))
326 * Macros for manipulating "link sets". Link sets are arrays of pointers
327 * to objects, which are gathered up by the linker.
329 * Object format-specific code has provided us with the following macros:
331 * __link_set_add_text(set, sym)
332 * Add a reference to the .text symbol `sym' to `set'.
334 * __link_set_add_rodata(set, sym)
335 * Add a reference to the .rodata symbol `sym' to `set'.
337 * __link_set_add_data(set, sym)
338 * Add a reference to the .data symbol `sym' to `set'.
340 * __link_set_add_bss(set, sym)
341 * Add a reference to the .bss symbol `sym' to `set'.
343 * __link_set_decl(set, ptype)
344 * Provide an extern declaration of the set `set', which
345 * contains an array of the pointer type `ptype'. This
346 * macro must be used by any code which wishes to reference
347 * the elements of a link set.
349 * __link_set_start(set)
350 * This points to the first slot in the link set.
352 * __link_set_end(set)
353 * This points to the (non-existent) slot after the last
354 * entry in the link set.
356 * __link_set_count(set)
357 * Count the number of entries in link set `set'.
359 * In addition, we provide the following macros for accessing link sets:
361 * __link_set_foreach(pvar, set)
362 * Iterate over the link set `set'. Because a link set is
363 * an array of pointers, pvar must be declared as "type **pvar",
364 * and the actual entry accessed as "*pvar".
366 * __link_set_entry(set, idx)
367 * Access the link set entry at index `idx' from set `set'.
369 #define __link_set_foreach(pvar, set) \
370 for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++)
372 #define __link_set_entry(set, idx) (__link_set_begin(set)[idx])
376 #endif /* !_SYS_CDEFS_H_ */