Path: blob/main/tools/build/cross-build/include/common/sys/cdefs.h
39587 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 __predict_true103#define __predict_true(exp) __builtin_expect((exp), 1)104#endif105#ifndef __predict_false106#define __predict_false(exp) __builtin_expect((exp), 0)107#endif108109#ifndef __weak_symbol110#define __weak_symbol __attribute__((__weak__))111#endif112#ifndef __weak_reference113#ifdef __ELF__114#define __weak_reference(sym, alias) \115__asm__(".weak " #alias); \116__asm__(".equ " #alias ", " #sym)117#else118#define __weak_reference(sym, alias) \119static int alias() __attribute__((weakref(#sym)));120#endif121#endif122123#ifndef __WEAK124#ifdef __ELF__125#define __WEAK(sym) __asm__(".weak " __XSTRING(sym))126#endif127#endif128129/* Some files built as part of the bootstrap libegacy use these macros, but130* since we aren't actually building libc.so, we can defined them to be empty */131#ifndef __sym_compat132#define __sym_compat(sym, impl, verid) /* not needed for bootstrapping */133#endif134#ifndef __sym_default135#define __sym_default(sym, impl, verid) /* not needed for bootstrapping */136#endif137#ifndef __sym_default138#define __warn_references(sym, msg) /* not needed for bootstrapping */139#endif140141#ifndef __malloc_like142#define __malloc_like __attribute__((__malloc__))143#endif144145#ifndef __min_size146#if !defined(__cplusplus)147#define __min_size(x) static(x)148#else149#define __min_size(x) (x)150#endif151#endif152153#ifndef __unused154#define __unused __attribute__((unused))155#endif156#define __format_arg(fmtarg) __attribute__((__format_arg__(fmtarg)))157158#ifndef __exported159#define __exported __attribute__((__visibility__("default")))160#endif161#ifndef __hidden162#define __hidden __attribute__((__visibility__("hidden")))163#endif164165#ifndef __unreachable166#define __unreachable() __builtin_unreachable()167#endif168169#ifndef __clang__170/* GCC doesn't like the printf0 format specifier. Clang treats it the same as171* printf so add the compatibility macro here. */172#define __printf0__ __printf__173#endif174175/* On MacOS __CONCAT is defined as x ## y, which won't expand macros */176#undef __CONCAT177#define __CONCAT1(x, y) x##y178#define __CONCAT(x, y) __CONCAT1(x, y)179180#ifndef __STRING181#define __STRING(x) #x /* stringify without expanding x */182#endif183#ifndef __XSTRING184#define __XSTRING(x) __STRING(x) /* expand x, then stringify */185#endif186187#ifndef __has_feature188#define __has_feature(...) 0189#endif190191#ifndef __has_builtin192#define __has_builtin(...) 0193#endif194195/*196* Nullability qualifiers: currently only supported by Clang.197*/198#if !(defined(__clang__) && __has_feature(nullability))199#define _Nonnull200#define _Nullable201#define _Null_unspecified202#define __NULLABILITY_PRAGMA_PUSH203#define __NULLABILITY_PRAGMA_POP204#else205#define __NULLABILITY_PRAGMA_PUSH \206_Pragma("clang diagnostic push") \207_Pragma("clang diagnostic ignored \"-Wnullability-completeness\"")208#define __NULLABILITY_PRAGMA_POP _Pragma("clang diagnostic pop")209#endif210211#ifndef __offsetof212#define __offsetof(type, field) __builtin_offsetof(type, field)213#endif214215#define __rangeof(type, start, end) \216(__offsetof(type, end) - __offsetof(type, start))217218#ifndef __containerof219#define __containerof(x, s, m) \220({ \221const volatile __typeof(((s *)0)->m) *__x = (x); \222__DEQUALIFY( \223s *, (const volatile char *)__x - __offsetof(s, m)); \224})225#endif226227#ifndef __RCSID228#define __RCSID(x)229#endif230#ifndef __FBSDID231#define __FBSDID(x)232#endif233#ifndef __RCSID234#define __RCSID(x)235#endif236#ifndef __RCSID_SOURCE237#define __RCSID_SOURCE(x)238#endif239#ifndef __SCCSID240#define __SCCSID(x)241#endif242#ifndef __COPYRIGHT243#define __COPYRIGHT(x)244#endif245#ifndef __DECONST246#define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var))247#endif248249#ifndef __DEVOLATILE250#define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var))251#endif252253#ifndef __DEQUALIFY254#define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var))255#endif256257#ifndef __nosanitizeaddress258#if __has_attribute(no_sanitize) && defined(__clang__)259#define __nosanitizeaddress __attribute__((no_sanitize("address")))260#else261#define __nosanitizeaddress262#endif263#endif264265/* Expose all declarations when using FreeBSD headers */266#define __POSIX_VISIBLE 200809267#define __XSI_VISIBLE 700268#define __BSD_VISIBLE 1269#define __ISO_C_VISIBLE 2011270#define __EXT1_VISIBLE 1271272/* Alignment builtins for better type checking and improved code generation. */273/* Provide fallback versions for other compilers (GCC/Clang < 10): */274#if !__has_builtin(__builtin_is_aligned)275#define __builtin_is_aligned(x, align) \276(((__uintptr_t)x & ((align) - 1)) == 0)277#endif278#if !__has_builtin(__builtin_align_up)279#define __builtin_align_up(x, align) \280((__typeof__(x))(((__uintptr_t)(x)+((align)-1))&(~((align)-1))))281#endif282#if !__has_builtin(__builtin_align_down)283#define __builtin_align_down(x, align) \284((__typeof__(x))((x)&(~((align)-1))))285#endif286287#define __align_up(x, y) __builtin_align_up(x, y)288#define __align_down(x, y) __builtin_align_down(x, y)289#define __is_aligned(x, y) __builtin_is_aligned(x, y)290291292