Subversion Repositories Kolibri OS

Rev

Rev 4921 | Rev 6109 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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.  * 4. 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 !__has_extension(c_atomic) && !__has_extension(cxx_atomic)
  299. /*
  300.  * No native support for _Atomic(). Place object in structure to prevent
  301.  * most forms of direct non-atomic access.
  302.  */
  303. #define _Atomic(T)              struct { T volatile __val; }
  304. #endif
  305.  
  306. #if defined(__cplusplus) && __cplusplus >= 201103L
  307. #define _Noreturn               [[noreturn]]
  308. #else
  309. #define _Noreturn               __dead2
  310. #endif
  311.  
  312. #if !__has_extension(c_static_assert)
  313. #if (defined(__cplusplus) && __cplusplus >= 201103L) || \
  314.     __has_extension(cxx_static_assert)
  315. #define _Static_assert(x, y)    static_assert(x, y)
  316. #elif __GNUC_PREREQ__(4,6)
  317. /* Nothing, gcc 4.6 and higher has _Static_assert built-in */
  318. #elif defined(__COUNTER__)
  319. #define _Static_assert(x, y)    __Static_assert(x, __COUNTER__)
  320. #define __Static_assert(x, y)   ___Static_assert(x, y)
  321. #define ___Static_assert(x, y)  typedef char __assert_ ## y[(x) ? 1 : -1] \
  322.                                 __unused
  323. #else
  324. #define _Static_assert(x, y)    struct __hack
  325. #endif
  326. #endif
  327.  
  328. #if !__has_extension(c_thread_local)
  329. /*
  330.  * XXX: Some compilers (Clang 3.3, GCC 4.7) falsely announce C++11 mode
  331.  * without actually supporting the thread_local keyword. Don't check for
  332.  * the presence of C++11 when defining _Thread_local.
  333.  */
  334. #if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \
  335.     __has_extension(cxx_thread_local)
  336. #define _Thread_local           thread_local
  337. #else
  338. #define _Thread_local           __thread
  339. #endif
  340. #endif
  341.  
  342. #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */
  343.  
  344. /*
  345.  * Emulation of C11 _Generic().  Unlike the previously defined C11
  346.  * keywords, it is not possible to implement this using exactly the same
  347.  * syntax.  Therefore implement something similar under the name
  348.  * __generic().  Unlike _Generic(), this macro can only distinguish
  349.  * between a single type, so it requires nested invocations to
  350.  * distinguish multiple cases.
  351.  */
  352.  
  353. #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
  354.     __has_extension(c_generic_selections)
  355. #define __generic(expr, t, yes, no)                                     \
  356.         _Generic(expr, t: yes, default: no)
  357. #elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus)
  358. #define __generic(expr, t, yes, no)                                     \
  359.         __builtin_choose_expr(                                          \
  360.             __builtin_types_compatible_p(__typeof(expr), t), yes, no)
  361. #endif
  362.  
  363. #if __GNUC_PREREQ__(2, 96)
  364. #define __malloc_like   __attribute__((__malloc__))
  365. #define __pure          __attribute__((__pure__))
  366. #else
  367. #define __malloc_like
  368. #define __pure
  369. #endif
  370.  
  371. #if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
  372. #define __always_inline __attribute__((__always_inline__))
  373. #else
  374. #define __always_inline
  375. #endif
  376.  
  377. #if __GNUC_PREREQ__(3, 1)
  378. #define __noinline      __attribute__ ((__noinline__))
  379. #else
  380. #define __noinline
  381. #endif
  382.  
  383. #if __GNUC_PREREQ__(3, 3)
  384. #define __nonnull(x)    __attribute__((__nonnull__(x)))
  385. #define __nonnull_all   __attribute__((__nonnull__))
  386. #else
  387. #define __nonnull(x)
  388. #define __nonnull_all
  389. #endif
  390.  
  391. #if __GNUC_PREREQ__(3, 4)
  392. #define __fastcall      __attribute__((__fastcall__))
  393. #define __result_use_check      __attribute__((__warn_unused_result__))
  394. #else
  395. #define __fastcall
  396. #define __result_use_check
  397. #endif
  398.  
  399. #if __GNUC_PREREQ__(4, 1)
  400. #define __returns_twice __attribute__((__returns_twice__))
  401. #else
  402. #define __returns_twice
  403. #endif
  404.  
  405. #if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable)
  406. #define __unreachable() __builtin_unreachable()
  407. #else
  408. #define __unreachable() ((void)0)
  409. #endif
  410.  
  411. /* XXX: should use `#if __STDC_VERSION__ < 199901'. */
  412. #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
  413. #define __func__        NULL
  414. #endif
  415.  
  416. /*
  417.  * GCC 2.95 provides `__restrict' as an extension to C90 to support the
  418.  * C99-specific `restrict' type qualifier.  We happen to use `__restrict' as
  419.  * a way to define the `restrict' type qualifier without disturbing older
  420.  * software that is unaware of C99 keywords.
  421.  */
  422. #if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
  423. #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 || defined(lint)
  424. #define __restrict
  425. #else
  426. #define __restrict      restrict
  427. #endif
  428. #endif
  429.  
  430. /*
  431.  * GNU C version 2.96 adds explicit branch prediction so that
  432.  * the CPU back-end can hint the processor and also so that
  433.  * code blocks can be reordered such that the predicted path
  434.  * sees a more linear flow, thus improving cache behavior, etc.
  435.  *
  436.  * The following two macros provide us with a way to utilize this
  437.  * compiler feature.  Use __predict_true() if you expect the expression
  438.  * to evaluate to true, and __predict_false() if you expect the
  439.  * expression to evaluate to false.
  440.  *
  441.  * A few notes about usage:
  442.  *
  443.  *      * Generally, __predict_false() error condition checks (unless
  444.  *        you have some _strong_ reason to do otherwise, in which case
  445.  *        document it), and/or __predict_true() `no-error' condition
  446.  *        checks, assuming you want to optimize for the no-error case.
  447.  *
  448.  *      * Other than that, if you don't know the likelihood of a test
  449.  *        succeeding from empirical or other `hard' evidence, don't
  450.  *        make predictions.
  451.  *
  452.  *      * These are meant to be used in places that are run `a lot'.
  453.  *        It is wasteful to make predictions in code that is run
  454.  *        seldomly (e.g. at subsystem initialization time) as the
  455.  *        basic block reordering that this affects can often generate
  456.  *        larger code.
  457.  */
  458. #if __GNUC_PREREQ__(2, 96)
  459. #define __predict_true(exp)     __builtin_expect((exp), 1)
  460. #define __predict_false(exp)    __builtin_expect((exp), 0)
  461. #else
  462. #define __predict_true(exp)     (exp)
  463. #define __predict_false(exp)    (exp)
  464. #endif
  465.  
  466. #if __GNUC_PREREQ__(4, 0)
  467. #define __sentinel      __attribute__((__sentinel__))
  468. #define __exported      __attribute__((__visibility__("default")))
  469. #define __hidden        __attribute__((__visibility__("hidden")))
  470. #else
  471. #define __sentinel
  472. #define __exported
  473. #define __hidden
  474. #endif
  475.  
  476. #define __offsetof(type, field) offsetof(type, field)
  477. #define __rangeof(type, start, end) \
  478.         (__offsetof(type, end) - __offsetof(type, start))
  479.  
  480. /*
  481.  * Given the pointer x to the member m of the struct s, return
  482.  * a pointer to the containing structure.  When using GCC, we first
  483.  * assign pointer x to a local variable, to check that its type is
  484.  * compatible with member m.
  485.  */
  486. #if __GNUC_PREREQ__(3, 1)
  487. #define __containerof(x, s, m) ({                                       \
  488.         const volatile __typeof(((s *)0)->m) *__x = (x);                \
  489.         __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\
  490. })
  491. #else
  492. #define __containerof(x, s, m)                                          \
  493.         __DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m))
  494. #endif
  495.  
  496. /*
  497.  * Compiler-dependent macros to declare that functions take printf-like
  498.  * or scanf-like arguments.  They are null except for versions of gcc
  499.  * that are known to support the features properly (old versions of gcc-2
  500.  * didn't permit keeping the keywords out of the application namespace).
  501.  */
  502. #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
  503. #define __printflike(fmtarg, firstvararg)
  504. #define __scanflike(fmtarg, firstvararg)
  505. #define __format_arg(fmtarg)
  506. #define __strfmonlike(fmtarg, firstvararg)
  507. #define __strftimelike(fmtarg, firstvararg)
  508. #else
  509. #define __printflike(fmtarg, firstvararg) \
  510.             __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
  511. #define __scanflike(fmtarg, firstvararg) \
  512.             __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
  513. #define __format_arg(fmtarg)    __attribute__((__format_arg__ (fmtarg)))
  514. #define __strfmonlike(fmtarg, firstvararg) \
  515.             __attribute__((__format__ (__strfmon__, fmtarg, firstvararg)))
  516. #define __strftimelike(fmtarg, firstvararg) \
  517.             __attribute__((__format__ (__strftime__, fmtarg, firstvararg)))
  518. #endif
  519.  
  520. /*
  521.  * FORTIFY_SOURCE, and perhaps other compiler-specific features, require
  522.  * the use of non-standard inlining.  In general we should try to avoid
  523.  * using these but GCC-compatible compilers tend to support the extensions
  524.  * well enough to use them in limited cases.
  525.  */
  526. #if defined(__GNUC_GNU_INLINE__) || defined(__GNUC_STDC_INLINE__)
  527. #if __GNUC_PREREQ__(4, 3) || __has_attribute(__artificial__)
  528. #define __gnu_inline    __attribute__((__gnu_inline__, __artificial__))
  529. #else
  530. #define __gnu_inline    __attribute__((__gnu_inline__))
  531. #endif /* artificial */
  532. #else
  533. #define __gnu_inline
  534. #endif
  535.  
  536. /* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
  537. #if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \
  538.     defined(__GNUC__) && !defined(__INTEL_COMPILER)
  539. #define __printf0like(fmtarg, firstvararg) \
  540.             __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
  541. #else
  542. #define __printf0like(fmtarg, firstvararg)
  543. #endif
  544.  
  545. #if defined(__GNUC__) || defined(__INTEL_COMPILER)
  546. #ifndef __INTEL_COMPILER
  547. #define __strong_reference(sym,aliassym)        \
  548.         extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
  549. #endif
  550. #ifdef __ELF__
  551. #ifdef __STDC__
  552. #define __weak_reference(sym,alias)     \
  553.         __asm__(".weak " #alias);       \
  554.         __asm__(".equ "  #alias ", " #sym)
  555. #define __warn_references(sym,msg)      \
  556.         __asm__(".section .gnu.warning." #sym); \
  557.         __asm__(".asciz \"" msg "\"");  \
  558.         __asm__(".previous")
  559. #define __sym_compat(sym,impl,verid)    \
  560.         __asm__(".symver " #impl ", " #sym "@" #verid)
  561. #define __sym_default(sym,impl,verid)   \
  562.         __asm__(".symver " #impl ", " #sym "@@" #verid)
  563. #else
  564. #define __weak_reference(sym,alias)     \
  565.         __asm__(".weak alias");         \
  566.         __asm__(".equ alias, sym")
  567. #define __warn_references(sym,msg)      \
  568.         __asm__(".section .gnu.warning.sym"); \
  569.         __asm__(".asciz \"msg\"");      \
  570.         __asm__(".previous")
  571. #define __sym_compat(sym,impl,verid)    \
  572.         __asm__(".symver impl, sym@verid")
  573. #define __sym_default(impl,sym,verid)   \
  574.         __asm__(".symver impl, sym@@verid")
  575. #endif  /* __STDC__ */
  576. #else   /* !__ELF__ */
  577. #ifdef __STDC__
  578. #define __weak_reference(sym,alias)     \
  579.         __asm__(".stabs \"_" #alias "\",11,0,0,0");     \
  580.         __asm__(".stabs \"_" #sym "\",1,0,0,0")
  581. #define __warn_references(sym,msg)      \
  582.         __asm__(".stabs \"" msg "\",30,0,0,0");         \
  583.         __asm__(".stabs \"_" #sym "\",1,0,0,0")
  584. #else
  585. #define __weak_reference(sym,alias)     \
  586.         __asm__(".stabs \"_/**/alias\",11,0,0,0");      \
  587.         __asm__(".stabs \"_/**/sym\",1,0,0,0")
  588. #define __warn_references(sym,msg)      \
  589.         __asm__(".stabs msg,30,0,0,0");                 \
  590.         __asm__(".stabs \"_/**/sym\",1,0,0,0")
  591. #endif  /* __STDC__ */
  592. #endif  /* __ELF__ */
  593. #endif  /* __GNUC__ || __INTEL_COMPILER */
  594.  
  595. #ifndef __FBSDID
  596. #define __FBSDID(s)     struct __hack
  597. #endif
  598.  
  599. #ifndef __RCSID
  600. #define __RCSID(s)      struct __hack
  601. #endif
  602.  
  603. #ifndef __RCSID_SOURCE
  604. #define __RCSID_SOURCE(s)       struct __hack
  605. #endif
  606.  
  607. #ifndef __SCCSID
  608. #define __SCCSID(s)     struct __hack
  609. #endif
  610.  
  611. #ifndef __COPYRIGHT
  612. #define __COPYRIGHT(s)  struct __hack
  613. #endif
  614.  
  615. #ifndef __DECONST
  616. #define __DECONST(type, var)    ((type)(__uintptr_t)(const void *)(var))
  617. #endif
  618.  
  619. #ifndef __DEVOLATILE
  620. #define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var))
  621. #endif
  622.  
  623. #ifndef __DEQUALIFY
  624. #define __DEQUALIFY(type, var)  ((type)(__uintptr_t)(const volatile void *)(var))
  625. #endif
  626.  
  627. /*-
  628.  * The following definitions are an extension of the behavior originally
  629.  * implemented in <sys/_posix.h>, but with a different level of granularity.
  630.  * POSIX.1 requires that the macros we test be defined before any standard
  631.  * header file is included.
  632.  *
  633.  * Here's a quick run-down of the versions:
  634.  *  defined(_POSIX_SOURCE)              1003.1-1988
  635.  *  _POSIX_C_SOURCE == 1                1003.1-1990
  636.  *  _POSIX_C_SOURCE == 2                1003.2-1992 C Language Binding Option
  637.  *  _POSIX_C_SOURCE == 199309           1003.1b-1993
  638.  *  _POSIX_C_SOURCE == 199506           1003.1c-1995, 1003.1i-1995,
  639.  *                                      and the omnibus ISO/IEC 9945-1: 1996
  640.  *  _POSIX_C_SOURCE == 200112           1003.1-2001
  641.  *  _POSIX_C_SOURCE == 200809           1003.1-2008
  642.  *
  643.  * In addition, the X/Open Portability Guide, which is now the Single UNIX
  644.  * Specification, defines a feature-test macro which indicates the version of
  645.  * that specification, and which subsumes _POSIX_C_SOURCE.
  646.  *
  647.  * Our macros begin with two underscores to avoid namespace screwage.
  648.  */
  649.  
  650. /* Deal with _GNU_SOURCE, which implies everything and the kitchen sink */
  651. #ifdef _GNU_SOURCE
  652. #undef _XOPEN_SOURCE
  653. #define _XOPEN_SOURCE           700
  654. #define __BSD_VISIBLE           1
  655. #define __GNU_VISIBLE           1
  656. #endif
  657.  
  658. /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
  659. #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
  660. #undef _POSIX_C_SOURCE          /* Probably illegal, but beyond caring now. */
  661. #define _POSIX_C_SOURCE         199009
  662. #endif
  663.  
  664. /* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
  665. #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2
  666. #undef _POSIX_C_SOURCE
  667. #define _POSIX_C_SOURCE         199209
  668. #endif
  669.  
  670. /* Deal with various X/Open Portability Guides and Single UNIX Spec. */
  671. #ifdef _XOPEN_SOURCE
  672. #if _XOPEN_SOURCE - 0 >= 700
  673. #define __XSI_VISIBLE           700
  674. #undef _POSIX_C_SOURCE
  675. #define _POSIX_C_SOURCE         200809
  676. #elif _XOPEN_SOURCE - 0 >= 600
  677. #define __XSI_VISIBLE           600
  678. #undef _POSIX_C_SOURCE
  679. #define _POSIX_C_SOURCE         200112
  680. #elif _XOPEN_SOURCE - 0 >= 500
  681. #define __XSI_VISIBLE           500
  682. #undef _POSIX_C_SOURCE
  683. #define _POSIX_C_SOURCE         199506
  684. #endif
  685. #endif
  686.  
  687. /*
  688.  * Deal with all versions of POSIX.  The ordering relative to the tests above is
  689.  * important.
  690.  */
  691. #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
  692. #define _POSIX_C_SOURCE         198808
  693. #endif
  694. #ifdef _POSIX_C_SOURCE
  695. #if _POSIX_C_SOURCE >= 200809
  696. #define __POSIX_VISIBLE         200809
  697. #define __ISO_C_VISIBLE         1999
  698. #elif _POSIX_C_SOURCE >= 200112
  699. #define __POSIX_VISIBLE         200112
  700. #define __ISO_C_VISIBLE         1999
  701. #elif _POSIX_C_SOURCE >= 199506
  702. #define __POSIX_VISIBLE         199506
  703. #define __ISO_C_VISIBLE         1990
  704. #elif _POSIX_C_SOURCE >= 199309
  705. #define __POSIX_VISIBLE         199309
  706. #define __ISO_C_VISIBLE         1990
  707. #elif _POSIX_C_SOURCE >= 199209
  708. #define __POSIX_VISIBLE         199209
  709. #define __ISO_C_VISIBLE         1990
  710. #elif _POSIX_C_SOURCE >= 199009
  711. #define __POSIX_VISIBLE         199009
  712. #define __ISO_C_VISIBLE         1990
  713. #else
  714. #define __POSIX_VISIBLE         198808
  715. #define __ISO_C_VISIBLE         0
  716. #endif /* _POSIX_C_SOURCE */
  717. #else
  718. /*-
  719.  * Deal with _ANSI_SOURCE:
  720.  * If it is defined, and no other compilation environment is explicitly
  721.  * requested, then define our internal feature-test macros to zero.  This
  722.  * makes no difference to the preprocessor (undefined symbols in preprocessing
  723.  * expressions are defined to have value zero), but makes it more convenient for
  724.  * a test program to print out the values.
  725.  *
  726.  * If a program mistakenly defines _ANSI_SOURCE and some other macro such as
  727.  * _POSIX_C_SOURCE, we will assume that it wants the broader compilation
  728.  * environment (and in fact we will never get here).
  729.  */
  730. #if defined(_ANSI_SOURCE)       /* Hide almost everything. */
  731. #define __POSIX_VISIBLE         0
  732. #define __XSI_VISIBLE           0
  733. #define __BSD_VISIBLE           0
  734. #define __ISO_C_VISIBLE         1990
  735. #elif defined(_C99_SOURCE)      /* Localism to specify strict C99 env. */
  736. #define __POSIX_VISIBLE         0
  737. #define __XSI_VISIBLE           0
  738. #define __BSD_VISIBLE           0
  739. #define __ISO_C_VISIBLE         1999
  740. #elif defined(_C11_SOURCE)      /* Localism to specify strict C11 env. */
  741. #define __POSIX_VISIBLE         0
  742. #define __XSI_VISIBLE           0
  743. #define __BSD_VISIBLE           0
  744. #define __ISO_C_VISIBLE         2011
  745. #else                           /* Default: everything except __GNU_VISIBLE. */
  746. #define __POSIX_VISIBLE         200809
  747. #define __XSI_VISIBLE           700
  748. #define __BSD_VISIBLE           1
  749. #define __ISO_C_VISIBLE         2011
  750. #endif
  751. #endif
  752.  
  753. /*
  754.  * Type Safety Checking
  755.  *
  756.  * Clang provides additional attributes to enable checking type safety
  757.  * properties that cannot be enforced by the C type system.
  758.  */
  759.  
  760. #if __has_attribute(__argument_with_type_tag__) && \
  761.     __has_attribute(__type_tag_for_datatype__) && !defined(lint)
  762. #define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) \
  763.             __attribute__((__argument_with_type_tag__(arg_kind, arg_idx, type_tag_idx)))
  764. #define __datatype_type_tag(kind, type) \
  765.             __attribute__((__type_tag_for_datatype__(kind, type)))
  766. #else
  767. #define __arg_type_tag(arg_kind, arg_idx, type_tag_idx)
  768. #define __datatype_type_tag(kind, type)
  769. #endif
  770.  
  771. /*
  772.  * Lock annotations.
  773.  *
  774.  * Clang provides support for doing basic thread-safety tests at
  775.  * compile-time, by marking which locks will/should be held when
  776.  * entering/leaving a functions.
  777.  *
  778.  * Furthermore, it is also possible to annotate variables and structure
  779.  * members to enforce that they are only accessed when certain locks are
  780.  * held.
  781.  */
  782.  
  783. #if __has_extension(c_thread_safety_attributes)
  784. #define __lock_annotate(x)      __attribute__((x))
  785. #else
  786. #define __lock_annotate(x)
  787. #endif
  788.  
  789. /* Structure implements a lock. */
  790. #define __lockable              __lock_annotate(lockable)
  791.  
  792. /* Function acquires an exclusive or shared lock. */
  793. #define __locks_exclusive(...) \
  794.         __lock_annotate(exclusive_lock_function(__VA_ARGS__))
  795. #define __locks_shared(...) \
  796.         __lock_annotate(shared_lock_function(__VA_ARGS__))
  797.  
  798. /* Function attempts to acquire an exclusive or shared lock. */
  799. #define __trylocks_exclusive(...) \
  800.         __lock_annotate(exclusive_trylock_function(__VA_ARGS__))
  801. #define __trylocks_shared(...) \
  802.         __lock_annotate(shared_trylock_function(__VA_ARGS__))
  803.  
  804. /* Function releases a lock. */
  805. #define __unlocks(...)          __lock_annotate(unlock_function(__VA_ARGS__))
  806.  
  807. /* Function asserts that an exclusive or shared lock is held. */
  808. #define __asserts_exclusive(...) \
  809.         __lock_annotate(assert_exclusive_lock(__VA_ARGS__))
  810. #define __asserts_shared(...) \
  811.         __lock_annotate(assert_shared_lock(__VA_ARGS__))
  812.  
  813. /* Function requires that an exclusive or shared lock is or is not held. */
  814. #define __requires_exclusive(...) \
  815.         __lock_annotate(exclusive_locks_required(__VA_ARGS__))
  816. #define __requires_shared(...) \
  817.         __lock_annotate(shared_locks_required(__VA_ARGS__))
  818. #define __requires_unlocked(...) \
  819.         __lock_annotate(locks_excluded(__VA_ARGS__))
  820.  
  821. /* Function should not be analyzed. */
  822. #define __no_lock_analysis      __lock_annotate(no_thread_safety_analysis)
  823.  
  824. /* Guard variables and structure members by lock. */
  825. #define __guarded_by(x)         __lock_annotate(guarded_by(x))
  826. #define __pt_guarded_by(x)      __lock_annotate(pt_guarded_by(x))
  827.  
  828. #endif /* !_SYS_CDEFS_H_ */
  829.