199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1991, 1993
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The Regents of the University of California. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This code is derived from software contributed to Berkeley by
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Berkeley Software Design, Inc.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are met:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 4. Neither the name of the University nor the names of its contributors
199767f8919635c4928607450d9e0abb932109ceToomas Soome * may be used to endorse or promote products derived from this software
199767f8919635c4928607450d9e0abb932109ceToomas Soome * without specific prior written permission.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * @(#)cdefs.h 8.8 (Berkeley) 1/9/95
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _SYS_CDEFS_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _SYS_CDEFS_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Testing against Clang-specific extensions.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __has_attribute
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __has_attribute(x) 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __has_extension
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __has_extension __has_feature
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __has_feature
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __has_feature(x) 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __has_include
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __has_include(x) 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __has_builtin
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __has_builtin(x) 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__cplusplus)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __BEGIN_DECLS extern "C" {
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __END_DECLS }
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __BEGIN_DECLS
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __END_DECLS
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This code has been put in place to help reduce the addition of
199767f8919635c4928607450d9e0abb932109ceToomas Soome * compiler specific defines in FreeBSD code. It helps to aid in
199767f8919635c4928607450d9e0abb932109ceToomas Soome * having a compiler-agnostic source tree.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__GNUC__) || defined(__INTEL_COMPILER)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC__ >= 3 || defined(__INTEL_COMPILER)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE_ASM 3
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE_MATH_BUILTIN_CONSTANTS
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE_ASM 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE___TYPEOF 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE___OFFSETOF 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE___SECTION 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __INTEL_COMPILER
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE_CTOR_SECTION_HANDLING 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE_BUILTIN_CONSTANT_P 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__INTEL_COMPILER) && defined(__cplusplus) && \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __INTEL_COMPILER < 800
199767f8919635c4928607450d9e0abb932109ceToomas Soome#undef __GNUCLIKE_BUILTIN_CONSTANT_P
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE_BUILTIN_VARARGS 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE_BUILTIN_STDARG 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE_BUILTIN_VAALIST 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__GNUC__)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUC_VA_LIST_COMPATIBILITY 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Compiler memory barriers, specific to gcc and clang.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__GNUC__)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __compiler_membar() __asm __volatile(" " : : : "memory")
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __INTEL_COMPILER
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE_BUILTIN_NEXT_ARG 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE_MATH_BUILTIN_RELOPS
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUCLIKE_BUILTIN_MEMCPY 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __CC_SUPPORTS_INLINE 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __CC_SUPPORTS___INLINE 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __CC_SUPPORTS___INLINE__ 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __CC_SUPPORTS___FUNC__ 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __CC_SUPPORTS_WARNING 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* __GNUC__ || __INTEL_COMPILER */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Macro to test if we're using a specific version of gcc or later.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUC_PREREQ__(ma, mi) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GNUC_PREREQ__(ma, mi) 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
199767f8919635c4928607450d9e0abb932109ceToomas Soome * mode -- there must be no spaces between its arguments, and for nested
199767f8919635c4928607450d9e0abb932109ceToomas Soome * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also
199767f8919635c4928607450d9e0abb932109ceToomas Soome * concatenate double-quoted strings produced by the __STRING macro, but
199767f8919635c4928607450d9e0abb932109ceToomas Soome * this only works with ANSI C.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * __XSTRING is like __STRING, but it expands any macros in its argument
199767f8919635c4928607450d9e0abb932109ceToomas Soome * first. It is only available with ANSI C.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__STDC__) || defined(__cplusplus)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __P(protos) protos /* full-blown ANSI C */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __CONCAT1(x,y) x ## y
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __CONCAT(x,y) __CONCAT1(x,y)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __STRING(x) #x /* stringify without expanding x */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __XSTRING(x) __STRING(x) /* expand x, then stringify */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __const const /* define reserved names to standard */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __signed signed
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __volatile volatile
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__cplusplus)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __inline inline /* convert to C++ keyword */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !(defined(__CC_SUPPORTS___INLINE))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __inline /* delete GCC keyword */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* ! __CC_SUPPORTS___INLINE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !__cplusplus */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else /* !(__STDC__ || __cplusplus) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __P(protos) () /* traditional C preprocessor */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __CONCAT(x,y) x/**/y
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __STRING(x) "x"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !defined(__CC_SUPPORTS___INLINE)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __const /* delete pseudo-ANSI C keywords */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __inline
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __signed
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __volatile
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * In non-ANSI C environments, new programs will want ANSI-only C keywords
199767f8919635c4928607450d9e0abb932109ceToomas Soome * deleted from the program and old programs will want them left alone.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * When using a compiler other than gcc, programs using the ANSI C keywords
199767f8919635c4928607450d9e0abb932109ceToomas Soome * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * When using "gcc -traditional", we assume that this is the intent; if
199767f8919635c4928607450d9e0abb932109ceToomas Soome * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef NO_ANSI_KEYWORDS
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define const /* delete ANSI C keywords */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define inline
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define signed
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define volatile
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !NO_ANSI_KEYWORDS */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !__CC_SUPPORTS___INLINE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !(__STDC__ || __cplusplus) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Compiler-dependent macros to help declare dead (non-returning) and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * pure (no side effects) functions, and unused variables. They are
199767f8919635c4928607450d9e0abb932109ceToomas Soome * null except for versions of gcc that are known to support the features
199767f8919635c4928607450d9e0abb932109ceToomas Soome * properly (old versions of gcc-2 supported the dead and pure features
199767f8919635c4928607450d9e0abb932109ceToomas Soome * in a different (wrong) way). If we do not provide an implementation
199767f8919635c4928607450d9e0abb932109ceToomas Soome * for a given compiler, let the compile fail if it is told to use
199767f8919635c4928607450d9e0abb932109ceToomas Soome * a feature that we cannot live without.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef lint
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __dead2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __pure2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __unused
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __packed
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __aligned(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __alloc_align(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __alloc_size(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __section(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __weak_symbol
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __weak_symbol __attribute__((__weak__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __dead2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __pure2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __unused
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __dead2 __attribute__((__noreturn__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __pure2 __attribute__((__const__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __unused
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* XXX Find out what to do for __packed, __aligned and __section */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(2, 7) || defined(__INTEL_COMPILER)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __dead2 __attribute__((__noreturn__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __pure2 __attribute__((__const__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __unused __attribute__((__unused__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __used __attribute__((__used__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __packed __attribute__((__packed__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __aligned(x) __attribute__((__aligned__(x)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __section(x) __attribute__((__section__(x)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(4, 3) || __has_attribute(__alloc_size__)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __alloc_size(x) __attribute__((__alloc_size__(x)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __alloc_size(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(4, 9) || __has_attribute(__alloc_align__)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __alloc_align(x) __attribute__((__alloc_align__(x)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __alloc_align(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* lint */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !__GNUC_PREREQ__(2, 95)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __alignof(x) __offsetof(struct { char __a; x __b; }, __b)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Keywords added in C11.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || defined(lint)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !__has_extension(c_alignas)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if (defined(__cplusplus) && __cplusplus >= 201103L) || \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __has_extension(cxx_alignas)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _Alignas(x) alignas(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _Alignas(x) __aligned(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__cplusplus) && __cplusplus >= 201103L
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _Alignof(x) alignof(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _Alignof(x) __alignof(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !__has_extension(c_atomic) && !__has_extension(cxx_atomic)
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * No native support for _Atomic(). Place object in structure to prevent
199767f8919635c4928607450d9e0abb932109ceToomas Soome * most forms of direct non-atomic access.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _Atomic(T) struct { T volatile __val; }
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__cplusplus) && __cplusplus >= 201103L
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _Noreturn [[noreturn]]
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _Noreturn __dead2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !__has_extension(c_static_assert)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if (defined(__cplusplus) && __cplusplus >= 201103L) || \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __has_extension(cxx_static_assert)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _Static_assert(x, y) static_assert(x, y)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#elif __GNUC_PREREQ__(4,6)
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Nothing, gcc 4.6 and higher has _Static_assert built-in */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#elif defined(__COUNTER__)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _Static_assert(x, y) __Static_assert(x, __COUNTER__)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __Static_assert(x, y) ___Static_assert(x, y)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1] \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __unused
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _Static_assert(x, y) struct __hack
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !__has_extension(c_thread_local)
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * XXX: Some compilers (Clang 3.3, GCC 4.7) falsely announce C++11 mode
199767f8919635c4928607450d9e0abb932109ceToomas Soome * without actually supporting the thread_local keyword. Don't check for
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the presence of C++11 when defining _Thread_local.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __has_extension(cxx_thread_local)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _Thread_local thread_local
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _Thread_local __thread
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Emulation of C11 _Generic(). Unlike the previously defined C11
199767f8919635c4928607450d9e0abb932109ceToomas Soome * keywords, it is not possible to implement this using exactly the same
199767f8919635c4928607450d9e0abb932109ceToomas Soome * syntax. Therefore implement something similar under the name
199767f8919635c4928607450d9e0abb932109ceToomas Soome * __generic(). Unlike _Generic(), this macro can only distinguish
199767f8919635c4928607450d9e0abb932109ceToomas Soome * between a single type, so it requires nested invocations to
199767f8919635c4928607450d9e0abb932109ceToomas Soome * distinguish multiple cases.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __has_extension(c_generic_selections)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __generic(expr, t, yes, no) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome _Generic(expr, t: yes, default: no)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __generic(expr, t, yes, no) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __builtin_choose_expr( \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __builtin_types_compatible_p(__typeof(expr), t), yes, no)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(2, 96)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __malloc_like __attribute__((__malloc__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __pure __attribute__((__pure__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __malloc_like
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __pure
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __always_inline __attribute__((__always_inline__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __always_inline
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(3, 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __noinline __attribute__ ((__noinline__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __noinline
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(3, 3)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __nonnull(x) __attribute__((__nonnull__(x)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __nonnull_all __attribute__((__nonnull__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __nonnull(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __nonnull_all
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(3, 4)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __fastcall __attribute__((__fastcall__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __result_use_check __attribute__((__warn_unused_result__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __fastcall
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __result_use_check
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(4, 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __returns_twice __attribute__((__returns_twice__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __returns_twice
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(4, 6) || __has_builtin(__builtin_unreachable)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __unreachable() __builtin_unreachable()
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __unreachable() ((void)0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* XXX: should use `#if __STDC_VERSION__ < 199901'. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __func__ NULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if (defined(__INTEL_COMPILER) || (defined(__GNUC__) && __GNUC__ >= 2)) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __LONG_LONG_SUPPORTED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* C++11 exposes a load of C99 stuff */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__cplusplus) && __cplusplus >= 201103L
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __LONG_LONG_SUPPORTED
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __STDC_LIMIT_MACROS
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __STDC_LIMIT_MACROS
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __STDC_CONSTANT_MACROS
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __STDC_CONSTANT_MACROS
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * GCC 2.95 provides `__restrict' as an extension to C90 to support the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * C99-specific `restrict' type qualifier. We happen to use `__restrict' as
199767f8919635c4928607450d9e0abb932109ceToomas Soome * a way to define the `restrict' type qualifier without disturbing older
199767f8919635c4928607450d9e0abb932109ceToomas Soome * software that is unaware of C99 keywords.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 || defined(lint)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __restrict
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __restrict restrict
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * GNU C version 2.96 adds explicit branch prediction so that
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the CPU back-end can hint the processor and also so that
199767f8919635c4928607450d9e0abb932109ceToomas Soome * code blocks can be reordered such that the predicted path
199767f8919635c4928607450d9e0abb932109ceToomas Soome * sees a more linear flow, thus improving cache behavior, etc.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The following two macros provide us with a way to utilize this
199767f8919635c4928607450d9e0abb932109ceToomas Soome * compiler feature. Use __predict_true() if you expect the expression
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to evaluate to true, and __predict_false() if you expect the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * expression to evaluate to false.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * A few notes about usage:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * * Generally, __predict_false() error condition checks (unless
199767f8919635c4928607450d9e0abb932109ceToomas Soome * you have some _strong_ reason to do otherwise, in which case
199767f8919635c4928607450d9e0abb932109ceToomas Soome * document it), and/or __predict_true() `no-error' condition
199767f8919635c4928607450d9e0abb932109ceToomas Soome * checks, assuming you want to optimize for the no-error case.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * * Other than that, if you don't know the likelihood of a test
199767f8919635c4928607450d9e0abb932109ceToomas Soome * succeeding from empirical or other `hard' evidence, don't
199767f8919635c4928607450d9e0abb932109ceToomas Soome * make predictions.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * * These are meant to be used in places that are run `a lot'.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * It is wasteful to make predictions in code that is run
199767f8919635c4928607450d9e0abb932109ceToomas Soome * seldomly (e.g. at subsystem initialization time) as the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * basic block reordering that this affects can often generate
199767f8919635c4928607450d9e0abb932109ceToomas Soome * larger code.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(2, 96)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __predict_true(exp) __builtin_expect((exp), 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __predict_false(exp) __builtin_expect((exp), 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __predict_true(exp) (exp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __predict_false(exp) (exp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(4, 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __null_sentinel __attribute__((__sentinel__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __exported __attribute__((__visibility__("default")))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __hidden __attribute__((__visibility__("hidden")))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __null_sentinel
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __exported
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __hidden
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * require it.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(4, 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __offsetof(type, field) __builtin_offsetof(type, field)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __cplusplus
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __offsetof(type, field) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((__size_t)(__uintptr_t)((const volatile void *)&((type *)0)->field))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __offsetof(type, field) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (__offsetof__ (reinterpret_cast <__size_t> \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (&reinterpret_cast <const volatile char &> \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (static_cast<type *> (0)->field))))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __rangeof(type, start, end) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (__offsetof(type, end) - __offsetof(type, start))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Given the pointer x to the member m of the struct s, return
199767f8919635c4928607450d9e0abb932109ceToomas Soome * a pointer to the containing structure. When using GCC, we first
199767f8919635c4928607450d9e0abb932109ceToomas Soome * assign pointer x to a local variable, to check that its type is
199767f8919635c4928607450d9e0abb932109ceToomas Soome * compatible with member m.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(3, 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __containerof(x, s, m) ({ \
199767f8919635c4928607450d9e0abb932109ceToomas Soome const volatile __typeof(((s *)0)->m) *__x = (x); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\
199767f8919635c4928607450d9e0abb932109ceToomas Soome})
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __containerof(x, s, m) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Compiler-dependent macros to declare that functions take printf-like
199767f8919635c4928607450d9e0abb932109ceToomas Soome * or scanf-like arguments. They are null except for versions of gcc
199767f8919635c4928607450d9e0abb932109ceToomas Soome * that are known to support the features properly (old versions of gcc-2
199767f8919635c4928607450d9e0abb932109ceToomas Soome * didn't permit keeping the keywords out of the application namespace).
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __printflike(fmtarg, firstvararg)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __scanflike(fmtarg, firstvararg)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __format_arg(fmtarg)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __strfmonlike(fmtarg, firstvararg)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __strftimelike(fmtarg, firstvararg)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __printflike(fmtarg, firstvararg) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __scanflike(fmtarg, firstvararg) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __strfmonlike(fmtarg, firstvararg) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __attribute__((__format__ (__strfmon__, fmtarg, firstvararg)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __strftimelike(fmtarg, firstvararg) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __attribute__((__format__ (__strftime__, fmtarg, firstvararg)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FORTIFY_SOURCE, and perhaps other compiler-specific features, require
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the use of non-standard inlining. In general we should try to avoid
199767f8919635c4928607450d9e0abb932109ceToomas Soome * using these but GCC-compatible compilers tend to support the extensions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * well enough to use them in limited cases.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__GNUC_GNU_INLINE__) || defined(__GNUC_STDC_INLINE__)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __GNUC_PREREQ__(4, 3) || __has_attribute(__artificial__)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __gnu_inline __attribute__((__gnu_inline__, __artificial__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __gnu_inline __attribute__((__gnu_inline__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* artificial */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __gnu_inline
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \
199767f8919635c4928607450d9e0abb932109ceToomas Soome defined(__GNUC__) && !defined(__INTEL_COMPILER)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __printf0like(fmtarg, firstvararg) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __printf0like(fmtarg, firstvararg)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__GNUC__) || defined(__INTEL_COMPILER)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __INTEL_COMPILER
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __strong_reference(sym,aliassym) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef __STDC__
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __weak_reference(sym,alias) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".weak " #alias); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".equ " #alias ", " #sym)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __warn_references(sym,msg) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".section .gnu.warning." #sym); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".asciz \"" msg "\""); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".previous")
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __sym_compat(sym,impl,verid) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".symver " #impl ", " #sym "@" #verid)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __sym_default(sym,impl,verid) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".symver " #impl ", " #sym "@@" #verid)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __weak_reference(sym,alias) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".weak alias"); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".equ alias, sym")
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __warn_references(sym,msg) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".section .gnu.warning.sym"); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".asciz \"msg\""); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".previous")
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __sym_compat(sym,impl,verid) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".symver impl, sym@verid")
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __sym_default(impl,sym,verid) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __asm__(".symver impl, sym@@verid")
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* __STDC__ */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* __GNUC__ || __INTEL_COMPILER */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GLOBL1(sym) __asm__(".globl " #sym)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __GLOBL(sym) __GLOBL1(sym)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__GNUC__) || defined(__INTEL_COMPILER)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"")
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The following definition might not work well if used in header files,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * but it should be better than nothing. If you want a "do nothing"
199767f8919635c4928607450d9e0abb932109ceToomas Soome * version, then it should generate some harmless declaration, such as:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * #define __IDSTRING(name,string) struct __hack
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __IDSTRING(name,string) static const char name[] __unused = string
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Embed the rcs id of a source file in the resulting library. Note that in
199767f8919635c4928607450d9e0abb932109ceToomas Soome * more recent ELF binutils, we use .ident allowing the ID to be stripped.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Usage:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * __FBSDID("$FreeBSD$");
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __FBSDID
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if !defined(lint) && !defined(STRIP_FBSDID)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __FBSDID(s) struct __hack
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __RCSID
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef NO__RCSID
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __RCSID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __RCSID(s) struct __hack
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __RCSID_SOURCE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef NO__RCSID_SOURCE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __RCSID_SOURCE(s) __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __RCSID_SOURCE(s) struct __hack
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __SCCSID
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef NO__SCCSID
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __SCCSID(s) __IDSTRING(__CONCAT(__sccsid_,__LINE__),s)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __SCCSID(s) struct __hack
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __COPYRIGHT
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef NO__COPYRIGHT
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __COPYRIGHT(s) struct __hack
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __DECONST
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __DEVOLATILE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef __DEQUALIFY
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The following definitions are an extension of the behavior originally
199767f8919635c4928607450d9e0abb932109ceToomas Soome * implemented in <sys/_posix.h>, but with a different level of granularity.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * POSIX.1 requires that the macros we test be defined before any standard
199767f8919635c4928607450d9e0abb932109ceToomas Soome * header file is included.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Here's a quick run-down of the versions:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * defined(_POSIX_SOURCE) 1003.1-1988
199767f8919635c4928607450d9e0abb932109ceToomas Soome * _POSIX_C_SOURCE == 1 1003.1-1990
199767f8919635c4928607450d9e0abb932109ceToomas Soome * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option
199767f8919635c4928607450d9e0abb932109ceToomas Soome * _POSIX_C_SOURCE == 199309 1003.1b-1993
199767f8919635c4928607450d9e0abb932109ceToomas Soome * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * and the omnibus ISO/IEC 9945-1: 1996
199767f8919635c4928607450d9e0abb932109ceToomas Soome * _POSIX_C_SOURCE == 200112 1003.1-2001
199767f8919635c4928607450d9e0abb932109ceToomas Soome * _POSIX_C_SOURCE == 200809 1003.1-2008
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * In addition, the X/Open Portability Guide, which is now the Single UNIX
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Specification, defines a feature-test macro which indicates the version of
199767f8919635c4928607450d9e0abb932109ceToomas Soome * that specification, and which subsumes _POSIX_C_SOURCE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Our macros begin with two underscores to avoid namespace screwage.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _POSIX_C_SOURCE 199009
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#undef _POSIX_C_SOURCE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _POSIX_C_SOURCE 199209
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _XOPEN_SOURCE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if _XOPEN_SOURCE - 0 >= 700
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __XSI_VISIBLE 700
199767f8919635c4928607450d9e0abb932109ceToomas Soome#undef _POSIX_C_SOURCE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _POSIX_C_SOURCE 200809
199767f8919635c4928607450d9e0abb932109ceToomas Soome#elif _XOPEN_SOURCE - 0 >= 600
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __XSI_VISIBLE 600
199767f8919635c4928607450d9e0abb932109ceToomas Soome#undef _POSIX_C_SOURCE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _POSIX_C_SOURCE 200112
199767f8919635c4928607450d9e0abb932109ceToomas Soome#elif _XOPEN_SOURCE - 0 >= 500
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __XSI_VISIBLE 500
199767f8919635c4928607450d9e0abb932109ceToomas Soome#undef _POSIX_C_SOURCE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _POSIX_C_SOURCE 199506
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Deal with all versions of POSIX. The ordering relative to the tests above is
199767f8919635c4928607450d9e0abb932109ceToomas Soome * important.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _POSIX_C_SOURCE 198808
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef _POSIX_C_SOURCE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if _POSIX_C_SOURCE >= 200809
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __POSIX_VISIBLE 200809
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __ISO_C_VISIBLE 1999
199767f8919635c4928607450d9e0abb932109ceToomas Soome#elif _POSIX_C_SOURCE >= 200112
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __POSIX_VISIBLE 200112
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __ISO_C_VISIBLE 1999
199767f8919635c4928607450d9e0abb932109ceToomas Soome#elif _POSIX_C_SOURCE >= 199506
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __POSIX_VISIBLE 199506
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __ISO_C_VISIBLE 1990
199767f8919635c4928607450d9e0abb932109ceToomas Soome#elif _POSIX_C_SOURCE >= 199309
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __POSIX_VISIBLE 199309
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __ISO_C_VISIBLE 1990
199767f8919635c4928607450d9e0abb932109ceToomas Soome#elif _POSIX_C_SOURCE >= 199209
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __POSIX_VISIBLE 199209
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __ISO_C_VISIBLE 1990
199767f8919635c4928607450d9e0abb932109ceToomas Soome#elif _POSIX_C_SOURCE >= 199009
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __POSIX_VISIBLE 199009
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __ISO_C_VISIBLE 1990
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __POSIX_VISIBLE 198808
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __ISO_C_VISIBLE 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* _POSIX_C_SOURCE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Deal with _ANSI_SOURCE:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If it is defined, and no other compilation environment is explicitly
199767f8919635c4928607450d9e0abb932109ceToomas Soome * requested, then define our internal feature-test macros to zero. This
199767f8919635c4928607450d9e0abb932109ceToomas Soome * makes no difference to the preprocessor (undefined symbols in preprocessing
199767f8919635c4928607450d9e0abb932109ceToomas Soome * expressions are defined to have value zero), but makes it more convenient for
199767f8919635c4928607450d9e0abb932109ceToomas Soome * a test program to print out the values.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If a program mistakenly defines _ANSI_SOURCE and some other macro such as
199767f8919635c4928607450d9e0abb932109ceToomas Soome * _POSIX_C_SOURCE, we will assume that it wants the broader compilation
199767f8919635c4928607450d9e0abb932109ceToomas Soome * environment (and in fact we will never get here).
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(_ANSI_SOURCE) /* Hide almost everything. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __POSIX_VISIBLE 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __XSI_VISIBLE 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __BSD_VISIBLE 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __ISO_C_VISIBLE 1990
199767f8919635c4928607450d9e0abb932109ceToomas Soome#elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __POSIX_VISIBLE 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __XSI_VISIBLE 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __BSD_VISIBLE 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __ISO_C_VISIBLE 1999
199767f8919635c4928607450d9e0abb932109ceToomas Soome#elif defined(_C11_SOURCE) /* Localism to specify strict C11 env. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __POSIX_VISIBLE 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __XSI_VISIBLE 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __BSD_VISIBLE 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __ISO_C_VISIBLE 2011
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else /* Default environment: show everything. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __POSIX_VISIBLE 200809
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __XSI_VISIBLE 700
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __BSD_VISIBLE 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __ISO_C_VISIBLE 2011
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if defined(__mips) || defined(__powerpc64__) || defined(__riscv__)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __NO_TLS 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Type Safety Checking
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Clang provides additional attributes to enable checking type safety
199767f8919635c4928607450d9e0abb932109ceToomas Soome * properties that cannot be enforced by the C type system.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __has_attribute(__argument_with_type_tag__) && \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __has_attribute(__type_tag_for_datatype__) && !defined(lint)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __arg_type_tag(arg_kind, arg_idx, type_tag_idx) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __attribute__((__argument_with_type_tag__(arg_kind, arg_idx, type_tag_idx)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __datatype_type_tag(kind, type) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __attribute__((__type_tag_for_datatype__(kind, type)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __arg_type_tag(arg_kind, arg_idx, type_tag_idx)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __datatype_type_tag(kind, type)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Lock annotations.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Clang provides support for doing basic thread-safety tests at
199767f8919635c4928607450d9e0abb932109ceToomas Soome * compile-time, by marking which locks will/should be held when
199767f8919635c4928607450d9e0abb932109ceToomas Soome * entering/leaving a functions.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Furthermore, it is also possible to annotate variables and structure
199767f8919635c4928607450d9e0abb932109ceToomas Soome * members to enforce that they are only accessed when certain locks are
199767f8919635c4928607450d9e0abb932109ceToomas Soome * held.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#if __has_extension(c_thread_safety_attributes)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __lock_annotate(x) __attribute__((x))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __lock_annotate(x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Structure implements a lock. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __lockable __lock_annotate(lockable)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Function acquires an exclusive or shared lock. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __locks_exclusive(...) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __lock_annotate(exclusive_lock_function(__VA_ARGS__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __locks_shared(...) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __lock_annotate(shared_lock_function(__VA_ARGS__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Function attempts to acquire an exclusive or shared lock. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __trylocks_exclusive(...) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __lock_annotate(exclusive_trylock_function(__VA_ARGS__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __trylocks_shared(...) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __lock_annotate(shared_trylock_function(__VA_ARGS__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Function releases a lock. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Function asserts that an exclusive or shared lock is held. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __asserts_exclusive(...) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __lock_annotate(assert_exclusive_lock(__VA_ARGS__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __asserts_shared(...) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __lock_annotate(assert_shared_lock(__VA_ARGS__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Function requires that an exclusive or shared lock is or is not held. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __requires_exclusive(...) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __lock_annotate(exclusive_locks_required(__VA_ARGS__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __requires_shared(...) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __lock_annotate(shared_locks_required(__VA_ARGS__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __requires_unlocked(...) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome __lock_annotate(locks_excluded(__VA_ARGS__))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Function should not be analyzed. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __no_lock_analysis __lock_annotate(no_thread_safety_analysis)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Guard variables and structure members by lock. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __guarded_by(x) __lock_annotate(guarded_by(x))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* !_SYS_CDEFS_H_ */