cdefs.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  1. /* Copyright (C) 1992-2026 Free Software Foundation, Inc.
  2. Copyright The GNU Toolchain Authors.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _SYS_CDEFS_H
  16. #define _SYS_CDEFS_H 1
  17. /* We are almost always included from features.h. */
  18. #ifndef _FEATURES_H
  19. # include <features.h>
  20. #endif
  21. /* The GNU libc does not support any K&R compilers or the traditional mode
  22. of ISO C compilers anymore. Check for some of the combinations not
  23. supported anymore. */
  24. #if defined __GNUC__ && !defined __STDC__ && !defined __cplusplus
  25. # error "You need a ISO C or C++ conforming compiler to use the glibc headers"
  26. #endif
  27. /* Some user header file might have defined this before. */
  28. #undef __P
  29. #undef __PMT
  30. /* Compilers that lack __has_attribute may object to
  31. #if defined __has_attribute && __has_attribute (...)
  32. even though they do not need to evaluate the right-hand side of the &&.
  33. Similarly for __has_builtin, etc. */
  34. #if (defined __has_attribute \
  35. && (!defined __clang_minor__ \
  36. || 3 < __clang_major__ + (5 <= __clang_minor__)))
  37. # define __glibc_has_attribute(attr) __has_attribute (attr)
  38. #else
  39. # define __glibc_has_attribute(attr) 0
  40. #endif
  41. #ifdef __has_builtin
  42. # define __glibc_has_builtin(name) __has_builtin (name)
  43. #else
  44. # define __glibc_has_builtin(name) 0
  45. #endif
  46. #ifdef __has_extension
  47. # define __glibc_has_extension(ext) __has_extension (ext)
  48. #else
  49. # define __glibc_has_extension(ext) 0
  50. #endif
  51. #if defined __GNUC__ || defined __clang__
  52. /* All functions, except those with callbacks or those that
  53. synchronize memory, are leaf functions. */
  54. # if __GNUC_PREREQ (4, 6) && !defined _LIBC
  55. # define __LEAF , __leaf__
  56. # define __LEAF_ATTR __attribute__ ((__leaf__))
  57. # else
  58. # define __LEAF
  59. # define __LEAF_ATTR
  60. # endif
  61. /* GCC can always grok prototypes. For C++ programs we add throw()
  62. to help it optimize the function calls. But this only works with
  63. gcc 2.8.x and egcs. For gcc 3.4 and up we even mark C functions
  64. as non-throwing using a function attribute since programs can use
  65. the -fexceptions options for C code as well. */
  66. # if !defined __cplusplus \
  67. && (__GNUC_PREREQ (3, 4) || __glibc_has_attribute (__nothrow__))
  68. # define __THROW __attribute__ ((__nothrow__ __LEAF))
  69. # define __THROWNL __attribute__ ((__nothrow__))
  70. # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
  71. # define __NTHNL(fct) __attribute__ ((__nothrow__)) fct
  72. # else
  73. # if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major__ >= 4)
  74. # if __cplusplus >= 201103L
  75. # define __THROW noexcept (true)
  76. # else
  77. # define __THROW throw ()
  78. # endif
  79. # define __THROWNL __THROW
  80. # define __NTH(fct) __LEAF_ATTR fct __THROW
  81. # define __NTHNL(fct) fct __THROW
  82. # else
  83. # define __THROW
  84. # define __THROWNL
  85. # define __NTH(fct) fct
  86. # define __NTHNL(fct) fct
  87. # endif
  88. # endif
  89. # if __GNUC_PREREQ (4, 3) || __glibc_has_attribute (__cold__)
  90. # define __COLD __attribute__ ((__cold__))
  91. # else
  92. # define __COLD
  93. # endif
  94. #else /* Not GCC or clang. */
  95. # if (defined __cplusplus \
  96. || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
  97. # define __inline inline
  98. # else
  99. # define __inline /* No inline functions. */
  100. # endif
  101. # define __THROW
  102. # define __THROWNL
  103. # define __NTH(fct) fct
  104. # define __COLD
  105. #endif /* GCC || clang. */
  106. /* These two macros are not used in glibc anymore. They are kept here
  107. only because some other projects expect the macros to be defined. */
  108. #define __P(args) args
  109. #define __PMT(args) args
  110. /* For these things, GCC behaves the ANSI way normally,
  111. and the non-ANSI way under -traditional. */
  112. #define __CONCAT(x,y) x ## y
  113. #define __STRING(x) #x
  114. /* This is not a typedef so `const __ptr_t' does the right thing. */
  115. #define __ptr_t void *
  116. /* C++ needs to know that types and declarations are C, not C++. */
  117. #ifdef __cplusplus
  118. # define __BEGIN_DECLS extern "C" {
  119. # define __END_DECLS }
  120. #else
  121. # define __BEGIN_DECLS
  122. # define __END_DECLS
  123. #endif
  124. /* The overloadable attribute was added on clang 2.6. */
  125. #if defined __clang_major__ \
  126. && (__clang_major__ + (__clang_minor__ >= 6) > 2)
  127. # define __attribute_overloadable__ __attribute__((__overloadable__))
  128. #else
  129. # define __attribute_overloadable__
  130. #endif
  131. /* Fortify support. */
  132. #define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
  133. #define __bos0(ptr) __builtin_object_size (ptr, 0)
  134. /* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available. */
  135. #if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0) \
  136. || __GNUC_PREREQ (12, 0))
  137. # define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0)
  138. # define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1)
  139. #else
  140. # define __glibc_objsize0(__o) __bos0 (__o)
  141. # define __glibc_objsize(__o) __bos (__o)
  142. #endif
  143. #if __USE_FORTIFY_LEVEL > 0
  144. /* Compile time conditions to choose between the regular, _chk and _chk_warn
  145. variants. These conditions should get evaluated to constant and optimized
  146. away. */
  147. #define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / (__s))
  148. #define __glibc_unsigned_or_positive(__l) \
  149. ((__typeof (__l)) 0 < (__typeof (__l)) -1 \
  150. || (__builtin_constant_p (__l) && (__l) > 0))
  151. /* Length is known to be safe at compile time if the __L * __S <= __OBJSZ
  152. condition can be folded to a constant and if it is true, or unknown (-1) */
  153. #define __glibc_safe_or_unknown_len(__l, __s, __osz) \
  154. ((__builtin_constant_p (__osz) && (__osz) == (__SIZE_TYPE__) -1) \
  155. || (__glibc_unsigned_or_positive (__l) \
  156. && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
  157. (__s), (__osz))) \
  158. && __glibc_safe_len_cond ((__SIZE_TYPE__) (__l), (__s), (__osz))))
  159. /* Conversely, we know at compile time that the length is unsafe if the
  160. __L * __S <= __OBJSZ condition can be folded to a constant and if it is
  161. false. */
  162. #define __glibc_unsafe_len(__l, __s, __osz) \
  163. (__glibc_unsigned_or_positive (__l) \
  164. && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
  165. __s, __osz)) \
  166. && !__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz))
  167. /* To correctly instrument the fortify wrapper clang requires the
  168. pass_object_size attribute, and the attribute has the restriction that the
  169. argument needs to be 'const'. Furthermore, to make it usable with C
  170. interfaces, clang provides the overload attribute, which provides a C++
  171. like function overload support. The overloaded fortify wrapper with the
  172. pass_object_size attribute has precedence over the default symbol.
  173. Also, clang does not support __va_arg_pack, so variadic functions are
  174. expanded to issue va_arg implementations. The error function must not have
  175. bodies (address takes are expanded to nonfortified calls), and with
  176. __fortify_function compiler might still create a body with the C++
  177. mangling name (due to the overload attribute). In this case, the function
  178. is defined with __fortify_function_error_function macro instead.
  179. The argument size check is also done with a clang-only attribute,
  180. __attribute__ ((__diagnose_if__ (...))), different than gcc which calls
  181. symbol_chk_warn alias with uses __warnattr attribute.
  182. The pass_object_size was added on clang 4.0, __diagnose_if__ on 5.0,
  183. and pass_dynamic_object_size on 9.0. */
  184. #if defined __clang_major__ && __clang_major__ >= 5
  185. # define __fortify_use_clang 1
  186. # define __fortify_function_error_function static __attribute__((__unused__))
  187. # define __fortify_clang_pass_object_size_n(n) \
  188. __attribute__ ((__pass_object_size__ (n)))
  189. # define __fortify_clang_pass_object_size0 \
  190. __fortify_clang_pass_object_size_n (0)
  191. # define __fortify_clang_pass_object_size \
  192. __fortify_clang_pass_object_size_n (__USE_FORTIFY_LEVEL > 1)
  193. # if __clang_major__ >= 9
  194. # define __fortify_clang_pass_dynamic_object_size_n(n) \
  195. __attribute__ ((__pass_dynamic_object_size__ (n)))
  196. # define __fortify_clang_pass_dynamic_object_size0 \
  197. __fortify_clang_pass_dynamic_object_size_n (0)
  198. # define __fortify_clang_pass_dynamic_object_size \
  199. __fortify_clang_pass_dynamic_object_size_n (1)
  200. # else
  201. # define __fortify_clang_pass_dynamic_object_size_n(n)
  202. # define __fortify_clang_pass_dynamic_object_size0
  203. # define __fortify_clang_pass_dynamic_object_size
  204. # endif
  205. # define __fortify_clang_bos_static_lt_impl(bos_val, n, s) \
  206. ((bos_val) != -1ULL && (n) > (bos_val) / (s))
  207. # define __fortify_clang_bos_static_lt2(__n, __e, __s) \
  208. __fortify_clang_bos_static_lt_impl (__bos (__e), __n, __s)
  209. # define __fortify_clang_bos_static_lt(__n, __e) \
  210. __fortify_clang_bos_static_lt2 (__n, __e, 1)
  211. # define __fortify_clang_bos0_static_lt2(__n, __e, __s) \
  212. __fortify_clang_bos_static_lt_impl (__bos0 (__e), __n, __s)
  213. # define __fortify_clang_bos0_static_lt(__n, __e) \
  214. __fortify_clang_bos0_static_lt2 (__n, __e, 1)
  215. # define __fortify_clang_bosn_args(bos_fn, n, buf, div, complaint) \
  216. (__fortify_clang_bos_static_lt_impl (bos_fn (buf), n, div)), (complaint), \
  217. "warning"
  218. # define __fortify_clang_warning(__c, __msg) \
  219. __attribute__ ((__diagnose_if__ ((__c), (__msg), "warning")))
  220. # define __fortify_clang_error(__c, __msg) \
  221. __attribute__ ((__diagnose_if__ ((__c), (__msg), "error")))
  222. # define __fortify_clang_warning_only_if_bos0_lt(n, buf, complaint) \
  223. __attribute__ ((__diagnose_if__ \
  224. (__fortify_clang_bosn_args (__bos0, n, buf, 1, complaint))))
  225. # define __fortify_clang_warning_only_if_bos0_lt2(n, buf, div, complaint) \
  226. __attribute__ ((__diagnose_if__ \
  227. (__fortify_clang_bosn_args (__bos0, n, buf, div, complaint))))
  228. # define __fortify_clang_warning_only_if_bos_lt(n, buf, complaint) \
  229. __attribute__ ((__diagnose_if__ \
  230. (__fortify_clang_bosn_args (__bos, n, buf, 1, complaint))))
  231. # define __fortify_clang_warning_only_if_bos_lt2(n, buf, div, complaint) \
  232. __attribute__ ((__diagnose_if__ \
  233. (__fortify_clang_bosn_args (__bos, n, buf, div, complaint))))
  234. # define __fortify_clang_prefer_this_overload \
  235. __attribute__ ((enable_if (1, "")))
  236. # define __fortify_clang_unavailable(__msg) \
  237. __attribute__ ((unavailable(__msg)))
  238. # if __USE_FORTIFY_LEVEL == 3
  239. # define __fortify_clang_overload_arg(__type, __attr, __name) \
  240. __type __attr const __fortify_clang_pass_dynamic_object_size __name
  241. # define __fortify_clang_overload_arg0(__type, __attr, __name) \
  242. __type __attr const __fortify_clang_pass_dynamic_object_size0 __name
  243. # else
  244. # define __fortify_clang_overload_arg(__type, __attr, __name) \
  245. __type __attr const __fortify_clang_pass_object_size __name
  246. # define __fortify_clang_overload_arg0(__type, __attr, __name) \
  247. __type __attr const __fortify_clang_pass_object_size0 __name
  248. # endif
  249. # define __fortify_clang_mul_may_overflow(size, n) \
  250. ((size | n) >= (((size_t)1) << (8 * sizeof (size_t) / 2)))
  251. # define __fortify_clang_size_too_small(__bos, __dest, __len) \
  252. (__bos (__dest) != (size_t) -1 && __bos (__dest) < __len)
  253. # define __fortify_clang_warn_if_src_too_large(__dest, __src) \
  254. __fortify_clang_warning (__fortify_clang_size_too_small (__glibc_objsize, \
  255. __dest, \
  256. __builtin_strlen (__src) + 1), \
  257. "destination buffer will always be overflown by source")
  258. # define __fortify_clang_warn_if_dest_too_small(__dest, __len) \
  259. __fortify_clang_warning (__fortify_clang_size_too_small (__glibc_objsize, \
  260. __dest, \
  261. __len), \
  262. "function called with bigger length than the destination buffer")
  263. # define __fortify_clang_warn_if_dest_too_small0(__dest, __len) \
  264. __fortify_clang_warning (__fortify_clang_size_too_small (__glibc_objsize0, \
  265. __dest, \
  266. __len), \
  267. "function called with bigger length than the destination buffer")
  268. #else
  269. # define __fortify_use_clang 0
  270. # define __fortify_clang_warning(__c, __msg)
  271. # define __fortify_clang_warning_only_if_bos0_lt(__n, __buf, __complaint)
  272. # define __fortify_clang_warning_only_if_bos0_lt2(__n, __buf, __div, complaint)
  273. # define __fortify_clang_warning_only_if_bos_lt(__n, __buf, __complaint)
  274. # define __fortify_clang_warning_only_if_bos_lt2(__n, __buf, div, __complaint)
  275. # define __fortify_clang_overload_arg(__type, __attr, __name) \
  276. __type __attr __name
  277. # define __fortify_clang_overload_arg0(__type, __attr, __name) \
  278. __fortify_clang_overload_arg (__type, __attr, __name)
  279. # define __fortify_clang_warn_if_src_too_large(__dest, __src)
  280. # define __fortify_clang_warn_if_dest_too_small(__dest, __len)
  281. # define __fortify_clang_warn_if_dest_too_small0(__dest, __len)
  282. #endif
  283. /* Fortify function f. __f_alias, __f_chk and __f_chk_warn must be
  284. declared. */
  285. #if !__fortify_use_clang
  286. # define __glibc_fortify(f, __l, __s, __osz, ...) \
  287. (__glibc_safe_or_unknown_len (__l, __s, __osz) \
  288. ? __ ## f ## _alias (__VA_ARGS__) \
  289. : (__glibc_unsafe_len (__l, __s, __osz) \
  290. ? __ ## f ## _chk_warn (__VA_ARGS__, __osz) \
  291. : __ ## f ## _chk (__VA_ARGS__, __osz)))
  292. #else
  293. # define __glibc_fortify(f, __l, __s, __osz, ...) \
  294. (__osz == (__SIZE_TYPE__) -1) \
  295. ? __ ## f ## _alias (__VA_ARGS__) \
  296. : __ ## f ## _chk (__VA_ARGS__, __osz)
  297. #endif
  298. /* Fortify function f, where object size argument passed to f is the number of
  299. elements and not total size. */
  300. #if !__fortify_use_clang
  301. # define __glibc_fortify_n(f, __l, __s, __osz, ...) \
  302. (__glibc_safe_or_unknown_len (__l, __s, __osz) \
  303. ? __ ## f ## _alias (__VA_ARGS__) \
  304. : (__glibc_unsafe_len (__l, __s, __osz) \
  305. ? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s)) \
  306. : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s))))
  307. # else
  308. # define __glibc_fortify_n(f, __l, __s, __osz, ...) \
  309. (__osz == (__SIZE_TYPE__) -1) \
  310. ? __ ## f ## _alias (__VA_ARGS__) \
  311. : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s))
  312. #endif
  313. #endif /* __USE_FORTIFY_LEVEL > 0 */
  314. #if __GNUC_PREREQ (4,3)
  315. # define __warnattr(msg) __attribute__((__warning__ (msg)))
  316. # define __errordecl(name, msg) \
  317. extern void name (void) __attribute__((__error__ (msg)))
  318. #else
  319. # define __warnattr(msg)
  320. # define __errordecl(name, msg) extern void name (void)
  321. #endif
  322. /* Support for flexible arrays.
  323. Headers that should use flexible arrays only if they're "real"
  324. (e.g. only if they won't affect sizeof()) should test
  325. #if __glibc_c99_flexarr_available. */
  326. #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __HP_cc
  327. # define __flexarr []
  328. # define __glibc_c99_flexarr_available 1
  329. #elif __GNUC_PREREQ (2,97) || defined __clang__
  330. /* GCC 2.97 and clang support C99 flexible array members as an extension,
  331. even when in C89 mode or compiling C++ (any version). */
  332. # define __flexarr []
  333. # define __glibc_c99_flexarr_available 1
  334. #elif defined __GNUC__
  335. /* Pre-2.97 GCC did not support C99 flexible arrays but did have
  336. an equivalent extension with slightly different notation. */
  337. # define __flexarr [0]
  338. # define __glibc_c99_flexarr_available 1
  339. #else
  340. /* Some other non-C99 compiler. Approximate with [1]. */
  341. # define __flexarr [1]
  342. # define __glibc_c99_flexarr_available 0
  343. #endif
  344. /* __asm__ ("xyz") is used throughout the headers to rename functions
  345. at the assembly language level. This is wrapped by the __REDIRECT
  346. macro, in order to support compilers that can do this some other
  347. way. When compilers don't support asm-names at all, we have to do
  348. preprocessor tricks instead (which don't have exactly the right
  349. semantics, but it's the best we can do).
  350. Example:
  351. int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
  352. #if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
  353. # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
  354. # ifdef __cplusplus
  355. # define __REDIRECT_NTH(name, proto, alias) \
  356. name proto __THROW __asm__ (__ASMNAME (#alias))
  357. # define __REDIRECT_NTHNL(name, proto, alias) \
  358. name proto __THROWNL __asm__ (__ASMNAME (#alias))
  359. # else
  360. # define __REDIRECT_NTH(name, proto, alias) \
  361. name proto __asm__ (__ASMNAME (#alias)) __THROW
  362. # define __REDIRECT_NTHNL(name, proto, alias) \
  363. name proto __asm__ (__ASMNAME (#alias)) __THROWNL
  364. # endif
  365. # define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
  366. # define __ASMNAME2(prefix, cname) __STRING (prefix) cname
  367. #ifndef __REDIRECT_FORTIFY
  368. #define __REDIRECT_FORTIFY __REDIRECT
  369. #endif
  370. #ifndef __REDIRECT_FORTIFY_NTH
  371. #define __REDIRECT_FORTIFY_NTH __REDIRECT_NTH
  372. #endif
  373. /*
  374. #elif __SOME_OTHER_COMPILER__
  375. # define __REDIRECT(name, proto, alias) name proto; \
  376. _Pragma("let " #name " = " #alias)
  377. */
  378. #endif
  379. /* GCC, clang, and compatible compilers have various useful declarations
  380. that can be made with the '__attribute__' syntax. All of the ways we use
  381. this do fine if they are omitted for compilers that don't understand it. */
  382. #if !(defined __GNUC__ || defined __clang__ || defined __TINYC__)
  383. # define __attribute__(xyz) /* Ignore */
  384. #endif
  385. /* At some point during the gcc 2.96 development the `malloc' attribute
  386. for functions was introduced. We don't want to use it unconditionally
  387. (although this would be possible) since it generates warnings. */
  388. #if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__malloc__)
  389. # define __attribute_malloc__ __attribute__ ((__malloc__))
  390. #else
  391. # define __attribute_malloc__ /* Ignore */
  392. #endif
  393. /* Tell the compiler which arguments to an allocation function
  394. indicate the size of the allocation. */
  395. #if __GNUC_PREREQ (4, 3)
  396. # define __attribute_alloc_size__(params) \
  397. __attribute__ ((__alloc_size__ params))
  398. #else
  399. # define __attribute_alloc_size__(params) /* Ignore. */
  400. #endif
  401. /* Tell the compiler which argument to an allocation function
  402. indicates the alignment of the allocation. */
  403. #if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__alloc_align__)
  404. # define __attribute_alloc_align__(param) \
  405. __attribute__ ((__alloc_align__ param))
  406. #else
  407. # define __attribute_alloc_align__(param) /* Ignore. */
  408. #endif
  409. /* At some point during the gcc 2.96 development the `pure' attribute
  410. for functions was introduced. We don't want to use it unconditionally
  411. (although this would be possible) since it generates warnings. */
  412. #if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__pure__)
  413. # define __attribute_pure__ __attribute__ ((__pure__))
  414. #else
  415. # define __attribute_pure__ /* Ignore */
  416. #endif
  417. /* This declaration tells the compiler that the value is constant. */
  418. #if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__)
  419. # define __attribute_const__ __attribute__ ((__const__))
  420. #else
  421. # define __attribute_const__ /* Ignore */
  422. #endif
  423. #if __GNUC_PREREQ (2,7) || __glibc_has_attribute (__unused__)
  424. # define __attribute_maybe_unused__ __attribute__ ((__unused__))
  425. #else
  426. # define __attribute_maybe_unused__ /* Ignore */
  427. #endif
  428. /* At some point during the gcc 3.1 development the `used' attribute
  429. for functions was introduced. We don't want to use it unconditionally
  430. (although this would be possible) since it generates warnings. */
  431. #if __GNUC_PREREQ (3,1) || __glibc_has_attribute (__used__)
  432. # define __attribute_used__ __attribute__ ((__used__))
  433. # define __attribute_noinline__ __attribute__ ((__noinline__))
  434. #else
  435. # define __attribute_used__ __attribute__ ((__unused__))
  436. # define __attribute_noinline__ /* Ignore */
  437. #endif
  438. /* Since version 3.2, gcc allows marking deprecated functions. */
  439. #if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__deprecated__)
  440. # define __attribute_deprecated__ __attribute__ ((__deprecated__))
  441. #else
  442. # define __attribute_deprecated__ /* Ignore */
  443. #endif
  444. /* Since version 4.5, gcc also allows one to specify the message printed
  445. when a deprecated function is used. clang claims to be gcc 4.2, but
  446. may also support this feature. */
  447. #if __GNUC_PREREQ (4,5) \
  448. || __glibc_has_extension (__attribute_deprecated_with_message__)
  449. # define __attribute_deprecated_msg__(msg) \
  450. __attribute__ ((__deprecated__ (msg)))
  451. #else
  452. # define __attribute_deprecated_msg__(msg) __attribute_deprecated__
  453. #endif
  454. /* At some point during the gcc 2.8 development the `format_arg' attribute
  455. for functions was introduced. We don't want to use it unconditionally
  456. (although this would be possible) since it generates warnings.
  457. If several `format_arg' attributes are given for the same function, in
  458. gcc-3.0 and older, all but the last one are ignored. In newer gccs,
  459. all designated arguments are considered. */
  460. #if __GNUC_PREREQ (2,8) || __glibc_has_attribute (__format_arg__)
  461. # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
  462. #else
  463. # define __attribute_format_arg__(x) /* Ignore */
  464. #endif
  465. /* At some point during the gcc 2.97 development the `strfmon' format
  466. attribute for functions was introduced. We don't want to use it
  467. unconditionally (although this would be possible) since it
  468. generates warnings. */
  469. #if __GNUC_PREREQ (2,97) || __glibc_has_attribute (__format__)
  470. # define __attribute_format_strfmon__(a,b) \
  471. __attribute__ ((__format__ (__strfmon__, a, b)))
  472. #else
  473. # define __attribute_format_strfmon__(a,b) /* Ignore */
  474. #endif
  475. /* The nonnull function attribute marks pointer parameters that
  476. must not be NULL. This has the name __nonnull in glibc,
  477. and __attribute_nonnull__ in files shared with Gnulib to avoid
  478. collision with a different __nonnull in DragonFlyBSD 5.9. */
  479. #ifndef __attribute_nonnull__
  480. # if __GNUC_PREREQ (3,3) || __glibc_has_attribute (__nonnull__)
  481. # define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params))
  482. # else
  483. # define __attribute_nonnull__(params)
  484. # endif
  485. #endif
  486. #ifndef __nonnull
  487. # define __nonnull(params) __attribute_nonnull__ (params)
  488. #endif
  489. /* The returns_nonnull function attribute marks the return type of the function
  490. as always being non-null. */
  491. #ifndef __returns_nonnull
  492. # if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__returns_nonnull__)
  493. # define __returns_nonnull __attribute__ ((__returns_nonnull__))
  494. # else
  495. # define __returns_nonnull
  496. # endif
  497. #endif
  498. /* If fortification mode, we warn about unused results of certain
  499. function calls which can lead to problems. */
  500. #if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__)
  501. # define __attribute_warn_unused_result__ \
  502. __attribute__ ((__warn_unused_result__))
  503. # if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0
  504. # define __wur __attribute_warn_unused_result__
  505. # endif
  506. #else
  507. # define __attribute_warn_unused_result__ /* empty */
  508. #endif
  509. #ifndef __wur
  510. # define __wur /* Ignore */
  511. #endif
  512. /* Forces a function to be always inlined. */
  513. #if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__always_inline__)
  514. /* The Linux kernel defines __always_inline in stddef.h (283d7573), and
  515. it conflicts with this definition. Therefore undefine it first to
  516. allow either header to be included first. */
  517. # undef __always_inline
  518. # define __always_inline __inline __attribute__ ((__always_inline__))
  519. #else
  520. # undef __always_inline
  521. # define __always_inline __inline
  522. #endif
  523. /* Associate error messages with the source location of the call site rather
  524. than with the source location inside the function. */
  525. #if __GNUC_PREREQ (4,3) || __glibc_has_attribute (__artificial__)
  526. # define __attribute_artificial__ __attribute__ ((__artificial__))
  527. #else
  528. # define __attribute_artificial__ /* Ignore */
  529. #endif
  530. /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 inline
  531. semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__ or
  532. __GNUC_GNU_INLINE__ is not a good enough check for gcc because gcc versions
  533. older than 4.3 may define these macros and still not guarantee GNU inlining
  534. semantics.
  535. clang++ identifies itself as gcc-4.2, but has support for GNU inlining
  536. semantics, that can be checked for by using the __GNUC_STDC_INLINE__ and
  537. __GNUC_GNU_INLINE__ macro definitions. */
  538. #if (!defined __cplusplus || __GNUC_PREREQ (4,3) \
  539. || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \
  540. || defined __GNUC_GNU_INLINE__)))
  541. # if defined __GNUC_STDC_INLINE__ || defined __cplusplus
  542. # define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
  543. # define __extern_always_inline \
  544. extern __always_inline __attribute__ ((__gnu_inline__))
  545. # else
  546. # define __extern_inline extern __inline
  547. # define __extern_always_inline extern __always_inline
  548. # endif
  549. #endif
  550. #ifdef __extern_always_inline
  551. # define __fortify_function __extern_always_inline __attribute_artificial__
  552. #endif
  553. /* GCC 4.3 and above allow passing all anonymous arguments of an
  554. __extern_always_inline function to some other vararg function. */
  555. #if __GNUC_PREREQ (4,3)
  556. # define __va_arg_pack() __builtin_va_arg_pack ()
  557. # define __va_arg_pack_len() __builtin_va_arg_pack_len ()
  558. #endif
  559. /* It is possible to compile containing GCC extensions even if GCC is
  560. run in pedantic mode if the uses are carefully marked using the
  561. `__extension__' keyword. But this is not generally available before
  562. version 2.8. */
  563. #if !(__GNUC_PREREQ (2,8) || defined __clang__)
  564. # define __extension__ /* Ignore */
  565. #endif
  566. /* __restrict is known in EGCS 1.2 and above, and in clang.
  567. It works also in C++ mode (outside of arrays), but only when spelled
  568. as '__restrict', not 'restrict'. */
  569. #if !(__GNUC_PREREQ (2,92) || __clang_major__ >= 3)
  570. # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
  571. # define __restrict restrict
  572. # else
  573. # define __restrict /* Ignore */
  574. # endif
  575. #endif
  576. /* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
  577. array_name[restrict]
  578. GCC 3.1 and clang support this.
  579. This syntax is not usable in C++ mode. */
  580. #if (__GNUC_PREREQ (3,1) || __clang_major__ >= 3) && !defined __cplusplus
  581. # define __restrict_arr __restrict
  582. #else
  583. # ifdef __GNUC__
  584. # define __restrict_arr /* Not supported in old GCC. */
  585. # else
  586. # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
  587. # define __restrict_arr restrict
  588. # else
  589. /* Some other non-C99 compiler. */
  590. # define __restrict_arr /* Not supported. */
  591. # endif
  592. # endif
  593. #endif
  594. #if (__GNUC__ >= 3) || __glibc_has_builtin (__builtin_expect)
  595. # define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
  596. # define __glibc_likely(cond) __builtin_expect ((cond), 1)
  597. #else
  598. # define __glibc_unlikely(cond) (cond)
  599. # define __glibc_likely(cond) (cond)
  600. #endif
  601. #if (!defined _Noreturn \
  602. && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
  603. && !(__GNUC_PREREQ (4,7) \
  604. || (3 < __clang_major__ + (5 <= __clang_minor__))))
  605. # if __GNUC_PREREQ (2,8)
  606. # define _Noreturn __attribute__ ((__noreturn__))
  607. # else
  608. # define _Noreturn
  609. # endif
  610. #endif
  611. #if __GNUC_PREREQ (8, 0)
  612. /* Describes a char array whose address can safely be passed as the first
  613. argument to strncpy and strncat, as the char array is not necessarily
  614. a NUL-terminated string. */
  615. # define __attribute_nonstring__ __attribute__ ((__nonstring__))
  616. #else
  617. # define __attribute_nonstring__
  618. #endif
  619. /* Undefine (also defined in libc-symbols.h). */
  620. #undef __attribute_copy__
  621. #if __GNUC_PREREQ (9, 0)
  622. /* Copies attributes from the declaration or type referenced by
  623. the argument. */
  624. # define __attribute_copy__(arg) __attribute__ ((__copy__ (arg)))
  625. #else
  626. # define __attribute_copy__(arg)
  627. #endif
  628. #if (!defined _Static_assert && !defined __cplusplus \
  629. && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
  630. && (!(__GNUC_PREREQ (4, 6) || __clang_major__ >= 4) \
  631. || defined __STRICT_ANSI__))
  632. # define _Static_assert(expr, diagnostic) \
  633. extern int (*__Static_assert_function (void)) \
  634. [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
  635. #endif
  636. /* Gnulib avoids including these, as they don't work on non-glibc or
  637. older glibc platforms. */
  638. #ifndef __GNULIB_CDEFS
  639. # include <bits/wordsize.h>
  640. # include <bits/long-double.h>
  641. #endif
  642. #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
  643. # ifdef __REDIRECT
  644. /* Alias name defined automatically. */
  645. # define __LDBL_REDIR(name, proto) ... unused__ldbl_redir
  646. # define __LDBL_REDIR_DECL(name) \
  647. extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128"));
  648. # define __REDIRECT_LDBL(name, proto, alias) \
  649. name proto __asm (__ASMNAME ("__" #alias "ieee128"))
  650. /* Alias name defined automatically, with leading underscores. */
  651. # define __LDBL_REDIR2_DECL(name) \
  652. extern __typeof (__##name) __##name \
  653. __asm (__ASMNAME ("__" #name "ieee128"));
  654. /* Alias name defined manually. */
  655. # define __LDBL_REDIR1(name, proto, alias) ... unused__ldbl_redir1
  656. # define __LDBL_REDIR1_DECL(name, alias) \
  657. extern __typeof (name) name __asm (__ASMNAME (#alias));
  658. # define __LDBL_REDIR1_NTH(name, proto, alias) \
  659. __REDIRECT_NTH (name, proto, alias)
  660. # define __REDIRECT_NTH_LDBL(name, proto, alias) \
  661. __LDBL_REDIR1_NTH (name, proto, __##alias##ieee128)
  662. /* Unused. */
  663. # define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth
  664. # else
  665. _Static_assert (0, "IEEE 128-bits long double requires redirection on this platform");
  666. # endif
  667. #elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
  668. # define __LDBL_COMPAT 1
  669. # ifdef __REDIRECT
  670. # define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
  671. # define __LDBL_REDIR(name, proto) \
  672. __LDBL_REDIR1 (name, proto, __nldbl_##name)
  673. # define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
  674. # define __LDBL_REDIR_NTH(name, proto) \
  675. __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
  676. # define __LDBL_REDIR2_DECL(name) \
  677. extern __typeof (__##name) __##name __asm (__ASMNAME ("__nldbl___" #name));
  678. # define __LDBL_REDIR1_DECL(name, alias) \
  679. extern __typeof (name) name __asm (__ASMNAME (#alias));
  680. # define __LDBL_REDIR_DECL(name) \
  681. extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
  682. # define __REDIRECT_LDBL(name, proto, alias) \
  683. __LDBL_REDIR1 (name, proto, __nldbl_##alias)
  684. # define __REDIRECT_NTH_LDBL(name, proto, alias) \
  685. __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
  686. # endif
  687. #endif
  688. #if (!defined __LDBL_COMPAT && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0) \
  689. || !defined __REDIRECT
  690. # define __LDBL_REDIR1(name, proto, alias) name proto
  691. # define __LDBL_REDIR(name, proto) name proto
  692. # define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
  693. # define __LDBL_REDIR_NTH(name, proto) name proto __THROW
  694. # define __LDBL_REDIR2_DECL(name)
  695. # define __LDBL_REDIR_DECL(name)
  696. # ifdef __REDIRECT
  697. # define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
  698. # define __REDIRECT_NTH_LDBL(name, proto, alias) \
  699. __REDIRECT_NTH (name, proto, alias)
  700. # endif
  701. #endif
  702. /* __glibc_macro_warning (MESSAGE) issues warning MESSAGE. This is
  703. intended for use in preprocessor macros.
  704. Note: MESSAGE must be a _single_ string; concatenation of string
  705. literals is not supported. */
  706. #if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
  707. # define __glibc_macro_warning1(message) _Pragma (#message)
  708. # define __glibc_macro_warning(message) \
  709. __glibc_macro_warning1 (GCC warning message)
  710. #else
  711. # define __glibc_macro_warning(msg)
  712. #endif
  713. /* Generic selection (ISO C11) is a C-only feature, available in GCC
  714. since version 4.9. Previous versions do not provide generic
  715. selection, even though they might set __STDC_VERSION__ to 201112L,
  716. when in -std=c11 mode. Thus, we must check for !defined __GNUC__
  717. when testing __STDC_VERSION__ for generic selection support.
  718. On the other hand, Clang also defines __GNUC__, so a clang-specific
  719. check is required to enable the use of generic selection. */
  720. #if !defined __cplusplus \
  721. && (__GNUC_PREREQ (4, 9) \
  722. || __glibc_has_extension (c_generic_selections) \
  723. || (!defined __GNUC__ && defined __STDC_VERSION__ \
  724. && __STDC_VERSION__ >= 201112L))
  725. # define __HAVE_GENERIC_SELECTION 1
  726. #else
  727. # define __HAVE_GENERIC_SELECTION 0
  728. #endif
  729. #if __HAVE_GENERIC_SELECTION
  730. /* If PTR is a pointer to const, return CALL cast to type CTYPE,
  731. otherwise return CALL. Pointers to types with non-const qualifiers
  732. are not valid. This should not be defined for C++, as macros are
  733. not an appropriate way of implementing such qualifier-generic
  734. operations for C++. */
  735. # define __glibc_const_generic(PTR, CTYPE, CALL) \
  736. _Generic (0 ? (PTR) : (void *) 1, \
  737. const void *: (CTYPE) (CALL), \
  738. default: CALL)
  739. #endif
  740. #if __GNUC_PREREQ (10, 0)
  741. /* Designates a 1-based positional argument ref-index of pointer type
  742. that can be used to access size-index elements of the pointed-to
  743. array according to access mode, or at least one element when
  744. size-index is not provided:
  745. access (access-mode, <ref-index> [, <size-index>]) */
  746. # define __attr_access(x) __attribute__ ((__access__ x))
  747. /* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may
  748. use the access attribute to get object sizes from function definition
  749. arguments, so we can't use them on functions we fortify. Drop the access
  750. attribute for such functions. */
  751. # if __USE_FORTIFY_LEVEL == 3
  752. # define __fortified_attr_access(a, o, s)
  753. # else
  754. # define __fortified_attr_access(a, o, s) __attr_access ((a, o, s))
  755. # endif
  756. # if __GNUC_PREREQ (11, 0)
  757. # define __attr_access_none(argno) __attribute__ ((__access__ (__none__, argno)))
  758. # else
  759. # define __attr_access_none(argno)
  760. # endif
  761. #else
  762. # define __fortified_attr_access(a, o, s)
  763. # define __attr_access(x)
  764. # define __attr_access_none(argno)
  765. #endif
  766. #if __GNUC_PREREQ (11, 0)
  767. /* Designates dealloc as a function to call to deallocate objects
  768. allocated by the declared function. */
  769. # define __attr_dealloc(dealloc, argno) \
  770. __attribute__ ((__malloc__ (dealloc, argno)))
  771. # define __attr_dealloc_free __attr_dealloc (__builtin_free, 1)
  772. #else
  773. # define __attr_dealloc(dealloc, argno)
  774. # define __attr_dealloc_free
  775. #endif
  776. /* Specify that a function such as setjmp or vfork may return
  777. twice. */
  778. #if __GNUC_PREREQ (4, 1)
  779. # define __attribute_returns_twice__ __attribute__ ((__returns_twice__))
  780. #else
  781. # define __attribute_returns_twice__ /* Ignore. */
  782. #endif
  783. /* Mark struct types as aliasable. Restricted to compilers that
  784. support forward declarations of structs in the presence of the
  785. attribute. */
  786. #if __GNUC_PREREQ (7, 1) || defined __clang__
  787. # define __attribute_struct_may_alias__ __attribute__ ((__may_alias__))
  788. #else
  789. # define __attribute_struct_may_alias__
  790. #endif
  791. #endif /* sys/cdefs.h */