t2ex/bsd_source/t2ex/network/net/src_bsd/sys/cdefs.h | bare source | permlink (0.02 seconds) |
1: /* $NetBSD: cdefs.h,v 1.69 2008/08/17 00:23:02 gmcgarry 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: #ifndef T2EX 60: #include <machine/cdefs.h> 61: #endif 62: #ifdef __ELF__ 63: #include <sys/cdefs_elf.h> 64: #else 65: #include <sys/cdefs_aout.h> 66: #endif 67: 68: #if defined(__cplusplus) 69: #define __BEGIN_DECLS extern "C" { 70: #define __END_DECLS } 71: #define __static_cast(x,y) static_cast<x>(y) 72: #else 73: #define __BEGIN_DECLS 74: #define __END_DECLS 75: #define __static_cast(x,y) (x)y 76: #endif 77: 78: /* 79: * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 80: * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 81: * The __CONCAT macro is a bit tricky -- make sure you don't put spaces 82: * in between its arguments. __CONCAT can also concatenate double-quoted 83: * strings produced by the __STRING macro, but this only works with ANSI C. 84: */ 85: 86: #define ___STRING(x) __STRING(x) 87: #define ___CONCAT(x,y) __CONCAT(x,y) 88: 89: #if __STDC__ || defined(__cplusplus) 90: #define __P(protos) protos /* full-blown ANSI C */ 91: #define __CONCAT(x,y) x ## y 92: #define __STRING(x) #x 93: 94: #define __const const /* define reserved names to standard */ 95: #define __signed signed 96: #define __volatile volatile 97: #if defined(__cplusplus) || defined(__PCC__) 98: #define __inline inline /* convert to C++/C99 keyword */ 99: #else 100: #if !defined(__GNUC__) && !defined(__lint__) 101: #define __inline /* delete GCC keyword */ 102: #endif /* !__GNUC__ && !__lint__ */ 103: #endif /* !__cplusplus */ 104: 105: #else /* !(__STDC__ || __cplusplus) */ 106: #define __P(protos) () /* traditional C preprocessor */ 107: #define __CONCAT(x,y) x/**/y 108: #define __STRING(x) "x" 109: 110: #ifndef __GNUC__ 111: #define __const /* delete pseudo-ANSI C keywords */ 112: #define __inline 113: #define __signed 114: #define __volatile 115: #endif /* !__GNUC__ */ 116: 117: /* 118: * In non-ANSI C environments, new programs will want ANSI-only C keywords 119: * deleted from the program and old programs will want them left alone. 120: * Programs using the ANSI C keywords const, inline etc. as normal 121: * identifiers should define -DNO_ANSI_KEYWORDS. 122: */ 123: #ifndef NO_ANSI_KEYWORDS 124: #define const __const /* convert ANSI C keywords */ 125: #define inline __inline 126: #define signed __signed 127: #define volatile __volatile 128: #endif /* !NO_ANSI_KEYWORDS */ 129: #endif /* !(__STDC__ || __cplusplus) */ 130: 131: /* 132: * Used for internal auditing of the NetBSD source tree. 133: */ 134: #ifdef __AUDIT__ 135: #define __aconst __const 136: #else 137: #define __aconst 138: #endif 139: 140: /* 141: * The following macro is used to remove const cast-away warnings 142: * from gcc -Wcast-qual; it should be used with caution because it 143: * can hide valid errors; in particular most valid uses are in 144: * situations where the API requires it, not to cast away string 145: * constants. We don't use *intptr_t on purpose here and we are 146: * explicit about unsigned long so that we don't have additional 147: * dependencies. 148: */ 149: #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 150: 151: /* 152: * The following macro is used to remove the volatile cast-away warnings 153: * from gcc -Wcast-qual; as above it should be used with caution 154: * because it can hide valid errors or warnings. Valid uses include 155: * making it possible to pass a volatile pointer to memset(). 156: * For the same reasons as above, we use unsigned long and not intptr_t. 157: */ 158: #define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a)) 159: 160: /* 161: * GCC2 provides __extension__ to suppress warnings for various GNU C 162: * language extensions under "-ansi -pedantic". 163: */ 164: #if !__GNUC_PREREQ__(2, 0) 165: #define __extension__ /* delete __extension__ if non-gcc or gcc1 */ 166: #endif 167: 168: /* 169: * GCC1 and some versions of GCC2 declare dead (non-returning) and 170: * pure (no side effects) functions using "volatile" and "const"; 171: * unfortunately, these then cause warnings under "-ansi -pedantic". 172: * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of 173: * these work for GNU C++ (modulo a slight glitch in the C++ grammar 174: * in the distribution version of 2.5.5). 175: */ 176: #if !__GNUC_PREREQ__(2, 0) 177: #define __attribute__(x) 178: #endif 179: 180: #if __GNUC_PREREQ__(2, 5) 181: #define __dead __attribute__((__noreturn__)) 182: #elif defined(__GNUC__) 183: #define __dead __volatile 184: #else 185: #define __dead 186: #endif 187: 188: #if __GNUC_PREREQ__(2, 96) 189: #define __pure __attribute__((__pure__)) 190: #elif defined(__GNUC__) 191: #define __pure __const 192: #else 193: #define __pure 194: #endif 195: 196: #if __GNUC_PREREQ__(3, 0) 197: #define __noinline __attribute__((__noinline__)) 198: #else 199: #define __noinline /* nothing */ 200: #endif 201: 202: #if __GNUC_PREREQ__(2, 7) 203: #define __unused __attribute__((__unused__)) 204: #else 205: #define __unused /* delete */ 206: #endif 207: 208: #if __GNUC_PREREQ__(3, 1) 209: #define __used __attribute__((__used__)) 210: #else 211: #define __used __unused 212: #endif 213: 214: #if __GNUC_PREREQ__(2, 7) 215: #define __packed __attribute__((__packed__)) 216: #define __aligned(x) __attribute__((__aligned__(x))) 217: #define __section(x) __attribute__((__section__(x))) 218: #elif defined(__PCC__) 219: #define __packed _Pragma("packed") 220: #define __aligned(x) _Pragma("aligned " #x) 221: #define __section(x) _Pragma("section " ## x) 222: #elif defined(__lint__) 223: #define __packed /* delete */ 224: #define __aligned(x) /* delete */ 225: #define __section(x) /* delete */ 226: #else 227: #define __packed error: no __packed for this compiler 228: #define __aligned(x) error: no __aligned for this compiler 229: #define __section(x) error: no __section for this compiler 230: #endif 231: 232: /* 233: * C99 defines the restrict type qualifier keyword, which was made available 234: * in GCC 2.92. 235: */ 236: #if defined(__lint__) 237: #define __restrict /* delete __restrict when not supported */ 238: #elif __STDC_VERSION__ >= 199901L 239: #define __restrict restrict 240: #elif !__GNUC_PREREQ__(2, 92) 241: #define __restrict /* delete __restrict when not supported */ 242: #endif 243: 244: /* 245: * C99 defines __func__ predefined identifier, which was made available 246: * in GCC 2.95. 247: */ 248: #if !(__STDC_VERSION__ >= 199901L) 249: #if __GNUC_PREREQ__(2, 6) 250: #define __func__ __PRETTY_FUNCTION__ 251: #elif __GNUC_PREREQ__(2, 4) 252: #define __func__ __FUNCTION__ 253: #else 254: #define __func__ "" 255: #endif 256: #endif /* !(__STDC_VERSION__ >= 199901L) */ 257: 258: #if defined(_KERNEL) 259: #if defined(NO_KERNEL_RCSIDS) 260: #undef __KERNEL_RCSID 261: #define __KERNEL_RCSID(_n, _s) /* nothing */ 262: #endif /* NO_KERNEL_RCSIDS */ 263: #endif /* _KERNEL */ 264: 265: #if !defined(_STANDALONE) && !defined(_KERNEL) 266: #if defined(__GNUC__) || defined(__PCC__) 267: #define __RENAME(x) ___RENAME(x) 268: #else 269: #ifdef __lint__ 270: #define __RENAME(x) __symbolrename(x) 271: #else 272: #error "No function renaming possible" 273: #endif /* __lint__ */ 274: #endif /* __GNUC__ */ 275: #else /* _STANDALONE || _KERNEL */ 276: #define __RENAME(x) no renaming in kernel or standalone environment 277: #endif 278: 279: /* 280: * A barrier to stop the optimizer from moving code or assume live 281: * register values. This is gcc specific, the version is more or less 282: * arbitrary, might work with older compilers. 283: */ 284: #if __GNUC_PREREQ__(2, 95) 285: #define __insn_barrier() __asm __volatile("":::"memory") 286: #else 287: #define __insn_barrier() /* */ 288: #endif 289: 290: /* 291: * GNU C version 2.96 adds explicit branch prediction so that 292: * the CPU back-end can hint the processor and also so that 293: * code blocks can be reordered such that the predicted path 294: * sees a more linear flow, thus improving cache behavior, etc. 295: * 296: * The following two macros provide us with a way to use this 297: * compiler feature. Use __predict_true() if you expect the expression 298: * to evaluate to true, and __predict_false() if you expect the 299: * expression to evaluate to false. 300: * 301: * A few notes about usage: 302: * 303: * * Generally, __predict_false() error condition checks (unless 304: * you have some _strong_ reason to do otherwise, in which case 305: * document it), and/or __predict_true() `no-error' condition 306: * checks, assuming you want to optimize for the no-error case. 307: * 308: * * Other than that, if you don't know the likelihood of a test 309: * succeeding from empirical or other `hard' evidence, don't 310: * make predictions. 311: * 312: * * These are meant to be used in places that are run `a lot'. 313: * It is wasteful to make predictions in code that is run 314: * seldomly (e.g. at subsystem initialization time) as the 315: * basic block reordering that this affects can often generate 316: * larger code. 317: */ 318: #if __GNUC_PREREQ__(2, 96) 319: #define __predict_true(exp) __builtin_expect((exp) != 0, 1) 320: #define __predict_false(exp) __builtin_expect((exp) != 0, 0) 321: #else 322: #define __predict_true(exp) (exp) 323: #define __predict_false(exp) (exp) 324: #endif 325: 326: /* 327: * Macros for manipulating "link sets". Link sets are arrays of pointers 328: * to objects, which are gathered up by the linker. 329: * 330: * Object format-specific code has provided us with the following macros: 331: * 332: * __link_set_add_text(set, sym) 333: * Add a reference to the .text symbol `sym' to `set'. 334: * 335: * __link_set_add_rodata(set, sym) 336: * Add a reference to the .rodata symbol `sym' to `set'. 337: * 338: * __link_set_add_data(set, sym) 339: * Add a reference to the .data symbol `sym' to `set'. 340: * 341: * __link_set_add_bss(set, sym) 342: * Add a reference to the .bss symbol `sym' to `set'. 343: * 344: * __link_set_decl(set, ptype) 345: * Provide an extern declaration of the set `set', which 346: * contains an array of the pointer type `ptype'. This 347: * macro must be used by any code which wishes to reference 348: * the elements of a link set. 349: * 350: * __link_set_start(set) 351: * This points to the first slot in the link set. 352: * 353: * __link_set_end(set) 354: * This points to the (non-existent) slot after the last 355: * entry in the link set. 356: * 357: * __link_set_count(set) 358: * Count the number of entries in link set `set'. 359: * 360: * In addition, we provide the following macros for accessing link sets: 361: * 362: * __link_set_foreach(pvar, set) 363: * Iterate over the link set `set'. Because a link set is 364: * an array of pointers, pvar must be declared as "type **pvar", 365: * and the actual entry accessed as "*pvar". 366: * 367: * __link_set_entry(set, idx) 368: * Access the link set entry at index `idx' from set `set'. 369: */ 370: #define __link_set_foreach(pvar, set) \ 371: for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) 372: 373: #define __link_set_entry(set, idx) (__link_set_begin(set)[idx]) 374: 375: /* 376: * Return the number of elements in a statically-allocated array, 377: * __x. 378: */ 379: #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) 380: 381: /* __BIT(n): nth bit, where __BIT(0) == 0x1. */ 382: #define __BIT(__n) \ 383: (((__n) >= NBBY * sizeof(uintmax_t)) ? 0 : ((uintmax_t)1 << (__n))) 384: 385: /* __BITS(m, n): bits m through n, m < n. */ 386: #define __BITS(__m, __n) \ 387: ((__BIT(MAX((__m), (__n)) + 1) - 1) ^ (__BIT(MIN((__m), (__n))) - 1)) 388: 389: /* find least significant bit that is set */ 390: #define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask)) 391: 392: #define __PRIuBIT PRIuMAX 393: #define __PRIuBITS __PRIuBIT 394: 395: #define __PRIxBIT PRIxMAX 396: #define __PRIxBITS __PRIxBIT 397: 398: #define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask)) 399: #define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask)) 400: #define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask)) 401: 402: #endif /* !_SYS_CDEFS_H_ */