cdefs.h revision 1.48
1/* $NetBSD: cdefs.h,v 1.48 2003/02/05 00:02:39 perry 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. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 39 */ 40 41#ifndef _SYS_CDEFS_H_ 42#define _SYS_CDEFS_H_ 43 44/* 45 * Macro to test if we're using a GNU C compiler of a specific vintage 46 * or later, for e.g. features that appeared in a particular version 47 * of GNU C. Usage: 48 * 49 * #if __GNUC_PREREQ__(major, minor) 50 * ...cool feature... 51 * #else 52 * ...delete feature... 53 * #endif 54 */ 55#ifdef __GNUC__ 56#define __GNUC_PREREQ__(x, y) \ 57 ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ 58 (__GNUC__ > (x))) 59#else 60#define __GNUC_PREREQ__(x, y) 0 61#endif 62 63#include <machine/cdefs.h> 64#ifdef __ELF__ 65#include <sys/cdefs_elf.h> 66#else 67#include <sys/cdefs_aout.h> 68#endif 69 70#if defined(__cplusplus) 71#define __BEGIN_DECLS extern "C" { 72#define __END_DECLS } 73#define __static_cast(x,y) static_cast<x>(y) 74#else 75#define __BEGIN_DECLS 76#define __END_DECLS 77#define __static_cast(x,y) (x)y 78#endif 79 80/* 81 * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 82 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 83 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces 84 * in between its arguments. __CONCAT can also concatenate double-quoted 85 * strings produced by the __STRING macro, but this only works with ANSI C. 86 */ 87 88#define ___STRING(x) __STRING(x) 89#define ___CONCAT(x,y) __CONCAT(x,y) 90 91#if __STDC__ || defined(__cplusplus) 92#define __P(protos) protos /* full-blown ANSI C */ 93#define __CONCAT(x,y) x ## y 94#define __STRING(x) #x 95 96#define __const const /* define reserved names to standard */ 97#define __signed signed 98#define __volatile volatile 99#if defined(__cplusplus) 100#define __inline inline /* convert to C++ keyword */ 101#else 102#if !defined(__GNUC__) && !defined(__lint__) 103#define __inline /* delete GCC keyword */ 104#endif /* !__GNUC__ && !__lint__ */ 105#endif /* !__cplusplus */ 106 107#else /* !(__STDC__ || __cplusplus) */ 108#define __P(protos) () /* traditional C preprocessor */ 109#define __CONCAT(x,y) x/**/y 110#define __STRING(x) "x" 111 112#ifndef __GNUC__ 113#define __const /* delete pseudo-ANSI C keywords */ 114#define __inline 115#define __signed 116#define __volatile 117#endif /* !__GNUC__ */ 118 119/* 120 * In non-ANSI C environments, new programs will want ANSI-only C keywords 121 * deleted from the program and old programs will want them left alone. 122 * Programs using the ANSI C keywords const, inline etc. as normal 123 * identifiers should define -DNO_ANSI_KEYWORDS. 124 */ 125#ifndef NO_ANSI_KEYWORDS 126#define const __const /* convert ANSI C keywords */ 127#define inline __inline 128#define signed __signed 129#define volatile __volatile 130#endif /* !NO_ANSI_KEYWORDS */ 131#endif /* !(__STDC__ || __cplusplus) */ 132 133/* 134 * Used for internal auditing of the NetBSD source tree. 135 */ 136#ifdef __AUDIT__ 137#define __aconst __const 138#else 139#define __aconst 140#endif 141 142/* 143 * GCC2 provides __extension__ to suppress warnings for various GNU C 144 * language extensions under "-ansi -pedantic". 145 */ 146#if !__GNUC_PREREQ__(2, 0) 147#define __extension__ /* delete __extension__ if non-gcc or gcc1 */ 148#endif 149 150/* 151 * GCC1 and some versions of GCC2 declare dead (non-returning) and 152 * pure (no side effects) functions using "volatile" and "const"; 153 * unfortunately, these then cause warnings under "-ansi -pedantic". 154 * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of 155 * these work for GNU C++ (modulo a slight glitch in the C++ grammar 156 * in the distribution version of 2.5.5). 157 */ 158#if !__GNUC_PREREQ__(2, 5) 159#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */ 160#if defined(__GNUC__) && !defined(__STRICT_ANSI__) 161#define __dead __volatile 162#define __pure __const 163#endif 164#endif 165 166/* Delete pseudo-keywords wherever they are not available or needed. */ 167#ifndef __dead 168#define __dead 169#define __pure 170#endif 171 172#if __GNUC_PREREQ__(2, 7) 173#define __unused __attribute__((__unused__)) 174#else 175#define __unused /* delete */ 176#endif 177 178#if __GNUC_PREREQ__(2, 7) 179#define __packed __attribute__((__packed__)) 180#define __aligned(x) __attribute__((__aligned__(x))) 181#define __section(x) __attribute__((__section__(x))) 182#elif defined(__lint__) 183#define __packed /* delete */ 184#define __aligned(x) /* delete */ 185#define __section(x) /* delete */ 186#else 187#define __packed error: no __packed for this compiler 188#define __aligned(x) error: no __aligned for this compiler 189#define __section(x) error: no __section for this compiler 190#endif 191 192/* 193 * C99 defines the restrict type qualifier keyword, which was made available 194 * in GCC 2.92. 195 */ 196#if __STDC_VERSION__ >= 199901L 197#define __restrict restrict 198#else 199#if !__GNUC_PREREQ__(2, 92) 200#define __restrict /* delete __restrict when not supported */ 201#endif 202#endif 203 204/* 205 * C99 defines __func__ predefined identifier, which was made available 206 * in GCC 2.95. 207 */ 208#if !(__STDC_VERSION__ >= 199901L) 209#if __GNUC_PREREQ__(2, 6) 210#define __func__ __PRETTY_FUNCTION__ 211#elif __GNUC_PREREQ__(2, 4) 212#define __func__ __FUNCTION__ 213#else 214#define __func__ "" 215#endif 216#endif /* !(__STDC_VERSION__ >= 199901L) */ 217 218#if defined(_KERNEL) 219#if defined(NO_KERNEL_RCSIDS) 220#undef __KERNEL_RCSID 221#define __KERNEL_RCSID(_n, _s) /* nothing */ 222#endif /* NO_KERNEL_RCSIDS */ 223#endif /* _KERNEL */ 224 225#if !defined(_STANDALONE) && !defined(_KERNEL) 226#ifdef __GNUC__ 227#define __RENAME(x) ___RENAME(x) 228#else 229#ifdef __lint__ 230#define __RENAME(x) __symbolrename(x) 231#else 232 #error "No function renaming possible" 233#endif /* __lint__ */ 234#endif /* __GNUC__ */ 235#else /* _STANDALONE || _KERNEL */ 236#define __RENAME(x) no renaming in kernel or standalone environment 237#endif 238 239/* 240 * GNU C version 2.96 adds explicit branch prediction so that 241 * the CPU back-end can hint the processor and also so that 242 * code blocks can be reordered such that the predicted path 243 * sees a more linear flow, thus improving cache behavior, etc. 244 * 245 * The following two macros provide us with a way to use this 246 * compiler feature. Use __predict_true() if you expect the expression 247 * to evaluate to true, and __predict_false() if you expect the 248 * expression to evaluate to false. 249 * 250 * A few notes about usage: 251 * 252 * * Generally, __predict_false() error condition checks (unless 253 * you have some _strong_ reason to do otherwise, in which case 254 * document it), and/or __predict_true() `no-error' condition 255 * checks, assuming you want to optimize for the no-error case. 256 * 257 * * Other than that, if you don't know the likelihood of a test 258 * succeeding from empirical or other `hard' evidence, don't 259 * make predictions. 260 * 261 * * These are meant to be used in places that are run `a lot'. 262 * It is wasteful to make predictions in code that is run 263 * seldomly (e.g. at subsystem initialization time) as the 264 * basic block reordering that this affects can often generate 265 * larger code. 266 */ 267#if __GNUC_PREREQ__(2, 96) 268#define __predict_true(exp) __builtin_expect((exp) != 0, 1) 269#define __predict_false(exp) __builtin_expect((exp) != 0, 0) 270#else 271#define __predict_true(exp) (exp) 272#define __predict_false(exp) (exp) 273#endif 274 275/* 276 * Macros for manipulating "link sets". Link sets are arrays of pointers 277 * to objects, which are gathered up by the linker. 278 * 279 * Object format-specific code has provided us with the following macros: 280 * 281 * __link_set_add_text(set, sym) 282 * Add a reference to the .text symbol `sym' to `set'. 283 * 284 * __link_set_add_rodata(set, sym) 285 * Add a reference to the .rodata symbol `sym' to `set'. 286 * 287 * __link_set_add_data(set, sym) 288 * Add a reference to the .data symbol `sym' to `set'. 289 * 290 * __link_set_add_bss(set, sym) 291 * Add a reference to the .bss symbol `sym' to `set'. 292 * 293 * __link_set_decl(set, ptype) 294 * Provide an extern declaration of the set `set', which 295 * contains an array of the pointer type `ptype'. This 296 * macro must be used by any code which wishes to reference 297 * the elements of a link set. 298 * 299 * __link_set_start(set) 300 * This points to the first slot in the link set. 301 * 302 * __link_set_end(set) 303 * This points to the (non-existent) slot after the last 304 * entry in the link set. 305 * 306 * __link_set_count(set) 307 * Count the number of entries in link set `set'. 308 * 309 * In addition, we provide the following macros for accessing link sets: 310 * 311 * __link_set_foreach(pvar, set) 312 * Iterate over the link set `set'. Because a link set is 313 * an array of pointers, pvar must be declared as "type **pvar", 314 * and the actual entry accessed as "*pvar". 315 * 316 * __link_set_entry(set, idx) 317 * Access the link set entry at index `idx' from set `set'. 318 */ 319#define __link_set_foreach(pvar, set) \ 320 for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) 321 322#define __link_set_entry(set, idx) (__link_set_begin(set)[idx]) 323 324#endif /* !_SYS_CDEFS_H_ */ 325