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