• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*	$NetBSD: cdefs.h,v 1.58 2004/12/11 05:59:00 christos 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 /* our implementation of wchar_t is only 8-bit - die die non-portable code */
42 #undef  __WCHAR_TYPE__
43 #define __WCHAR_TYPE__  unsigned char
44 
45 
46 /*
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
49  * of GNU C.  Usage:
50  *
51  *	#if __GNUC_PREREQ__(major, minor)
52  *	...cool feature...
53  *	#else
54  *	...delete feature...
55  *	#endif
56  */
57 #ifdef __GNUC__
58 #define	__GNUC_PREREQ__(x, y)						\
59 	((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) ||			\
60 	 (__GNUC__ > (x)))
61 #else
62 #define	__GNUC_PREREQ__(x, y)	0
63 #endif
64 
65 //XXX #include <machine/cdefs.h>
66 
67 /* BIONIC: simpler definition */
68 #define __BSD_VISIBLE   1
69 
70 #include <sys/cdefs_elf.h>
71 
72 #if defined(__cplusplus)
73 #define	__BEGIN_DECLS		extern "C" {
74 #define	__END_DECLS		}
75 #define	__static_cast(x,y)	static_cast<x>(y)
76 #else
77 #define	__BEGIN_DECLS
78 #define	__END_DECLS
79 #define	__static_cast(x,y)	(x)y
80 #endif
81 
82 /*
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.
88  */
89 
90 #define	___STRING(x)	__STRING(x)
91 #define	___CONCAT(x,y)	__CONCAT(x,y)
92 
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
97 
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 */
103 #else
104 #if !defined(__GNUC__) && !defined(__lint__)
105 #define	__inline			/* delete GCC keyword */
106 #endif /* !__GNUC__  && !__lint__ */
107 #endif /* !__cplusplus */
108 
109 #else	/* !(__STDC__ || __cplusplus) */
110 #define	__P(protos)	()		/* traditional C preprocessor */
111 #define	__CONCAT(x,y)	x/**/y
112 #define	__STRING(x)	"x"
113 
114 #ifndef __GNUC__
115 #define	__const				/* delete pseudo-ANSI C keywords */
116 #define	__inline
117 #define	__signed
118 #define	__volatile
119 #endif	/* !__GNUC__ */
120 
121 /*
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.
126  */
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) */
134 
135 /*
136  * Used for internal auditing of the NetBSD source tree.
137  */
138 #ifdef __AUDIT__
139 #define	__aconst	__const
140 #else
141 #define	__aconst
142 #endif
143 
144 /*
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
151  * dependencies.
152  */
153 #define __UNCONST(a)	((void *)(unsigned long)(const void *)(a))
154 
155 /*
156  * GCC2 provides __extension__ to suppress warnings for various GNU C
157  * language extensions under "-ansi -pedantic".
158  */
159 #if !__GNUC_PREREQ__(2, 0)
160 #define	__extension__		/* delete __extension__ if non-gcc or gcc1 */
161 #endif
162 
163 /*
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).
170  */
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
176 #endif
177 #endif
178 
179 /* Delete pseudo-keywords wherever they are not available or needed. */
180 #ifndef __dead
181 #define	__dead
182 #define	__pure
183 #endif
184 
185 #if __GNUC_PREREQ__(2, 7)
186 #define	__unused	__attribute__((__unused__))
187 #else
188 #define	__unused	/* delete */
189 #endif
190 
191 #if __GNUC_PREREQ__(3, 1)
192 #define	__used		__attribute__((__used__))
193 #else
194 #define	__used		/* delete */
195 #endif
196 
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 */
205 #else
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
209 #endif
210 
211 #if !__GNUC_PREREQ__(2, 8)
212 #define	__extension__
213 #endif
214 
215 #if __GNUC_PREREQ__(2, 8)
216 #define __statement(x)	__extension__(x)
217 #elif defined(lint)
218 #define __statement(x)	(0)
219 #else
220 #define __statement(x)	(x)
221 #endif
222 
223 /*
224  * C99 defines the restrict type qualifier keyword, which was made available
225  * in GCC 2.92.
226  */
227 #if __STDC_VERSION__ >= 199901L
228 #define	__restrict	restrict
229 #else
230 #if !__GNUC_PREREQ__(2, 92)
231 #define	__restrict	/* delete __restrict when not supported */
232 #endif
233 #endif
234 
235 /*
236  * C99 defines __func__ predefined identifier, which was made available
237  * in GCC 2.95.
238  */
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__
244 #else
245 #define	__func__	""
246 #endif
247 #endif /* !(__STDC_VERSION__ >= 199901L) */
248 
249 #if defined(_KERNEL)
250 #if defined(NO_KERNEL_RCSIDS)
251 #undef __KERNEL_RCSID
252 #define	__KERNEL_RCSID(_n, _s)		/* nothing */
253 #endif /* NO_KERNEL_RCSIDS */
254 #endif /* _KERNEL */
255 
256 #if !defined(_STANDALONE) && !defined(_KERNEL)
257 #ifdef __GNUC__
258 #define	__RENAME(x)	___RENAME(x)
259 #else
260 #ifdef __lint__
261 #define	__RENAME(x)	__symbolrename(x)
262 #else
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
268 #endif
269 
270 /*
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.
274  */
275 #if __GNUC_PREREQ__(2, 95)
276 #define	__insn_barrier()	__asm __volatile("":::"memory")
277 #else
278 #define	__insn_barrier()	/* */
279 #endif
280 
281 /*
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.
286  *
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.
291  *
292  * A few notes about usage:
293  *
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.
298  *
299  *	* Other than that, if you don't know the likelihood of a test
300  *	  succeeding from empirical or other `hard' evidence, don't
301  *	  make predictions.
302  *
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
307  *	  larger code.
308  */
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)
312 #else
313 #define	__predict_true(exp)	(exp)
314 #define	__predict_false(exp)	(exp)
315 #endif
316 
317 #if __GNUC_PREREQ__(2, 96)
318 #define __noreturn    __attribute__((__noreturn__))
319 #define __mallocfunc  __attribute__((malloc))
320 #else
321 #define __noreturn
322 #define __mallocfunc
323 #endif
324 
325 /*
326  * Macros for manipulating "link sets".  Link sets are arrays of pointers
327  * to objects, which are gathered up by the linker.
328  *
329  * Object format-specific code has provided us with the following macros:
330  *
331  *	__link_set_add_text(set, sym)
332  *		Add a reference to the .text symbol `sym' to `set'.
333  *
334  *	__link_set_add_rodata(set, sym)
335  *		Add a reference to the .rodata symbol `sym' to `set'.
336  *
337  *	__link_set_add_data(set, sym)
338  *		Add a reference to the .data symbol `sym' to `set'.
339  *
340  *	__link_set_add_bss(set, sym)
341  *		Add a reference to the .bss symbol `sym' to `set'.
342  *
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.
348  *
349  *	__link_set_start(set)
350  *		This points to the first slot in the link set.
351  *
352  *	__link_set_end(set)
353  *		This points to the (non-existent) slot after the last
354  *		entry in the link set.
355  *
356  *	__link_set_count(set)
357  *		Count the number of entries in link set `set'.
358  *
359  * In addition, we provide the following macros for accessing link sets:
360  *
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".
365  *
366  *	__link_set_entry(set, idx)
367  *		Access the link set entry at index `idx' from set `set'.
368  */
369 #define	__link_set_foreach(pvar, set)					\
370 	for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++)
371 
372 #define	__link_set_entry(set, idx)	(__link_set_begin(set)[idx])
373 
374 #define  __BIONIC__   1
375 
376 #endif /* !_SYS_CDEFS_H_ */
377