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 * Testing against Clang-specific extensions. 42 */ 43 44 #ifndef __has_extension 45 #define __has_extension __has_feature 46 #endif 47 #ifndef __has_feature 48 #define __has_feature(x) 0 49 #endif 50 #ifndef __has_include 51 #define __has_include(x) 0 52 #endif 53 #ifndef __has_builtin 54 #define __has_builtin(x) 0 55 #endif 56 57 58 /* 59 * Macro to test if we're using a GNU C compiler of a specific vintage 60 * or later, for e.g. features that appeared in a particular version 61 * of GNU C. Usage: 62 * 63 * #if __GNUC_PREREQ(major, minor) 64 * ...cool feature... 65 * #else 66 * ...delete feature... 67 * #endif 68 */ 69 #ifdef __GNUC__ 70 #define __GNUC_PREREQ(x, y) \ 71 ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ 72 (__GNUC__ > (x))) 73 #else 74 #define __GNUC_PREREQ(x, y) 0 75 #endif 76 77 #include <sys/cdefs_elf.h> 78 79 #if defined(__cplusplus) 80 #define __BEGIN_DECLS extern "C" { 81 #define __END_DECLS } 82 #define __static_cast(x,y) static_cast<x>(y) 83 #else 84 #define __BEGIN_DECLS 85 #define __END_DECLS 86 #define __static_cast(x,y) (x)y 87 #endif 88 89 #if defined(__cplusplus) 90 #define __BIONIC_CAST(_k,_t,_v) (_k<_t>(_v)) 91 #else 92 #define __BIONIC_CAST(_k,_t,_v) ((_t) (_v)) 93 #endif 94 95 /* 96 * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 97 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 98 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces 99 * in between its arguments. __CONCAT can also concatenate double-quoted 100 * strings produced by the __STRING macro, but this only works with ANSI C. 101 */ 102 103 #define ___STRING(x) __STRING(x) 104 #define ___CONCAT(x,y) __CONCAT(x,y) 105 106 #if defined(__STDC__) || defined(__cplusplus) 107 #define __P(protos) protos /* full-blown ANSI C */ 108 #define __CONCAT(x,y) x ## y 109 #define __STRING(x) #x 110 111 #define __const const /* define reserved names to standard */ 112 #define __signed signed 113 #define __volatile volatile 114 #if defined(__cplusplus) 115 #define __inline inline /* convert to C++ keyword */ 116 #else 117 #if !defined(__GNUC__) && !defined(__lint__) 118 #define __inline /* delete GCC keyword */ 119 #endif /* !__GNUC__ && !__lint__ */ 120 #endif /* !__cplusplus */ 121 122 #else /* !(__STDC__ || __cplusplus) */ 123 #define __P(protos) () /* traditional C preprocessor */ 124 #define __CONCAT(x,y) x/**/y 125 #define __STRING(x) "x" 126 127 #ifndef __GNUC__ 128 #define __const /* delete pseudo-ANSI C keywords */ 129 #define __inline 130 #define __signed 131 #define __volatile 132 #endif /* !__GNUC__ */ 133 134 /* 135 * In non-ANSI C environments, new programs will want ANSI-only C keywords 136 * deleted from the program and old programs will want them left alone. 137 * Programs using the ANSI C keywords const, inline etc. as normal 138 * identifiers should define -DNO_ANSI_KEYWORDS. 139 */ 140 #ifndef NO_ANSI_KEYWORDS 141 #define const __const /* convert ANSI C keywords */ 142 #define inline __inline 143 #define signed __signed 144 #define volatile __volatile 145 #endif /* !NO_ANSI_KEYWORDS */ 146 #endif /* !(__STDC__ || __cplusplus) */ 147 148 /* 149 * Used for internal auditing of the NetBSD source tree. 150 */ 151 #ifdef __AUDIT__ 152 #define __aconst __const 153 #else 154 #define __aconst 155 #endif 156 157 /* 158 * The following macro is used to remove const cast-away warnings 159 * from gcc -Wcast-qual; it should be used with caution because it 160 * can hide valid errors; in particular most valid uses are in 161 * situations where the API requires it, not to cast away string 162 * constants. We don't use *intptr_t on purpose here and we are 163 * explicit about unsigned long so that we don't have additional 164 * dependencies. 165 */ 166 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 167 168 /* 169 * GCC2 provides __extension__ to suppress warnings for various GNU C 170 * language extensions under "-ansi -pedantic". 171 */ 172 #if !__GNUC_PREREQ(2, 0) 173 #define __extension__ /* delete __extension__ if non-gcc or gcc1 */ 174 #endif 175 176 /* 177 * GCC1 and some versions of GCC2 declare dead (non-returning) and 178 * pure (no side effects) functions using "volatile" and "const"; 179 * unfortunately, these then cause warnings under "-ansi -pedantic". 180 * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of 181 * these work for GNU C++ (modulo a slight glitch in the C++ grammar 182 * in the distribution version of 2.5.5). 183 */ 184 #if !__GNUC_PREREQ(2, 5) 185 #define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */ 186 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 187 #define __dead __volatile 188 #define __pure __const 189 #endif 190 #endif 191 192 /* Delete pseudo-keywords wherever they are not available or needed. */ 193 #ifndef __dead 194 #define __dead 195 #define __pure 196 #endif 197 198 #if __GNUC_PREREQ(2, 7) 199 #define __unused __attribute__((__unused__)) 200 #else 201 #define __unused /* delete */ 202 #endif 203 204 #define __pure2 __attribute__((__const__)) /* Android-added: used by FreeBSD libm */ 205 206 #if __GNUC_PREREQ(3, 1) 207 #define __used __attribute__((__used__)) 208 #else 209 #define __used /* delete */ 210 #endif 211 212 #if __GNUC_PREREQ(2, 7) 213 #define __packed __attribute__((__packed__)) 214 #define __aligned(x) __attribute__((__aligned__(x))) 215 #define __section(x) __attribute__((__section__(x))) 216 #elif defined(__lint__) 217 #define __packed /* delete */ 218 #define __aligned(x) /* delete */ 219 #define __section(x) /* delete */ 220 #else 221 #define __packed error: no __packed for this compiler 222 #define __aligned(x) error: no __aligned for this compiler 223 #define __section(x) error: no __section for this compiler 224 #endif 225 226 #if !__GNUC_PREREQ(2, 8) 227 #define __extension__ 228 #endif 229 230 #if __GNUC_PREREQ(2, 8) 231 #define __statement(x) __extension__(x) 232 #elif defined(lint) 233 #define __statement(x) (0) 234 #else 235 #define __statement(x) (x) 236 #endif 237 238 #define __nonnull(args) __attribute__((__nonnull__ args)) 239 240 #define __printflike(x, y) __attribute__((__format__(printf, x, y))) __nonnull((x)) 241 #define __scanflike(x, y) __attribute__((__format__(scanf, x, y))) __nonnull((x)) 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 #define __purefunc __attribute__((pure)) 341 #else 342 #define __noreturn 343 #define __mallocfunc 344 #define __purefunc 345 #endif 346 347 #if __GNUC_PREREQ(3, 1) 348 #define __always_inline __attribute__((__always_inline__)) 349 #else 350 #define __always_inline 351 #endif 352 353 #if __GNUC_PREREQ(3, 4) 354 #define __wur __attribute__((__warn_unused_result__)) 355 #else 356 #define __wur 357 #endif 358 359 #if __GNUC_PREREQ(4, 3) 360 #define __errordecl(name, msg) extern void name(void) __attribute__((__error__(msg))) 361 #define __warnattr(msg) __attribute__((__warning__(msg))) 362 #else 363 #define __errordecl(name, msg) extern void name(void) 364 #define __warnattr(msg) 365 #endif 366 367 /* 368 * Macros for manipulating "link sets". Link sets are arrays of pointers 369 * to objects, which are gathered up by the linker. 370 * 371 * Object format-specific code has provided us with the following macros: 372 * 373 * __link_set_add_text(set, sym) 374 * Add a reference to the .text symbol `sym' to `set'. 375 * 376 * __link_set_add_rodata(set, sym) 377 * Add a reference to the .rodata symbol `sym' to `set'. 378 * 379 * __link_set_add_data(set, sym) 380 * Add a reference to the .data symbol `sym' to `set'. 381 * 382 * __link_set_add_bss(set, sym) 383 * Add a reference to the .bss symbol `sym' to `set'. 384 * 385 * __link_set_decl(set, ptype) 386 * Provide an extern declaration of the set `set', which 387 * contains an array of the pointer type `ptype'. This 388 * macro must be used by any code which wishes to reference 389 * the elements of a link set. 390 * 391 * __link_set_start(set) 392 * This points to the first slot in the link set. 393 * 394 * __link_set_end(set) 395 * This points to the (non-existent) slot after the last 396 * entry in the link set. 397 * 398 * __link_set_count(set) 399 * Count the number of entries in link set `set'. 400 * 401 * In addition, we provide the following macros for accessing link sets: 402 * 403 * __link_set_foreach(pvar, set) 404 * Iterate over the link set `set'. Because a link set is 405 * an array of pointers, pvar must be declared as "type **pvar", 406 * and the actual entry accessed as "*pvar". 407 * 408 * __link_set_entry(set, idx) 409 * Access the link set entry at index `idx' from set `set'. 410 */ 411 #define __link_set_foreach(pvar, set) \ 412 for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) 413 414 #define __link_set_entry(set, idx) (__link_set_begin(set)[idx]) 415 416 /* 417 * Some of the FreeBSD sources used in Bionic need this. 418 * Originally, this is used to embed the rcs versions of each source file 419 * in the generated binary. We certainly don't want this in Bionic. 420 */ 421 #define __FBSDID(s) /* nothing */ 422 423 /*- 424 * The following definitions are an extension of the behavior originally 425 * implemented in <sys/_posix.h>, but with a different level of granularity. 426 * POSIX.1 requires that the macros we test be defined before any standard 427 * header file is included. 428 * 429 * Here's a quick run-down of the versions: 430 * defined(_POSIX_SOURCE) 1003.1-1988 431 * _POSIX_C_SOURCE == 1 1003.1-1990 432 * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option 433 * _POSIX_C_SOURCE == 199309 1003.1b-1993 434 * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, 435 * and the omnibus ISO/IEC 9945-1: 1996 436 * _POSIX_C_SOURCE == 200112 1003.1-2001 437 * _POSIX_C_SOURCE == 200809 1003.1-2008 438 * 439 * In addition, the X/Open Portability Guide, which is now the Single UNIX 440 * Specification, defines a feature-test macro which indicates the version of 441 * that specification, and which subsumes _POSIX_C_SOURCE. 442 * 443 * Our macros begin with two underscores to avoid namespace screwage. 444 */ 445 446 /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ 447 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1 448 #undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ 449 #define _POSIX_C_SOURCE 199009 450 #endif 451 452 /* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ 453 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2 454 #undef _POSIX_C_SOURCE 455 #define _POSIX_C_SOURCE 199209 456 #endif 457 458 /* Deal with various X/Open Portability Guides and Single UNIX Spec. */ 459 #ifdef _XOPEN_SOURCE 460 #if _XOPEN_SOURCE - 0 >= 700 461 #define __XSI_VISIBLE 700 462 #undef _POSIX_C_SOURCE 463 #define _POSIX_C_SOURCE 200809 464 #elif _XOPEN_SOURCE - 0 >= 600 465 #define __XSI_VISIBLE 600 466 #undef _POSIX_C_SOURCE 467 #define _POSIX_C_SOURCE 200112 468 #elif _XOPEN_SOURCE - 0 >= 500 469 #define __XSI_VISIBLE 500 470 #undef _POSIX_C_SOURCE 471 #define _POSIX_C_SOURCE 199506 472 #endif 473 #endif 474 475 /* 476 * Deal with all versions of POSIX. The ordering relative to the tests above is 477 * important. 478 */ 479 #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) 480 #define _POSIX_C_SOURCE 198808 481 #endif 482 #ifdef _POSIX_C_SOURCE 483 #if _POSIX_C_SOURCE >= 200809 484 #define __POSIX_VISIBLE 200809 485 #define __ISO_C_VISIBLE 1999 486 #elif _POSIX_C_SOURCE >= 200112 487 #define __POSIX_VISIBLE 200112 488 #define __ISO_C_VISIBLE 1999 489 #elif _POSIX_C_SOURCE >= 199506 490 #define __POSIX_VISIBLE 199506 491 #define __ISO_C_VISIBLE 1990 492 #elif _POSIX_C_SOURCE >= 199309 493 #define __POSIX_VISIBLE 199309 494 #define __ISO_C_VISIBLE 1990 495 #elif _POSIX_C_SOURCE >= 199209 496 #define __POSIX_VISIBLE 199209 497 #define __ISO_C_VISIBLE 1990 498 #elif _POSIX_C_SOURCE >= 199009 499 #define __POSIX_VISIBLE 199009 500 #define __ISO_C_VISIBLE 1990 501 #else 502 #define __POSIX_VISIBLE 198808 503 #define __ISO_C_VISIBLE 0 504 #endif /* _POSIX_C_SOURCE */ 505 #else 506 /*- 507 * Deal with _ANSI_SOURCE: 508 * If it is defined, and no other compilation environment is explicitly 509 * requested, then define our internal feature-test macros to zero. This 510 * makes no difference to the preprocessor (undefined symbols in preprocessing 511 * expressions are defined to have value zero), but makes it more convenient for 512 * a test program to print out the values. 513 * 514 * If a program mistakenly defines _ANSI_SOURCE and some other macro such as 515 * _POSIX_C_SOURCE, we will assume that it wants the broader compilation 516 * environment (and in fact we will never get here). 517 */ 518 #if defined(_ANSI_SOURCE) /* Hide almost everything. */ 519 #define __POSIX_VISIBLE 0 520 #define __XSI_VISIBLE 0 521 #define __BSD_VISIBLE 0 522 #define __ISO_C_VISIBLE 1990 523 #elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ 524 #define __POSIX_VISIBLE 0 525 #define __XSI_VISIBLE 0 526 #define __BSD_VISIBLE 0 527 #define __ISO_C_VISIBLE 1999 528 #else /* Default environment: show everything. */ 529 #define __POSIX_VISIBLE 200809 530 #define __XSI_VISIBLE 700 531 #define __BSD_VISIBLE 1 532 #define __ISO_C_VISIBLE 1999 533 #endif 534 #endif 535 536 /* 537 * Default values. 538 */ 539 #ifndef __XPG_VISIBLE 540 # define __XPG_VISIBLE 700 541 #endif 542 #ifndef __POSIX_VISIBLE 543 # define __POSIX_VISIBLE 200809 544 #endif 545 #ifndef __ISO_C_VISIBLE 546 # define __ISO_C_VISIBLE 1999 547 #endif 548 #ifndef __BSD_VISIBLE 549 # define __BSD_VISIBLE 1 550 #endif 551 552 #define __BIONIC__ 1 553 #include <android/api-level.h> 554 555 /* glibc compatibility. */ 556 #if __LP64__ 557 #define __WORDSIZE 64 558 #else 559 #define __WORDSIZE 32 560 #endif 561 562 /* 563 * When _FORTIFY_SOURCE is defined, automatic bounds checking is 564 * added to commonly used libc functions. If a buffer overrun is 565 * detected, the program is safely aborted. 566 * 567 * See 568 * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html for details. 569 */ 570 #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 571 #define __BIONIC_FORTIFY 1 572 #if _FORTIFY_SOURCE == 2 573 #define __bos(s) __builtin_object_size((s), 1) 574 #else 575 #define __bos(s) __builtin_object_size((s), 0) 576 #endif 577 #define __bos0(s) __builtin_object_size((s), 0) 578 579 #define __BIONIC_FORTIFY_INLINE \ 580 extern __inline__ \ 581 __attribute__ ((always_inline)) \ 582 __attribute__ ((gnu_inline)) 583 #endif 584 #define __BIONIC_FORTIFY_UNKNOWN_SIZE ((size_t) -1) 585 586 #endif /* !_SYS_CDEFS_H_ */ 587