Path: blob/main/tools/build/cross-build/include/common/sys/cdefs.h
106465 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright 2018-2020 Alex Richardson <[email protected]>4*5* This software was developed by SRI International and the University of6* Cambridge Computer Laboratory (Department of Computer Science and7* Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the8* DARPA SSITH research programme.9*10* This software was developed by SRI International and the University of11* Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)12* ("CTSRD"), as part of the DARPA CRASH research programme.13*14* Redistribution and use in source and binary forms, with or without15* modification, are permitted provided that the following conditions16* are met:17* 1. Redistributions of source code must retain the above copyright18* notice, this list of conditions and the following disclaimer.19* 2. Redistributions in binary form must reproduce the above copyright20* notice, this list of conditions and the following disclaimer in the21* documentation and/or other materials provided with the distribution.22*23* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND24* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE25* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE26* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE27* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL28* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS29* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)30* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT31* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY32* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF33* SUCH DAMAGE.34*/35#pragma once36/* musl libc does not provide a sys/cdefs.h header */37#if __has_include_next(<sys/cdefs.h>)38#include_next <sys/cdefs.h>39#else40/* No sys/cdefs.h header exists so we have to provide some basic macros */41#ifdef __cplusplus42#define __BEGIN_DECLS extern "C" {43#define __END_DECLS }44#else45#define __BEGIN_DECLS46#define __END_DECLS47#endif4849#endif5051#ifndef __FBSDID52#define __FBSDID(id)53#endif5455#ifndef __IDSTRING56#define __IDSTRING(name, string)57#endif5859#ifndef __pure60#define __pure __attribute__((__pure__))61#endif62#ifndef __packed63#define __packed __attribute__((__packed__))64#endif65#ifndef __dead266#define __dead2 __attribute__((__noreturn__))67#endif68#ifndef __pure269#define __pure2 __attribute__((__const__))70#endif71#ifndef __used72#define __used __attribute__((__used__))73#endif74#ifndef __aligned75#define __aligned(x) __attribute__((__aligned__(x)))76#endif77#ifndef __section78#define __section(x) __attribute__((__section__(x)))79#endif8081#ifndef __alloc_size82#define __alloc_size(...) __attribute__((__alloc_size__(__VA_ARGS__)))83#endif84#ifndef __alloc_size285#define __alloc_size2(n, x) __attribute__((__alloc_size__(n, x)))86#endif87#ifndef __alloc_align88#define __alloc_align(x) __attribute__((__alloc_align__(x)))89#endif90#ifndef __result_use_check91#define __result_use_check __attribute__((__warn_unused_result__))92#endif93#ifndef __printflike94#define __printflike(fmtarg, firstvararg) \95__attribute__((__format__(__printf__, fmtarg, firstvararg)))96#endif97#ifndef __printf0like98#define __printf0like(fmtarg, firstvararg) \99__attribute__((__format__(__printf0__, fmtarg, firstvararg)))100#endif101102#ifndef __nonstring103#if __has_attribute(__nonstring__)104#define __nonstring __attribute__((__nonstring__))105#else106#define __nonstring107#endif108#endif109110#ifndef __predict_true111#define __predict_true(exp) __builtin_expect((exp), 1)112#endif113#ifndef __predict_false114#define __predict_false(exp) __builtin_expect((exp), 0)115#endif116117#ifndef __weak_symbol118#define __weak_symbol __attribute__((__weak__))119#endif120#ifndef __weak_reference121#ifdef __ELF__122#define __weak_reference(sym, alias) \123__asm__(".weak " #alias); \124__asm__(".equ " #alias ", " #sym)125#else126#define __weak_reference(sym, alias) \127static int alias() __attribute__((weakref(#sym)));128#endif129#endif130131#ifndef __WEAK132#ifdef __ELF__133#define __WEAK(sym) __asm__(".weak " __XSTRING(sym))134#endif135#endif136137/* Some files built as part of the bootstrap libegacy use these macros, but138* since we aren't actually building libc.so, we can defined them to be empty */139#ifndef __sym_compat140#define __sym_compat(sym, impl, verid) /* not needed for bootstrapping */141#endif142#ifndef __sym_default143#define __sym_default(sym, impl, verid) /* not needed for bootstrapping */144#endif145#ifndef __sym_default146#define __warn_references(sym, msg) /* not needed for bootstrapping */147#endif148149#ifndef __malloc_like150#define __malloc_like __attribute__((__malloc__))151#endif152153#ifndef __min_size154#if !defined(__cplusplus)155#define __min_size(x) static(x)156#else157#define __min_size(x) (x)158#endif159#endif160161#ifndef __unused162#define __unused __attribute__((unused))163#endif164#define __format_arg(fmtarg) __attribute__((__format_arg__(fmtarg)))165166#ifndef __exported167#define __exported __attribute__((__visibility__("default")))168#endif169#ifndef __hidden170#define __hidden __attribute__((__visibility__("hidden")))171#endif172173#ifndef __unreachable174#define __unreachable() __builtin_unreachable()175#endif176177#ifndef __clang__178/* GCC doesn't like the printf0 format specifier. Clang treats it the same as179* printf so add the compatibility macro here. */180#define __printf0__ __printf__181#endif182183/* On MacOS __CONCAT is defined as x ## y, which won't expand macros */184#undef __CONCAT185#define __CONCAT1(x, y) x##y186#define __CONCAT(x, y) __CONCAT1(x, y)187188#ifndef __STRING189#define __STRING(x) #x /* stringify without expanding x */190#endif191#ifndef __XSTRING192#define __XSTRING(x) __STRING(x) /* expand x, then stringify */193#endif194195#ifndef __has_feature196#define __has_feature(...) 0197#endif198199#ifndef __has_builtin200#define __has_builtin(...) 0201#endif202203/*204* Nullability qualifiers: currently only supported by Clang.205*/206#if !(defined(__clang__) && __has_feature(nullability))207#define _Nonnull208#define _Nullable209#define _Null_unspecified210#define __NULLABILITY_PRAGMA_PUSH211#define __NULLABILITY_PRAGMA_POP212#else213#define __NULLABILITY_PRAGMA_PUSH \214_Pragma("clang diagnostic push") \215_Pragma("clang diagnostic ignored \"-Wnullability-completeness\"")216#define __NULLABILITY_PRAGMA_POP _Pragma("clang diagnostic pop")217#endif218219#ifndef __offsetof220#define __offsetof(type, field) __builtin_offsetof(type, field)221#endif222223#define __rangeof(type, start, end) \224(__offsetof(type, end) - __offsetof(type, start))225226#ifndef __containerof227#define __containerof(x, s, m) \228({ \229const volatile __typeof(((s *)0)->m) *__x = (x); \230__DEQUALIFY( \231s *, (const volatile char *)__x - __offsetof(s, m)); \232})233#endif234235#ifndef __RCSID236#define __RCSID(x)237#endif238#ifndef __FBSDID239#define __FBSDID(x)240#endif241#ifndef __RCSID242#define __RCSID(x)243#endif244#ifndef __RCSID_SOURCE245#define __RCSID_SOURCE(x)246#endif247#ifndef __SCCSID248#define __SCCSID(x)249#endif250#ifndef __COPYRIGHT251#define __COPYRIGHT(x)252#endif253#ifndef __DECONST254#define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var))255#endif256257#ifndef __DEVOLATILE258#define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var))259#endif260261#ifndef __DEQUALIFY262#define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var))263#endif264265#ifndef __nosanitizeaddress266#if __has_attribute(no_sanitize) && defined(__clang__)267#define __nosanitizeaddress __attribute__((no_sanitize("address")))268#else269#define __nosanitizeaddress270#endif271#endif272273/* Expose all declarations when using FreeBSD headers */274#define __POSIX_VISIBLE 200809275#define __XSI_VISIBLE 700276#define __BSD_VISIBLE 1277#define __ISO_C_VISIBLE 2011278#define __EXT1_VISIBLE 1279280/*281* Macro to test if we're using a specific version of gcc or later.282*/283#if defined(__GNUC__)284#define __GNUC_PREREQ__(ma, mi) \285(__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))286#else287#define __GNUC_PREREQ__(ma, mi) 0288#endif289290/* Alignment builtins for better type checking and improved code generation. */291/* Provide fallback versions for other compilers (GCC/Clang < 10): */292#if !__has_builtin(__builtin_is_aligned)293#define __builtin_is_aligned(x, align) \294(((__uintptr_t)x & ((align) - 1)) == 0)295#endif296#if !__has_builtin(__builtin_align_up)297#define __builtin_align_up(x, align) \298((__typeof__(x))(((__uintptr_t)(x)+((align)-1))&(~((align)-1))))299#endif300#if !__has_builtin(__builtin_align_down)301#define __builtin_align_down(x, align) \302((__typeof__(x))((x)&(~((align)-1))))303#endif304305#define __align_up(x, y) __builtin_align_up(x, y)306#define __align_down(x, y) __builtin_align_down(x, y)307#define __is_aligned(x, y) __builtin_is_aligned(x, y)308309310