bsd_cdefs.h 27 KB

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