1199767f8SToomas Soome /*- 2199767f8SToomas Soome * Copyright (c) 1991, 1993 3199767f8SToomas Soome * The Regents of the University of California. All rights reserved. 4199767f8SToomas Soome * 5199767f8SToomas Soome * This code is derived from software contributed to Berkeley by 6199767f8SToomas Soome * Berkeley Software Design, Inc. 7199767f8SToomas Soome * 8199767f8SToomas Soome * Redistribution and use in source and binary forms, with or without 9199767f8SToomas Soome * modification, are permitted provided that the following conditions 10199767f8SToomas Soome * are met: 11199767f8SToomas Soome * 1. Redistributions of source code must retain the above copyright 12199767f8SToomas Soome * notice, this list of conditions and the following disclaimer. 13199767f8SToomas Soome * 2. Redistributions in binary form must reproduce the above copyright 14199767f8SToomas Soome * notice, this list of conditions and the following disclaimer in the 15199767f8SToomas Soome * documentation and/or other materials provided with the distribution. 16199767f8SToomas Soome * 4. Neither the name of the University nor the names of its contributors 17199767f8SToomas Soome * may be used to endorse or promote products derived from this software 18199767f8SToomas Soome * without specific prior written permission. 19199767f8SToomas Soome * 20199767f8SToomas Soome * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21199767f8SToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22199767f8SToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23199767f8SToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24199767f8SToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25199767f8SToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26199767f8SToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27199767f8SToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28199767f8SToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29199767f8SToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30199767f8SToomas Soome * SUCH DAMAGE. 31199767f8SToomas Soome * 32199767f8SToomas Soome * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 33199767f8SToomas Soome * $FreeBSD$ 34199767f8SToomas Soome */ 35199767f8SToomas Soome 36199767f8SToomas Soome #ifndef _SYS_CDEFS_H_ 37199767f8SToomas Soome #define _SYS_CDEFS_H_ 38199767f8SToomas Soome 39199767f8SToomas Soome /* 40199767f8SToomas Soome * Testing against Clang-specific extensions. 41199767f8SToomas Soome */ 42199767f8SToomas Soome #ifndef __has_attribute 43199767f8SToomas Soome #define __has_attribute(x) 0 44199767f8SToomas Soome #endif 45199767f8SToomas Soome #ifndef __has_extension 46199767f8SToomas Soome #define __has_extension __has_feature 47199767f8SToomas Soome #endif 48199767f8SToomas Soome #ifndef __has_feature 49199767f8SToomas Soome #define __has_feature(x) 0 50199767f8SToomas Soome #endif 51199767f8SToomas Soome #ifndef __has_include 52199767f8SToomas Soome #define __has_include(x) 0 53199767f8SToomas Soome #endif 54199767f8SToomas Soome #ifndef __has_builtin 55199767f8SToomas Soome #define __has_builtin(x) 0 56199767f8SToomas Soome #endif 57199767f8SToomas Soome 58199767f8SToomas Soome #if defined(__cplusplus) 59199767f8SToomas Soome #define __BEGIN_DECLS extern "C" { 60199767f8SToomas Soome #define __END_DECLS } 61199767f8SToomas Soome #else 62199767f8SToomas Soome #define __BEGIN_DECLS 63199767f8SToomas Soome #define __END_DECLS 64199767f8SToomas Soome #endif 65199767f8SToomas Soome 66199767f8SToomas Soome /* 67199767f8SToomas Soome * This code has been put in place to help reduce the addition of 68199767f8SToomas Soome * compiler specific defines in FreeBSD code. It helps to aid in 69199767f8SToomas Soome * having a compiler-agnostic source tree. 70199767f8SToomas Soome */ 71199767f8SToomas Soome 72199767f8SToomas Soome #if defined(__GNUC__) || defined(__INTEL_COMPILER) 73199767f8SToomas Soome 74199767f8SToomas Soome #if __GNUC__ >= 3 || defined(__INTEL_COMPILER) 75199767f8SToomas Soome #define __GNUCLIKE_ASM 3 76199767f8SToomas Soome #define __GNUCLIKE_MATH_BUILTIN_CONSTANTS 77199767f8SToomas Soome #else 78199767f8SToomas Soome #define __GNUCLIKE_ASM 2 79199767f8SToomas Soome #endif 80199767f8SToomas Soome #define __GNUCLIKE___TYPEOF 1 81199767f8SToomas Soome #define __GNUCLIKE___OFFSETOF 1 82199767f8SToomas Soome #define __GNUCLIKE___SECTION 1 83199767f8SToomas Soome 84199767f8SToomas Soome #ifndef __INTEL_COMPILER 85199767f8SToomas Soome #define __GNUCLIKE_CTOR_SECTION_HANDLING 1 86199767f8SToomas Soome #endif 87199767f8SToomas Soome 88199767f8SToomas Soome #define __GNUCLIKE_BUILTIN_CONSTANT_P 1 89199767f8SToomas Soome #if defined(__INTEL_COMPILER) && defined(__cplusplus) && \ 90199767f8SToomas Soome __INTEL_COMPILER < 800 91199767f8SToomas Soome #undef __GNUCLIKE_BUILTIN_CONSTANT_P 92199767f8SToomas Soome #endif 93199767f8SToomas Soome 94199767f8SToomas Soome #if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) 95199767f8SToomas Soome #define __GNUCLIKE_BUILTIN_VARARGS 1 96199767f8SToomas Soome #define __GNUCLIKE_BUILTIN_STDARG 1 97199767f8SToomas Soome #define __GNUCLIKE_BUILTIN_VAALIST 1 98199767f8SToomas Soome #endif 99199767f8SToomas Soome 100199767f8SToomas Soome #if defined(__GNUC__) 101199767f8SToomas Soome #define __GNUC_VA_LIST_COMPATIBILITY 1 102199767f8SToomas Soome #endif 103199767f8SToomas Soome 104199767f8SToomas Soome /* 105199767f8SToomas Soome * Compiler memory barriers, specific to gcc and clang. 106199767f8SToomas Soome */ 107199767f8SToomas Soome #if defined(__GNUC__) 108199767f8SToomas Soome #define __compiler_membar() __asm __volatile(" " : : : "memory") 109199767f8SToomas Soome #endif 110199767f8SToomas Soome 111199767f8SToomas Soome #ifndef __INTEL_COMPILER 112199767f8SToomas Soome #define __GNUCLIKE_BUILTIN_NEXT_ARG 1 113199767f8SToomas Soome #define __GNUCLIKE_MATH_BUILTIN_RELOPS 114199767f8SToomas Soome #endif 115199767f8SToomas Soome 116199767f8SToomas Soome #define __GNUCLIKE_BUILTIN_MEMCPY 1 117199767f8SToomas Soome 118199767f8SToomas Soome /* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */ 119199767f8SToomas Soome #define __CC_SUPPORTS_INLINE 1 120199767f8SToomas Soome #define __CC_SUPPORTS___INLINE 1 121199767f8SToomas Soome #define __CC_SUPPORTS___INLINE__ 1 122199767f8SToomas Soome 123199767f8SToomas Soome #define __CC_SUPPORTS___FUNC__ 1 124199767f8SToomas Soome #define __CC_SUPPORTS_WARNING 1 125199767f8SToomas Soome 126199767f8SToomas Soome #define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */ 127199767f8SToomas Soome 128199767f8SToomas Soome #define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1 129199767f8SToomas Soome 130199767f8SToomas Soome #endif /* __GNUC__ || __INTEL_COMPILER */ 131199767f8SToomas Soome 132199767f8SToomas Soome /* 133199767f8SToomas Soome * Macro to test if we're using a specific version of gcc or later. 134199767f8SToomas Soome */ 135199767f8SToomas Soome #if defined(__GNUC__) && !defined(__INTEL_COMPILER) 136199767f8SToomas Soome #define __GNUC_PREREQ__(ma, mi) \ 137199767f8SToomas Soome (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) 138199767f8SToomas Soome #else 139199767f8SToomas Soome #define __GNUC_PREREQ__(ma, mi) 0 140199767f8SToomas Soome #endif 141199767f8SToomas Soome 142199767f8SToomas Soome /* 143199767f8SToomas Soome * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 144199767f8SToomas Soome * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 145199767f8SToomas Soome * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI 146199767f8SToomas Soome * mode -- there must be no spaces between its arguments, and for nested 147199767f8SToomas Soome * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also 148199767f8SToomas Soome * concatenate double-quoted strings produced by the __STRING macro, but 149199767f8SToomas Soome * this only works with ANSI C. 150199767f8SToomas Soome * 151199767f8SToomas Soome * __XSTRING is like __STRING, but it expands any macros in its argument 152199767f8SToomas Soome * first. It is only available with ANSI C. 153199767f8SToomas Soome */ 154199767f8SToomas Soome #if defined(__STDC__) || defined(__cplusplus) 155199767f8SToomas Soome #define __P(protos) protos /* full-blown ANSI C */ 156199767f8SToomas Soome #define __CONCAT1(x,y) x ## y 157199767f8SToomas Soome #define __CONCAT(x,y) __CONCAT1(x,y) 158199767f8SToomas Soome #define __STRING(x) #x /* stringify without expanding x */ 159199767f8SToomas Soome #define __XSTRING(x) __STRING(x) /* expand x, then stringify */ 160199767f8SToomas Soome 161199767f8SToomas Soome #define __const const /* define reserved names to standard */ 162199767f8SToomas Soome #define __signed signed 163199767f8SToomas Soome #define __volatile volatile 164199767f8SToomas Soome #if defined(__cplusplus) 165199767f8SToomas Soome #define __inline inline /* convert to C++ keyword */ 166199767f8SToomas Soome #else 167199767f8SToomas Soome #if !(defined(__CC_SUPPORTS___INLINE)) 168199767f8SToomas Soome #define __inline /* delete GCC keyword */ 169199767f8SToomas Soome #endif /* ! __CC_SUPPORTS___INLINE */ 170199767f8SToomas Soome #endif /* !__cplusplus */ 171199767f8SToomas Soome 172199767f8SToomas Soome #else /* !(__STDC__ || __cplusplus) */ 173199767f8SToomas Soome #define __P(protos) () /* traditional C preprocessor */ 174199767f8SToomas Soome #define __CONCAT(x,y) x/**/y 175199767f8SToomas Soome #define __STRING(x) "x" 176199767f8SToomas Soome 177199767f8SToomas Soome #if !defined(__CC_SUPPORTS___INLINE) 178199767f8SToomas Soome #define __const /* delete pseudo-ANSI C keywords */ 179199767f8SToomas Soome #define __inline 180199767f8SToomas Soome #define __signed 181199767f8SToomas Soome #define __volatile 182199767f8SToomas Soome /* 183199767f8SToomas Soome * In non-ANSI C environments, new programs will want ANSI-only C keywords 184199767f8SToomas Soome * deleted from the program and old programs will want them left alone. 185199767f8SToomas Soome * When using a compiler other than gcc, programs using the ANSI C keywords 186199767f8SToomas Soome * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. 187199767f8SToomas Soome * When using "gcc -traditional", we assume that this is the intent; if 188199767f8SToomas Soome * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. 189199767f8SToomas Soome */ 190199767f8SToomas Soome #ifndef NO_ANSI_KEYWORDS 191199767f8SToomas Soome #define const /* delete ANSI C keywords */ 192199767f8SToomas Soome #define inline 193199767f8SToomas Soome #define signed 194199767f8SToomas Soome #define volatile 195199767f8SToomas Soome #endif /* !NO_ANSI_KEYWORDS */ 196199767f8SToomas Soome #endif /* !__CC_SUPPORTS___INLINE */ 197199767f8SToomas Soome #endif /* !(__STDC__ || __cplusplus) */ 198199767f8SToomas Soome 199199767f8SToomas Soome /* 200199767f8SToomas Soome * Compiler-dependent macros to help declare dead (non-returning) and 201199767f8SToomas Soome * pure (no side effects) functions, and unused variables. They are 202199767f8SToomas Soome * null except for versions of gcc that are known to support the features 203199767f8SToomas Soome * properly (old versions of gcc-2 supported the dead and pure features 204199767f8SToomas Soome * in a different (wrong) way). If we do not provide an implementation 205199767f8SToomas Soome * for a given compiler, let the compile fail if it is told to use 206199767f8SToomas Soome * a feature that we cannot live without. 207199767f8SToomas Soome */ 208199767f8SToomas Soome #ifdef lint 209199767f8SToomas Soome #define __dead2 210199767f8SToomas Soome #define __pure2 211199767f8SToomas Soome #define __unused 212199767f8SToomas Soome #define __packed 213199767f8SToomas Soome #define __aligned(x) 214199767f8SToomas Soome #define __alloc_align(x) 215199767f8SToomas Soome #define __alloc_size(x) 216199767f8SToomas Soome #define __section(x) 217199767f8SToomas Soome #define __weak_symbol 218199767f8SToomas Soome #else 219199767f8SToomas Soome #define __weak_symbol __attribute__((__weak__)) 220199767f8SToomas Soome #if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER) 221199767f8SToomas Soome #define __dead2 222199767f8SToomas Soome #define __pure2 223199767f8SToomas Soome #define __unused 224199767f8SToomas Soome #endif 225199767f8SToomas Soome #if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER) 226199767f8SToomas Soome #define __dead2 __attribute__((__noreturn__)) 227199767f8SToomas Soome #define __pure2 __attribute__((__const__)) 228199767f8SToomas Soome #define __unused 229199767f8SToomas Soome /* XXX Find out what to do for __packed, __aligned and __section */ 230199767f8SToomas Soome #endif 231199767f8SToomas Soome #if __GNUC_PREREQ__(2, 7) || defined(__INTEL_COMPILER) 232199767f8SToomas Soome #define __dead2 __attribute__((__noreturn__)) 233199767f8SToomas Soome #define __pure2 __attribute__((__const__)) 234199767f8SToomas Soome #define __unused __attribute__((__unused__)) 235199767f8SToomas Soome #define __used __attribute__((__used__)) 236199767f8SToomas Soome #define __packed __attribute__((__packed__)) 237199767f8SToomas Soome #define __aligned(x) __attribute__((__aligned__(x))) 238199767f8SToomas Soome #define __section(x) __attribute__((__section__(x))) 239199767f8SToomas Soome #endif 240199767f8SToomas Soome #if __GNUC_PREREQ__(4, 3) || __has_attribute(__alloc_size__) 241199767f8SToomas Soome #define __alloc_size(x) __attribute__((__alloc_size__(x))) 242*59c22e7aSToomas Soome #define __alloc_size2(n, x) __attribute__((__alloc_size__(n, x))) 243199767f8SToomas Soome #else 244199767f8SToomas Soome #define __alloc_size(x) 245*59c22e7aSToomas Soome #define __alloc_size2(n, x) 246199767f8SToomas Soome #endif 247199767f8SToomas Soome #if __GNUC_PREREQ__(4, 9) || __has_attribute(__alloc_align__) 248199767f8SToomas Soome #define __alloc_align(x) __attribute__((__alloc_align__(x))) 249199767f8SToomas Soome #else 250199767f8SToomas Soome #define __alloc_align(x) 251199767f8SToomas Soome #endif 252199767f8SToomas Soome #endif /* lint */ 253199767f8SToomas Soome 254199767f8SToomas Soome #if !__GNUC_PREREQ__(2, 95) 255199767f8SToomas Soome #define __alignof(x) __offsetof(struct { char __a; x __b; }, __b) 256199767f8SToomas Soome #endif 257199767f8SToomas Soome 258199767f8SToomas Soome /* 259199767f8SToomas Soome * Keywords added in C11. 260199767f8SToomas Soome */ 261199767f8SToomas Soome 262199767f8SToomas Soome #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint) 263199767f8SToomas Soome 264199767f8SToomas Soome #if !__has_extension(c_alignas) 265199767f8SToomas Soome #if (defined(__cplusplus) && __cplusplus >= 201103L) || \ 266199767f8SToomas Soome __has_extension(cxx_alignas) 267199767f8SToomas Soome #define _Alignas(x) alignas(x) 268199767f8SToomas Soome #else 269199767f8SToomas Soome /* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */ 270199767f8SToomas Soome #define _Alignas(x) __aligned(x) 271199767f8SToomas Soome #endif 272199767f8SToomas Soome #endif 273199767f8SToomas Soome 274199767f8SToomas Soome #if defined(__cplusplus) && __cplusplus >= 201103L 275199767f8SToomas Soome #define _Alignof(x) alignof(x) 276199767f8SToomas Soome #else 277199767f8SToomas Soome #define _Alignof(x) __alignof(x) 278199767f8SToomas Soome #endif 279199767f8SToomas Soome 280199767f8SToomas Soome #if !__has_extension(c_atomic) && !__has_extension(cxx_atomic) 281199767f8SToomas Soome /* 282199767f8SToomas Soome * No native support for _Atomic(). Place object in structure to prevent 283199767f8SToomas Soome * most forms of direct non-atomic access. 284199767f8SToomas Soome */ 285199767f8SToomas Soome #define _Atomic(T) struct { T volatile __val; } 286199767f8SToomas Soome #endif 287199767f8SToomas Soome 288199767f8SToomas Soome #if defined(__cplusplus) && __cplusplus >= 201103L 289199767f8SToomas Soome #define _Noreturn [[noreturn]] 290199767f8SToomas Soome #else 291199767f8SToomas Soome #define _Noreturn __dead2 292199767f8SToomas Soome #endif 293199767f8SToomas Soome 294199767f8SToomas Soome #if !__has_extension(c_static_assert) 295199767f8SToomas Soome #if (defined(__cplusplus) && __cplusplus >= 201103L) || \ 296199767f8SToomas Soome __has_extension(cxx_static_assert) 297199767f8SToomas Soome #define _Static_assert(x, y) static_assert(x, y) 298199767f8SToomas Soome #elif __GNUC_PREREQ__(4,6) 299199767f8SToomas Soome /* Nothing, gcc 4.6 and higher has _Static_assert built-in */ 300199767f8SToomas Soome #elif defined(__COUNTER__) 301199767f8SToomas Soome #define _Static_assert(x, y) __Static_assert(x, __COUNTER__) 302199767f8SToomas Soome #define __Static_assert(x, y) ___Static_assert(x, y) 303199767f8SToomas Soome #define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] \ 304199767f8SToomas Soome __unused 305199767f8SToomas Soome #else 306199767f8SToomas Soome #define _Static_assert(x, y) struct __hack 307199767f8SToomas Soome #endif 308199767f8SToomas Soome #endif 309199767f8SToomas Soome 310199767f8SToomas Soome #if !__has_extension(c_thread_local) 311199767f8SToomas Soome /* 312199767f8SToomas Soome * XXX: Some compilers (Clang 3.3, GCC 4.7) falsely announce C++11 mode 313199767f8SToomas Soome * without actually supporting the thread_local keyword. Don't check for 314199767f8SToomas Soome * the presence of C++11 when defining _Thread_local. 315199767f8SToomas Soome */ 316199767f8SToomas Soome #if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \ 317199767f8SToomas Soome __has_extension(cxx_thread_local) 318199767f8SToomas Soome #define _Thread_local thread_local 319199767f8SToomas Soome #else 320199767f8SToomas Soome #define _Thread_local __thread 321199767f8SToomas Soome #endif 322199767f8SToomas Soome #endif 323199767f8SToomas Soome 324199767f8SToomas Soome #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ 325199767f8SToomas Soome 326199767f8SToomas Soome /* 327199767f8SToomas Soome * Emulation of C11 _Generic(). Unlike the previously defined C11 328199767f8SToomas Soome * keywords, it is not possible to implement this using exactly the same 329199767f8SToomas Soome * syntax. Therefore implement something similar under the name 330199767f8SToomas Soome * __generic(). Unlike _Generic(), this macro can only distinguish 331199767f8SToomas Soome * between a single type, so it requires nested invocations to 332199767f8SToomas Soome * distinguish multiple cases. 333199767f8SToomas Soome */ 334199767f8SToomas Soome 335199767f8SToomas Soome #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ 336199767f8SToomas Soome __has_extension(c_generic_selections) 337199767f8SToomas Soome #define __generic(expr, t, yes, no) \ 338199767f8SToomas Soome _Generic(expr, t: yes, default: no) 339199767f8SToomas Soome #elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus) 340199767f8SToomas Soome #define __generic(expr, t, yes, no) \ 341199767f8SToomas Soome __builtin_choose_expr( \ 342199767f8SToomas Soome __builtin_types_compatible_p(__typeof(expr), t), yes, no) 343199767f8SToomas Soome #endif 344199767f8SToomas Soome 345199767f8SToomas Soome #if __GNUC_PREREQ__(2, 96) 346199767f8SToomas Soome #define __malloc_like __attribute__((__malloc__)) 347199767f8SToomas Soome #define __pure __attribute__((__pure__)) 348199767f8SToomas Soome #else 349199767f8SToomas Soome #define __malloc_like 350199767f8SToomas Soome #define __pure 351199767f8SToomas Soome #endif 352199767f8SToomas Soome 353199767f8SToomas Soome #if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) 354199767f8SToomas Soome #define __always_inline __attribute__((__always_inline__)) 355199767f8SToomas Soome #else 356199767f8SToomas Soome #define __always_inline 357199767f8SToomas Soome #endif 358199767f8SToomas Soome 359199767f8SToomas Soome #if __GNUC_PREREQ__(3, 1) 360199767f8SToomas Soome #define __noinline __attribute__ ((__noinline__)) 361199767f8SToomas Soome #else 362199767f8SToomas Soome #define __noinline 363199767f8SToomas Soome #endif 364199767f8SToomas Soome 365199767f8SToomas Soome #if __GNUC_PREREQ__(3, 3) 366199767f8SToomas Soome #define __nonnull(x) __attribute__((__nonnull__(x))) 367199767f8SToomas Soome #define __nonnull_all __attribute__((__nonnull__)) 368199767f8SToomas Soome #else 369199767f8SToomas Soome #define __nonnull(x) 370199767f8SToomas Soome #define __nonnull_all 371199767f8SToomas Soome #endif 372199767f8SToomas Soome 373199767f8SToomas Soome #if __GNUC_PREREQ__(3, 4) 374199767f8SToomas Soome #define __fastcall __attribute__((__fastcall__)) 375199767f8SToomas Soome #define __result_use_check __attribute__((__warn_unused_result__)) 376199767f8SToomas Soome #else 377199767f8SToomas Soome #define __fastcall 378199767f8SToomas Soome #define __result_use_check 379199767f8SToomas Soome #endif 380199767f8SToomas Soome 381199767f8SToomas Soome #if __GNUC_PREREQ__(4, 1) 382199767f8SToomas Soome #define __returns_twice __attribute__((__returns_twice__)) 383199767f8SToomas Soome #else 384199767f8SToomas Soome #define __returns_twice 385199767f8SToomas Soome #endif 386199767f8SToomas Soome 387199767f8SToomas Soome #if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable) 388199767f8SToomas Soome #define __unreachable() __builtin_unreachable() 389199767f8SToomas Soome #else 390199767f8SToomas Soome #define __unreachable() ((void)0) 391199767f8SToomas Soome #endif 392199767f8SToomas Soome 393199767f8SToomas Soome /* XXX: should use `#if __STDC_VERSION__ < 199901'. */ 394199767f8SToomas Soome #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) 395199767f8SToomas Soome #define __func__ NULL 396199767f8SToomas Soome #endif 397199767f8SToomas Soome 398199767f8SToomas Soome #if (defined(__INTEL_COMPILER) || (defined(__GNUC__) && __GNUC__ >= 2)) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901 399199767f8SToomas Soome #define __LONG_LONG_SUPPORTED 400199767f8SToomas Soome #endif 401199767f8SToomas Soome 402199767f8SToomas Soome /* C++11 exposes a load of C99 stuff */ 403199767f8SToomas Soome #if defined(__cplusplus) && __cplusplus >= 201103L 404199767f8SToomas Soome #define __LONG_LONG_SUPPORTED 405199767f8SToomas Soome #ifndef __STDC_LIMIT_MACROS 406199767f8SToomas Soome #define __STDC_LIMIT_MACROS 407199767f8SToomas Soome #endif 408199767f8SToomas Soome #ifndef __STDC_CONSTANT_MACROS 409199767f8SToomas Soome #define __STDC_CONSTANT_MACROS 410199767f8SToomas Soome #endif 411199767f8SToomas Soome #endif 412199767f8SToomas Soome 413199767f8SToomas Soome /* 414199767f8SToomas Soome * GCC 2.95 provides `__restrict' as an extension to C90 to support the 415199767f8SToomas Soome * C99-specific `restrict' type qualifier. We happen to use `__restrict' as 416199767f8SToomas Soome * a way to define the `restrict' type qualifier without disturbing older 417199767f8SToomas Soome * software that is unaware of C99 keywords. 418199767f8SToomas Soome */ 419199767f8SToomas Soome #if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) 420199767f8SToomas Soome #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 || defined(lint) 421199767f8SToomas Soome #define __restrict 422199767f8SToomas Soome #else 423199767f8SToomas Soome #define __restrict restrict 424199767f8SToomas Soome #endif 425199767f8SToomas Soome #endif 426199767f8SToomas Soome 427199767f8SToomas Soome /* 428199767f8SToomas Soome * GNU C version 2.96 adds explicit branch prediction so that 429199767f8SToomas Soome * the CPU back-end can hint the processor and also so that 430199767f8SToomas Soome * code blocks can be reordered such that the predicted path 431199767f8SToomas Soome * sees a more linear flow, thus improving cache behavior, etc. 432199767f8SToomas Soome * 433199767f8SToomas Soome * The following two macros provide us with a way to utilize this 434199767f8SToomas Soome * compiler feature. Use __predict_true() if you expect the expression 435199767f8SToomas Soome * to evaluate to true, and __predict_false() if you expect the 436199767f8SToomas Soome * expression to evaluate to false. 437199767f8SToomas Soome * 438199767f8SToomas Soome * A few notes about usage: 439199767f8SToomas Soome * 440199767f8SToomas Soome * * Generally, __predict_false() error condition checks (unless 441199767f8SToomas Soome * you have some _strong_ reason to do otherwise, in which case 442199767f8SToomas Soome * document it), and/or __predict_true() `no-error' condition 443199767f8SToomas Soome * checks, assuming you want to optimize for the no-error case. 444199767f8SToomas Soome * 445199767f8SToomas Soome * * Other than that, if you don't know the likelihood of a test 446199767f8SToomas Soome * succeeding from empirical or other `hard' evidence, don't 447199767f8SToomas Soome * make predictions. 448199767f8SToomas Soome * 449199767f8SToomas Soome * * These are meant to be used in places that are run `a lot'. 450199767f8SToomas Soome * It is wasteful to make predictions in code that is run 451199767f8SToomas Soome * seldomly (e.g. at subsystem initialization time) as the 452199767f8SToomas Soome * basic block reordering that this affects can often generate 453199767f8SToomas Soome * larger code. 454199767f8SToomas Soome */ 455199767f8SToomas Soome #if __GNUC_PREREQ__(2, 96) 456199767f8SToomas Soome #define __predict_true(exp) __builtin_expect((exp), 1) 457199767f8SToomas Soome #define __predict_false(exp) __builtin_expect((exp), 0) 458199767f8SToomas Soome #else 459199767f8SToomas Soome #define __predict_true(exp) (exp) 460199767f8SToomas Soome #define __predict_false(exp) (exp) 461199767f8SToomas Soome #endif 462199767f8SToomas Soome 463199767f8SToomas Soome #if __GNUC_PREREQ__(4, 0) 464199767f8SToomas Soome #define __null_sentinel __attribute__((__sentinel__)) 465199767f8SToomas Soome #define __exported __attribute__((__visibility__("default"))) 466199767f8SToomas Soome #define __hidden __attribute__((__visibility__("hidden"))) 467199767f8SToomas Soome #else 468199767f8SToomas Soome #define __null_sentinel 469199767f8SToomas Soome #define __exported 470199767f8SToomas Soome #define __hidden 471199767f8SToomas Soome #endif 472199767f8SToomas Soome 473199767f8SToomas Soome /* 474199767f8SToomas Soome * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h> 475199767f8SToomas Soome * require it. 476199767f8SToomas Soome */ 477199767f8SToomas Soome #if __GNUC_PREREQ__(4, 1) 478199767f8SToomas Soome #define __offsetof(type, field) __builtin_offsetof(type, field) 479199767f8SToomas Soome #else 480199767f8SToomas Soome #ifndef __cplusplus 481199767f8SToomas Soome #define __offsetof(type, field) \ 482199767f8SToomas Soome ((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field)) 483199767f8SToomas Soome #else 484199767f8SToomas Soome #define __offsetof(type, field) \ 485199767f8SToomas Soome (__offsetof__ (reinterpret_cast <__size_t> \ 486199767f8SToomas Soome (&reinterpret_cast <const volatile char &> \ 487199767f8SToomas Soome (static_cast<type *> (0)->field)))) 488199767f8SToomas Soome #endif 489199767f8SToomas Soome #endif 490199767f8SToomas Soome #define __rangeof(type, start, end) \ 491199767f8SToomas Soome (__offsetof(type, end) - __offsetof(type, start)) 492199767f8SToomas Soome 493199767f8SToomas Soome /* 494199767f8SToomas Soome * Given the pointer x to the member m of the struct s, return 495199767f8SToomas Soome * a pointer to the containing structure. When using GCC, we first 496199767f8SToomas Soome * assign pointer x to a local variable, to check that its type is 497199767f8SToomas Soome * compatible with member m. 498199767f8SToomas Soome */ 499199767f8SToomas Soome #if __GNUC_PREREQ__(3, 1) 500199767f8SToomas Soome #define __containerof(x, s, m) ({ \ 501199767f8SToomas Soome const volatile __typeof(((s *)0)->m) *__x = (x); \ 502199767f8SToomas Soome __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\ 503199767f8SToomas Soome }) 504199767f8SToomas Soome #else 505199767f8SToomas Soome #define __containerof(x, s, m) \ 506199767f8SToomas Soome __DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m)) 507199767f8SToomas Soome #endif 508199767f8SToomas Soome 509199767f8SToomas Soome /* 510199767f8SToomas Soome * Compiler-dependent macros to declare that functions take printf-like 511199767f8SToomas Soome * or scanf-like arguments. They are null except for versions of gcc 512199767f8SToomas Soome * that are known to support the features properly (old versions of gcc-2 513199767f8SToomas Soome * didn't permit keeping the keywords out of the application namespace). 514199767f8SToomas Soome */ 515199767f8SToomas Soome #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) 516199767f8SToomas Soome #define __printflike(fmtarg, firstvararg) 517199767f8SToomas Soome #define __scanflike(fmtarg, firstvararg) 518199767f8SToomas Soome #define __format_arg(fmtarg) 519199767f8SToomas Soome #define __strfmonlike(fmtarg, firstvararg) 520199767f8SToomas Soome #define __strftimelike(fmtarg, firstvararg) 521199767f8SToomas Soome #else 522199767f8SToomas Soome #define __printflike(fmtarg, firstvararg) \ 523199767f8SToomas Soome __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 524199767f8SToomas Soome #define __scanflike(fmtarg, firstvararg) \ 525199767f8SToomas Soome __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) 526199767f8SToomas Soome #define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) 527199767f8SToomas Soome #define __strfmonlike(fmtarg, firstvararg) \ 528199767f8SToomas Soome __attribute__((__format__ (__strfmon__, fmtarg, firstvararg))) 529199767f8SToomas Soome #define __strftimelike(fmtarg, firstvararg) \ 530199767f8SToomas Soome __attribute__((__format__ (__strftime__, fmtarg, firstvararg))) 531199767f8SToomas Soome #endif 532199767f8SToomas Soome 533199767f8SToomas Soome /* 534199767f8SToomas Soome * FORTIFY_SOURCE, and perhaps other compiler-specific features, require 535199767f8SToomas Soome * the use of non-standard inlining. In general we should try to avoid 536199767f8SToomas Soome * using these but GCC-compatible compilers tend to support the extensions 537199767f8SToomas Soome * well enough to use them in limited cases. 538*59c22e7aSToomas Soome */ 539199767f8SToomas Soome #if defined(__GNUC_GNU_INLINE__) || defined(__GNUC_STDC_INLINE__) 540199767f8SToomas Soome #if __GNUC_PREREQ__(4, 3) || __has_attribute(__artificial__) 541199767f8SToomas Soome #define __gnu_inline __attribute__((__gnu_inline__, __artificial__)) 542199767f8SToomas Soome #else 543199767f8SToomas Soome #define __gnu_inline __attribute__((__gnu_inline__)) 544199767f8SToomas Soome #endif /* artificial */ 545199767f8SToomas Soome #else 546199767f8SToomas Soome #define __gnu_inline 547199767f8SToomas Soome #endif 548199767f8SToomas Soome 549199767f8SToomas Soome /* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ 550199767f8SToomas Soome #if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \ 551199767f8SToomas Soome defined(__GNUC__) && !defined(__INTEL_COMPILER) 552199767f8SToomas Soome #define __printf0like(fmtarg, firstvararg) \ 553199767f8SToomas Soome __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) 554199767f8SToomas Soome #else 555199767f8SToomas Soome #define __printf0like(fmtarg, firstvararg) 556199767f8SToomas Soome #endif 557199767f8SToomas Soome 558199767f8SToomas Soome #if defined(__GNUC__) || defined(__INTEL_COMPILER) 559199767f8SToomas Soome #ifndef __INTEL_COMPILER 560199767f8SToomas Soome #define __strong_reference(sym,aliassym) \ 561199767f8SToomas Soome extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))) 562199767f8SToomas Soome #endif 563199767f8SToomas Soome #ifdef __STDC__ 564199767f8SToomas Soome #define __weak_reference(sym,alias) \ 565199767f8SToomas Soome __asm__(".weak " #alias); \ 566199767f8SToomas Soome __asm__(".equ " #alias ", " #sym) 567199767f8SToomas Soome #define __warn_references(sym,msg) \ 568199767f8SToomas Soome __asm__(".section .gnu.warning." #sym); \ 569199767f8SToomas Soome __asm__(".asciz \"" msg "\""); \ 570199767f8SToomas Soome __asm__(".previous") 571199767f8SToomas Soome #define __sym_compat(sym,impl,verid) \ 572199767f8SToomas Soome __asm__(".symver " #impl ", " #sym "@" #verid) 573199767f8SToomas Soome #define __sym_default(sym,impl,verid) \ 574199767f8SToomas Soome __asm__(".symver " #impl ", " #sym "@@" #verid) 575199767f8SToomas Soome #else 576199767f8SToomas Soome #define __weak_reference(sym,alias) \ 577199767f8SToomas Soome __asm__(".weak alias"); \ 578199767f8SToomas Soome __asm__(".equ alias, sym") 579199767f8SToomas Soome #define __warn_references(sym,msg) \ 580199767f8SToomas Soome __asm__(".section .gnu.warning.sym"); \ 581199767f8SToomas Soome __asm__(".asciz \"msg\""); \ 582199767f8SToomas Soome __asm__(".previous") 583199767f8SToomas Soome #define __sym_compat(sym,impl,verid) \ 584199767f8SToomas Soome __asm__(".symver impl, sym@verid") 585199767f8SToomas Soome #define __sym_default(impl,sym,verid) \ 586199767f8SToomas Soome __asm__(".symver impl, sym@@verid") 587199767f8SToomas Soome #endif /* __STDC__ */ 588199767f8SToomas Soome #endif /* __GNUC__ || __INTEL_COMPILER */ 589199767f8SToomas Soome 590199767f8SToomas Soome #define __GLOBL1(sym) __asm__(".globl " #sym) 591199767f8SToomas Soome #define __GLOBL(sym) __GLOBL1(sym) 592199767f8SToomas Soome 593199767f8SToomas Soome #if defined(__GNUC__) || defined(__INTEL_COMPILER) 594199767f8SToomas Soome #define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"") 595199767f8SToomas Soome #else 596199767f8SToomas Soome /* 597199767f8SToomas Soome * The following definition might not work well if used in header files, 598199767f8SToomas Soome * but it should be better than nothing. If you want a "do nothing" 599199767f8SToomas Soome * version, then it should generate some harmless declaration, such as: 600199767f8SToomas Soome * #define __IDSTRING(name,string) struct __hack 601199767f8SToomas Soome */ 602199767f8SToomas Soome #define __IDSTRING(name,string) static const char name[] __unused = string 603199767f8SToomas Soome #endif 604199767f8SToomas Soome 605199767f8SToomas Soome /* 606199767f8SToomas Soome * Embed the rcs id of a source file in the resulting library. Note that in 607199767f8SToomas Soome * more recent ELF binutils, we use .ident allowing the ID to be stripped. 608199767f8SToomas Soome * Usage: 609199767f8SToomas Soome * __FBSDID("$FreeBSD$"); 610199767f8SToomas Soome */ 611199767f8SToomas Soome #ifndef __FBSDID 612199767f8SToomas Soome #if !defined(lint) && !defined(STRIP_FBSDID) 613199767f8SToomas Soome #define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) 614199767f8SToomas Soome #else 615199767f8SToomas Soome #define __FBSDID(s) struct __hack 616199767f8SToomas Soome #endif 617199767f8SToomas Soome #endif 618199767f8SToomas Soome 619199767f8SToomas Soome #ifndef __RCSID 620199767f8SToomas Soome #ifndef NO__RCSID 621199767f8SToomas Soome #define __RCSID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) 622199767f8SToomas Soome #else 623199767f8SToomas Soome #define __RCSID(s) struct __hack 624199767f8SToomas Soome #endif 625199767f8SToomas Soome #endif 626199767f8SToomas Soome 627199767f8SToomas Soome #ifndef __RCSID_SOURCE 628199767f8SToomas Soome #ifndef NO__RCSID_SOURCE 629199767f8SToomas Soome #define __RCSID_SOURCE(s) __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s) 630199767f8SToomas Soome #else 631199767f8SToomas Soome #define __RCSID_SOURCE(s) struct __hack 632199767f8SToomas Soome #endif 633199767f8SToomas Soome #endif 634199767f8SToomas Soome 635199767f8SToomas Soome #ifndef __SCCSID 636199767f8SToomas Soome #ifndef NO__SCCSID 637199767f8SToomas Soome #define __SCCSID(s) __IDSTRING(__CONCAT(__sccsid_,__LINE__),s) 638199767f8SToomas Soome #else 639199767f8SToomas Soome #define __SCCSID(s) struct __hack 640199767f8SToomas Soome #endif 641199767f8SToomas Soome #endif 642199767f8SToomas Soome 643199767f8SToomas Soome #ifndef __COPYRIGHT 644199767f8SToomas Soome #ifndef NO__COPYRIGHT 645199767f8SToomas Soome #define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s) 646199767f8SToomas Soome #else 647199767f8SToomas Soome #define __COPYRIGHT(s) struct __hack 648199767f8SToomas Soome #endif 649199767f8SToomas Soome #endif 650199767f8SToomas Soome 651199767f8SToomas Soome #ifndef __DECONST 652199767f8SToomas Soome #define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var)) 653199767f8SToomas Soome #endif 654199767f8SToomas Soome 655199767f8SToomas Soome #ifndef __DEVOLATILE 656199767f8SToomas Soome #define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var)) 657199767f8SToomas Soome #endif 658199767f8SToomas Soome 659199767f8SToomas Soome #ifndef __DEQUALIFY 660199767f8SToomas Soome #define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var)) 661199767f8SToomas Soome #endif 662199767f8SToomas Soome 663199767f8SToomas Soome /*- 664199767f8SToomas Soome * The following definitions are an extension of the behavior originally 665199767f8SToomas Soome * implemented in <sys/_posix.h>, but with a different level of granularity. 666199767f8SToomas Soome * POSIX.1 requires that the macros we test be defined before any standard 667199767f8SToomas Soome * header file is included. 668199767f8SToomas Soome * 669199767f8SToomas Soome * Here's a quick run-down of the versions: 670199767f8SToomas Soome * defined(_POSIX_SOURCE) 1003.1-1988 671199767f8SToomas Soome * _POSIX_C_SOURCE == 1 1003.1-1990 672199767f8SToomas Soome * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option 673199767f8SToomas Soome * _POSIX_C_SOURCE == 199309 1003.1b-1993 674199767f8SToomas Soome * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, 675199767f8SToomas Soome * and the omnibus ISO/IEC 9945-1: 1996 676199767f8SToomas Soome * _POSIX_C_SOURCE == 200112 1003.1-2001 677199767f8SToomas Soome * _POSIX_C_SOURCE == 200809 1003.1-2008 678199767f8SToomas Soome * 679199767f8SToomas Soome * In addition, the X/Open Portability Guide, which is now the Single UNIX 680199767f8SToomas Soome * Specification, defines a feature-test macro which indicates the version of 681199767f8SToomas Soome * that specification, and which subsumes _POSIX_C_SOURCE. 682199767f8SToomas Soome * 683199767f8SToomas Soome * Our macros begin with two underscores to avoid namespace screwage. 684199767f8SToomas Soome */ 685199767f8SToomas Soome 686199767f8SToomas Soome /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ 687199767f8SToomas Soome #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1 688199767f8SToomas Soome #undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ 689199767f8SToomas Soome #define _POSIX_C_SOURCE 199009 690199767f8SToomas Soome #endif 691199767f8SToomas Soome 692199767f8SToomas Soome /* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ 693199767f8SToomas Soome #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2 694199767f8SToomas Soome #undef _POSIX_C_SOURCE 695199767f8SToomas Soome #define _POSIX_C_SOURCE 199209 696199767f8SToomas Soome #endif 697199767f8SToomas Soome 698199767f8SToomas Soome /* Deal with various X/Open Portability Guides and Single UNIX Spec. */ 699199767f8SToomas Soome #ifdef _XOPEN_SOURCE 700199767f8SToomas Soome #if _XOPEN_SOURCE - 0 >= 700 701199767f8SToomas Soome #define __XSI_VISIBLE 700 702199767f8SToomas Soome #undef _POSIX_C_SOURCE 703199767f8SToomas Soome #define _POSIX_C_SOURCE 200809 704199767f8SToomas Soome #elif _XOPEN_SOURCE - 0 >= 600 705199767f8SToomas Soome #define __XSI_VISIBLE 600 706199767f8SToomas Soome #undef _POSIX_C_SOURCE 707199767f8SToomas Soome #define _POSIX_C_SOURCE 200112 708199767f8SToomas Soome #elif _XOPEN_SOURCE - 0 >= 500 709199767f8SToomas Soome #define __XSI_VISIBLE 500 710199767f8SToomas Soome #undef _POSIX_C_SOURCE 711199767f8SToomas Soome #define _POSIX_C_SOURCE 199506 712199767f8SToomas Soome #endif 713199767f8SToomas Soome #endif 714199767f8SToomas Soome 715199767f8SToomas Soome /* 716199767f8SToomas Soome * Deal with all versions of POSIX. The ordering relative to the tests above is 717199767f8SToomas Soome * important. 718199767f8SToomas Soome */ 719199767f8SToomas Soome #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) 720199767f8SToomas Soome #define _POSIX_C_SOURCE 198808 721199767f8SToomas Soome #endif 722199767f8SToomas Soome #ifdef _POSIX_C_SOURCE 723199767f8SToomas Soome #if _POSIX_C_SOURCE >= 200809 724199767f8SToomas Soome #define __POSIX_VISIBLE 200809 725199767f8SToomas Soome #define __ISO_C_VISIBLE 1999 726199767f8SToomas Soome #elif _POSIX_C_SOURCE >= 200112 727199767f8SToomas Soome #define __POSIX_VISIBLE 200112 728199767f8SToomas Soome #define __ISO_C_VISIBLE 1999 729199767f8SToomas Soome #elif _POSIX_C_SOURCE >= 199506 730199767f8SToomas Soome #define __POSIX_VISIBLE 199506 731199767f8SToomas Soome #define __ISO_C_VISIBLE 1990 732199767f8SToomas Soome #elif _POSIX_C_SOURCE >= 199309 733199767f8SToomas Soome #define __POSIX_VISIBLE 199309 734199767f8SToomas Soome #define __ISO_C_VISIBLE 1990 735199767f8SToomas Soome #elif _POSIX_C_SOURCE >= 199209 736199767f8SToomas Soome #define __POSIX_VISIBLE 199209 737199767f8SToomas Soome #define __ISO_C_VISIBLE 1990 738199767f8SToomas Soome #elif _POSIX_C_SOURCE >= 199009 739199767f8SToomas Soome #define __POSIX_VISIBLE 199009 740199767f8SToomas Soome #define __ISO_C_VISIBLE 1990 741199767f8SToomas Soome #else 742199767f8SToomas Soome #define __POSIX_VISIBLE 198808 743199767f8SToomas Soome #define __ISO_C_VISIBLE 0 744199767f8SToomas Soome #endif /* _POSIX_C_SOURCE */ 745199767f8SToomas Soome #else 746199767f8SToomas Soome /*- 747199767f8SToomas Soome * Deal with _ANSI_SOURCE: 748199767f8SToomas Soome * If it is defined, and no other compilation environment is explicitly 749199767f8SToomas Soome * requested, then define our internal feature-test macros to zero. This 750199767f8SToomas Soome * makes no difference to the preprocessor (undefined symbols in preprocessing 751199767f8SToomas Soome * expressions are defined to have value zero), but makes it more convenient for 752199767f8SToomas Soome * a test program to print out the values. 753199767f8SToomas Soome * 754199767f8SToomas Soome * If a program mistakenly defines _ANSI_SOURCE and some other macro such as 755199767f8SToomas Soome * _POSIX_C_SOURCE, we will assume that it wants the broader compilation 756199767f8SToomas Soome * environment (and in fact we will never get here). 757199767f8SToomas Soome */ 758199767f8SToomas Soome #if defined(_ANSI_SOURCE) /* Hide almost everything. */ 759199767f8SToomas Soome #define __POSIX_VISIBLE 0 760199767f8SToomas Soome #define __XSI_VISIBLE 0 761199767f8SToomas Soome #define __BSD_VISIBLE 0 762199767f8SToomas Soome #define __ISO_C_VISIBLE 1990 763199767f8SToomas Soome #elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ 764199767f8SToomas Soome #define __POSIX_VISIBLE 0 765199767f8SToomas Soome #define __XSI_VISIBLE 0 766199767f8SToomas Soome #define __BSD_VISIBLE 0 767199767f8SToomas Soome #define __ISO_C_VISIBLE 1999 768199767f8SToomas Soome #elif defined(_C11_SOURCE) /* Localism to specify strict C11 env. */ 769199767f8SToomas Soome #define __POSIX_VISIBLE 0 770199767f8SToomas Soome #define __XSI_VISIBLE 0 771199767f8SToomas Soome #define __BSD_VISIBLE 0 772199767f8SToomas Soome #define __ISO_C_VISIBLE 2011 773199767f8SToomas Soome #else /* Default environment: show everything. */ 774199767f8SToomas Soome #define __POSIX_VISIBLE 200809 775199767f8SToomas Soome #define __XSI_VISIBLE 700 776199767f8SToomas Soome #define __BSD_VISIBLE 1 777199767f8SToomas Soome #define __ISO_C_VISIBLE 2011 778199767f8SToomas Soome #endif 779199767f8SToomas Soome #endif 780199767f8SToomas Soome 781199767f8SToomas Soome #if defined(__mips) || defined(__powerpc64__) || defined(__riscv__) 782199767f8SToomas Soome #define __NO_TLS 1 783199767f8SToomas Soome #endif 784199767f8SToomas Soome 785199767f8SToomas Soome /* 786199767f8SToomas Soome * Type Safety Checking 787199767f8SToomas Soome * 788199767f8SToomas Soome * Clang provides additional attributes to enable checking type safety 789*59c22e7aSToomas Soome * properties that cannot be enforced by the C type system. 790199767f8SToomas Soome */ 791199767f8SToomas Soome 792199767f8SToomas Soome #if __has_attribute(__argument_with_type_tag__) && \ 793199767f8SToomas Soome __has_attribute(__type_tag_for_datatype__) && !defined(lint) 794199767f8SToomas Soome #define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) \ 795199767f8SToomas Soome __attribute__((__argument_with_type_tag__(arg_kind, arg_idx, type_tag_idx))) 796199767f8SToomas Soome #define __datatype_type_tag(kind, type) \ 797199767f8SToomas Soome __attribute__((__type_tag_for_datatype__(kind, type))) 798199767f8SToomas Soome #else 799199767f8SToomas Soome #define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) 800199767f8SToomas Soome #define __datatype_type_tag(kind, type) 801199767f8SToomas Soome #endif 802199767f8SToomas Soome 803199767f8SToomas Soome /* 804199767f8SToomas Soome * Lock annotations. 805199767f8SToomas Soome * 806199767f8SToomas Soome * Clang provides support for doing basic thread-safety tests at 807199767f8SToomas Soome * compile-time, by marking which locks will/should be held when 808199767f8SToomas Soome * entering/leaving a functions. 809199767f8SToomas Soome * 810199767f8SToomas Soome * Furthermore, it is also possible to annotate variables and structure 811199767f8SToomas Soome * members to enforce that they are only accessed when certain locks are 812199767f8SToomas Soome * held. 813199767f8SToomas Soome */ 814199767f8SToomas Soome 815199767f8SToomas Soome #if __has_extension(c_thread_safety_attributes) 816199767f8SToomas Soome #define __lock_annotate(x) __attribute__((x)) 817199767f8SToomas Soome #else 818199767f8SToomas Soome #define __lock_annotate(x) 819199767f8SToomas Soome #endif 820199767f8SToomas Soome 821199767f8SToomas Soome /* Structure implements a lock. */ 822199767f8SToomas Soome #define __lockable __lock_annotate(lockable) 823199767f8SToomas Soome 824199767f8SToomas Soome /* Function acquires an exclusive or shared lock. */ 825199767f8SToomas Soome #define __locks_exclusive(...) \ 826199767f8SToomas Soome __lock_annotate(exclusive_lock_function(__VA_ARGS__)) 827199767f8SToomas Soome #define __locks_shared(...) \ 828199767f8SToomas Soome __lock_annotate(shared_lock_function(__VA_ARGS__)) 829199767f8SToomas Soome 830199767f8SToomas Soome /* Function attempts to acquire an exclusive or shared lock. */ 831199767f8SToomas Soome #define __trylocks_exclusive(...) \ 832199767f8SToomas Soome __lock_annotate(exclusive_trylock_function(__VA_ARGS__)) 833199767f8SToomas Soome #define __trylocks_shared(...) \ 834199767f8SToomas Soome __lock_annotate(shared_trylock_function(__VA_ARGS__)) 835199767f8SToomas Soome 836199767f8SToomas Soome /* Function releases a lock. */ 837199767f8SToomas Soome #define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__)) 838199767f8SToomas Soome 839199767f8SToomas Soome /* Function asserts that an exclusive or shared lock is held. */ 840199767f8SToomas Soome #define __asserts_exclusive(...) \ 841199767f8SToomas Soome __lock_annotate(assert_exclusive_lock(__VA_ARGS__)) 842199767f8SToomas Soome #define __asserts_shared(...) \ 843199767f8SToomas Soome __lock_annotate(assert_shared_lock(__VA_ARGS__)) 844199767f8SToomas Soome 845199767f8SToomas Soome /* Function requires that an exclusive or shared lock is or is not held. */ 846199767f8SToomas Soome #define __requires_exclusive(...) \ 847199767f8SToomas Soome __lock_annotate(exclusive_locks_required(__VA_ARGS__)) 848199767f8SToomas Soome #define __requires_shared(...) \ 849199767f8SToomas Soome __lock_annotate(shared_locks_required(__VA_ARGS__)) 850199767f8SToomas Soome #define __requires_unlocked(...) \ 851199767f8SToomas Soome __lock_annotate(locks_excluded(__VA_ARGS__)) 852199767f8SToomas Soome 853199767f8SToomas Soome /* Function should not be analyzed. */ 854199767f8SToomas Soome #define __no_lock_analysis __lock_annotate(no_thread_safety_analysis) 855199767f8SToomas Soome 856199767f8SToomas Soome /* Guard variables and structure members by lock. */ 857199767f8SToomas Soome #define __guarded_by(x) __lock_annotate(guarded_by(x)) 858199767f8SToomas Soome #define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x)) 859199767f8SToomas Soome 860199767f8SToomas Soome #endif /* !_SYS_CDEFS_H_ */ 861