1/* Copyright (C) 1992-2021 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18#ifndef _SYS_CDEFS_H
19#define _SYS_CDEFS_H 1
20
21/* We are almost always included from features.h. */
22#ifndef _FEATURES_H
23# include <features.h>
24#endif
25
26/* The GNU libc does not support any K&R compilers or the traditional mode
27 of ISO C compilers anymore. Check for some of the combinations not
28 supported anymore. */
29#if defined __GNUC__ && !defined __STDC__
30# error "You need a ISO C conforming compiler to use the glibc headers"
31#endif
32
33/* Some user header file might have defined this before. */
34#undef __P
35#undef __PMT
36
37#ifdef __GNUC__
38
39/* All functions, except those with callbacks or those that
40 synchronize memory, are leaf functions. */
41# if __GNUC_PREREQ (4, 6) && !defined _LIBC
42# define __LEAF , __leaf__
43# define __LEAF_ATTR __attribute__ ((__leaf__))
44# else
45# define __LEAF
46# define __LEAF_ATTR
47# endif
48
49/* GCC can always grok prototypes. For C++ programs we add throw()
50 to help it optimize the function calls. But this only works with
51 gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions
52 as non-throwing using a function attribute since programs can use
53 the -fexceptions options for C code as well. */
54# if !defined __cplusplus && __GNUC_PREREQ (3, 3)
55# define __THROW __attribute__ ((__nothrow__ __LEAF))
56# define __THROWNL __attribute__ ((__nothrow__))
57# define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
58# define __NTHNL(fct) __attribute__ ((__nothrow__)) fct
59# else
60# if defined __cplusplus && __GNUC_PREREQ (2,8)
61# if __cplusplus >= 201103L
62# define __THROW noexcept (true)
63# else
64# define __THROW throw ()
65# endif
66# define __THROWNL __THROW
67# define __NTH(fct) __LEAF_ATTR fct __THROW
68# define __NTHNL(fct) fct __THROW
69# else
70# define __THROW
71# define __THROWNL
72# define __NTH(fct) fct
73# define __NTHNL(fct) fct
74# endif
75# endif
76
77#else /* Not GCC. */
78
79# if (defined __cplusplus \
80 || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
81# define __inline inline
82# else
83# define __inline /* No inline functions. */
84# endif
85
86# define __THROW
87# define __THROWNL
88# define __NTH(fct) fct
89
90#endif /* GCC. */
91
92/* Compilers that are not clang may object to
93 #if defined __clang__ && __has_extension(...)
94 even though they do not need to evaluate the right-hand side of the &&. */
95#if defined __clang__ && defined __has_extension
96# define __glibc_clang_has_extension(ext) __has_extension (ext)
97#else
98# define __glibc_clang_has_extension(ext) 0
99#endif
100
101/* These two macros are not used in glibc anymore. They are kept here
102 only because some other projects expect the macros to be defined. */
103#define __P(args) args
104#define __PMT(args) args
105
106/* For these things, GCC behaves the ANSI way normally,
107 and the non-ANSI way under -traditional. */
108
109#define __CONCAT(x,y) x ## y
110#define __STRING(x) #x
111
112/* This is not a typedef so `const __ptr_t' does the right thing. */
113#define __ptr_t void *
114
115
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
125
126/* Fortify support. */
127#define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
128#define __bos0(ptr) __builtin_object_size (ptr, 0)
129
130/* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available. */
131#if __USE_FORTIFY_LEVEL == 3 && __glibc_clang_prereq (9, 0)
132# define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0)
133# define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1)
134#else
135# define __glibc_objsize0(__o) __bos0 (__o)
136# define __glibc_objsize(__o) __bos (__o)
137#endif
138
139#if __GNUC_PREREQ (4,3)
140# define __warnattr(msg) __attribute__((__warning__ (msg)))
141# define __errordecl(name, msg) \
142 extern void name (void) __attribute__((__error__ (msg)))
143#else
144# define __warnattr(msg)
145# define __errordecl(name, msg) extern void name (void)
146#endif
147
148/* Support for flexible arrays.
149 Headers that should use flexible arrays only if they're "real"
150 (e.g. only if they won't affect sizeof()) should test
151 #if __glibc_c99_flexarr_available. */
152#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
153# define __flexarr []
154# define __glibc_c99_flexarr_available 1
155#elif __GNUC_PREREQ (2,97)
156/* GCC 2.97 supports C99 flexible array members as an extension,
157 even when in C89 mode or compiling C++ (any version). */
158# define __flexarr []
159# define __glibc_c99_flexarr_available 1
160#elif defined __GNUC__
161/* Pre-2.97 GCC did not support C99 flexible arrays but did have
162 an equivalent extension with slightly different notation. */
163# define __flexarr [0]
164# define __glibc_c99_flexarr_available 1
165#else
166/* Some other non-C99 compiler. Approximate with [1]. */
167# define __flexarr [1]
168# define __glibc_c99_flexarr_available 0
169#endif
170
171
172/* __asm__ ("xyz") is used throughout the headers to rename functions
173 at the assembly language level. This is wrapped by the __REDIRECT
174 macro, in order to support compilers that can do this some other
175 way. When compilers don't support asm-names at all, we have to do
176 preprocessor tricks instead (which don't have exactly the right
177 semantics, but it's the best we can do).
178
179 Example:
180 int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
181
182#if defined __GNUC__ && __GNUC__ >= 2
183
184# define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
185# ifdef __cplusplus
186# define __REDIRECT_NTH(name, proto, alias) \
187 name proto __THROW __asm__ (__ASMNAME (#alias))
188# define __REDIRECT_NTHNL(name, proto, alias) \
189 name proto __THROWNL __asm__ (__ASMNAME (#alias))
190# else
191# define __REDIRECT_NTH(name, proto, alias) \
192 name proto __asm__ (__ASMNAME (#alias)) __THROW
193# define __REDIRECT_NTHNL(name, proto, alias) \
194 name proto __asm__ (__ASMNAME (#alias)) __THROWNL
195# endif
196# define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
197# define __ASMNAME2(prefix, cname) __STRING (prefix) cname
198
199/*
200#elif __SOME_OTHER_COMPILER__
201
202# define __REDIRECT(name, proto, alias) name proto; \
203 _Pragma("let " #name " = " #alias)
204*/
205#endif
206
207/* GCC has various useful declarations that can be made with the
208 `__attribute__' syntax. All of the ways we use this do fine if
209 they are omitted for compilers that don't understand it. */
210#if !defined __GNUC__ || __GNUC__ < 2
211# define __attribute__(xyz) /* Ignore */
212#endif
213
214/* At some point during the gcc 2.96 development the `malloc' attribute
215 for functions was introduced. We don't want to use it unconditionally
216 (although this would be possible) since it generates warnings. */
217#if __GNUC_PREREQ (2,96)
218# define __attribute_malloc__ __attribute__ ((__malloc__))
219#else
220# define __attribute_malloc__ /* Ignore */
221#endif
222
223/* Tell the compiler which arguments to an allocation function
224 indicate the size of the allocation. */
225#if __GNUC_PREREQ (4, 3)
226# define __attribute_alloc_size__(params) \
227 __attribute__ ((__alloc_size__ params))
228#else
229# define __attribute_alloc_size__(params) /* Ignore. */
230#endif
231
232/* At some point during the gcc 2.96 development the `pure' attribute
233 for functions was introduced. We don't want to use it unconditionally
234 (although this would be possible) since it generates warnings. */
235#if __GNUC_PREREQ (2,96)
236# define __attribute_pure__ __attribute__ ((__pure__))
237#else
238# define __attribute_pure__ /* Ignore */
239#endif
240
241/* This declaration tells the compiler that the value is constant. */
242#if __GNUC_PREREQ (2,5)
243# define __attribute_const__ __attribute__ ((__const__))
244#else
245# define __attribute_const__ /* Ignore */
246#endif
247
248/* At some point during the gcc 3.1 development the `used' attribute
249 for functions was introduced. We don't want to use it unconditionally
250 (although this would be possible) since it generates warnings. */
251#if __GNUC_PREREQ (3,1)
252# define __attribute_used__ __attribute__ ((__used__))
253# define __attribute_noinline__ __attribute__ ((__noinline__))
254#else
255# define __attribute_used__ __attribute__ ((__unused__))
256# define __attribute_noinline__ /* Ignore */
257#endif
258
259/* Since version 3.2, gcc allows marking deprecated functions. */
260#if __GNUC_PREREQ (3,2)
261# define __attribute_deprecated__ __attribute__ ((__deprecated__))
262#else
263# define __attribute_deprecated__ /* Ignore */
264#endif
265
266/* Since version 4.5, gcc also allows one to specify the message printed
267 when a deprecated function is used. clang claims to be gcc 4.2, but
268 may also support this feature. */
269#if __GNUC_PREREQ (4,5) \
270 || __glibc_clang_has_extension (__attribute_deprecated_with_message__)
271# define __attribute_deprecated_msg__(msg) \
272 __attribute__ ((__deprecated__ (msg)))
273#else
274# define __attribute_deprecated_msg__(msg) __attribute_deprecated__
275#endif
276
277/* At some point during the gcc 2.8 development the `format_arg' attribute
278 for functions was introduced. We don't want to use it unconditionally
279 (although this would be possible) since it generates warnings.
280 If several `format_arg' attributes are given for the same function, in
281 gcc-3.0 and older, all but the last one are ignored. In newer gccs,
282 all designated arguments are considered. */
283#if __GNUC_PREREQ (2,8)
284# define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
285#else
286# define __attribute_format_arg__(x) /* Ignore */
287#endif
288
289/* At some point during the gcc 2.97 development the `strfmon' format
290 attribute for functions was introduced. We don't want to use it
291 unconditionally (although this would be possible) since it
292 generates warnings. */
293#if __GNUC_PREREQ (2,97)
294# define __attribute_format_strfmon__(a,b) \
295 __attribute__ ((__format__ (__strfmon__, a, b)))
296#else
297# define __attribute_format_strfmon__(a,b) /* Ignore */
298#endif
299
300/* The nonull function attribute allows to mark pointer parameters which
301 must not be NULL. */
302#if __GNUC_PREREQ (3,3)
303# define __nonnull(params) __attribute__ ((__nonnull__ params))
304#else
305# define __nonnull(params)
306#endif
307
308/* If fortification mode, we warn about unused results of certain
309 function calls which can lead to problems. */
310#if __GNUC_PREREQ (3,4)
311# define __attribute_warn_unused_result__ \
312 __attribute__ ((__warn_unused_result__))
313# if __USE_FORTIFY_LEVEL > 0
314# define __wur __attribute_warn_unused_result__
315# endif
316#else
317# define __attribute_warn_unused_result__ /* empty */
318#endif
319#ifndef __wur
320# define __wur /* Ignore */
321#endif
322
323/* Forces a function to be always inlined. */
324#if __GNUC_PREREQ (3,2)
325/* The Linux kernel defines __always_inline in stddef.h (283d7573), and
326 it conflicts with this definition. Therefore undefine it first to
327 allow either header to be included first. */
328# undef __always_inline
329# define __always_inline __inline __attribute__ ((__always_inline__))
330#else
331# undef __always_inline
332# define __always_inline __inline
333#endif
334
335/* Associate error messages with the source location of the call site rather
336 than with the source location inside the function. */
337#if __GNUC_PREREQ (4,3)
338# define __attribute_artificial__ __attribute__ ((__artificial__))
339#else
340# define __attribute_artificial__ /* Ignore */
341#endif
342
343/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
344 inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__
345 or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions
346 older than 4.3 may define these macros and still not guarantee GNU inlining
347 semantics.
348
349 clang++ identifies itself as gcc-4.2, but has support for GNU inlining
350 semantics, that can be checked for by using the __GNUC_STDC_INLINE_ and
351 __GNUC_GNU_INLINE__ macro definitions. */
352#if (!defined __cplusplus || __GNUC_PREREQ (4,3) \
353 || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \
354 || defined __GNUC_GNU_INLINE__)))
355# if defined __GNUC_STDC_INLINE__ || defined __cplusplus
356# define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
357# define __extern_always_inline \
358 extern __always_inline __attribute__ ((__gnu_inline__))
359# else
360# define __extern_inline extern __inline
361# define __extern_always_inline extern __always_inline
362# endif
363#endif
364
365#ifdef __extern_always_inline
366# define __fortify_function __extern_always_inline __attribute_artificial__
367#endif
368
369/* GCC 4.3 and above allow passing all anonymous arguments of an
370 __extern_always_inline function to some other vararg function. */
371#if __GNUC_PREREQ (4,3)
372# define __va_arg_pack() __builtin_va_arg_pack ()
373# define __va_arg_pack_len() __builtin_va_arg_pack_len ()
374#endif
375
376/* It is possible to compile containing GCC extensions even if GCC is
377 run in pedantic mode if the uses are carefully marked using the
378 `__extension__' keyword. But this is not generally available before
379 version 2.8. */
380#if !__GNUC_PREREQ (2,8)
381# define __extension__ /* Ignore */
382#endif
383
384/* __restrict is known in EGCS 1.2 and above. */
385#if !__GNUC_PREREQ (2,92)
386# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
387# define __restrict restrict
388# else
389# define __restrict /* Ignore */
390# endif
391#endif
392
393/* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
394 array_name[restrict]
395 GCC 3.1 supports this. */
396#if __GNUC_PREREQ (3,1) && !defined __GNUG__
397# define __restrict_arr __restrict
398#else
399# ifdef __GNUC__
400# define __restrict_arr /* Not supported in old GCC. */
401# else
402# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
403# define __restrict_arr restrict
404# else
405/* Some other non-C99 compiler. */
406# define __restrict_arr /* Not supported. */
407# endif
408# endif
409#endif
410
411#if __GNUC__ >= 3
412# define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
413# define __glibc_likely(cond) __builtin_expect ((cond), 1)
414#else
415# define __glibc_unlikely(cond) (cond)
416# define __glibc_likely(cond) (cond)
417#endif
418
419#ifdef __has_attribute
420# define __glibc_has_attribute(attr) __has_attribute (attr)
421#else
422# define __glibc_has_attribute(attr) 0
423#endif
424
425#if (!defined _Noreturn \
426 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
427 && !__GNUC_PREREQ (4,7))
428# if __GNUC_PREREQ (2,8)
429# define _Noreturn __attribute__ ((__noreturn__))
430# else
431# define _Noreturn
432# endif
433#endif
434
435#if __GNUC_PREREQ (8, 0)
436/* Describes a char array whose address can safely be passed as the first
437 argument to strncpy and strncat, as the char array is not necessarily
438 a NUL-terminated string. */
439# define __attribute_nonstring__ __attribute__ ((__nonstring__))
440#else
441# define __attribute_nonstring__
442#endif
443
444/* Undefine (also defined in libc-symbols.h). */
445#undef __attribute_copy__
446#if __GNUC_PREREQ (9, 0)
447/* Copies attributes from the declaration or type referenced by
448 the argument. */
449# define __attribute_copy__(arg) __attribute__ ((__copy__ (arg)))
450#else
451# define __attribute_copy__(arg)
452#endif
453
454#if (!defined _Static_assert && !defined __cplusplus \
455 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
456 && (!__GNUC_PREREQ (4, 6) || defined __STRICT_ANSI__))
457# define _Static_assert(expr, diagnostic) \
458 extern int (*__Static_assert_function (void)) \
459 [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
460#endif
461
462#include <bits/wordsize.h>
463#include <bits/long-double.h>
464
465#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
466# ifdef __REDIRECT
467
468/* Alias name defined automatically. */
469# define __LDBL_REDIR(name, proto) ... unused__ldbl_redir
470# define __LDBL_REDIR_DECL(name) \
471 extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128"));
472
473/* Alias name defined automatically, with leading underscores. */
474# define __LDBL_REDIR2_DECL(name) \
475 extern __typeof (__##name) __##name \
476 __asm (__ASMNAME ("__" #name "ieee128"));
477
478/* Alias name defined manually. */
479# define __LDBL_REDIR1(name, proto, alias) ... unused__ldbl_redir1
480# define __LDBL_REDIR1_DECL(name, alias) \
481 extern __typeof (name) name __asm (__ASMNAME (#alias));
482
483# define __LDBL_REDIR1_NTH(name, proto, alias) \
484 __REDIRECT_NTH (name, proto, alias)
485# define __REDIRECT_NTH_LDBL(name, proto, alias) \
486 __LDBL_REDIR1_NTH (name, proto, __##alias##ieee128)
487
488/* Unused. */
489# define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl
490# define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth
491
492# else
493_Static_assert (0, "IEEE 128-bits long double requires redirection on this platform");
494# endif
495#elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
496# define __LDBL_COMPAT 1
497# ifdef __REDIRECT
498# define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
499# define __LDBL_REDIR(name, proto) \
500 __LDBL_REDIR1 (name, proto, __nldbl_##name)
501# define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
502# define __LDBL_REDIR_NTH(name, proto) \
503 __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
504# define __LDBL_REDIR2_DECL(name) \
505 extern __typeof (__##name) __##name __asm (__ASMNAME ("__nldbl___" #name));
506# define __LDBL_REDIR1_DECL(name, alias) \
507 extern __typeof (name) name __asm (__ASMNAME (#alias));
508# define __LDBL_REDIR_DECL(name) \
509 extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
510# define __REDIRECT_LDBL(name, proto, alias) \
511 __LDBL_REDIR1 (name, proto, __nldbl_##alias)
512# define __REDIRECT_NTH_LDBL(name, proto, alias) \
513 __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
514# endif
515#endif
516#if (!defined __LDBL_COMPAT && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0) \
517 || !defined __REDIRECT
518# define __LDBL_REDIR1(name, proto, alias) name proto
519# define __LDBL_REDIR(name, proto) name proto
520# define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
521# define __LDBL_REDIR_NTH(name, proto) name proto __THROW
522# define __LDBL_REDIR2_DECL(name)
523# define __LDBL_REDIR_DECL(name)
524# ifdef __REDIRECT
525# define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
526# define __REDIRECT_NTH_LDBL(name, proto, alias) \
527 __REDIRECT_NTH (name, proto, alias)
528# endif
529#endif
530
531/* __glibc_macro_warning (MESSAGE) issues warning MESSAGE. This is
532 intended for use in preprocessor macros.
533
534 Note: MESSAGE must be a _single_ string; concatenation of string
535 literals is not supported. */
536#if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
537# define __glibc_macro_warning1(message) _Pragma (#message)
538# define __glibc_macro_warning(message) \
539 __glibc_macro_warning1 (GCC warning message)
540#else
541# define __glibc_macro_warning(msg)
542#endif
543
544/* Generic selection (ISO C11) is a C-only feature, available in GCC
545 since version 4.9. Previous versions do not provide generic
546 selection, even though they might set __STDC_VERSION__ to 201112L,
547 when in -std=c11 mode. Thus, we must check for !defined __GNUC__
548 when testing __STDC_VERSION__ for generic selection support.
549 On the other hand, Clang also defines __GNUC__, so a clang-specific
550 check is required to enable the use of generic selection. */
551#if !defined __cplusplus \
552 && (__GNUC_PREREQ (4, 9) \
553 || __glibc_clang_has_extension (c_generic_selections) \
554 || (!defined __GNUC__ && defined __STDC_VERSION__ \
555 && __STDC_VERSION__ >= 201112L))
556# define __HAVE_GENERIC_SELECTION 1
557#else
558# define __HAVE_GENERIC_SELECTION 0
559#endif
560
561#if __GNUC_PREREQ (10, 0)
562/* Designates a 1-based positional argument ref-index of pointer type
563 that can be used to access size-index elements of the pointed-to
564 array according to access mode, or at least one element when
565 size-index is not provided:
566 access (access-mode, <ref-index> [, <size-index>]) */
567#define __attr_access(x) __attribute__ ((__access__ x))
568#else
569# define __attr_access(x)
570#endif
571
572/* Specify that a function such as setjmp or vfork may return
573 twice. */
574#if __GNUC_PREREQ (4, 1)
575# define __attribute_returns_twice__ __attribute__ ((__returns_twice__))
576#else
577# define __attribute_returns_twice__ /* Ignore. */
578#endif
579
580#endif /* sys/cdefs.h */
581