2009-03-04 03:28:35 +00:00
|
|
|
/* $NetBSD: cdefs.h,v 1.58 2004/12/11 05:59:00 christos Exp $ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Berkeley Software Design, Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)cdefs.h 8.8 (Berkeley) 1/9/95
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SYS_CDEFS_H_
|
|
|
|
#define _SYS_CDEFS_H_
|
|
|
|
|
2014-05-24 03:06:03 +00:00
|
|
|
/*
|
|
|
|
* Testing against Clang-specific extensions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __has_extension
|
|
|
|
#define __has_extension __has_feature
|
|
|
|
#endif
|
|
|
|
#ifndef __has_feature
|
|
|
|
#define __has_feature(x) 0
|
|
|
|
#endif
|
|
|
|
#ifndef __has_include
|
|
|
|
#define __has_include(x) 0
|
|
|
|
#endif
|
|
|
|
#ifndef __has_builtin
|
|
|
|
#define __has_builtin(x) 0
|
|
|
|
#endif
|
2014-10-06 21:49:00 +00:00
|
|
|
#ifndef __has_attribute
|
|
|
|
#define __has_attribute(x) 0
|
|
|
|
#endif
|
2014-05-24 03:06:03 +00:00
|
|
|
|
|
|
|
|
2014-12-20 03:30:11 +00:00
|
|
|
#define __strong_alias(alias, sym) \
|
|
|
|
__asm__(".global " #alias "\n" \
|
|
|
|
#alias " = " #sym);
|
2009-03-04 03:28:35 +00:00
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define __BEGIN_DECLS extern "C" {
|
|
|
|
#define __END_DECLS }
|
|
|
|
#define __static_cast(x,y) static_cast<x>(y)
|
|
|
|
#else
|
|
|
|
#define __BEGIN_DECLS
|
|
|
|
#define __END_DECLS
|
|
|
|
#define __static_cast(x,y) (x)y
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The __CONCAT macro is used to concatenate parts of symbol names, e.g.
|
|
|
|
* with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
|
|
|
|
* The __CONCAT macro is a bit tricky -- make sure you don't put spaces
|
|
|
|
* in between its arguments. __CONCAT can also concatenate double-quoted
|
|
|
|
* strings produced by the __STRING macro, but this only works with ANSI C.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ___STRING(x) __STRING(x)
|
|
|
|
#define ___CONCAT(x,y) __CONCAT(x,y)
|
|
|
|
|
2011-03-17 09:56:25 +00:00
|
|
|
#if defined(__STDC__) || defined(__cplusplus)
|
2009-03-04 03:28:35 +00:00
|
|
|
#define __P(protos) protos /* full-blown ANSI C */
|
|
|
|
#define __CONCAT(x,y) x ## y
|
|
|
|
#define __STRING(x) #x
|
|
|
|
|
|
|
|
#define __const const /* define reserved names to standard */
|
|
|
|
#define __signed signed
|
|
|
|
#define __volatile volatile
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define __inline inline /* convert to C++ keyword */
|
|
|
|
#endif /* !__cplusplus */
|
|
|
|
|
|
|
|
#else /* !(__STDC__ || __cplusplus) */
|
|
|
|
#define __P(protos) () /* traditional C preprocessor */
|
|
|
|
#define __CONCAT(x,y) x/**/y
|
|
|
|
#define __STRING(x) "x"
|
|
|
|
|
|
|
|
#endif /* !(__STDC__ || __cplusplus) */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following macro is used to remove const cast-away warnings
|
|
|
|
* from gcc -Wcast-qual; it should be used with caution because it
|
|
|
|
* can hide valid errors; in particular most valid uses are in
|
|
|
|
* situations where the API requires it, not to cast away string
|
|
|
|
* constants. We don't use *intptr_t on purpose here and we are
|
|
|
|
* explicit about unsigned long so that we don't have additional
|
|
|
|
* dependencies.
|
|
|
|
*/
|
|
|
|
#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
|
|
|
|
|
2016-06-07 00:35:53 +00:00
|
|
|
#define __always_inline __attribute__((__always_inline__))
|
2015-09-22 20:00:21 +00:00
|
|
|
#define __dead __attribute__((__noreturn__))
|
2016-06-07 00:35:53 +00:00
|
|
|
#define __noreturn __attribute__((__noreturn__))
|
|
|
|
#define __mallocfunc __attribute__((malloc))
|
|
|
|
#define __packed __attribute__((__packed__))
|
2015-09-22 20:00:21 +00:00
|
|
|
#define __pure __attribute__((__const__))
|
|
|
|
#define __pure2 __attribute__((__const__)) /* Android-added: used by FreeBSD libm */
|
2016-06-07 00:35:53 +00:00
|
|
|
#define __purefunc __attribute__((pure))
|
|
|
|
#define __unused __attribute__((__unused__))
|
|
|
|
#define __used __attribute__((__used__))
|
2013-07-09 20:25:03 +00:00
|
|
|
|
2015-08-13 23:58:50 +00:00
|
|
|
/*
|
|
|
|
* _Nonnull is similar to the nonnull attribute in that it will instruct
|
|
|
|
* compilers to warn the user if it can prove that a null argument is being
|
|
|
|
* passed. Unlike the nonnull attribute, this annotation indicated that a value
|
|
|
|
* *should not* be null, not that it *cannot* be null, or even that the behavior
|
|
|
|
* is undefined. The important distinction is that the optimizer will perform
|
|
|
|
* surprising optimizations like the following:
|
|
|
|
*
|
|
|
|
* void foo(void*) __attribute__(nonnull, 1);
|
|
|
|
*
|
|
|
|
* int bar(int* p) {
|
|
|
|
* foo(p);
|
|
|
|
*
|
|
|
|
* // The following null check will be elided because nonnull attribute
|
|
|
|
* // means that, since we call foo with p, p can be assumed to not be
|
|
|
|
* // null. Thus this will crash if we are called with a null pointer.
|
|
|
|
* if (src != NULL) {
|
|
|
|
* return *p;
|
|
|
|
* }
|
|
|
|
* return 0;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* int main() {
|
|
|
|
* return bar(NULL);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* http://clang.llvm.org/docs/AttributeReference.html#nonnull
|
|
|
|
*/
|
|
|
|
#if !(defined(__clang__) && __has_feature(nullability))
|
|
|
|
#define _Nonnull
|
|
|
|
#endif
|
|
|
|
|
2016-06-07 00:35:53 +00:00
|
|
|
#define __nonnull(args) __attribute__((__nonnull__ args))
|
|
|
|
|
2013-07-09 20:25:03 +00:00
|
|
|
#define __printflike(x, y) __attribute__((__format__(printf, x, y))) __nonnull((x))
|
|
|
|
#define __scanflike(x, y) __attribute__((__format__(scanf, x, y))) __nonnull((x))
|
2013-05-14 23:08:43 +00:00
|
|
|
|
2009-03-04 03:28:35 +00:00
|
|
|
/*
|
2015-09-22 20:00:21 +00:00
|
|
|
* C99 defines the restrict type qualifier keyword.
|
2009-03-04 03:28:35 +00:00
|
|
|
*/
|
2016-06-07 00:35:53 +00:00
|
|
|
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
|
|
|
|
#define __restrict restrict
|
2009-03-04 03:28:35 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2016-06-07 00:35:53 +00:00
|
|
|
* C99 defines the __func__ predefined identifier.
|
2009-03-04 03:28:35 +00:00
|
|
|
*/
|
2011-03-17 09:56:25 +00:00
|
|
|
#if !defined(__STDC_VERSION__) || !(__STDC_VERSION__ >= 199901L)
|
2016-06-07 00:35:53 +00:00
|
|
|
#define __func__ __PRETTY_FUNCTION__
|
|
|
|
#endif
|
2009-03-04 03:28:35 +00:00
|
|
|
|
|
|
|
/*
|
2016-06-07 00:35:53 +00:00
|
|
|
* GNU C version 2.96 added explicit branch prediction so that
|
2009-03-04 03:28:35 +00:00
|
|
|
* the CPU back-end can hint the processor and also so that
|
|
|
|
* code blocks can be reordered such that the predicted path
|
|
|
|
* sees a more linear flow, thus improving cache behavior, etc.
|
|
|
|
*
|
|
|
|
* The following two macros provide us with a way to use this
|
|
|
|
* compiler feature. Use __predict_true() if you expect the expression
|
|
|
|
* to evaluate to true, and __predict_false() if you expect the
|
|
|
|
* expression to evaluate to false.
|
|
|
|
*
|
|
|
|
* A few notes about usage:
|
|
|
|
*
|
|
|
|
* * Generally, __predict_false() error condition checks (unless
|
|
|
|
* you have some _strong_ reason to do otherwise, in which case
|
|
|
|
* document it), and/or __predict_true() `no-error' condition
|
|
|
|
* checks, assuming you want to optimize for the no-error case.
|
|
|
|
*
|
|
|
|
* * Other than that, if you don't know the likelihood of a test
|
|
|
|
* succeeding from empirical or other `hard' evidence, don't
|
|
|
|
* make predictions.
|
|
|
|
*
|
|
|
|
* * These are meant to be used in places that are run `a lot'.
|
|
|
|
* It is wasteful to make predictions in code that is run
|
|
|
|
* seldomly (e.g. at subsystem initialization time) as the
|
|
|
|
* basic block reordering that this affects can often generate
|
|
|
|
* larger code.
|
|
|
|
*/
|
|
|
|
#define __predict_true(exp) __builtin_expect((exp) != 0, 1)
|
|
|
|
#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
|
|
|
|
|
2013-02-04 21:44:14 +00:00
|
|
|
#define __wur __attribute__((__warn_unused_result__))
|
|
|
|
|
2016-04-25 21:53:13 +00:00
|
|
|
#ifdef __clang__
|
|
|
|
#define __errorattr(msg) __attribute__((unavailable(msg)))
|
|
|
|
#else
|
2015-02-13 18:52:35 +00:00
|
|
|
#define __errorattr(msg) __attribute__((__error__(msg)))
|
2016-04-25 21:53:13 +00:00
|
|
|
#endif
|
|
|
|
|
2015-02-17 23:54:40 +00:00
|
|
|
#define __warnattr(msg) __attribute__((__warning__(msg)))
|
2013-06-18 17:46:02 +00:00
|
|
|
|
2015-02-13 18:52:35 +00:00
|
|
|
#define __errordecl(name, msg) extern void name(void) __errorattr(msg)
|
|
|
|
|
2009-03-04 03:28:35 +00:00
|
|
|
/*
|
2014-08-18 21:45:42 +00:00
|
|
|
* Some BSD source needs these macros.
|
|
|
|
* Originally they embedded the rcs versions of each source file
|
|
|
|
* in the generated binary. We strip strings during build anyway,.
|
2010-06-15 00:18:35 +00:00
|
|
|
*/
|
2014-08-18 21:45:42 +00:00
|
|
|
#define __IDSTRING(_prefix,_s) /* nothing */
|
|
|
|
#define __COPYRIGHT(_s) /* nothing */
|
|
|
|
#define __FBSDID(_s) /* nothing */
|
|
|
|
#define __RCSID(_s) /* nothing */
|
|
|
|
#define __SCCSID(_s) /* nothing */
|
2010-06-15 00:18:35 +00:00
|
|
|
|
2014-08-19 18:16:41 +00:00
|
|
|
/*
|
|
|
|
* _BSD_SOURCE and _GNU_SOURCE are expected to be defined by callers before
|
|
|
|
* any standard header file is included. In those header files we test
|
|
|
|
* against __USE_BSD and __USE_GNU. glibc does this in <features.h> but we
|
|
|
|
* do it in <sys/cdefs.h> instead because that's where our existing
|
|
|
|
* _POSIX_C_SOURCE tests were, and we're already confident that <sys/cdefs.h>
|
|
|
|
* is included everywhere it should be.
|
2014-09-04 15:52:38 +00:00
|
|
|
*
|
|
|
|
* The _GNU_SOURCE test needs to come before any _BSD_SOURCE or _POSIX* tests
|
|
|
|
* because _GNU_SOURCE implies everything else.
|
2014-08-19 18:16:41 +00:00
|
|
|
*/
|
|
|
|
#if defined(_GNU_SOURCE)
|
|
|
|
# define __USE_GNU 1
|
2014-09-04 15:52:38 +00:00
|
|
|
# undef _POSIX_SOURCE
|
|
|
|
# define _POSIX_SOURCE 1
|
|
|
|
# undef _POSIX_C_SOURCE
|
|
|
|
# define _POSIX_C_SOURCE 200809L
|
|
|
|
# undef _BSD_SOURCE
|
|
|
|
# define _BSD_SOURCE 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(_BSD_SOURCE)
|
|
|
|
# define __USE_BSD 1
|
2014-08-19 18:16:41 +00:00
|
|
|
#endif
|
|
|
|
|
2015-02-07 06:28:49 +00:00
|
|
|
/*
|
|
|
|
* _FILE_OFFSET_BITS 64 support.
|
|
|
|
*/
|
|
|
|
#if !defined(__LP64__) && defined(_FILE_OFFSET_BITS)
|
|
|
|
#if _FILE_OFFSET_BITS == 64
|
|
|
|
#define __USE_FILE_OFFSET64 1
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2010-06-16 23:36:41 +00:00
|
|
|
/*-
|
|
|
|
* POSIX.1 requires that the macros we test be defined before any standard
|
|
|
|
* header file is included.
|
|
|
|
*
|
|
|
|
* Here's a quick run-down of the versions:
|
|
|
|
* defined(_POSIX_SOURCE) 1003.1-1988
|
|
|
|
* _POSIX_C_SOURCE == 1 1003.1-1990
|
|
|
|
* _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option
|
|
|
|
* _POSIX_C_SOURCE == 199309 1003.1b-1993
|
|
|
|
* _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995,
|
|
|
|
* and the omnibus ISO/IEC 9945-1: 1996
|
|
|
|
* _POSIX_C_SOURCE == 200112 1003.1-2001
|
|
|
|
* _POSIX_C_SOURCE == 200809 1003.1-2008
|
|
|
|
*
|
|
|
|
* In addition, the X/Open Portability Guide, which is now the Single UNIX
|
|
|
|
* Specification, defines a feature-test macro which indicates the version of
|
|
|
|
* that specification, and which subsumes _POSIX_C_SOURCE.
|
|
|
|
*
|
|
|
|
* Our macros begin with two underscores to avoid namespace screwage.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
|
|
|
|
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
|
|
|
|
#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */
|
|
|
|
#define _POSIX_C_SOURCE 199009
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
|
|
|
|
#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2
|
|
|
|
#undef _POSIX_C_SOURCE
|
|
|
|
#define _POSIX_C_SOURCE 199209
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
|
|
|
|
#ifdef _XOPEN_SOURCE
|
|
|
|
#if _XOPEN_SOURCE - 0 >= 700
|
|
|
|
#define __XSI_VISIBLE 700
|
|
|
|
#undef _POSIX_C_SOURCE
|
|
|
|
#define _POSIX_C_SOURCE 200809
|
|
|
|
#elif _XOPEN_SOURCE - 0 >= 600
|
|
|
|
#define __XSI_VISIBLE 600
|
|
|
|
#undef _POSIX_C_SOURCE
|
|
|
|
#define _POSIX_C_SOURCE 200112
|
|
|
|
#elif _XOPEN_SOURCE - 0 >= 500
|
|
|
|
#define __XSI_VISIBLE 500
|
|
|
|
#undef _POSIX_C_SOURCE
|
|
|
|
#define _POSIX_C_SOURCE 199506
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Deal with all versions of POSIX. The ordering relative to the tests above is
|
|
|
|
* important.
|
|
|
|
*/
|
|
|
|
#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
|
|
|
|
#define _POSIX_C_SOURCE 198808
|
|
|
|
#endif
|
|
|
|
#ifdef _POSIX_C_SOURCE
|
|
|
|
#if _POSIX_C_SOURCE >= 200809
|
|
|
|
#define __POSIX_VISIBLE 200809
|
|
|
|
#define __ISO_C_VISIBLE 1999
|
|
|
|
#elif _POSIX_C_SOURCE >= 200112
|
|
|
|
#define __POSIX_VISIBLE 200112
|
|
|
|
#define __ISO_C_VISIBLE 1999
|
|
|
|
#elif _POSIX_C_SOURCE >= 199506
|
|
|
|
#define __POSIX_VISIBLE 199506
|
|
|
|
#define __ISO_C_VISIBLE 1990
|
|
|
|
#elif _POSIX_C_SOURCE >= 199309
|
|
|
|
#define __POSIX_VISIBLE 199309
|
|
|
|
#define __ISO_C_VISIBLE 1990
|
|
|
|
#elif _POSIX_C_SOURCE >= 199209
|
|
|
|
#define __POSIX_VISIBLE 199209
|
|
|
|
#define __ISO_C_VISIBLE 1990
|
|
|
|
#elif _POSIX_C_SOURCE >= 199009
|
|
|
|
#define __POSIX_VISIBLE 199009
|
|
|
|
#define __ISO_C_VISIBLE 1990
|
|
|
|
#else
|
|
|
|
#define __POSIX_VISIBLE 198808
|
|
|
|
#define __ISO_C_VISIBLE 0
|
|
|
|
#endif /* _POSIX_C_SOURCE */
|
|
|
|
#else /* Default environment: show everything. */
|
|
|
|
#define __POSIX_VISIBLE 200809
|
|
|
|
#define __XSI_VISIBLE 700
|
|
|
|
#define __BSD_VISIBLE 1
|
|
|
|
#define __ISO_C_VISIBLE 1999
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default values.
|
|
|
|
*/
|
|
|
|
#ifndef __XPG_VISIBLE
|
|
|
|
# define __XPG_VISIBLE 700
|
|
|
|
#endif
|
|
|
|
#ifndef __POSIX_VISIBLE
|
|
|
|
# define __POSIX_VISIBLE 200809
|
|
|
|
#endif
|
|
|
|
#ifndef __ISO_C_VISIBLE
|
|
|
|
# define __ISO_C_VISIBLE 1999
|
|
|
|
#endif
|
|
|
|
#ifndef __BSD_VISIBLE
|
|
|
|
# define __BSD_VISIBLE 1
|
|
|
|
#endif
|
2010-06-15 00:18:35 +00:00
|
|
|
|
2009-03-04 03:28:35 +00:00
|
|
|
#define __BIONIC__ 1
|
2010-12-06 11:05:11 +00:00
|
|
|
#include <android/api-level.h>
|
2009-03-04 03:28:35 +00:00
|
|
|
|
2014-04-03 20:59:14 +00:00
|
|
|
/* glibc compatibility. */
|
2015-07-07 16:22:32 +00:00
|
|
|
#if __POSIX_VISIBLE >= 200809
|
|
|
|
#define __USE_ISOC99 1
|
|
|
|
#define __USE_XOPEN2K 1
|
|
|
|
#define __USE_XOPEN2K8 1
|
|
|
|
#endif
|
2014-04-03 20:59:14 +00:00
|
|
|
#if __LP64__
|
|
|
|
#define __WORDSIZE 64
|
|
|
|
#else
|
|
|
|
#define __WORDSIZE 32
|
|
|
|
#endif
|
|
|
|
|
2013-08-28 20:22:52 +00:00
|
|
|
/*
|
|
|
|
* When _FORTIFY_SOURCE is defined, automatic bounds checking is
|
|
|
|
* added to commonly used libc functions. If a buffer overrun is
|
|
|
|
* detected, the program is safely aborted.
|
|
|
|
*
|
|
|
|
* See
|
|
|
|
* http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html for details.
|
|
|
|
*/
|
libc: add limited FORTIFY_SOURCE support for clang
In 829c089f83ddee37203b52bcb294867a9ae7bdbc, we disabled all
FORTIFY_SOURCE support when compiling under clang. At the time,
we didn't have proper test cases, and couldn't easily create targeted
clang tests.
This change re-enables FORTIFY_SOURCE support under clang for a
limited set of functions, where we have explicit unittests available.
The functions are:
* memcpy
* memmove
* strcpy
* strncpy
* strcat
* strncat
* memset
* strlen (with modifications)
* strchr (with modifications)
* strrchr (with modifications)
It may be possible, in the future, to enable other functions. However,
I need to write unittests first.
For strlen, strchr, and strrchr, clang unconditionally calls the
fortified version of the relevant function. If it doesn't know the
size of the buffer it's dealing with, it passes in ((size_t) -1),
which is the largest possible size_t.
I added two new clang specific unittest files, primarily copied
from fortify?_test.cpp.
I've also rebuild the entire system with these changes, and didn't
observe any obvious problems.
Change-Id: If12a15089bb0ffe93824b485290d05b14355fcaa
2013-06-17 21:49:19 +00:00
|
|
|
#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0
|
2015-09-22 20:00:21 +00:00
|
|
|
# define __BIONIC_FORTIFY 1
|
|
|
|
# if _FORTIFY_SOURCE == 2
|
|
|
|
# define __bos(s) __builtin_object_size((s), 1)
|
|
|
|
# else
|
|
|
|
# define __bos(s) __builtin_object_size((s), 0)
|
|
|
|
# endif
|
|
|
|
# define __bos0(s) __builtin_object_size((s), 0)
|
|
|
|
# define __BIONIC_FORTIFY_INLINE extern __inline__ __always_inline __attribute__((gnu_inline)) __attribute__((__artificial__))
|
2014-10-06 21:49:00 +00:00
|
|
|
#endif
|
2013-03-22 17:58:55 +00:00
|
|
|
#define __BIONIC_FORTIFY_UNKNOWN_SIZE ((size_t) -1)
|
2012-06-07 21:01:26 +00:00
|
|
|
|
2014-08-18 21:45:42 +00:00
|
|
|
/* Used to tag non-static symbols that are private and never exposed by the shared library. */
|
|
|
|
#define __LIBC_HIDDEN__ __attribute__((visibility("hidden")))
|
|
|
|
|
|
|
|
/* Like __LIBC_HIDDEN__, but preserves binary compatibility for LP32. */
|
|
|
|
#ifdef __LP64__
|
2015-10-23 19:32:52 +00:00
|
|
|
#define __LIBC32_LEGACY_PUBLIC__ __LIBC_HIDDEN__
|
2014-08-18 21:45:42 +00:00
|
|
|
#else
|
2015-10-23 19:32:52 +00:00
|
|
|
#define __LIBC32_LEGACY_PUBLIC__ __LIBC_ABI_PUBLIC__
|
2014-08-18 21:45:42 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Used to tag non-static symbols that are public and exposed by the shared library. */
|
|
|
|
#define __LIBC_ABI_PUBLIC__ __attribute__((visibility ("default")))
|
|
|
|
|
|
|
|
/* Used to rename functions so that the compiler emits a call to 'x' rather than the function this was applied to. */
|
|
|
|
#define __RENAME(x) __asm__(#x)
|
|
|
|
|
2016-04-14 00:18:20 +00:00
|
|
|
#if __ANDROID_API__ < 21
|
|
|
|
#define __BIONIC_LEGACY_INLINE static __inline
|
|
|
|
#else
|
|
|
|
#define __BIONIC_LEGACY_INLINE extern
|
|
|
|
#endif
|
|
|
|
|
2015-08-06 21:32:25 +00:00
|
|
|
#ifdef __clang__
|
|
|
|
#define __AVAILABILITY(...) __attribute__((availability(android,__VA_ARGS__)))
|
2016-04-29 19:15:18 +00:00
|
|
|
#else
|
|
|
|
#define __AVAILABILITY(...)
|
|
|
|
#endif // __clang__
|
|
|
|
|
2015-08-06 21:32:25 +00:00
|
|
|
#define __INTRODUCED_IN(api_level) __AVAILABILITY(introduced=api_level)
|
|
|
|
#define __DEPRECATED_IN(api_level) __AVAILABILITY(deprecated=api_level)
|
|
|
|
#define __REMOVED_IN(api_level) __AVAILABILITY(obsoleted=api_level)
|
2016-04-29 19:15:18 +00:00
|
|
|
|
2016-04-29 20:45:25 +00:00
|
|
|
#define __INTRODUCED_IN_FUTURE __INTRODUCED_IN(10000)
|
|
|
|
|
2016-04-29 19:15:18 +00:00
|
|
|
#if __LP64__
|
|
|
|
#define __INTRODUCED_IN_32(api_level)
|
|
|
|
#define __INTRODUCED_IN_64 __INTRODUCED_IN
|
2015-01-29 02:16:08 +00:00
|
|
|
#else
|
2016-04-29 19:15:18 +00:00
|
|
|
#define __INTRODUCED_IN_32 __INTRODUCED_IN
|
|
|
|
#define __INTRODUCED_IN_64(api_level)
|
|
|
|
#endif
|
2015-01-29 02:16:08 +00:00
|
|
|
|
2016-05-27 18:14:16 +00:00
|
|
|
#if defined(__arm__)
|
|
|
|
#define __INTRODUCED_IN_ARM __INTRODUCED_IN
|
|
|
|
#else
|
|
|
|
#define __INTRODUCED_IN_ARM(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__i386__)
|
|
|
|
#define __INTRODUCED_IN_X86 __INTRODUCED_IN
|
|
|
|
#else
|
|
|
|
#define __INTRODUCED_IN_X86(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__mips__)
|
|
|
|
#define __INTRODUCED_IN_MIPS __INTRODUCED_IN
|
|
|
|
#else
|
|
|
|
#define __INTRODUCED_IN_MIPS(x)
|
|
|
|
#endif
|
|
|
|
|
2015-07-18 17:55:51 +00:00
|
|
|
#if __has_builtin(__builtin_umul_overflow) || __GNUC__ >= 5
|
|
|
|
#if __LP64__
|
|
|
|
#define __size_mul_overflow(a, b, result) __builtin_umull_overflow(a, b, result)
|
|
|
|
#else
|
|
|
|
#define __size_mul_overflow(a, b, result) __builtin_umul_overflow(a, b, result)
|
|
|
|
#endif
|
|
|
|
#else
|
2016-01-21 02:34:59 +00:00
|
|
|
extern __inline__ __always_inline __attribute__((gnu_inline))
|
|
|
|
int __size_mul_overflow(__SIZE_TYPE__ a, __SIZE_TYPE__ b, __SIZE_TYPE__ *result) {
|
2015-07-18 17:55:51 +00:00
|
|
|
*result = a * b;
|
|
|
|
static const __SIZE_TYPE__ mul_no_overflow = 1UL << (sizeof(__SIZE_TYPE__) * 4);
|
|
|
|
return (a >= mul_no_overflow || b >= mul_no_overflow) && a > 0 && (__SIZE_TYPE__)-1 / a < b;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-03-04 03:28:35 +00:00
|
|
|
#endif /* !_SYS_CDEFS_H_ */
|