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 /* In previous NDK releases, wchar_t was defined as 'unsigned char' 41 * when targetting API level < 9 (i.e. Froyo or older). 42 * 43 * This is no longer the case, but you can define _WCHAR_IS_8BIT 44 * at compile time to restore the old behaviour. 45 * 46 * The reason for this redefine is purely historical. Until Android 2.3, 47 * i.e. API level 9, there was absolutely no official support for wchar_t 48 * in the C library, but compiling GCC and the GNU libstdc++ required a 49 * working <wchar.h>. 50 * 51 * To allow this while keeping the C library small, wchar_t was redefined 52 * explicitely as an 8-bit unsigned integer (which is perfectly allowed 53 * by the standard) and a very small set of wcs-xxx functions provided 54 * as wrappers around the corresponding str-xxx ones. 55 * 56 * Starting with API level 9, wchar_t is properly defined as a 32-bit 57 * type (as mandated by the compiler itself), and the lines below 58 * were removed (see $NDK/platforms/android-9/include/sys/cdefs.h). 59 * 60 * Note that this only affects C source compilation. For C++, wchar_t 61 * is a compiler keyboard that cannot be redefined and is always 32-bit. 62 * 63 * On the other hand, _WCHAR_IS_8BIT also affects the definition of 64 * WCHAR_MIN, WCHAR_MAX and WEOF (see <wchar.h> comments). 65 */ 66 #ifdef _WCHAR_IS_8BIT 67 #undef __WCHAR_TYPE__ 68 #define __WCHAR_TYPE__ unsigned char 69 #endif 70 71 /* 72 * Macro to test if we're using a GNU C compiler of a specific vintage 73 * or later, for e.g. features that appeared in a particular version 74 * of GNU C. Usage: 75 * 76 * #if __GNUC_PREREQ__(major, minor) 77 * ...cool feature... 78 * #else 79 * ...delete feature... 80 * #endif 81 */ 82 #ifdef __GNUC__ 83 #define __GNUC_PREREQ__(x, y) \ 84 ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ 85 (__GNUC__ > (x))) 86 #else 87 #define __GNUC_PREREQ__(x, y) 0 88 #endif 89 90 #include <sys/cdefs_elf.h> 91 92 #if defined(__cplusplus) 93 #define __BEGIN_DECLS extern "C" { 94 #define __END_DECLS } 95 #define __static_cast(x,y) static_cast<x>(y) 96 #else 97 #define __BEGIN_DECLS 98 #define __END_DECLS 99 #define __static_cast(x,y) (x)y 100 #endif 101 102 /* 103 * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 104 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 105 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces 106 * in between its arguments. __CONCAT can also concatenate double-quoted 107 * strings produced by the __STRING macro, but this only works with ANSI C. 108 */ 109 110 #define ___STRING(x) __STRING(x) 111 #define ___CONCAT(x,y) __CONCAT(x,y) 112 113 #if defined(__STDC__) || defined(__cplusplus) 114 #define __P(protos) protos /* full-blown ANSI C */ 115 #define __CONCAT(x,y) x ## y 116 #define __STRING(x) #x 117 118 #define __const const /* define reserved names to standard */ 119 #define __signed signed 120 #define __volatile volatile 121 #if defined(__cplusplus) 122 #define __inline inline /* convert to C++ keyword */ 123 #else 124 #if !defined(__GNUC__) && !defined(__lint__) 125 #define __inline /* delete GCC keyword */ 126 #endif /* !__GNUC__ && !__lint__ */ 127 #endif /* !__cplusplus */ 128 129 #else /* !(__STDC__ || __cplusplus) */ 130 #define __P(protos) () /* traditional C preprocessor */ 131 #define __CONCAT(x,y) x/**/y 132 #define __STRING(x) "x" 133 134 #ifndef __GNUC__ 135 #define __const /* delete pseudo-ANSI C keywords */ 136 #define __inline 137 #define __signed 138 #define __volatile 139 #endif /* !__GNUC__ */ 140 141 /* 142 * In non-ANSI C environments, new programs will want ANSI-only C keywords 143 * deleted from the program and old programs will want them left alone. 144 * Programs using the ANSI C keywords const, inline etc. as normal 145 * identifiers should define -DNO_ANSI_KEYWORDS. 146 */ 147 #ifndef NO_ANSI_KEYWORDS 148 #define const __const /* convert ANSI C keywords */ 149 #define inline __inline 150 #define signed __signed 151 #define volatile __volatile 152 #endif /* !NO_ANSI_KEYWORDS */ 153 #endif /* !(__STDC__ || __cplusplus) */ 154 155 /* 156 * Used for internal auditing of the NetBSD source tree. 157 */ 158 #ifdef __AUDIT__ 159 #define __aconst __const 160 #else 161 #define __aconst 162 #endif 163 164 /* 165 * The following macro is used to remove const cast-away warnings 166 * from gcc -Wcast-qual; it should be used with caution because it 167 * can hide valid errors; in particular most valid uses are in 168 * situations where the API requires it, not to cast away string 169 * constants. We don't use *intptr_t on purpose here and we are 170 * explicit about unsigned long so that we don't have additional 171 * dependencies. 172 */ 173 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 174 175 /* 176 * GCC2 provides __extension__ to suppress warnings for various GNU C 177 * language extensions under "-ansi -pedantic". 178 */ 179 #if !__GNUC_PREREQ__(2, 0) 180 #define __extension__ /* delete __extension__ if non-gcc or gcc1 */ 181 #endif 182 183 /* 184 * GCC1 and some versions of GCC2 declare dead (non-returning) and 185 * pure (no side effects) functions using "volatile" and "const"; 186 * unfortunately, these then cause warnings under "-ansi -pedantic". 187 * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of 188 * these work for GNU C++ (modulo a slight glitch in the C++ grammar 189 * in the distribution version of 2.5.5). 190 */ 191 #if !__GNUC_PREREQ__(2, 5) 192 #define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */ 193 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 194 #define __dead __volatile 195 #define __pure __const 196 #endif 197 #endif 198 199 /* Delete pseudo-keywords wherever they are not available or needed. */ 200 #ifndef __dead 201 #define __dead 202 #define __pure 203 #endif 204 205 #if __GNUC_PREREQ__(2, 7) 206 #define __unused __attribute__((__unused__)) 207 #else 208 #define __unused /* delete */ 209 #endif 210 211 #if __GNUC_PREREQ__(3, 1) 212 #define __used __attribute__((__used__)) 213 #else 214 #define __used /* delete */ 215 #endif 216 217 #if __GNUC_PREREQ__(2, 7) 218 #define __packed __attribute__((__packed__)) 219 #define __aligned(x) __attribute__((__aligned__(x))) 220 #define __section(x) __attribute__((__section__(x))) 221 #elif defined(__lint__) 222 #define __packed /* delete */ 223 #define __aligned(x) /* delete */ 224 #define __section(x) /* delete */ 225 #else 226 #define __packed error: no __packed for this compiler 227 #define __aligned(x) error: no __aligned for this compiler 228 #define __section(x) error: no __section for this compiler 229 #endif 230 231 #if !__GNUC_PREREQ__(2, 8) 232 #define __extension__ 233 #endif 234 235 #if __GNUC_PREREQ__(2, 8) 236 #define __statement(x) __extension__(x) 237 #elif defined(lint) 238 #define __statement(x) (0) 239 #else 240 #define __statement(x) (x) 241 #endif 242 243 /* 244 * C99 defines the restrict type qualifier keyword, which was made available 245 * in GCC 2.92. 246 */ 247 #if defined(__STDC__VERSION__) && __STDC_VERSION__ >= 199901L 248 #define __restrict restrict 249 #else 250 #if !__GNUC_PREREQ__(2, 92) 251 #define __restrict /* delete __restrict when not supported */ 252 #endif 253 #endif 254 255 /* 256 * C99 defines __func__ predefined identifier, which was made available 257 * in GCC 2.95. 258 */ 259 #if !defined(__STDC_VERSION__) || !(__STDC_VERSION__ >= 199901L) 260 #if __GNUC_PREREQ__(2, 6) 261 #define __func__ __PRETTY_FUNCTION__ 262 #elif __GNUC_PREREQ__(2, 4) 263 #define __func__ __FUNCTION__ 264 #else 265 #define __func__ "" 266 #endif 267 #endif /* !(__STDC_VERSION__ >= 199901L) */ 268 269 #if defined(_KERNEL) 270 #if defined(NO_KERNEL_RCSIDS) 271 #undef __KERNEL_RCSID 272 #define __KERNEL_RCSID(_n, _s) /* nothing */ 273 #endif /* NO_KERNEL_RCSIDS */ 274 #endif /* _KERNEL */ 275 276 #if !defined(_STANDALONE) && !defined(_KERNEL) 277 #ifdef __GNUC__ 278 #define __RENAME(x) ___RENAME(x) 279 #else 280 #ifdef __lint__ 281 #define __RENAME(x) __symbolrename(x) 282 #else 283 #error "No function renaming possible" 284 #endif /* __lint__ */ 285 #endif /* __GNUC__ */ 286 #else /* _STANDALONE || _KERNEL */ 287 #define __RENAME(x) no renaming in kernel or standalone environment 288 #endif 289 290 /* 291 * A barrier to stop the optimizer from moving code or assume live 292 * register values. This is gcc specific, the version is more or less 293 * arbitrary, might work with older compilers. 294 */ 295 #if __GNUC_PREREQ__(2, 95) 296 #define __insn_barrier() __asm __volatile("":::"memory") 297 #else 298 #define __insn_barrier() /* */ 299 #endif 300 301 /* 302 * GNU C version 2.96 adds explicit branch prediction so that 303 * the CPU back-end can hint the processor and also so that 304 * code blocks can be reordered such that the predicted path 305 * sees a more linear flow, thus improving cache behavior, etc. 306 * 307 * The following two macros provide us with a way to use this 308 * compiler feature. Use __predict_true() if you expect the expression 309 * to evaluate to true, and __predict_false() if you expect the 310 * expression to evaluate to false. 311 * 312 * A few notes about usage: 313 * 314 * * Generally, __predict_false() error condition checks (unless 315 * you have some _strong_ reason to do otherwise, in which case 316 * document it), and/or __predict_true() `no-error' condition 317 * checks, assuming you want to optimize for the no-error case. 318 * 319 * * Other than that, if you don't know the likelihood of a test 320 * succeeding from empirical or other `hard' evidence, don't 321 * make predictions. 322 * 323 * * These are meant to be used in places that are run `a lot'. 324 * It is wasteful to make predictions in code that is run 325 * seldomly (e.g. at subsystem initialization time) as the 326 * basic block reordering that this affects can often generate 327 * larger code. 328 */ 329 #if __GNUC_PREREQ__(2, 96) 330 #define __predict_true(exp) __builtin_expect((exp) != 0, 1) 331 #define __predict_false(exp) __builtin_expect((exp) != 0, 0) 332 #else 333 #define __predict_true(exp) (exp) 334 #define __predict_false(exp) (exp) 335 #endif 336 337 #if __GNUC_PREREQ__(2, 96) 338 #define __noreturn __attribute__((__noreturn__)) 339 #define __mallocfunc __attribute__((malloc)) 340 #else 341 #define __noreturn 342 #define __mallocfunc 343 #endif 344 345 /* 346 * Macros for manipulating "link sets". Link sets are arrays of pointers 347 * to objects, which are gathered up by the linker. 348 * 349 * Object format-specific code has provided us with the following macros: 350 * 351 * __link_set_add_text(set, sym) 352 * Add a reference to the .text symbol `sym' to `set'. 353 * 354 * __link_set_add_rodata(set, sym) 355 * Add a reference to the .rodata symbol `sym' to `set'. 356 * 357 * __link_set_add_data(set, sym) 358 * Add a reference to the .data symbol `sym' to `set'. 359 * 360 * __link_set_add_bss(set, sym) 361 * Add a reference to the .bss symbol `sym' to `set'. 362 * 363 * __link_set_decl(set, ptype) 364 * Provide an extern declaration of the set `set', which 365 * contains an array of the pointer type `ptype'. This 366 * macro must be used by any code which wishes to reference 367 * the elements of a link set. 368 * 369 * __link_set_start(set) 370 * This points to the first slot in the link set. 371 * 372 * __link_set_end(set) 373 * This points to the (non-existent) slot after the last 374 * entry in the link set. 375 * 376 * __link_set_count(set) 377 * Count the number of entries in link set `set'. 378 * 379 * In addition, we provide the following macros for accessing link sets: 380 * 381 * __link_set_foreach(pvar, set) 382 * Iterate over the link set `set'. Because a link set is 383 * an array of pointers, pvar must be declared as "type **pvar", 384 * and the actual entry accessed as "*pvar". 385 * 386 * __link_set_entry(set, idx) 387 * Access the link set entry at index `idx' from set `set'. 388 */ 389 #define __link_set_foreach(pvar, set) \ 390 for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) 391 392 #define __link_set_entry(set, idx) (__link_set_begin(set)[idx]) 393 394 /* 395 * Some of the recend FreeBSD sources used in Bionic need this. 396 * Originally, this is used to embed the rcs versions of each source file 397 * in the generated binary. We certainly don't want this in Bionic. 398 */ 399 #define __FBSDID(s) struct __hack 400 401 /*- 402 * The following definitions are an extension of the behavior originally 403 * implemented in <sys/_posix.h>, but with a different level of granularity. 404 * POSIX.1 requires that the macros we test be defined before any standard 405 * header file is included. 406 * 407 * Here's a quick run-down of the versions: 408 * defined(_POSIX_SOURCE) 1003.1-1988 409 * _POSIX_C_SOURCE == 1 1003.1-1990 410 * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option 411 * _POSIX_C_SOURCE == 199309 1003.1b-1993 412 * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, 413 * and the omnibus ISO/IEC 9945-1: 1996 414 * _POSIX_C_SOURCE == 200112 1003.1-2001 415 * _POSIX_C_SOURCE == 200809 1003.1-2008 416 * 417 * In addition, the X/Open Portability Guide, which is now the Single UNIX 418 * Specification, defines a feature-test macro which indicates the version of 419 * that specification, and which subsumes _POSIX_C_SOURCE. 420 * 421 * Our macros begin with two underscores to avoid namespace screwage. 422 */ 423 424 /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ 425 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1 426 #undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ 427 #define _POSIX_C_SOURCE 199009 428 #endif 429 430 /* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ 431 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2 432 #undef _POSIX_C_SOURCE 433 #define _POSIX_C_SOURCE 199209 434 #endif 435 436 /* Deal with various X/Open Portability Guides and Single UNIX Spec. */ 437 #ifdef _XOPEN_SOURCE 438 #if _XOPEN_SOURCE - 0 >= 700 439 #define __XSI_VISIBLE 700 440 #undef _POSIX_C_SOURCE 441 #define _POSIX_C_SOURCE 200809 442 #elif _XOPEN_SOURCE - 0 >= 600 443 #define __XSI_VISIBLE 600 444 #undef _POSIX_C_SOURCE 445 #define _POSIX_C_SOURCE 200112 446 #elif _XOPEN_SOURCE - 0 >= 500 447 #define __XSI_VISIBLE 500 448 #undef _POSIX_C_SOURCE 449 #define _POSIX_C_SOURCE 199506 450 #endif 451 #endif 452 453 /* 454 * Deal with all versions of POSIX. The ordering relative to the tests above is 455 * important. 456 */ 457 #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) 458 #define _POSIX_C_SOURCE 198808 459 #endif 460 #ifdef _POSIX_C_SOURCE 461 #if _POSIX_C_SOURCE >= 200809 462 #define __POSIX_VISIBLE 200809 463 #define __ISO_C_VISIBLE 1999 464 #elif _POSIX_C_SOURCE >= 200112 465 #define __POSIX_VISIBLE 200112 466 #define __ISO_C_VISIBLE 1999 467 #elif _POSIX_C_SOURCE >= 199506 468 #define __POSIX_VISIBLE 199506 469 #define __ISO_C_VISIBLE 1990 470 #elif _POSIX_C_SOURCE >= 199309 471 #define __POSIX_VISIBLE 199309 472 #define __ISO_C_VISIBLE 1990 473 #elif _POSIX_C_SOURCE >= 199209 474 #define __POSIX_VISIBLE 199209 475 #define __ISO_C_VISIBLE 1990 476 #elif _POSIX_C_SOURCE >= 199009 477 #define __POSIX_VISIBLE 199009 478 #define __ISO_C_VISIBLE 1990 479 #else 480 #define __POSIX_VISIBLE 198808 481 #define __ISO_C_VISIBLE 0 482 #endif /* _POSIX_C_SOURCE */ 483 #else 484 /*- 485 * Deal with _ANSI_SOURCE: 486 * If it is defined, and no other compilation environment is explicitly 487 * requested, then define our internal feature-test macros to zero. This 488 * makes no difference to the preprocessor (undefined symbols in preprocessing 489 * expressions are defined to have value zero), but makes it more convenient for 490 * a test program to print out the values. 491 * 492 * If a program mistakenly defines _ANSI_SOURCE and some other macro such as 493 * _POSIX_C_SOURCE, we will assume that it wants the broader compilation 494 * environment (and in fact we will never get here). 495 */ 496 #if defined(_ANSI_SOURCE) /* Hide almost everything. */ 497 #define __POSIX_VISIBLE 0 498 #define __XSI_VISIBLE 0 499 #define __BSD_VISIBLE 0 500 #define __ISO_C_VISIBLE 1990 501 #elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ 502 #define __POSIX_VISIBLE 0 503 #define __XSI_VISIBLE 0 504 #define __BSD_VISIBLE 0 505 #define __ISO_C_VISIBLE 1999 506 #else /* Default environment: show everything. */ 507 #define __POSIX_VISIBLE 200809 508 #define __XSI_VISIBLE 700 509 #define __BSD_VISIBLE 1 510 #define __ISO_C_VISIBLE 1999 511 #endif 512 #endif 513 514 /* 515 * Default values. 516 */ 517 #ifndef __XPG_VISIBLE 518 # define __XPG_VISIBLE 700 519 #endif 520 #ifndef __POSIX_VISIBLE 521 # define __POSIX_VISIBLE 200809 522 #endif 523 #ifndef __ISO_C_VISIBLE 524 # define __ISO_C_VISIBLE 1999 525 #endif 526 #ifndef __BSD_VISIBLE 527 # define __BSD_VISIBLE 1 528 #endif 529 530 #define __BIONIC__ 1 531 #include <android/api-level.h> 532 533 #endif /* !_SYS_CDEFS_H_ */ 534