[444] | 1 | /* libc/sys/linux/sys/cdefs.h - Helper macros for K&R vs. ANSI C compat. */ |
---|
| 2 | |
---|
| 3 | /* Written 2000 by Werner Almesberger */ |
---|
| 4 | |
---|
| 5 | /*- |
---|
| 6 | * Copyright (c) 1991, 1993 |
---|
| 7 | * The Regents of the University of California. All rights reserved. |
---|
| 8 | * |
---|
| 9 | * This code is derived from software contributed to Berkeley by |
---|
| 10 | * Berkeley Software Design, Inc. |
---|
| 11 | * |
---|
| 12 | * Redistribution and use in source and binary forms, with or without |
---|
| 13 | * modification, are permitted provided that the following conditions |
---|
| 14 | * are met: |
---|
| 15 | * 1. Redistributions of source code must retain the above copyright |
---|
| 16 | * notice, this list of conditions and the following disclaimer. |
---|
| 17 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 18 | * notice, this list of conditions and the following disclaimer in the |
---|
| 19 | * documentation and/or other materials provided with the distribution. |
---|
| 20 | * 3. Neither the name of the University nor the names of its contributors |
---|
| 21 | * may be used to endorse or promote products derived from this software |
---|
| 22 | * without specific prior written permission. |
---|
| 23 | * |
---|
| 24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
---|
| 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
---|
| 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
| 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
| 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
| 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
| 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
| 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
| 34 | * SUCH DAMAGE. |
---|
| 35 | * |
---|
| 36 | * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 |
---|
| 37 | * $FreeBSD$ |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | #ifndef _SYS_CDEFS_H_ |
---|
| 41 | #define _SYS_CDEFS_H_ |
---|
| 42 | |
---|
| 43 | #include <machine/_default_types.h> |
---|
| 44 | #include <sys/features.h> |
---|
| 45 | #include <stddef.h> |
---|
| 46 | |
---|
| 47 | #define __PMT(args) args |
---|
| 48 | #define __DOTS , ... |
---|
| 49 | #define __THROW |
---|
| 50 | |
---|
| 51 | #ifdef __GNUC__ |
---|
| 52 | # define __ASMNAME(cname) __XSTRING (__USER_LABEL_PREFIX__) cname |
---|
| 53 | #endif |
---|
| 54 | |
---|
| 55 | #define __ptr_t void * |
---|
| 56 | #define __long_double_t long double |
---|
| 57 | |
---|
| 58 | #define __attribute_malloc__ |
---|
| 59 | #define __attribute_pure__ |
---|
| 60 | #define __attribute_format_strfmon__(a,b) |
---|
| 61 | #define __flexarr [0] |
---|
| 62 | |
---|
| 63 | #ifndef __BOUNDED_POINTERS__ |
---|
| 64 | # define __bounded /* nothing */ |
---|
| 65 | # define __unbounded /* nothing */ |
---|
| 66 | # define __ptrvalue /* nothing */ |
---|
| 67 | #endif |
---|
| 68 | |
---|
| 69 | /* |
---|
| 70 | * Testing against Clang-specific extensions. |
---|
| 71 | */ |
---|
| 72 | #ifndef __has_attribute |
---|
| 73 | #define __has_attribute(x) 0 |
---|
| 74 | #endif |
---|
| 75 | #ifndef __has_extension |
---|
| 76 | #define __has_extension __has_feature |
---|
| 77 | #endif |
---|
| 78 | #ifndef __has_feature |
---|
| 79 | #define __has_feature(x) 0 |
---|
| 80 | #endif |
---|
| 81 | #ifndef __has_include |
---|
| 82 | #define __has_include(x) 0 |
---|
| 83 | #endif |
---|
| 84 | #ifndef __has_builtin |
---|
| 85 | #define __has_builtin(x) 0 |
---|
| 86 | #endif |
---|
| 87 | |
---|
| 88 | #if defined(__cplusplus) |
---|
| 89 | #define __BEGIN_DECLS extern "C" { |
---|
| 90 | #define __END_DECLS } |
---|
| 91 | #else |
---|
| 92 | #define __BEGIN_DECLS |
---|
| 93 | #define __END_DECLS |
---|
| 94 | #endif |
---|
| 95 | |
---|
| 96 | /* |
---|
| 97 | * This code has been put in place to help reduce the addition of |
---|
| 98 | * compiler specific defines in FreeBSD code. It helps to aid in |
---|
| 99 | * having a compiler-agnostic source tree. |
---|
| 100 | */ |
---|
| 101 | |
---|
| 102 | #if defined(__GNUC__) || defined(__INTEL_COMPILER) |
---|
| 103 | |
---|
| 104 | #if __GNUC__ >= 3 || defined(__INTEL_COMPILER) |
---|
| 105 | #define __GNUCLIKE_ASM 3 |
---|
| 106 | #define __GNUCLIKE_MATH_BUILTIN_CONSTANTS |
---|
| 107 | #else |
---|
| 108 | #define __GNUCLIKE_ASM 2 |
---|
| 109 | #endif |
---|
| 110 | #define __GNUCLIKE___TYPEOF 1 |
---|
| 111 | #define __GNUCLIKE___OFFSETOF 1 |
---|
| 112 | #define __GNUCLIKE___SECTION 1 |
---|
| 113 | |
---|
| 114 | #ifndef __INTEL_COMPILER |
---|
| 115 | #define __GNUCLIKE_CTOR_SECTION_HANDLING 1 |
---|
| 116 | #endif |
---|
| 117 | |
---|
| 118 | #define __GNUCLIKE_BUILTIN_CONSTANT_P 1 |
---|
| 119 | #if defined(__INTEL_COMPILER) && defined(__cplusplus) && \ |
---|
| 120 | __INTEL_COMPILER < 800 |
---|
| 121 | #undef __GNUCLIKE_BUILTIN_CONSTANT_P |
---|
| 122 | #endif |
---|
| 123 | |
---|
| 124 | #if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) |
---|
| 125 | #define __GNUCLIKE_BUILTIN_VARARGS 1 |
---|
| 126 | #define __GNUCLIKE_BUILTIN_STDARG 1 |
---|
| 127 | #define __GNUCLIKE_BUILTIN_VAALIST 1 |
---|
| 128 | #endif |
---|
| 129 | |
---|
| 130 | #if defined(__GNUC__) |
---|
| 131 | #define __GNUC_VA_LIST_COMPATIBILITY 1 |
---|
| 132 | #endif |
---|
| 133 | |
---|
| 134 | /* |
---|
| 135 | * Compiler memory barriers, specific to gcc and clang. |
---|
| 136 | */ |
---|
| 137 | #if defined(__GNUC__) |
---|
| 138 | #define __compiler_membar() __asm __volatile(" " : : : "memory") |
---|
| 139 | #endif |
---|
| 140 | |
---|
| 141 | #ifndef __INTEL_COMPILER |
---|
| 142 | #define __GNUCLIKE_BUILTIN_NEXT_ARG 1 |
---|
| 143 | #define __GNUCLIKE_MATH_BUILTIN_RELOPS |
---|
| 144 | #endif |
---|
| 145 | |
---|
| 146 | #define __GNUCLIKE_BUILTIN_MEMCPY 1 |
---|
| 147 | |
---|
| 148 | /* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */ |
---|
| 149 | #define __CC_SUPPORTS_INLINE 1 |
---|
| 150 | #define __CC_SUPPORTS___INLINE 1 |
---|
| 151 | #define __CC_SUPPORTS___INLINE__ 1 |
---|
| 152 | |
---|
| 153 | #define __CC_SUPPORTS___FUNC__ 1 |
---|
| 154 | #define __CC_SUPPORTS_WARNING 1 |
---|
| 155 | |
---|
| 156 | #define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */ |
---|
| 157 | |
---|
| 158 | #define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1 |
---|
| 159 | |
---|
| 160 | #endif /* __GNUC__ || __INTEL_COMPILER */ |
---|
| 161 | |
---|
| 162 | /* |
---|
| 163 | * The __CONCAT macro is used to concatenate parts of symbol names, e.g. |
---|
| 164 | * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. |
---|
| 165 | * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI |
---|
| 166 | * mode -- there must be no spaces between its arguments, and for nested |
---|
| 167 | * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also |
---|
| 168 | * concatenate double-quoted strings produced by the __STRING macro, but |
---|
| 169 | * this only works with ANSI C. |
---|
| 170 | * |
---|
| 171 | * __XSTRING is like __STRING, but it expands any macros in its argument |
---|
| 172 | * first. It is only available with ANSI C. |
---|
| 173 | */ |
---|
| 174 | #if defined(__STDC__) || defined(__cplusplus) |
---|
| 175 | #define __P(protos) protos /* full-blown ANSI C */ |
---|
| 176 | #define __CONCAT1(x,y) x ## y |
---|
| 177 | #define __CONCAT(x,y) __CONCAT1(x,y) |
---|
| 178 | #define __STRING(x) #x /* stringify without expanding x */ |
---|
| 179 | #define __XSTRING(x) __STRING(x) /* expand x, then stringify */ |
---|
| 180 | |
---|
| 181 | #define __const const /* define reserved names to standard */ |
---|
| 182 | #define __signed signed |
---|
| 183 | #define __volatile volatile |
---|
| 184 | #if defined(__cplusplus) |
---|
| 185 | #define __inline inline /* convert to C++ keyword */ |
---|
| 186 | #else |
---|
| 187 | #if !(defined(__CC_SUPPORTS___INLINE)) |
---|
| 188 | #define __inline /* delete GCC keyword */ |
---|
| 189 | #endif /* ! __CC_SUPPORTS___INLINE */ |
---|
| 190 | #endif /* !__cplusplus */ |
---|
| 191 | |
---|
| 192 | #else /* !(__STDC__ || __cplusplus) */ |
---|
| 193 | #define __P(protos) () /* traditional C preprocessor */ |
---|
| 194 | #define __CONCAT(x,y) x/**/y |
---|
| 195 | #define __STRING(x) "x" |
---|
| 196 | |
---|
| 197 | #if !defined(__CC_SUPPORTS___INLINE) |
---|
| 198 | #define __const /* delete pseudo-ANSI C keywords */ |
---|
| 199 | #define __inline |
---|
| 200 | #define __signed |
---|
| 201 | #define __volatile |
---|
| 202 | /* |
---|
| 203 | * In non-ANSI C environments, new programs will want ANSI-only C keywords |
---|
| 204 | * deleted from the program and old programs will want them left alone. |
---|
| 205 | * When using a compiler other than gcc, programs using the ANSI C keywords |
---|
| 206 | * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. |
---|
| 207 | * When using "gcc -traditional", we assume that this is the intent; if |
---|
| 208 | * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. |
---|
| 209 | */ |
---|
| 210 | #ifndef NO_ANSI_KEYWORDS |
---|
| 211 | #define const /* delete ANSI C keywords */ |
---|
| 212 | #define inline |
---|
| 213 | #define signed |
---|
| 214 | #define volatile |
---|
| 215 | #endif /* !NO_ANSI_KEYWORDS */ |
---|
| 216 | #endif /* !__CC_SUPPORTS___INLINE */ |
---|
| 217 | #endif /* !(__STDC__ || __cplusplus) */ |
---|
| 218 | |
---|
| 219 | /* |
---|
| 220 | * Compiler-dependent macros to help declare dead (non-returning) and |
---|
| 221 | * pure (no side effects) functions, and unused variables. They are |
---|
| 222 | * null except for versions of gcc that are known to support the features |
---|
| 223 | * properly (old versions of gcc-2 supported the dead and pure features |
---|
| 224 | * in a different (wrong) way). If we do not provide an implementation |
---|
| 225 | * for a given compiler, let the compile fail if it is told to use |
---|
| 226 | * a feature that we cannot live without. |
---|
| 227 | */ |
---|
| 228 | #ifdef lint |
---|
| 229 | #define __dead2 |
---|
| 230 | #define __pure2 |
---|
| 231 | #define __unused |
---|
| 232 | #define __packed |
---|
| 233 | #define __aligned(x) |
---|
| 234 | #define __alloc_align(x) |
---|
| 235 | #define __alloc_size(x) |
---|
| 236 | #define __section(x) |
---|
| 237 | #define __weak_symbol |
---|
| 238 | #else |
---|
| 239 | #define __weak_symbol __attribute__((__weak__)) |
---|
| 240 | #if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER) |
---|
| 241 | #define __dead2 |
---|
| 242 | #define __pure2 |
---|
| 243 | #define __unused |
---|
| 244 | #endif |
---|
| 245 | #if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER) |
---|
| 246 | #define __dead2 __attribute__((__noreturn__)) |
---|
| 247 | #define __pure2 __attribute__((__const__)) |
---|
| 248 | #define __unused |
---|
| 249 | /* XXX Find out what to do for __packed, __aligned and __section */ |
---|
| 250 | #endif |
---|
| 251 | #if __GNUC_PREREQ__(2, 7) || defined(__INTEL_COMPILER) |
---|
| 252 | #define __dead2 __attribute__((__noreturn__)) |
---|
| 253 | #define __pure2 __attribute__((__const__)) |
---|
| 254 | #define __unused __attribute__((__unused__)) |
---|
| 255 | #define __used __attribute__((__used__)) |
---|
| 256 | #define __packed __attribute__((__packed__)) |
---|
| 257 | #define __aligned(x) __attribute__((__aligned__(x))) |
---|
| 258 | #define __section(x) __attribute__((__section__(x))) |
---|
| 259 | #endif |
---|
| 260 | #if __GNUC_PREREQ__(4, 3) || __has_attribute(__alloc_size__) |
---|
| 261 | #define __alloc_size(x) __attribute__((__alloc_size__(x))) |
---|
| 262 | #else |
---|
| 263 | #define __alloc_size(x) |
---|
| 264 | #endif |
---|
| 265 | #if __GNUC_PREREQ__(4, 9) || __has_attribute(__alloc_align__) |
---|
| 266 | #define __alloc_align(x) __attribute__((__alloc_align__(x))) |
---|
| 267 | #else |
---|
| 268 | #define __alloc_align(x) |
---|
| 269 | #endif |
---|
| 270 | #endif /* lint */ |
---|
| 271 | |
---|
| 272 | #if !__GNUC_PREREQ__(2, 95) |
---|
| 273 | #define __alignof(x) __offsetof(struct { char __a; x __b; }, __b) |
---|
| 274 | #endif |
---|
| 275 | |
---|
| 276 | /* |
---|
| 277 | * Keywords added in C11. |
---|
| 278 | */ |
---|
| 279 | |
---|
| 280 | #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint) |
---|
| 281 | |
---|
| 282 | #if !__has_extension(c_alignas) |
---|
| 283 | #if (defined(__cplusplus) && __cplusplus >= 201103L) || \ |
---|
| 284 | __has_extension(cxx_alignas) |
---|
| 285 | #define _Alignas(x) alignas(x) |
---|
| 286 | #else |
---|
| 287 | /* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */ |
---|
| 288 | #define _Alignas(x) __aligned(x) |
---|
| 289 | #endif |
---|
| 290 | #endif |
---|
| 291 | |
---|
| 292 | #if defined(__cplusplus) && __cplusplus >= 201103L |
---|
| 293 | #define _Alignof(x) alignof(x) |
---|
| 294 | #else |
---|
| 295 | #define _Alignof(x) __alignof(x) |
---|
| 296 | #endif |
---|
| 297 | |
---|
| 298 | #if !defined(__cplusplus) && !__has_extension(c_atomic) && \ |
---|
| 299 | !__has_extension(cxx_atomic) |
---|
| 300 | /* |
---|
| 301 | * No native support for _Atomic(). Place object in structure to prevent |
---|
| 302 | * most forms of direct non-atomic access. |
---|
| 303 | */ |
---|
| 304 | #define _Atomic(T) struct { T volatile __val; } |
---|
| 305 | #endif |
---|
| 306 | |
---|
| 307 | #if defined(__cplusplus) && __cplusplus >= 201103L |
---|
| 308 | #define _Noreturn [[noreturn]] |
---|
| 309 | #else |
---|
| 310 | #define _Noreturn __dead2 |
---|
| 311 | #endif |
---|
| 312 | |
---|
| 313 | #if !__has_extension(c_static_assert) |
---|
| 314 | #if (defined(__cplusplus) && __cplusplus >= 201103L) || \ |
---|
| 315 | __has_extension(cxx_static_assert) |
---|
| 316 | #define _Static_assert(x, y) static_assert(x, y) |
---|
| 317 | #elif __GNUC_PREREQ__(4,6) |
---|
| 318 | /* Nothing, gcc 4.6 and higher has _Static_assert built-in */ |
---|
| 319 | #elif defined(__COUNTER__) |
---|
| 320 | #define _Static_assert(x, y) __Static_assert(x, __COUNTER__) |
---|
| 321 | #define __Static_assert(x, y) ___Static_assert(x, y) |
---|
| 322 | #define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] \ |
---|
| 323 | __unused |
---|
| 324 | #else |
---|
| 325 | #define _Static_assert(x, y) struct __hack |
---|
| 326 | #endif |
---|
| 327 | #endif |
---|
| 328 | |
---|
| 329 | #if !__has_extension(c_thread_local) |
---|
| 330 | /* |
---|
| 331 | * XXX: Some compilers (Clang 3.3, GCC 4.7) falsely announce C++11 mode |
---|
| 332 | * without actually supporting the thread_local keyword. Don't check for |
---|
| 333 | * the presence of C++11 when defining _Thread_local. |
---|
| 334 | */ |
---|
| 335 | #if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \ |
---|
| 336 | __has_extension(cxx_thread_local) |
---|
| 337 | #define _Thread_local thread_local |
---|
| 338 | #else |
---|
| 339 | #define _Thread_local __thread |
---|
| 340 | #endif |
---|
| 341 | #endif |
---|
| 342 | |
---|
| 343 | #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */ |
---|
| 344 | |
---|
| 345 | /* |
---|
| 346 | * Emulation of C11 _Generic(). Unlike the previously defined C11 |
---|
| 347 | * keywords, it is not possible to implement this using exactly the same |
---|
| 348 | * syntax. Therefore implement something similar under the name |
---|
| 349 | * __generic(). Unlike _Generic(), this macro can only distinguish |
---|
| 350 | * between a single type, so it requires nested invocations to |
---|
| 351 | * distinguish multiple cases. |
---|
| 352 | */ |
---|
| 353 | |
---|
| 354 | #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ |
---|
| 355 | __has_extension(c_generic_selections) |
---|
| 356 | #define __generic(expr, t, yes, no) \ |
---|
| 357 | _Generic(expr, t: yes, default: no) |
---|
| 358 | #elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus) |
---|
| 359 | #define __generic(expr, t, yes, no) \ |
---|
| 360 | __builtin_choose_expr( \ |
---|
| 361 | __builtin_types_compatible_p(__typeof(expr), t), yes, no) |
---|
| 362 | #endif |
---|
| 363 | |
---|
| 364 | /* |
---|
| 365 | * C99 Static array indices in function parameter declarations. Syntax such as: |
---|
| 366 | * void bar(int myArray[static 10]); |
---|
| 367 | * is allowed in C99 but not in C++. Define __min_size appropriately so |
---|
| 368 | * headers using it can be compiled in either language. Use like this: |
---|
| 369 | * void bar(int myArray[__min_size(10)]); |
---|
| 370 | */ |
---|
| 371 | #if !defined(__cplusplus) && \ |
---|
| 372 | (defined(__clang__) || __GNUC_PREREQ__(4, 6)) && \ |
---|
| 373 | (!defined(__STDC_VERSION__) || (__STDC_VERSION__ >= 199901)) |
---|
| 374 | #define __min_size(x) static (x) |
---|
| 375 | #else |
---|
| 376 | #define __min_size(x) (x) |
---|
| 377 | #endif |
---|
| 378 | |
---|
| 379 | #if __GNUC_PREREQ__(2, 96) |
---|
| 380 | #define __malloc_like __attribute__((__malloc__)) |
---|
| 381 | #define __pure __attribute__((__pure__)) |
---|
| 382 | #else |
---|
| 383 | #define __malloc_like |
---|
| 384 | #define __pure |
---|
| 385 | #endif |
---|
| 386 | |
---|
| 387 | #if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) |
---|
| 388 | #define __always_inline __inline__ __attribute__((__always_inline__)) |
---|
| 389 | #else |
---|
| 390 | #define __always_inline |
---|
| 391 | #endif |
---|
| 392 | |
---|
| 393 | #if __GNUC_PREREQ__(3, 1) |
---|
| 394 | #define __noinline __attribute__ ((__noinline__)) |
---|
| 395 | #else |
---|
| 396 | #define __noinline |
---|
| 397 | #endif |
---|
| 398 | |
---|
| 399 | #if __GNUC_PREREQ__(3, 3) |
---|
| 400 | #define __nonnull(x) __attribute__((__nonnull__ x)) |
---|
| 401 | #define __nonnull_all __attribute__((__nonnull__)) |
---|
| 402 | #else |
---|
| 403 | #define __nonnull(x) |
---|
| 404 | #define __nonnull_all |
---|
| 405 | #endif |
---|
| 406 | |
---|
| 407 | #if __GNUC_PREREQ__(3, 4) |
---|
| 408 | #define __fastcall __attribute__((__fastcall__)) |
---|
| 409 | #define __result_use_check __attribute__((__warn_unused_result__)) |
---|
| 410 | #else |
---|
| 411 | #define __fastcall |
---|
| 412 | #define __result_use_check |
---|
| 413 | #endif |
---|
| 414 | |
---|
| 415 | #if __GNUC_PREREQ__(4, 1) |
---|
| 416 | #define __returns_twice __attribute__((__returns_twice__)) |
---|
| 417 | #else |
---|
| 418 | #define __returns_twice |
---|
| 419 | #endif |
---|
| 420 | |
---|
| 421 | #if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable) |
---|
| 422 | #define __unreachable() __builtin_unreachable() |
---|
| 423 | #else |
---|
| 424 | #define __unreachable() ((void)0) |
---|
| 425 | #endif |
---|
| 426 | |
---|
| 427 | /* XXX: should use `#if __STDC_VERSION__ < 199901'. */ |
---|
| 428 | #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) |
---|
| 429 | #define __func__ NULL |
---|
| 430 | #endif |
---|
| 431 | |
---|
| 432 | /* |
---|
| 433 | * GCC 2.95 provides `__restrict' as an extension to C90 to support the |
---|
| 434 | * C99-specific `restrict' type qualifier. We happen to use `__restrict' as |
---|
| 435 | * a way to define the `restrict' type qualifier without disturbing older |
---|
| 436 | * software that is unaware of C99 keywords. |
---|
| 437 | */ |
---|
| 438 | #if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) |
---|
| 439 | #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 || defined(lint) |
---|
| 440 | #define __restrict |
---|
| 441 | #else |
---|
| 442 | #define __restrict restrict |
---|
| 443 | #endif |
---|
| 444 | #endif |
---|
| 445 | |
---|
| 446 | /* |
---|
| 447 | * GNU C version 2.96 adds explicit branch prediction so that |
---|
| 448 | * the CPU back-end can hint the processor and also so that |
---|
| 449 | * code blocks can be reordered such that the predicted path |
---|
| 450 | * sees a more linear flow, thus improving cache behavior, etc. |
---|
| 451 | * |
---|
| 452 | * The following two macros provide us with a way to utilize this |
---|
| 453 | * compiler feature. Use __predict_true() if you expect the expression |
---|
| 454 | * to evaluate to true, and __predict_false() if you expect the |
---|
| 455 | * expression to evaluate to false. |
---|
| 456 | * |
---|
| 457 | * A few notes about usage: |
---|
| 458 | * |
---|
| 459 | * * Generally, __predict_false() error condition checks (unless |
---|
| 460 | * you have some _strong_ reason to do otherwise, in which case |
---|
| 461 | * document it), and/or __predict_true() `no-error' condition |
---|
| 462 | * checks, assuming you want to optimize for the no-error case. |
---|
| 463 | * |
---|
| 464 | * * Other than that, if you don't know the likelihood of a test |
---|
| 465 | * succeeding from empirical or other `hard' evidence, don't |
---|
| 466 | * make predictions. |
---|
| 467 | * |
---|
| 468 | * * These are meant to be used in places that are run `a lot'. |
---|
| 469 | * It is wasteful to make predictions in code that is run |
---|
| 470 | * seldomly (e.g. at subsystem initialization time) as the |
---|
| 471 | * basic block reordering that this affects can often generate |
---|
| 472 | * larger code. |
---|
| 473 | */ |
---|
| 474 | #if __GNUC_PREREQ__(2, 96) |
---|
| 475 | #define __predict_true(exp) __builtin_expect((exp), 1) |
---|
| 476 | #define __predict_false(exp) __builtin_expect((exp), 0) |
---|
| 477 | #else |
---|
| 478 | #define __predict_true(exp) (exp) |
---|
| 479 | #define __predict_false(exp) (exp) |
---|
| 480 | #endif |
---|
| 481 | |
---|
| 482 | #if __GNUC_PREREQ__(4, 0) |
---|
| 483 | #define __null_sentinel __attribute__((__sentinel__)) |
---|
| 484 | #define __exported __attribute__((__visibility__("default"))) |
---|
| 485 | /* Only default visibility is supported on PE/COFF targets. */ |
---|
| 486 | #ifndef __CYGWIN__ |
---|
| 487 | #define __hidden __attribute__((__visibility__("hidden"))) |
---|
| 488 | #else |
---|
| 489 | #define __hidden |
---|
| 490 | #endif |
---|
| 491 | #else |
---|
| 492 | #define __null_sentinel |
---|
| 493 | #define __exported |
---|
| 494 | #define __hidden |
---|
| 495 | #endif |
---|
| 496 | |
---|
| 497 | #define __offsetof(type, field) offsetof(type, field) |
---|
| 498 | #define __rangeof(type, start, end) \ |
---|
| 499 | (__offsetof(type, end) - __offsetof(type, start)) |
---|
| 500 | |
---|
| 501 | /* |
---|
| 502 | * Given the pointer x to the member m of the struct s, return |
---|
| 503 | * a pointer to the containing structure. When using GCC, we first |
---|
| 504 | * assign pointer x to a local variable, to check that its type is |
---|
| 505 | * compatible with member m. |
---|
| 506 | */ |
---|
| 507 | #if __GNUC_PREREQ__(3, 1) |
---|
| 508 | #define __containerof(x, s, m) ({ \ |
---|
| 509 | const volatile __typeof(((s *)0)->m) *__x = (x); \ |
---|
| 510 | __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\ |
---|
| 511 | }) |
---|
| 512 | #else |
---|
| 513 | #define __containerof(x, s, m) \ |
---|
| 514 | __DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m)) |
---|
| 515 | #endif |
---|
| 516 | |
---|
| 517 | /* |
---|
| 518 | * Compiler-dependent macros to declare that functions take printf-like |
---|
| 519 | * or scanf-like arguments. They are null except for versions of gcc |
---|
| 520 | * that are known to support the features properly (old versions of gcc-2 |
---|
| 521 | * didn't permit keeping the keywords out of the application namespace). |
---|
| 522 | */ |
---|
| 523 | #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) |
---|
| 524 | #define __printflike(fmtarg, firstvararg) |
---|
| 525 | #define __scanflike(fmtarg, firstvararg) |
---|
| 526 | #define __format_arg(fmtarg) |
---|
| 527 | #define __strfmonlike(fmtarg, firstvararg) |
---|
| 528 | #define __strftimelike(fmtarg, firstvararg) |
---|
| 529 | #else |
---|
| 530 | #define __printflike(fmtarg, firstvararg) \ |
---|
| 531 | __attribute__((__format__ (__printf__, fmtarg, firstvararg))) |
---|
| 532 | #define __scanflike(fmtarg, firstvararg) \ |
---|
| 533 | __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) |
---|
| 534 | #define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) |
---|
| 535 | #define __strfmonlike(fmtarg, firstvararg) \ |
---|
| 536 | __attribute__((__format__ (__strfmon__, fmtarg, firstvararg))) |
---|
| 537 | #define __strftimelike(fmtarg, firstvararg) \ |
---|
| 538 | __attribute__((__format__ (__strftime__, fmtarg, firstvararg))) |
---|
| 539 | #endif |
---|
| 540 | |
---|
| 541 | /* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ |
---|
| 542 | #if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \ |
---|
| 543 | defined(__GNUC__) && !defined(__INTEL_COMPILER) |
---|
| 544 | #define __printf0like(fmtarg, firstvararg) \ |
---|
| 545 | __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) |
---|
| 546 | #else |
---|
| 547 | #define __printf0like(fmtarg, firstvararg) |
---|
| 548 | #endif |
---|
| 549 | |
---|
| 550 | #if defined(__GNUC__) || defined(__INTEL_COMPILER) |
---|
| 551 | #ifndef __INTEL_COMPILER |
---|
| 552 | #define __strong_reference(sym,aliassym) \ |
---|
| 553 | extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))) |
---|
| 554 | #endif |
---|
| 555 | #ifdef __ELF__ |
---|
| 556 | #ifdef __STDC__ |
---|
| 557 | #define __weak_reference(sym,alias) \ |
---|
| 558 | __asm__(".weak " #alias); \ |
---|
| 559 | __asm__(".equ " #alias ", " #sym) |
---|
| 560 | #define __warn_references(sym,msg) \ |
---|
| 561 | __asm__(".section .gnu.warning." #sym); \ |
---|
| 562 | __asm__(".asciz \"" msg "\""); \ |
---|
| 563 | __asm__(".previous") |
---|
| 564 | #define __sym_compat(sym,impl,verid) \ |
---|
| 565 | __asm__(".symver " #impl ", " #sym "@" #verid) |
---|
| 566 | #define __sym_default(sym,impl,verid) \ |
---|
| 567 | __asm__(".symver " #impl ", " #sym "@@" #verid) |
---|
| 568 | #else |
---|
| 569 | #define __weak_reference(sym,alias) \ |
---|
| 570 | __asm__(".weak alias"); \ |
---|
| 571 | __asm__(".equ alias, sym") |
---|
| 572 | #define __warn_references(sym,msg) \ |
---|
| 573 | __asm__(".section .gnu.warning.sym"); \ |
---|
| 574 | __asm__(".asciz \"msg\""); \ |
---|
| 575 | __asm__(".previous") |
---|
| 576 | #define __sym_compat(sym,impl,verid) \ |
---|
| 577 | __asm__(".symver impl, sym@verid") |
---|
| 578 | #define __sym_default(impl,sym,verid) \ |
---|
| 579 | __asm__(".symver impl, sym@@verid") |
---|
| 580 | #endif /* __STDC__ */ |
---|
| 581 | #else /* !__ELF__ */ |
---|
| 582 | #ifdef __STDC__ |
---|
| 583 | #define __weak_reference(sym,alias) \ |
---|
| 584 | __asm__(".stabs \"_" #alias "\",11,0,0,0"); \ |
---|
| 585 | __asm__(".stabs \"_" #sym "\",1,0,0,0") |
---|
| 586 | #define __warn_references(sym,msg) \ |
---|
| 587 | __asm__(".stabs \"" msg "\",30,0,0,0"); \ |
---|
| 588 | __asm__(".stabs \"_" #sym "\",1,0,0,0") |
---|
| 589 | #else |
---|
| 590 | #define __weak_reference(sym,alias) \ |
---|
| 591 | __asm__(".stabs \"_/**/alias\",11,0,0,0"); \ |
---|
| 592 | __asm__(".stabs \"_/**/sym\",1,0,0,0") |
---|
| 593 | #define __warn_references(sym,msg) \ |
---|
| 594 | __asm__(".stabs msg,30,0,0,0"); \ |
---|
| 595 | __asm__(".stabs \"_/**/sym\",1,0,0,0") |
---|
| 596 | #endif /* __STDC__ */ |
---|
| 597 | #endif /* __ELF__ */ |
---|
| 598 | #endif /* __GNUC__ || __INTEL_COMPILER */ |
---|
| 599 | |
---|
| 600 | #ifndef __FBSDID |
---|
| 601 | #define __FBSDID(s) struct __hack |
---|
| 602 | #endif |
---|
| 603 | |
---|
| 604 | #ifndef __RCSID |
---|
| 605 | #define __RCSID(s) struct __hack |
---|
| 606 | #endif |
---|
| 607 | |
---|
| 608 | #ifndef __RCSID_SOURCE |
---|
| 609 | #define __RCSID_SOURCE(s) struct __hack |
---|
| 610 | #endif |
---|
| 611 | |
---|
| 612 | #ifndef __SCCSID |
---|
| 613 | #define __SCCSID(s) struct __hack |
---|
| 614 | #endif |
---|
| 615 | |
---|
| 616 | #ifndef __COPYRIGHT |
---|
| 617 | #define __COPYRIGHT(s) struct __hack |
---|
| 618 | #endif |
---|
| 619 | |
---|
| 620 | #ifndef __DECONST |
---|
| 621 | #define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var)) |
---|
| 622 | #endif |
---|
| 623 | |
---|
| 624 | #ifndef __DEVOLATILE |
---|
| 625 | #define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var)) |
---|
| 626 | #endif |
---|
| 627 | |
---|
| 628 | #ifndef __DEQUALIFY |
---|
| 629 | #define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var)) |
---|
| 630 | #endif |
---|
| 631 | |
---|
| 632 | /* |
---|
| 633 | * Nullability qualifiers: currently only supported by Clang. |
---|
| 634 | */ |
---|
| 635 | #if !(defined(__clang__) && __has_feature(nullability)) |
---|
| 636 | #define _Nonnull |
---|
| 637 | #define _Nullable |
---|
| 638 | #define _Null_unspecified |
---|
| 639 | #define __NULLABILITY_PRAGMA_PUSH |
---|
| 640 | #define __NULLABILITY_PRAGMA_POP |
---|
| 641 | #else |
---|
| 642 | #define __NULLABILITY_PRAGMA_PUSH _Pragma("clang diagnostic push") \ |
---|
| 643 | _Pragma("clang diagnostic ignored \"-Wnullability-completeness\"") |
---|
| 644 | #define __NULLABILITY_PRAGMA_POP _Pragma("clang diagnostic pop") |
---|
| 645 | #endif |
---|
| 646 | |
---|
| 647 | /* |
---|
| 648 | * Type Safety Checking |
---|
| 649 | * |
---|
| 650 | * Clang provides additional attributes to enable checking type safety |
---|
| 651 | * properties that cannot be enforced by the C type system. |
---|
| 652 | */ |
---|
| 653 | |
---|
| 654 | #if __has_attribute(__argument_with_type_tag__) && \ |
---|
| 655 | __has_attribute(__type_tag_for_datatype__) && !defined(lint) |
---|
| 656 | #define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) \ |
---|
| 657 | __attribute__((__argument_with_type_tag__(arg_kind, arg_idx, type_tag_idx))) |
---|
| 658 | #define __datatype_type_tag(kind, type) \ |
---|
| 659 | __attribute__((__type_tag_for_datatype__(kind, type))) |
---|
| 660 | #else |
---|
| 661 | #define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) |
---|
| 662 | #define __datatype_type_tag(kind, type) |
---|
| 663 | #endif |
---|
| 664 | |
---|
| 665 | /* |
---|
| 666 | * Lock annotations. |
---|
| 667 | * |
---|
| 668 | * Clang provides support for doing basic thread-safety tests at |
---|
| 669 | * compile-time, by marking which locks will/should be held when |
---|
| 670 | * entering/leaving a functions. |
---|
| 671 | * |
---|
| 672 | * Furthermore, it is also possible to annotate variables and structure |
---|
| 673 | * members to enforce that they are only accessed when certain locks are |
---|
| 674 | * held. |
---|
| 675 | */ |
---|
| 676 | |
---|
| 677 | #if __has_extension(c_thread_safety_attributes) |
---|
| 678 | #define __lock_annotate(x) __attribute__((x)) |
---|
| 679 | #else |
---|
| 680 | #define __lock_annotate(x) |
---|
| 681 | #endif |
---|
| 682 | |
---|
| 683 | /* Structure implements a lock. */ |
---|
| 684 | /* FIXME: Use __lockable__, etc. to avoid colliding with user namespace macros, |
---|
| 685 | * once clang is fixed: https://bugs.llvm.org/show_bug.cgi?id=34319 */ |
---|
| 686 | #define __lockable __lock_annotate(lockable) |
---|
| 687 | |
---|
| 688 | /* Function acquires an exclusive or shared lock. */ |
---|
| 689 | #define __locks_exclusive(...) \ |
---|
| 690 | __lock_annotate(exclusive_lock_function(__VA_ARGS__)) |
---|
| 691 | #define __locks_shared(...) \ |
---|
| 692 | __lock_annotate(shared_lock_function(__VA_ARGS__)) |
---|
| 693 | |
---|
| 694 | /* Function attempts to acquire an exclusive or shared lock. */ |
---|
| 695 | #define __trylocks_exclusive(...) \ |
---|
| 696 | __lock_annotate(exclusive_trylock_function(__VA_ARGS__)) |
---|
| 697 | #define __trylocks_shared(...) \ |
---|
| 698 | __lock_annotate(shared_trylock_function(__VA_ARGS__)) |
---|
| 699 | |
---|
| 700 | /* Function releases a lock. */ |
---|
| 701 | #define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__)) |
---|
| 702 | |
---|
| 703 | /* Function asserts that an exclusive or shared lock is held. */ |
---|
| 704 | #define __asserts_exclusive(...) \ |
---|
| 705 | __lock_annotate(assert_exclusive_lock(__VA_ARGS__)) |
---|
| 706 | #define __asserts_shared(...) \ |
---|
| 707 | __lock_annotate(assert_shared_lock(__VA_ARGS__)) |
---|
| 708 | |
---|
| 709 | /* Function requires that an exclusive or shared lock is or is not held. */ |
---|
| 710 | #define __requires_exclusive(...) \ |
---|
| 711 | __lock_annotate(exclusive_locks_required(__VA_ARGS__)) |
---|
| 712 | #define __requires_shared(...) \ |
---|
| 713 | __lock_annotate(shared_locks_required(__VA_ARGS__)) |
---|
| 714 | #define __requires_unlocked(...) \ |
---|
| 715 | __lock_annotate(locks_excluded(__VA_ARGS__)) |
---|
| 716 | |
---|
| 717 | /* Function should not be analyzed. */ |
---|
| 718 | #define __no_lock_analysis __lock_annotate(no_thread_safety_analysis) |
---|
| 719 | |
---|
| 720 | /* Guard variables and structure members by lock. */ |
---|
| 721 | #define __guarded_by(x) __lock_annotate(guarded_by(x)) |
---|
| 722 | #define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x)) |
---|
| 723 | |
---|
| 724 | #endif /* !_SYS_CDEFS_H_ */ |
---|