1 /** $MirOS: src/sys/sys/cdefs.h,v 1.32 2014/03/13 00:58:53 tg Exp $ */ 2 /* $OpenBSD: cdefs.h,v 1.18 2005/05/27 21:28:12 millert Exp $ */ 3 /* $NetBSD: cdefs.h,v 1.16 1996/04/03 20:46:39 christos Exp $ */ 4 5 /*- 6 * Copyright © 2005, 2006, 2011, 2013, 2014 7 * Thorsten “mirabilos” Glaser <tg@mirbsd.org> 8 * Copyright (c) 1991, 1993 9 * The Regents of the University of California. All rights reserved. 10 * 11 * This code is derived from software contributed to Berkeley by 12 * Berkeley Software Design, Inc. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the distribution. 22 * 3. 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.7 (Berkeley) 1/21/94 39 */ 40 41 #ifndef _CDEFS_H_ 42 #define _CDEFS_H_ 43 44 #ifdef __KPRINTF_ATTRIBUTE__ 45 #undef __KPRINTF_ATTRIBUTE__ 46 #endif 47 48 #if defined(__cplusplus) 49 #define __BEGIN_DECLS extern "C" { 50 #define __END_DECLS } 51 #else 52 #define __BEGIN_DECLS 53 #define __END_DECLS 54 #endif 55 56 /* 57 * Macro to test if we're using a specific version of gcc or later. 58 */ 59 #ifdef lint 60 #undef __GNUC__ 61 #endif 62 #ifdef __GNUC__ 63 #define __GNUC_PREREQ__(ma, mi) \ 64 ((__GNUC__ > (ma)) || (__GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))) 65 #else 66 #define __GNUC_PREREQ__(ma, mi) 0 67 #endif 68 69 /* 70 * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 71 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 72 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces 73 * in between its arguments. __CONCAT can also concatenate double-quoted 74 * strings produced by the __STRING macro, but this only works with ANSI C. 75 */ 76 #if defined(__STDC__) || defined(__cplusplus) 77 #define __P(protos) protos /* full-blown ANSI C */ 78 #define __CONCAT(x,y) x ## y 79 #define __STRING(x) #x 80 81 #define __const const /* define reserved names to standard */ 82 #define __signed signed 83 #define __volatile volatile 84 #if (defined(__cplusplus) || defined(__PCC__)) && !defined(__inline) 85 #define __inline inline /* convert to C++/C99 keyword */ 86 #elif !defined(__GNUC__) && !defined(lint) && !defined(__inline) 87 #define __inline /* delete GCC keyword */ 88 #endif 89 90 #else /* !(__STDC__ || __cplusplus) */ 91 #define __P(protos) () /* traditional C preprocessor */ 92 #define __CONCAT(x,y) x/**/y 93 #define __STRING(x) "x" 94 95 #if !defined(__GNUC__) && !defined(lint) 96 #define __const /* delete pseudo-ANSI C keywords */ 97 #define __inline 98 #define __signed 99 #define __volatile 100 #endif /* !__GNUC__ && !lint */ 101 102 /* 103 * In non-ANSI C environments, new programs will want ANSI-only C keywords 104 * deleted from the program and old programs will want them left alone. 105 * Programs using the ANSI C keywords const, inline etc. as normal 106 * identifiers should define -DNO_ANSI_KEYWORDS. 107 */ 108 #ifndef NO_ANSI_KEYWORDS 109 #define const __const /* convert ANSI C keywords */ 110 #define inline __inline 111 #define signed __signed 112 #define volatile __volatile 113 #endif /* !NO_ANSI_KEYWORDS */ 114 #endif /* !(__STDC__ || __cplusplus) */ 115 116 /* 117 * GCC1 and some versions of GCC2 declare dead (non-returning) and 118 * pure (no side effects) functions using "volatile" and "const"; 119 * unfortunately, these then cause warnings under "-ansi -pedantic". 120 * GCC >= 2.5 uses the __attribute__((__attrs__)) style. All of these 121 * work for GNU C++ (modulo a slight glitch in the C++ grammar in 122 * the distribution version of 2.5.5). 123 * For GCC 3, the ANSI parser seems to be able to cope with attributes. 124 */ 125 #if !__GNUC_PREREQ__(2, 5) && !defined(__NWCC__) 126 #define __attribute__(x) /* delete __attribute__ if no or old gcc */ 127 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 128 #define __dead __volatile 129 #define __pure __const 130 #endif 131 #elif __GNUC_PREREQ__(3, 4) || !defined(__STRICT_ANSI__) 132 #define __dead __attribute__((__noreturn__)) 133 #define __pure __attribute__((__const__)) 134 #endif 135 136 /* 137 * GNU C version 2.96 adds explicit branch prediction so that 138 * the CPU back-end can hint the processor and also so that 139 * code blocks can be reordered such that the predicted path 140 * sees a more linear flow, thus improving cache behavior, etc. 141 * 142 * The following two macros provide us with a way to utilize this 143 * compiler feature. Use __predict_true() if you expect the expression 144 * to evaluate to true, and __predict_false() if you expect the 145 * expression to evaluate to false. 146 * 147 * A few notes about usage: 148 * 149 * * Generally, __predict_false() error condition checks (unless 150 * you have some _strong_ reason to do otherwise, in which case 151 * document it), and/or __predict_true() 'no-error' condition 152 * checks, assuming you want to optimize for the no-error case. 153 * 154 * * Other than that, if you don't know the likelihood of a test 155 * succeeding from empirical or other 'hard' evidence, don't 156 * make predictions. 157 * 158 * * These are meant to be used in places that are run 'a lot'. 159 * It is wasteful to make predictions in code that is run 160 * seldomly (e.g. at subsystem initialization time) as the 161 * basic block reordering that this affects can often generate 162 * larger code. 163 */ 164 #if defined(lint) 165 #define __predict_true(exp) (exp) 166 #define __predict_false(exp) (exp) 167 #elif __GNUC_PREREQ__(2, 96) 168 #define __predict_true(exp) __builtin_expect(((exp) != 0), 1) 169 #define __predict_false(exp) __builtin_expect(((exp) != 0), 0) 170 #else 171 #define __predict_true(exp) ((exp) != 0) 172 #define __predict_false(exp) ((exp) != 0) 173 #endif 174 175 /* Delete pseudo-keywords wherever they are not available or needed. */ 176 #ifndef __dead 177 #define __dead 178 #define __pure 179 #endif 180 181 #ifdef __ELF__ 182 #define __weak_extern(sym) __asm__(".weak " #sym); 183 #endif 184 185 #if (__GNUC__ >= 3) || __GNUC_PREREQ__(2, 7) 186 #define __packed __attribute__((__packed__)) 187 #elif defined(__PCC__) 188 #define __packed _Pragma("packed 1") 189 #elif defined(lint) 190 #define __packed 191 #endif 192 193 #if !__GNUC_PREREQ__(2, 8) 194 #define __extension__ 195 #endif 196 197 #ifdef lint 198 #define __aligned(x) 199 #define __func__ "__func__" 200 #define __restrict 201 #define __unused 202 #define __a_used 203 #define __a_deprecated 204 #elif defined(__PCC__) 205 #define __aligned(x) _Pragma("aligned " #x) 206 #define __restrict restrict 207 #define __unused __attribute__((__unused__)) 208 #define __a_used 209 #define __a_deprecated 210 #else 211 #define __aligned(x) __attribute__((__aligned__(x))) 212 #define __unused __attribute__((__unused__)) 213 #define __a_used __attribute__((__used__)) 214 #define __a_deprecated __attribute__((__deprecated__)) 215 #endif 216 217 #if !defined(__restrict) && !defined(__cplusplus) 218 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 219 #define __restrict restrict 220 #else 221 #define __restrict 222 #endif 223 #endif 224 #define __restrict__ __restrict 225 226 #if defined(__ELF__) && defined(__GNUC__) && \ 227 !defined(__llvm__) && !defined(__NWCC__) 228 #define __IDSTRING(prefix, string) \ 229 __asm__(".section .comment" \ 230 "\n .ascii \"@(\"\"#)" #prefix ": \"" \ 231 "\n .asciz \"" string "\"" \ 232 "\n .previous") 233 #else 234 #define __IDSTRING_CONCAT(l,p) __LINTED__ ## l ## _ ## p 235 #define __IDSTRING_EXPAND(l,p) __IDSTRING_CONCAT(l,p) 236 #define __IDSTRING(prefix, string) \ 237 static const char __IDSTRING_EXPAND(__LINE__,prefix) [] \ 238 __a_used = "@(""#)" #prefix ": " string 239 #endif 240 #define __COPYRIGHT(x) __IDSTRING(copyright,x) 241 #define __KERNEL_RCSID(n,x) __IDSTRING(rcsid_ ## n,x) 242 #define __RCSID(x) __IDSTRING(rcsid,x) 243 #define __SCCSID(x) __IDSTRING(sccsid,x) 244 #define __FBSDID(x) __IDSTRING(fbsdid,x) 245 246 #ifndef _DIAGASSERT 247 #define _DIAGASSERT(x) /* nothing */ 248 #endif 249 250 #ifdef __ELF__ 251 #define _C_LABEL_STRING(x) x 252 #ifdef __GNUC__ 253 #define __strong_alias(alias,sym) \ 254 __asm__(".globl " __STRING(alias) " ; " __STRING(alias) " = " __STRING(sym)) 255 #define __weak_alias(alias,sym) \ 256 __asm__(".weak " __STRING(alias) " ; " __STRING(alias) " = " __STRING(sym)) 257 #define __warn_references(sym,msg) \ 258 __asm__(".section .gnu.warning." __STRING(sym) " ; .ascii \"REF! " msg "\" ; .previous") 259 #endif 260 #else 261 #define _C_LABEL_STRING(x) "_"x 262 #endif 263 264 #ifdef __NEED_NETBSD_COMPAT /* one of the worst */ 265 #ifdef __GNUC__ 266 #define __UNCONST(x) __extension__({ \ 267 union { \ 268 const void *cptr; \ 269 void *vptr; \ 270 } __UC_v; \ 271 \ 272 __UC_v.cptr = (x); \ 273 (__UC_v.vptr); \ 274 }) 275 #else 276 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 277 #endif 278 #endif 279 280 /* 281 * "The nice thing about standards is that there are so many to choose from." 282 * There are a number of "feature test macros" specified by (different) 283 * standards that determine which interfaces and types the header files 284 * should expose. 285 * 286 * Because of inconsistencies in these macros, we define our own 287 * set in the private name space that end in _VISIBLE. These are 288 * always defined and so headers can test their values easily. 289 * Things can get tricky when multiple feature macros are defined. 290 * We try to take the union of all the features requested. 291 * 292 * The following macros are guaranteed to have a value after cdefs.h 293 * has been included: 294 * __POSIX_VISIBLE 295 * __XPG_VISIBLE 296 * __ISO_C_VISIBLE 297 * __BSD_VISIBLE 298 */ 299 300 /* 301 * X/Open Portability Guides and Single Unix Specifications. 302 * _XOPEN_SOURCE XPG3 303 * _XOPEN_SOURCE && _XOPEN_VERSION = 4 XPG4 304 * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1 XPG4v2 305 * _XOPEN_SOURCE == 500 XPG5 306 * _XOPEN_SOURCE == 520 XPG5v2 307 * _XOPEN_SOURCE == 600 POSIX 1003.1-2001 with XSI 308 * 309 * The XPG spec implies a specific value for _POSIX_C_SOURCE. 310 */ 311 #ifdef _XOPEN_SOURCE 312 # if (_XOPEN_SOURCE - 0 >= 600) 313 # define __XPG_VISIBLE 600 314 # undef _POSIX_C_SOURCE 315 # define _POSIX_C_SOURCE 200112L 316 # elif (_XOPEN_SOURCE - 0 >= 520) 317 # define __XPG_VISIBLE 520 318 # undef _POSIX_C_SOURCE 319 # define _POSIX_C_SOURCE 199506L 320 # elif (_XOPEN_SOURCE - 0 >= 500) 321 # define __XPG_VISIBLE 500 322 # undef _POSIX_C_SOURCE 323 # define _POSIX_C_SOURCE 199506L 324 # elif (_XOPEN_SOURCE_EXTENDED - 0 == 1) 325 # define __XPG_VISIBLE 420 326 # elif (_XOPEN_VERSION - 0 >= 4) 327 # define __XPG_VISIBLE 400 328 # else 329 # define __XPG_VISIBLE 300 330 # endif 331 #endif 332 333 /* 334 * POSIX macros, these checks must follow the XOPEN ones above. 335 * 336 * _POSIX_SOURCE == 1 1003.1-1988 (superseded by _POSIX_C_SOURCE) 337 * _POSIX_C_SOURCE == 1 1003.1-1990 338 * _POSIX_C_SOURCE == 2 1003.2-1992 339 * _POSIX_C_SOURCE == 199309L 1003.1b-1993 340 * _POSIX_C_SOURCE == 199506L 1003.1c-1995, 1003.1i-1995, 341 * and the omnibus ISO/IEC 9945-1:1996 342 * _POSIX_C_SOURCE == 200112L 1003.1-2001 343 * 344 * The POSIX spec implies a specific value for __ISO_C_VISIBLE, though 345 * this may be overridden by the _ISOC99_SOURCE macro later. 346 */ 347 #ifdef _POSIX_C_SOURCE 348 # if (_POSIX_C_SOURCE - 0 >= 200112) 349 # define __POSIX_VISIBLE 200112 350 # define __ISO_C_VISIBLE 1999 351 # elif (_POSIX_C_SOURCE - 0 >= 199506) 352 # define __POSIX_VISIBLE 199506 353 # define __ISO_C_VISIBLE 1990 354 # elif (_POSIX_C_SOURCE - 0 >= 199309) 355 # define __POSIX_VISIBLE 199309 356 # define __ISO_C_VISIBLE 1990 357 # elif (_POSIX_C_SOURCE - 0 >= 2) 358 # define __POSIX_VISIBLE 199209 359 # define __ISO_C_VISIBLE 1990 360 # else 361 # define __POSIX_VISIBLE 199009 362 # define __ISO_C_VISIBLE 1990 363 # endif 364 #elif defined(_POSIX_SOURCE) 365 # define __POSIX_VISIBLE 198808 366 # define __ISO_C_VISIBLE 0 367 #endif 368 369 /* 370 * _ANSI_SOURCE means to expose ANSI C89 interfaces only. 371 * If the the user defines it in addition to one of the POSIX or XOPEN 372 * macros, assume the POSIX/XOPEN macro(s) should take precedence. 373 */ 374 #if defined(_ANSI_SOURCE) && !defined(__POSIX_VISIBLE) && \ 375 !defined(__XPG_VISIBLE) 376 # define __POSIX_VISIBLE 0 377 # define __XPG_VISIBLE 0 378 # define __ISO_C_VISIBLE 1990 379 #endif 380 381 /* 382 * _ISOC99_SOURCE and __STDC_VERSION__ override any of the other macros since 383 * they are non-exclusive. 384 */ 385 #if defined(_ISOC99_SOURCE) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) 386 # undef __ISO_C_VISIBLE 387 # define __ISO_C_VISIBLE 1999 388 #endif 389 390 /* 391 * Finally deal with BSD-specific interfaces that are not covered 392 * by any standards. We expose these when one of the POSIX or XPG 393 * macros is not defined or if the user explicitly asks for them. 394 */ 395 #if !defined(_OPENBSD_SOURCE) && !defined(_NETBSD_SOURCE) && \ 396 (defined(_ANSI_SOURCE) || defined(__XPG_VISIBLE) || defined(__POSIX_VISIBLE)) 397 # define __OPENBSD_VISIBLE 0 398 #endif 399 400 /* 401 * _ALL_SOURCE and _GNU_SOURCE enable everything 402 */ 403 #if defined(_ALL_SOURCE) || defined(_GNU_SOURCE) 404 # undef __POSIX_VISIBLE 405 # undef __XPG_VISIBLE 406 # undef __ISO_C_VISIBLE 407 # undef __OPENBSD_VISIBLE 408 /* no #define, cf. default values below */ 409 #endif 410 411 /* 412 * __STRICT_ANSI__ (gcc -ansi) overrides everything else. 413 */ 414 #ifdef __STRICT_ANSI__ 415 # undef __POSIX_VISIBLE 416 # define __POSIX_VISIBLE 0 417 # undef __XPG_VISIBLE 418 # define __XPG_VISIBLE 0 419 # undef __ISO_C_VISIBLE 420 # define __ISO_C_VISIBLE 1990 421 # undef __OPENBSD_VISIBLE 422 # define __OPENBSD_VISIBLE 0 423 # undef __STDC_WANT_LIB_EXT1__ 424 # define __STDC_WANT_LIB_EXT1__ 0 425 #endif 426 427 /* 428 * Default values. 429 */ 430 #ifndef __XPG_VISIBLE 431 # define __XPG_VISIBLE 600 432 #endif 433 #ifndef __POSIX_VISIBLE 434 # define __POSIX_VISIBLE 200112 435 #endif 436 #ifndef __ISO_C_VISIBLE 437 # define __ISO_C_VISIBLE 1999 438 #endif 439 #ifndef __OPENBSD_VISIBLE 440 # define __OPENBSD_VISIBLE 1 441 #endif 442 443 /* transitional period */ 444 #undef __BSD_VISIBLE 445 #ifdef __OPENBSD_VISIBLE 446 #define __BSD_VISIBLE __OPENBSD_VISIBLE 447 #endif 448 449 #endif /* !_CDEFS_H_ */ 450