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