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