xref: /aosp_15_r20/bionic/libc/include/sys/cdefs.h (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
1*8d67ca89SAndroid Build Coastguard Worker /*	$NetBSD: cdefs.h,v 1.58 2004/12/11 05:59:00 christos Exp $	*/
2*8d67ca89SAndroid Build Coastguard Worker 
3*8d67ca89SAndroid Build Coastguard Worker /*
4*8d67ca89SAndroid Build Coastguard Worker  * Copyright (c) 1991, 1993
5*8d67ca89SAndroid Build Coastguard Worker  *	The Regents of the University of California.  All rights reserved.
6*8d67ca89SAndroid Build Coastguard Worker  *
7*8d67ca89SAndroid Build Coastguard Worker  * This code is derived from software contributed to Berkeley by
8*8d67ca89SAndroid Build Coastguard Worker  * Berkeley Software Design, Inc.
9*8d67ca89SAndroid Build Coastguard Worker  *
10*8d67ca89SAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
11*8d67ca89SAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
12*8d67ca89SAndroid Build Coastguard Worker  * are met:
13*8d67ca89SAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright
14*8d67ca89SAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
15*8d67ca89SAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright
16*8d67ca89SAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in the
17*8d67ca89SAndroid Build Coastguard Worker  *    documentation and/or other materials provided with the distribution.
18*8d67ca89SAndroid Build Coastguard Worker  * 3. Neither the name of the University nor the names of its contributors
19*8d67ca89SAndroid Build Coastguard Worker  *    may be used to endorse or promote products derived from this software
20*8d67ca89SAndroid Build Coastguard Worker  *    without specific prior written permission.
21*8d67ca89SAndroid Build Coastguard Worker  *
22*8d67ca89SAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23*8d67ca89SAndroid Build Coastguard Worker  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24*8d67ca89SAndroid Build Coastguard Worker  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*8d67ca89SAndroid Build Coastguard Worker  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26*8d67ca89SAndroid Build Coastguard Worker  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27*8d67ca89SAndroid Build Coastguard Worker  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28*8d67ca89SAndroid Build Coastguard Worker  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29*8d67ca89SAndroid Build Coastguard Worker  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30*8d67ca89SAndroid Build Coastguard Worker  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*8d67ca89SAndroid Build Coastguard Worker  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*8d67ca89SAndroid Build Coastguard Worker  * SUCH DAMAGE.
33*8d67ca89SAndroid Build Coastguard Worker  *
34*8d67ca89SAndroid Build Coastguard Worker  *	@(#)cdefs.h	8.8 (Berkeley) 1/9/95
35*8d67ca89SAndroid Build Coastguard Worker  */
36*8d67ca89SAndroid Build Coastguard Worker 
37*8d67ca89SAndroid Build Coastguard Worker #pragma once
38*8d67ca89SAndroid Build Coastguard Worker 
39*8d67ca89SAndroid Build Coastguard Worker /**
40*8d67ca89SAndroid Build Coastguard Worker  * `__BIONIC__` is always defined if you're building with bionic. See
41*8d67ca89SAndroid Build Coastguard Worker  * https://android.googlesource.com/platform/bionic/+/main/docs/defines.md.
42*8d67ca89SAndroid Build Coastguard Worker  */
43*8d67ca89SAndroid Build Coastguard Worker #define __BIONIC__ 1
44*8d67ca89SAndroid Build Coastguard Worker 
45*8d67ca89SAndroid Build Coastguard Worker #if defined(__cplusplus)
46*8d67ca89SAndroid Build Coastguard Worker #define __BEGIN_DECLS extern "C" {
47*8d67ca89SAndroid Build Coastguard Worker #define __END_DECLS }
48*8d67ca89SAndroid Build Coastguard Worker #else
49*8d67ca89SAndroid Build Coastguard Worker #define __BEGIN_DECLS
50*8d67ca89SAndroid Build Coastguard Worker #define __END_DECLS
51*8d67ca89SAndroid Build Coastguard Worker #endif
52*8d67ca89SAndroid Build Coastguard Worker 
53*8d67ca89SAndroid Build Coastguard Worker #define __strong_alias(alias, sym) \
54*8d67ca89SAndroid Build Coastguard Worker     __asm__(".global " #alias "\n" \
55*8d67ca89SAndroid Build Coastguard Worker             #alias " = " #sym);
56*8d67ca89SAndroid Build Coastguard Worker 
57*8d67ca89SAndroid Build Coastguard Worker #if defined(__cplusplus)
58*8d67ca89SAndroid Build Coastguard Worker #define __BIONIC_CAST(_k,_t,_v) (_k<_t>(_v))
59*8d67ca89SAndroid Build Coastguard Worker #else
60*8d67ca89SAndroid Build Coastguard Worker #define __BIONIC_CAST(_k,_t,_v) ((_t) (_v))
61*8d67ca89SAndroid Build Coastguard Worker #endif
62*8d67ca89SAndroid Build Coastguard Worker 
63*8d67ca89SAndroid Build Coastguard Worker #define __BIONIC_ALIGN(__value, __alignment) (((__value) + (__alignment)-1) & ~((__alignment)-1))
64*8d67ca89SAndroid Build Coastguard Worker 
65*8d67ca89SAndroid Build Coastguard Worker /*
66*8d67ca89SAndroid Build Coastguard Worker  * The nullness constraints of this parameter or return value are
67*8d67ca89SAndroid Build Coastguard Worker  * quite complex. This is used to highlight spots where developers
68*8d67ca89SAndroid Build Coastguard Worker  * are encouraged to read relevant manuals or code to understand
69*8d67ca89SAndroid Build Coastguard Worker  * the full picture of nullness for this pointer.
70*8d67ca89SAndroid Build Coastguard Worker  */
71*8d67ca89SAndroid Build Coastguard Worker #define __BIONIC_COMPLICATED_NULLNESS _Null_unspecified
72*8d67ca89SAndroid Build Coastguard Worker 
73*8d67ca89SAndroid Build Coastguard Worker /*
74*8d67ca89SAndroid Build Coastguard Worker  * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
75*8d67ca89SAndroid Build Coastguard Worker  * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
76*8d67ca89SAndroid Build Coastguard Worker  * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
77*8d67ca89SAndroid Build Coastguard Worker  * in between its arguments.  __CONCAT can also concatenate double-quoted
78*8d67ca89SAndroid Build Coastguard Worker  * strings produced by the __STRING macro, but this only works with ANSI C.
79*8d67ca89SAndroid Build Coastguard Worker  */
80*8d67ca89SAndroid Build Coastguard Worker 
81*8d67ca89SAndroid Build Coastguard Worker #define	__P(protos)	protos		/* full-blown ANSI C */
82*8d67ca89SAndroid Build Coastguard Worker 
83*8d67ca89SAndroid Build Coastguard Worker #define	__CONCAT1(x,y)	x ## y
84*8d67ca89SAndroid Build Coastguard Worker #define	__CONCAT(x,y)	__CONCAT1(x,y)
85*8d67ca89SAndroid Build Coastguard Worker #define	___CONCAT(x,y)	__CONCAT(x,y)
86*8d67ca89SAndroid Build Coastguard Worker 
87*8d67ca89SAndroid Build Coastguard Worker #define	__STRING(x)	#x
88*8d67ca89SAndroid Build Coastguard Worker #define	___STRING(x)	__STRING(x)
89*8d67ca89SAndroid Build Coastguard Worker 
90*8d67ca89SAndroid Build Coastguard Worker // C++ has `inline` as a keyword, as does C99, but ANSI C (aka C89 aka C90)
91*8d67ca89SAndroid Build Coastguard Worker // does not. Everything accepts the `__inline__` extension though. We could
92*8d67ca89SAndroid Build Coastguard Worker // just use that directly in our own code, but there's historical precedent
93*8d67ca89SAndroid Build Coastguard Worker // for `__inline` meaning it's still used in upstream BSD code (and potentially
94*8d67ca89SAndroid Build Coastguard Worker // downstream in vendor or app code).
95*8d67ca89SAndroid Build Coastguard Worker #define	__inline __inline__
96*8d67ca89SAndroid Build Coastguard Worker 
97*8d67ca89SAndroid Build Coastguard Worker #define __always_inline __attribute__((__always_inline__))
98*8d67ca89SAndroid Build Coastguard Worker #define __attribute_const__ __attribute__((__const__))
99*8d67ca89SAndroid Build Coastguard Worker #define __attribute_pure__ __attribute__((__pure__))
100*8d67ca89SAndroid Build Coastguard Worker #define __dead __attribute__((__noreturn__))
101*8d67ca89SAndroid Build Coastguard Worker #define __noreturn __attribute__((__noreturn__))
102*8d67ca89SAndroid Build Coastguard Worker #define __mallocfunc  __attribute__((__malloc__))
103*8d67ca89SAndroid Build Coastguard Worker #define __packed __attribute__((__packed__))
104*8d67ca89SAndroid Build Coastguard Worker #define __returns_twice __attribute__((__returns_twice__))
105*8d67ca89SAndroid Build Coastguard Worker #define __unused __attribute__((__unused__))
106*8d67ca89SAndroid Build Coastguard Worker #define __used __attribute__((__used__))
107*8d67ca89SAndroid Build Coastguard Worker 
108*8d67ca89SAndroid Build Coastguard Worker #define __printflike(x, y) __attribute__((__format__(printf, x, y)))
109*8d67ca89SAndroid Build Coastguard Worker #define __scanflike(x, y) __attribute__((__format__(scanf, x, y)))
110*8d67ca89SAndroid Build Coastguard Worker #define __strftimelike(x) __attribute__((__format__(strftime, x, 0)))
111*8d67ca89SAndroid Build Coastguard Worker 
112*8d67ca89SAndroid Build Coastguard Worker /*
113*8d67ca89SAndroid Build Coastguard Worker  * GNU C version 2.96 added explicit branch prediction so that
114*8d67ca89SAndroid Build Coastguard Worker  * the CPU back-end can hint the processor and also so that
115*8d67ca89SAndroid Build Coastguard Worker  * code blocks can be reordered such that the predicted path
116*8d67ca89SAndroid Build Coastguard Worker  * sees a more linear flow, thus improving cache behavior, etc.
117*8d67ca89SAndroid Build Coastguard Worker  *
118*8d67ca89SAndroid Build Coastguard Worker  * The following two macros provide us with a way to use this
119*8d67ca89SAndroid Build Coastguard Worker  * compiler feature.  Use __predict_true() if you expect the expression
120*8d67ca89SAndroid Build Coastguard Worker  * to evaluate to true, and __predict_false() if you expect the
121*8d67ca89SAndroid Build Coastguard Worker  * expression to evaluate to false.
122*8d67ca89SAndroid Build Coastguard Worker  *
123*8d67ca89SAndroid Build Coastguard Worker  * A few notes about usage:
124*8d67ca89SAndroid Build Coastguard Worker  *
125*8d67ca89SAndroid Build Coastguard Worker  *	* Generally, __predict_false() error condition checks (unless
126*8d67ca89SAndroid Build Coastguard Worker  *	  you have some _strong_ reason to do otherwise, in which case
127*8d67ca89SAndroid Build Coastguard Worker  *	  document it), and/or __predict_true() `no-error' condition
128*8d67ca89SAndroid Build Coastguard Worker  *	  checks, assuming you want to optimize for the no-error case.
129*8d67ca89SAndroid Build Coastguard Worker  *
130*8d67ca89SAndroid Build Coastguard Worker  *	* Other than that, if you don't know the likelihood of a test
131*8d67ca89SAndroid Build Coastguard Worker  *	  succeeding from empirical or other `hard' evidence, don't
132*8d67ca89SAndroid Build Coastguard Worker  *	  make predictions.
133*8d67ca89SAndroid Build Coastguard Worker  *
134*8d67ca89SAndroid Build Coastguard Worker  *	* These are meant to be used in places that are run `a lot'.
135*8d67ca89SAndroid Build Coastguard Worker  *	  It is wasteful to make predictions in code that is run
136*8d67ca89SAndroid Build Coastguard Worker  *	  seldomly (e.g. at subsystem initialization time) as the
137*8d67ca89SAndroid Build Coastguard Worker  *	  basic block reordering that this affects can often generate
138*8d67ca89SAndroid Build Coastguard Worker  *	  larger code.
139*8d67ca89SAndroid Build Coastguard Worker  */
140*8d67ca89SAndroid Build Coastguard Worker #define	__predict_true(exp)	__builtin_expect((exp) != 0, 1)
141*8d67ca89SAndroid Build Coastguard Worker #define	__predict_false(exp)	__builtin_expect((exp) != 0, 0)
142*8d67ca89SAndroid Build Coastguard Worker 
143*8d67ca89SAndroid Build Coastguard Worker #define __nodiscard __attribute__((__warn_unused_result__))
144*8d67ca89SAndroid Build Coastguard Worker #define __wur __nodiscard
145*8d67ca89SAndroid Build Coastguard Worker 
146*8d67ca89SAndroid Build Coastguard Worker #define __errorattr(msg) __attribute__((__unavailable__(msg)))
147*8d67ca89SAndroid Build Coastguard Worker #define __warnattr(msg) __attribute__((__deprecated__(msg)))
148*8d67ca89SAndroid Build Coastguard Worker #define __warnattr_real(msg) __attribute__((__deprecated__(msg)))
149*8d67ca89SAndroid Build Coastguard Worker #define __enable_if(cond, msg) __attribute__((__enable_if__(cond, msg)))
150*8d67ca89SAndroid Build Coastguard Worker #define __clang_error_if(cond, msg) __attribute__((__diagnose_if__(cond, msg, "error")))
151*8d67ca89SAndroid Build Coastguard Worker #define __clang_warning_if(cond, msg) __attribute__((__diagnose_if__(cond, msg, "warning")))
152*8d67ca89SAndroid Build Coastguard Worker 
153*8d67ca89SAndroid Build Coastguard Worker #if defined(ANDROID_STRICT)
154*8d67ca89SAndroid Build Coastguard Worker /*
155*8d67ca89SAndroid Build Coastguard Worker  * For things that are sketchy, but not necessarily an error. FIXME: Enable
156*8d67ca89SAndroid Build Coastguard Worker  * this.
157*8d67ca89SAndroid Build Coastguard Worker  */
158*8d67ca89SAndroid Build Coastguard Worker #  define __warnattr_strict(msg) /* __warnattr(msg) */
159*8d67ca89SAndroid Build Coastguard Worker #else
160*8d67ca89SAndroid Build Coastguard Worker #  define __warnattr_strict(msg)
161*8d67ca89SAndroid Build Coastguard Worker #endif
162*8d67ca89SAndroid Build Coastguard Worker 
163*8d67ca89SAndroid Build Coastguard Worker /*
164*8d67ca89SAndroid Build Coastguard Worker  * Some BSD source needs these macros.
165*8d67ca89SAndroid Build Coastguard Worker  * Originally they embedded the rcs versions of each source file
166*8d67ca89SAndroid Build Coastguard Worker  * in the generated binary. We strip strings during build anyway,.
167*8d67ca89SAndroid Build Coastguard Worker  */
168*8d67ca89SAndroid Build Coastguard Worker #define __IDSTRING(_prefix,_s) /* nothing */
169*8d67ca89SAndroid Build Coastguard Worker #define __COPYRIGHT(_s) /* nothing */
170*8d67ca89SAndroid Build Coastguard Worker #define __FBSDID(_s) /* nothing */
171*8d67ca89SAndroid Build Coastguard Worker #define __RCSID(_s) /* nothing */
172*8d67ca89SAndroid Build Coastguard Worker #define __SCCSID(_s) /* nothing */
173*8d67ca89SAndroid Build Coastguard Worker 
174*8d67ca89SAndroid Build Coastguard Worker /*
175*8d67ca89SAndroid Build Coastguard Worker  * With bionic, you always get all C and POSIX API.
176*8d67ca89SAndroid Build Coastguard Worker  *
177*8d67ca89SAndroid Build Coastguard Worker  * If you want BSD and/or GNU extensions, _BSD_SOURCE and/or _GNU_SOURCE are
178*8d67ca89SAndroid Build Coastguard Worker  * expected to be defined by callers before *any* standard header file is
179*8d67ca89SAndroid Build Coastguard Worker  * included.
180*8d67ca89SAndroid Build Coastguard Worker  *
181*8d67ca89SAndroid Build Coastguard Worker  * In our header files we test against __USE_BSD and __USE_GNU.
182*8d67ca89SAndroid Build Coastguard Worker  */
183*8d67ca89SAndroid Build Coastguard Worker #if defined(_GNU_SOURCE)
184*8d67ca89SAndroid Build Coastguard Worker #  define __USE_BSD 1
185*8d67ca89SAndroid Build Coastguard Worker #  define __USE_GNU 1
186*8d67ca89SAndroid Build Coastguard Worker #endif
187*8d67ca89SAndroid Build Coastguard Worker 
188*8d67ca89SAndroid Build Coastguard Worker #if defined(_BSD_SOURCE)
189*8d67ca89SAndroid Build Coastguard Worker #  define __USE_BSD 1
190*8d67ca89SAndroid Build Coastguard Worker #endif
191*8d67ca89SAndroid Build Coastguard Worker 
192*8d67ca89SAndroid Build Coastguard Worker /*
193*8d67ca89SAndroid Build Coastguard Worker  * _FILE_OFFSET_BITS 64 support.
194*8d67ca89SAndroid Build Coastguard Worker  * See https://android.googlesource.com/platform/bionic/+/main/docs/32-bit-abi.md
195*8d67ca89SAndroid Build Coastguard Worker  */
196*8d67ca89SAndroid Build Coastguard Worker #if !defined(__LP64__) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
197*8d67ca89SAndroid Build Coastguard Worker #  define __USE_FILE_OFFSET64 1
198*8d67ca89SAndroid Build Coastguard Worker /*
199*8d67ca89SAndroid Build Coastguard Worker  * Note that __RENAME_IF_FILE_OFFSET64 is only valid if the off_t and off64_t
200*8d67ca89SAndroid Build Coastguard Worker  * functions were both added at the same API level because if you use this,
201*8d67ca89SAndroid Build Coastguard Worker  * you only have one declaration to attach __INTRODUCED_IN to.
202*8d67ca89SAndroid Build Coastguard Worker  */
203*8d67ca89SAndroid Build Coastguard Worker #  define __RENAME_IF_FILE_OFFSET64(func) __RENAME(func)
204*8d67ca89SAndroid Build Coastguard Worker #else
205*8d67ca89SAndroid Build Coastguard Worker #  define __RENAME_IF_FILE_OFFSET64(func)
206*8d67ca89SAndroid Build Coastguard Worker #endif
207*8d67ca89SAndroid Build Coastguard Worker 
208*8d67ca89SAndroid Build Coastguard Worker /* glibc compatibility. */
209*8d67ca89SAndroid Build Coastguard Worker #if defined(__LP64__)
210*8d67ca89SAndroid Build Coastguard Worker #define __WORDSIZE 64
211*8d67ca89SAndroid Build Coastguard Worker #else
212*8d67ca89SAndroid Build Coastguard Worker #define __WORDSIZE 32
213*8d67ca89SAndroid Build Coastguard Worker #endif
214*8d67ca89SAndroid Build Coastguard Worker 
215*8d67ca89SAndroid Build Coastguard Worker /*
216*8d67ca89SAndroid Build Coastguard Worker  * When _FORTIFY_SOURCE is defined, automatic bounds checking is
217*8d67ca89SAndroid Build Coastguard Worker  * added to commonly used libc functions. If a buffer overrun is
218*8d67ca89SAndroid Build Coastguard Worker  * detected, the program is safely aborted.
219*8d67ca89SAndroid Build Coastguard Worker  *
220*8d67ca89SAndroid Build Coastguard Worker  * https://android-developers.googleblog.com/2017/04/fortify-in-android.html
221*8d67ca89SAndroid Build Coastguard Worker  */
222*8d67ca89SAndroid Build Coastguard Worker 
223*8d67ca89SAndroid Build Coastguard Worker #define __BIONIC_FORTIFY_UNKNOWN_SIZE ((size_t) -1)
224*8d67ca89SAndroid Build Coastguard Worker 
225*8d67ca89SAndroid Build Coastguard Worker #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0
226*8d67ca89SAndroid Build Coastguard Worker /* FORTIFY can interfere with pattern-matching of clang-tidy/the static analyzer.  */
227*8d67ca89SAndroid Build Coastguard Worker #  if !defined(__clang_analyzer__)
228*8d67ca89SAndroid Build Coastguard Worker #    define __BIONIC_FORTIFY 1
229*8d67ca89SAndroid Build Coastguard Worker /* ASAN has interceptors that FORTIFY's _chk functions can break.  */
230*8d67ca89SAndroid Build Coastguard Worker #    if __has_feature(address_sanitizer)
231*8d67ca89SAndroid Build Coastguard Worker #      define __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED 0
232*8d67ca89SAndroid Build Coastguard Worker #    else
233*8d67ca89SAndroid Build Coastguard Worker #      define __BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED 1
234*8d67ca89SAndroid Build Coastguard Worker #    endif
235*8d67ca89SAndroid Build Coastguard Worker #  endif
236*8d67ca89SAndroid Build Coastguard Worker #endif
237*8d67ca89SAndroid Build Coastguard Worker 
238*8d67ca89SAndroid Build Coastguard Worker // As we move some FORTIFY checks to be always on, __bos needs to be
239*8d67ca89SAndroid Build Coastguard Worker // always available.
240*8d67ca89SAndroid Build Coastguard Worker #if defined(__BIONIC_FORTIFY)
241*8d67ca89SAndroid Build Coastguard Worker #  if _FORTIFY_SOURCE == 2
242*8d67ca89SAndroid Build Coastguard Worker #    define __bos_level 1
243*8d67ca89SAndroid Build Coastguard Worker #  else
244*8d67ca89SAndroid Build Coastguard Worker #    define __bos_level 0
245*8d67ca89SAndroid Build Coastguard Worker #  endif
246*8d67ca89SAndroid Build Coastguard Worker #else
247*8d67ca89SAndroid Build Coastguard Worker #  define __bos_level 0
248*8d67ca89SAndroid Build Coastguard Worker #endif
249*8d67ca89SAndroid Build Coastguard Worker 
250*8d67ca89SAndroid Build Coastguard Worker #define __bosn(s, n) __builtin_object_size((s), (n))
251*8d67ca89SAndroid Build Coastguard Worker #define __bos(s) __bosn((s), __bos_level)
252*8d67ca89SAndroid Build Coastguard Worker 
253*8d67ca89SAndroid Build Coastguard Worker #if defined(__BIONIC_FORTIFY)
254*8d67ca89SAndroid Build Coastguard Worker #  define __bos0(s) __bosn((s), 0)
255*8d67ca89SAndroid Build Coastguard Worker #  define __pass_object_size_n(n) __attribute__((__pass_object_size__(n)))
256*8d67ca89SAndroid Build Coastguard Worker /*
257*8d67ca89SAndroid Build Coastguard Worker  * FORTIFY'ed functions all have either enable_if or pass_object_size, which
258*8d67ca89SAndroid Build Coastguard Worker  * makes taking their address impossible. Saying (&read)(foo, bar, baz); will
259*8d67ca89SAndroid Build Coastguard Worker  * therefore call the unFORTIFYed version of read.
260*8d67ca89SAndroid Build Coastguard Worker  */
261*8d67ca89SAndroid Build Coastguard Worker #  define __call_bypassing_fortify(fn) (&fn)
262*8d67ca89SAndroid Build Coastguard Worker /*
263*8d67ca89SAndroid Build Coastguard Worker  * Because clang-FORTIFY uses overloads, we can't mark functions as `extern inline` without making
264*8d67ca89SAndroid Build Coastguard Worker  * them available externally. FORTIFY'ed functions try to be as close to possible as 'invisible';
265*8d67ca89SAndroid Build Coastguard Worker  * having stack protectors detracts from that (b/182948263).
266*8d67ca89SAndroid Build Coastguard Worker  */
267*8d67ca89SAndroid Build Coastguard Worker #  define __BIONIC_FORTIFY_INLINE static __inline __attribute__((__no_stack_protector__)) \
268*8d67ca89SAndroid Build Coastguard Worker       __always_inline
269*8d67ca89SAndroid Build Coastguard Worker /*
270*8d67ca89SAndroid Build Coastguard Worker  * We should use __BIONIC_FORTIFY_VARIADIC instead of __BIONIC_FORTIFY_INLINE
271*8d67ca89SAndroid Build Coastguard Worker  * for variadic functions because compilers cannot inline them.
272*8d67ca89SAndroid Build Coastguard Worker  * The __always_inline attribute is useless, misleading, and could trigger
273*8d67ca89SAndroid Build Coastguard Worker  * clang compiler bug to incorrectly inline variadic functions.
274*8d67ca89SAndroid Build Coastguard Worker  */
275*8d67ca89SAndroid Build Coastguard Worker #  define __BIONIC_FORTIFY_VARIADIC static __inline
276*8d67ca89SAndroid Build Coastguard Worker /* Error functions don't have bodies, so they can just be static. */
277*8d67ca89SAndroid Build Coastguard Worker #  define __BIONIC_ERROR_FUNCTION_VISIBILITY static __unused
278*8d67ca89SAndroid Build Coastguard Worker #else
279*8d67ca89SAndroid Build Coastguard Worker /* Further increase sharing for some inline functions */
280*8d67ca89SAndroid Build Coastguard Worker #  define __pass_object_size_n(n)
281*8d67ca89SAndroid Build Coastguard Worker #endif
282*8d67ca89SAndroid Build Coastguard Worker #define __pass_object_size __pass_object_size_n(__bos_level)
283*8d67ca89SAndroid Build Coastguard Worker #define __pass_object_size0 __pass_object_size_n(0)
284*8d67ca89SAndroid Build Coastguard Worker 
285*8d67ca89SAndroid Build Coastguard Worker /* Intended for use in unevaluated contexts, e.g. diagnose_if conditions. */
286*8d67ca89SAndroid Build Coastguard Worker #define __bos_unevaluated_lt(bos_val, val) \
287*8d67ca89SAndroid Build Coastguard Worker   ((bos_val) != __BIONIC_FORTIFY_UNKNOWN_SIZE && (bos_val) < (val))
288*8d67ca89SAndroid Build Coastguard Worker 
289*8d67ca89SAndroid Build Coastguard Worker #define __bos_unevaluated_le(bos_val, val) \
290*8d67ca89SAndroid Build Coastguard Worker   ((bos_val) != __BIONIC_FORTIFY_UNKNOWN_SIZE && (bos_val) <= (val))
291*8d67ca89SAndroid Build Coastguard Worker 
292*8d67ca89SAndroid Build Coastguard Worker /* Intended for use in evaluated contexts. */
293*8d67ca89SAndroid Build Coastguard Worker #define __bos_dynamic_check_impl_and(bos_val, op, index, cond) \
294*8d67ca89SAndroid Build Coastguard Worker   ((bos_val) == __BIONIC_FORTIFY_UNKNOWN_SIZE ||                 \
295*8d67ca89SAndroid Build Coastguard Worker    (__builtin_constant_p(index) && bos_val op index && (cond)))
296*8d67ca89SAndroid Build Coastguard Worker 
297*8d67ca89SAndroid Build Coastguard Worker #define __bos_dynamic_check_impl(bos_val, op, index) \
298*8d67ca89SAndroid Build Coastguard Worker   __bos_dynamic_check_impl_and(bos_val, op, index, 1)
299*8d67ca89SAndroid Build Coastguard Worker 
300*8d67ca89SAndroid Build Coastguard Worker #define __bos_trivially_ge(bos_val, index) __bos_dynamic_check_impl((bos_val), >=, (index))
301*8d67ca89SAndroid Build Coastguard Worker #define __bos_trivially_gt(bos_val, index) __bos_dynamic_check_impl((bos_val), >, (index))
302*8d67ca89SAndroid Build Coastguard Worker 
303*8d67ca89SAndroid Build Coastguard Worker #if defined(__BIONIC_FORTIFY) || defined(__BIONIC_DECLARE_FORTIFY_HELPERS)
304*8d67ca89SAndroid Build Coastguard Worker #  define __BIONIC_INCLUDE_FORTIFY_HEADERS 1
305*8d67ca89SAndroid Build Coastguard Worker #endif
306*8d67ca89SAndroid Build Coastguard Worker 
307*8d67ca89SAndroid Build Coastguard Worker #define __overloadable __attribute__((__overloadable__))
308*8d67ca89SAndroid Build Coastguard Worker 
309*8d67ca89SAndroid Build Coastguard Worker #define __diagnose_as_builtin(...) __attribute__((__diagnose_as_builtin__(__VA_ARGS__)))
310*8d67ca89SAndroid Build Coastguard Worker 
311*8d67ca89SAndroid Build Coastguard Worker /* Used to tag non-static symbols that are private and never exposed by the shared library. */
312*8d67ca89SAndroid Build Coastguard Worker #define __LIBC_HIDDEN__ __attribute__((__visibility__("hidden")))
313*8d67ca89SAndroid Build Coastguard Worker 
314*8d67ca89SAndroid Build Coastguard Worker /*
315*8d67ca89SAndroid Build Coastguard Worker  * Used to tag symbols that should be hidden for 64-bit,
316*8d67ca89SAndroid Build Coastguard Worker  * but visible to preserve binary compatibility for LP32.
317*8d67ca89SAndroid Build Coastguard Worker  */
318*8d67ca89SAndroid Build Coastguard Worker #ifdef __LP64__
319*8d67ca89SAndroid Build Coastguard Worker #define __LIBC32_LEGACY_PUBLIC__ __attribute__((__visibility__("hidden")))
320*8d67ca89SAndroid Build Coastguard Worker #else
321*8d67ca89SAndroid Build Coastguard Worker #define __LIBC32_LEGACY_PUBLIC__ __attribute__((__visibility__("default")))
322*8d67ca89SAndroid Build Coastguard Worker #endif
323*8d67ca89SAndroid Build Coastguard Worker 
324*8d67ca89SAndroid Build Coastguard Worker /* Used to rename functions so that the compiler emits a call to 'x' rather than the function this was applied to. */
325*8d67ca89SAndroid Build Coastguard Worker #define __RENAME(x) __asm__(#x)
326*8d67ca89SAndroid Build Coastguard Worker 
327*8d67ca89SAndroid Build Coastguard Worker /*
328*8d67ca89SAndroid Build Coastguard Worker  * Used when we need to check for overflow when multiplying x and y. This
329*8d67ca89SAndroid Build Coastguard Worker  * should only be used where __builtin_umull_overflow can not work, because it makes
330*8d67ca89SAndroid Build Coastguard Worker  * assumptions that __builtin_umull_overflow doesn't (x and y are positive, ...),
331*8d67ca89SAndroid Build Coastguard Worker  * *and* doesn't make use of compiler intrinsics, so it's probably slower than
332*8d67ca89SAndroid Build Coastguard Worker  * __builtin_umull_overflow.
333*8d67ca89SAndroid Build Coastguard Worker  */
334*8d67ca89SAndroid Build Coastguard Worker #define __unsafe_check_mul_overflow(x, y) ((__SIZE_TYPE__)-1 / (x) < (y))
335*8d67ca89SAndroid Build Coastguard Worker 
336*8d67ca89SAndroid Build Coastguard Worker #include <android/versioning.h>
337*8d67ca89SAndroid Build Coastguard Worker #include <android/api-level.h>
338*8d67ca89SAndroid Build Coastguard Worker #if __has_include(<android/ndk-version.h>)
339*8d67ca89SAndroid Build Coastguard Worker #include <android/ndk-version.h>
340*8d67ca89SAndroid Build Coastguard Worker #endif
341