zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

cdefs.h (41508B) - Raw


      1 /*
      2  * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
      3  *
      4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
      5  *
      6  * This file contains Original Code and/or Modifications of Original Code
      7  * as defined in and that are subject to the Apple Public Source License
      8  * Version 2.0 (the 'License'). You may not use this file except in
      9  * compliance with the License. The rights granted to you under the License
     10  * may not be used to create, or enable the creation or redistribution of,
     11  * unlawful or unlicensed copies of an Apple operating system, or to
     12  * circumvent, violate, or enable the circumvention or violation of, any
     13  * terms of an Apple operating system software license agreement.
     14  *
     15  * Please obtain a copy of the License at
     16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
     17  *
     18  * The Original Code and all software distributed under the License are
     19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
     20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
     21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
     22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
     23  * Please see the License for the specific language governing rights and
     24  * limitations under the License.
     25  *
     26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
     27  */
     28 /* Copyright 1995 NeXT Computer, Inc. All rights reserved. */
     29 /*
     30  * Copyright (c) 1991, 1993
     31  *	The Regents of the University of California.  All rights reserved.
     32  *
     33  * This code is derived from software contributed to Berkeley by
     34  * Berkeley Software Design, Inc.
     35  *
     36  * Redistribution and use in source and binary forms, with or without
     37  * modification, are permitted provided that the following conditions
     38  * are met:
     39  * 1. Redistributions of source code must retain the above copyright
     40  *    notice, this list of conditions and the following disclaimer.
     41  * 2. Redistributions in binary form must reproduce the above copyright
     42  *    notice, this list of conditions and the following disclaimer in the
     43  *    documentation and/or other materials provided with the distribution.
     44  * 3. All advertising materials mentioning features or use of this software
     45  *    must display the following acknowledgement:
     46  *	This product includes software developed by the University of
     47  *	California, Berkeley and its contributors.
     48  * 4. Neither the name of the University nor the names of its contributors
     49  *    may be used to endorse or promote products derived from this software
     50  *    without specific prior written permission.
     51  *
     52  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     53  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     54  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     55  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     56  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     57  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     58  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     59  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     60  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     61  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     62  * SUCH DAMAGE.
     63  *
     64  *	@(#)cdefs.h	8.8 (Berkeley) 1/9/95
     65  */
     66 
     67 #ifndef _CDEFS_H_
     68 #define _CDEFS_H_
     69 
     70 #if defined(__cplusplus)
     71 #define __BEGIN_DECLS   extern "C" {
     72 #define __END_DECLS     }
     73 #else
     74 #define __BEGIN_DECLS
     75 #define __END_DECLS
     76 #endif
     77 
     78 /* This SDK is designed to work with clang and specific versions of
     79  * gcc >= 4.0 with Apple's patch sets */
     80 #if !defined(__GNUC__) || __GNUC__ < 4
     81 #warning "Unsupported compiler detected"
     82 #endif
     83 
     84 /*
     85  * Compatibility with compilers and environments that don't support compiler
     86  * feature checking function-like macros.
     87  */
     88 #ifndef __has_builtin
     89 #define __has_builtin(x) 0
     90 #endif
     91 #ifndef __has_include
     92 #define __has_include(x) 0
     93 #endif
     94 #ifndef __has_feature
     95 #define __has_feature(x) 0
     96 #endif
     97 #ifndef __has_attribute
     98 #define __has_attribute(x) 0
     99 #endif
    100 #ifndef __has_cpp_attribute
    101 #define __has_cpp_attribute(x) 0
    102 #endif
    103 #ifndef __has_extension
    104 #define __has_extension(x) 0
    105 #endif
    106 
    107 /*
    108  * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
    109  * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
    110  * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
    111  * in between its arguments.  __CONCAT can also concatenate double-quoted
    112  * strings produced by the __STRING macro, but this only works with ANSI C.
    113  */
    114 #if defined(__STDC__) || defined(__cplusplus)
    115 #define __P(protos)     protos          /* full-blown ANSI C */
    116 #define __CONCAT(x, y)   x ## y
    117 #define __STRING(x)     #x
    118 
    119 #define __const         const           /* define reserved names to standard */
    120 #define __signed        signed
    121 #define __volatile      volatile
    122 #if defined(__cplusplus)
    123 #define __inline        inline          /* convert to C++ keyword */
    124 #else
    125 #ifndef __GNUC__
    126 #define __inline                        /* delete GCC keyword */
    127 #endif /* !__GNUC__ */
    128 #endif /* !__cplusplus */
    129 
    130 #else   /* !(__STDC__ || __cplusplus) */
    131 #define __P(protos)     ()              /* traditional C preprocessor */
    132 #define __CONCAT(x, y)   x /**/ y
    133 #define __STRING(x)     "x"
    134 
    135 #ifndef __GNUC__
    136 #define __const                         /* delete pseudo-ANSI C keywords */
    137 #define __inline
    138 #define __signed
    139 #define __volatile
    140 #endif  /* !__GNUC__ */
    141 
    142 /*
    143  * In non-ANSI C environments, new programs will want ANSI-only C keywords
    144  * deleted from the program and old programs will want them left alone.
    145  * When using a compiler other than gcc, programs using the ANSI C keywords
    146  * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
    147  * When using "gcc -traditional", we assume that this is the intent; if
    148  * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
    149  */
    150 #ifndef NO_ANSI_KEYWORDS
    151 #define const           __const                 /* convert ANSI C keywords */
    152 #define inline          __inline
    153 #define signed          __signed
    154 #define volatile        __volatile
    155 #endif /* !NO_ANSI_KEYWORDS */
    156 #endif /* !(__STDC__ || __cplusplus) */
    157 
    158 /*
    159  * __pure2 can be used for functions that are only a function of their scalar
    160  * arguments (meaning they can't dereference pointers).
    161  *
    162  * __stateful_pure can be used for functions that have no side effects,
    163  * but depend on the state of the memory.
    164  */
    165 #define __dead2         __attribute__((__noreturn__))
    166 #define __pure2         __attribute__((__const__))
    167 #define __stateful_pure __attribute__((__pure__))
    168 
    169 /* __unused denotes variables and functions that may not be used, preventing
    170  * the compiler from warning about it if not used.
    171  */
    172 #define __unused        __attribute__((__unused__))
    173 
    174 /* __used forces variables and functions to be included even if it appears
    175  * to the compiler that they are not used (and would thust be discarded).
    176  */
    177 #define __used          __attribute__((__used__))
    178 
    179 /* __cold marks code used for debugging or that is rarely taken
    180  * and tells the compiler to optimize for size and outline code.
    181  */
    182 #if __has_attribute(cold)
    183 #define __cold          __attribute__((__cold__))
    184 #else
    185 #define __cold
    186 #endif
    187 
    188 /* __returns_nonnull marks functions that return a non-null pointer. */
    189 #if __has_attribute(returns_nonnull)
    190 #define __returns_nonnull __attribute((returns_nonnull))
    191 #else
    192 #define __returns_nonnull
    193 #endif
    194 
    195 /* __exported denotes symbols that should be exported even when symbols
    196  * are hidden by default.
    197  * __exported_push/_exported_pop are pragmas used to delimit a range of
    198  *  symbols that should be exported even when symbols are hidden by default.
    199  */
    200 #define __exported      __attribute__((__visibility__("default")))
    201 #define __exported_push _Pragma("GCC visibility push(default)")
    202 #define __exported_pop  _Pragma("GCC visibility pop")
    203 
    204 /* __deprecated causes the compiler to produce a warning when encountering
    205  * code using the deprecated functionality.
    206  * __deprecated_msg() does the same, and compilers that support it will print
    207  * a message along with the deprecation warning.
    208  * This may require turning on such warning with the -Wdeprecated flag.
    209  * __deprecated_enum_msg() should be used on enums, and compilers that support
    210  * it will print the deprecation warning.
    211  * __kpi_deprecated() specifically indicates deprecation of kernel programming
    212  * interfaces in Kernel.framework used by KEXTs.
    213  */
    214 #define __deprecated    __attribute__((__deprecated__))
    215 
    216 #if __has_extension(attribute_deprecated_with_message) || \
    217         (defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5))))
    218 	#define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
    219 #else
    220 	#define __deprecated_msg(_msg) __attribute__((__deprecated__))
    221 #endif
    222 
    223 #if __has_extension(enumerator_attributes)
    224 	#define __deprecated_enum_msg(_msg) __deprecated_msg(_msg)
    225 #else
    226 	#define __deprecated_enum_msg(_msg)
    227 #endif
    228 
    229 #define __kpi_deprecated(_msg)
    230 
    231 /* __unavailable causes the compiler to error out when encountering
    232  * code using the tagged function
    233  */
    234 #if __has_attribute(unavailable)
    235 #define __unavailable __attribute__((__unavailable__))
    236 #else
    237 #define __unavailable
    238 #endif
    239 
    240 #define __kpi_unavailable
    241 
    242 #define __kpi_deprecated_arm64_macos_unavailable
    243 
    244 /* Delete pseudo-keywords wherever they are not available or needed. */
    245 #ifndef __dead
    246 #define __dead
    247 #define __pure
    248 #endif
    249 
    250 /*
    251  * We use `__restrict' as a way to define the `restrict' type qualifier
    252  * without disturbing older software that is unaware of C99 keywords.
    253  */
    254 #if __STDC_VERSION__ < 199901
    255 #define __restrict
    256 #else
    257 #define __restrict      restrict
    258 #endif
    259 
    260 /* Compatibility with compilers and environments that don't support the
    261  * nullability feature.
    262  */
    263 
    264 #if !__has_feature(nullability)
    265 #ifndef __nullable
    266 #define __nullable
    267 #endif
    268 #ifndef __nonnull
    269 #define __nonnull
    270 #endif
    271 #ifndef __null_unspecified
    272 #define __null_unspecified
    273 #endif
    274 #ifndef _Nullable
    275 #define _Nullable
    276 #endif
    277 #ifndef _Nonnull
    278 #define _Nonnull
    279 #endif
    280 #ifndef _Null_unspecified
    281 #define _Null_unspecified
    282 #endif
    283 #endif
    284 
    285 /*
    286  * __disable_tail_calls causes the compiler to not perform tail call
    287  * optimization inside the marked function.
    288  */
    289 #if __has_attribute(disable_tail_calls)
    290 #define __disable_tail_calls    __attribute__((__disable_tail_calls__))
    291 #else
    292 #define __disable_tail_calls
    293 #endif
    294 
    295 /*
    296  * __not_tail_called causes the compiler to prevent tail call optimization
    297  * on statically bound calls to the function.  It has no effect on indirect
    298  * calls.  Virtual functions, objective-c methods, and functions marked as
    299  * "always_inline" cannot be marked as __not_tail_called.
    300  */
    301 #if __has_attribute(not_tail_called)
    302 #define __not_tail_called       __attribute__((__not_tail_called__))
    303 #else
    304 #define __not_tail_called
    305 #endif
    306 
    307 /*
    308  * __result_use_check warns callers of a function that not using the function
    309  * return value is a bug, i.e. dismissing malloc() return value results in a
    310  * memory leak.
    311  */
    312 #if __has_attribute(warn_unused_result)
    313 #define __result_use_check __attribute__((__warn_unused_result__))
    314 #else
    315 #define __result_use_check
    316 #endif
    317 
    318 /*
    319  * __swift_unavailable causes the compiler to mark a symbol as specifically
    320  * unavailable in Swift, regardless of any other availability in C.
    321  */
    322 #if __has_feature(attribute_availability_swift)
    323 #define __swift_unavailable(_msg)       __attribute__((__availability__(swift, unavailable, message=_msg)))
    324 #else
    325 #define __swift_unavailable(_msg)
    326 #endif
    327 
    328 /*
    329  * Attributes to support Swift concurrency.
    330  */
    331 #if __has_attribute(__swift_attr__)
    332 #define __swift_unavailable_from_async(_msg)    __attribute__((__swift_attr__("@_unavailableFromAsync(message: \"" _msg "\")")))
    333 #define __swift_nonisolated                     __attribute__((__swift_attr__("nonisolated")))
    334 #define __swift_nonisolated_unsafe              __attribute__((__swift_attr__("nonisolated(unsafe)")))
    335 #else
    336 #define __swift_unavailable_from_async(_msg)
    337 #define __swift_nonisolated
    338 #define __swift_nonisolated_unsafe
    339 #endif
    340 
    341 /*
    342  * __abortlike is the attribute to put on functions like abort() that are
    343  * typically used to mark assertions. These optimize the codegen
    344  * for outlining while still maintaining debugability.
    345  */
    346 #ifndef __abortlike
    347 #define __abortlike __dead2 __cold __not_tail_called
    348 #endif
    349 
    350 /* Declaring inline functions within headers is error-prone due to differences
    351  * across various versions of the C language and extensions.  __header_inline
    352  * can be used to declare inline functions within system headers.  In cases
    353  * where you want to force inlining instead of letting the compiler make
    354  * the decision, you can use __header_always_inline.
    355  *
    356  * Be aware that using inline for functions which compilers may also provide
    357  * builtins can behave differently under various compilers.  If you intend to
    358  * provide an inline version of such a function, you may want to use a macro
    359  * instead.
    360  *
    361  * The check for !__GNUC__ || __clang__ is because gcc doesn't correctly
    362  * support c99 inline in some cases:
    363  * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55965
    364  */
    365 
    366 #if defined(__cplusplus) || \
    367         (__STDC_VERSION__ >= 199901L && \
    368         !defined(__GNUC_GNU_INLINE__) && \
    369         (!defined(__GNUC__) || defined(__clang__)))
    370 # define __header_inline           inline
    371 #elif defined(__GNUC__) && defined(__GNUC_STDC_INLINE__)
    372 # define __header_inline           extern __inline __attribute__((__gnu_inline__))
    373 #elif defined(__GNUC__)
    374 # define __header_inline           extern __inline
    375 #else
    376 /* If we land here, we've encountered an unsupported compiler,
    377  * so hopefully it understands static __inline as a fallback.
    378  */
    379 # define __header_inline           static __inline
    380 #endif
    381 
    382 #ifdef __GNUC__
    383 # define __header_always_inline    __header_inline __attribute__ ((__always_inline__))
    384 #else
    385 /* Unfortunately, we're using a compiler that we don't know how to force to
    386  * inline.  Oh well.
    387  */
    388 # define __header_always_inline    __header_inline
    389 #endif
    390 
    391 /*
    392  * Compiler-dependent macros that bracket portions of code where the
    393  * "-Wunreachable-code" warning should be ignored. Please use sparingly.
    394  */
    395 #if defined(__clang__)
    396 # define __unreachable_ok_push \
    397 	 _Pragma("clang diagnostic push") \
    398 	 _Pragma("clang diagnostic ignored \"-Wunreachable-code\"")
    399 # define __unreachable_ok_pop \
    400 	 _Pragma("clang diagnostic pop")
    401 #elif defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
    402 # define __unreachable_ok_push \
    403 	 _Pragma("GCC diagnostic push") \
    404 	 _Pragma("GCC diagnostic ignored \"-Wunreachable-code\"")
    405 # define __unreachable_ok_pop \
    406 	 _Pragma("GCC diagnostic pop")
    407 #else
    408 # define __unreachable_ok_push
    409 # define __unreachable_ok_pop
    410 #endif
    411 
    412 /*
    413  * Compiler-dependent macros to declare that functions take printf-like
    414  * or scanf-like arguments.  They are null except for versions of gcc
    415  * that are known to support the features properly.  Functions declared
    416  * with these attributes will cause compilation warnings if there is a
    417  * mismatch between the format string and subsequent function parameter
    418  * types.
    419  */
    420 #define __printflike(fmtarg, firstvararg) \
    421 	__attribute__((__format__ (__printf__, fmtarg, firstvararg)))
    422 #define __printf0like(fmtarg, firstvararg) \
    423 	__attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
    424 #define __scanflike(fmtarg, firstvararg) \
    425 	__attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
    426 #define __osloglike(fmtarg, firstvararg) \
    427 	__attribute__((__format__ (__os_log__, fmtarg, firstvararg)))
    428 
    429 #define __IDSTRING(name, string) static const char name[] __used = string
    430 
    431 #ifndef __COPYRIGHT
    432 #define __COPYRIGHT(s) __IDSTRING(copyright,s)
    433 #endif
    434 
    435 #ifndef __RCSID
    436 #define __RCSID(s) __IDSTRING(rcsid,s)
    437 #endif
    438 
    439 #ifndef __SCCSID
    440 #define __SCCSID(s) __IDSTRING(sccsid,s)
    441 #endif
    442 
    443 #ifndef __PROJECT_VERSION
    444 #define __PROJECT_VERSION(s) __IDSTRING(project_version,s)
    445 #endif
    446 
    447 /* Source compatibility only, ID string not emitted in object file */
    448 #ifndef __FBSDID
    449 #define __FBSDID(s)
    450 #endif
    451 
    452 #ifndef __DECONST
    453 #define __DECONST(type, var)    __CAST_AWAY_QUALIFIER(var, const, type)
    454 #endif
    455 
    456 #ifndef __DEVOLATILE
    457 #define __DEVOLATILE(type, var) __CAST_AWAY_QUALIFIER(var, volatile, type)
    458 #endif
    459 
    460 #ifndef __DEQUALIFY
    461 #define __DEQUALIFY(type, var)  __CAST_AWAY_QUALIFIER(var, const volatile, type)
    462 #endif
    463 
    464 /*
    465  * __alloc_align can be used to label function arguments that represent the
    466  * alignment of the returned pointer.
    467  */
    468 #ifndef __alloc_align
    469 #if __has_attribute(alloc_align)
    470 #define __alloc_align(n) __attribute__((alloc_align(n)))
    471 #else
    472 #define __alloc_align(n)
    473 #endif
    474 #endif // __alloc_align
    475 
    476 /*
    477  * __alloc_size can be used to label function arguments that represent the
    478  * size of memory that the function allocates and returns. The one-argument
    479  * form labels a single argument that gives the allocation size (where the
    480  * arguments are numbered from 1):
    481  *
    482  * void	*malloc(size_t __size) __alloc_size(1);
    483  *
    484  * The two-argument form handles the case where the size is calculated as the
    485  * product of two arguments:
    486  *
    487  * void	*calloc(size_t __count, size_t __size) __alloc_size(1,2);
    488  */
    489 #ifndef __alloc_size
    490 #if __has_attribute(alloc_size)
    491 #define __alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
    492 #else
    493 #define __alloc_size(...)
    494 #endif
    495 #endif // __alloc_size
    496 
    497 /*
    498  * Facilities below assist adoption of -Wunsafe-buffer-usage, an off-by-default
    499  * Clang compiler warning that helps the developer minimize unsafe, raw
    500  * buffer manipulation in the code that may lead to buffer overflow
    501  * vulnerabilities.
    502  *
    503  * They are primarily designed for modern C++ code where -Wunsafe-buffer-usage
    504  * comes with automatic fix-it hints that help the developer transform
    505  * their code to use modern C++ containers, which may be made bounds-safe by
    506  * linking against a version of the C++ standard library that offers
    507  * bounds-checked containers.
    508  * They can be used in plain C, but -fbounds-safety is the preferred solution
    509  * for plain C (see also <ptrcheck.h>).
    510  *
    511  * Attribute __unsafe_buffer_usage can be used to label functions that should be
    512  * avoided as they may perform or otherwise introduce unsafe buffer
    513  * manipulation operations.
    514  *
    515  * Calls to such functions are flagged by -Wunsafe-buffer-usage, similarly to
    516  * how unchecked buffer manipulation operations are flagged when observed
    517  * by the compiler directly:
    518  *
    519  *   // An unsafe function that needs to be avoided.
    520  *   __unsafe_buffer_usage
    521  *   void foo(int *buf, size_t size);
    522  *
    523  *   // A safe alternative to foo().
    524  *   void foo(std::span<int> buf);
    525  *
    526  *   void bar(size_t idx) {
    527  *       int array[5];
    528  *
    529  *       // Direct unsafe buffer manipulation through subscript operator:
    530  *       array[idx] = 3;  // warning [-Wunsafe-buffer-usage]
    531  *       // Unsafe buffer manipulation through function foo():
    532  *       foo(array, 5);   // warning [-Wunsafe-buffer-usage]
    533  *       // Checked buffer manipulation, with bounds information automatically
    534  *       // preserved for the purposes of runtime checks in standard library:
    535  *       foo(array);      // no warning
    536  *   }
    537  *
    538  * While annotating a function as __unsafe_buffer_usage has an effect similar
    539  * to annotating it as __deprecated, the __unsafe_buffer_usage attribute
    540  * should be used whenever the resulting warning needs to be controlled
    541  * by the -Wunsafe-buffer-usage flag (which is turned off in codebases that
    542  * don't attempt to achieve bounds safety this way) as opposed to -Wdeprecated
    543  * (enabled in most codebases).
    544  *
    545  * The attribute does NOT suppress -Wunsafe-buffer-usage warnings inside
    546  * the function's body; it simply introduces new warnings at each call site
    547  * to help the developers avoid the function entirely. Most of the time
    548  * it does not make sense to annotate a function as __unsafe_buffer_usage
    549  * without providing the users with a safe alternative.
    550  *
    551  * Pragmas __unsafe_buffer_usage_begin and __unsafe_buffer_usage_end
    552  * annotate a range of code as intentionally containing unsafe buffer
    553  * operations. They suppress -Wunsafe-buffer-usage warnings
    554  * for unsafe operations in range:
    555  *
    556  *   __unsafe_buffer_usage_begin
    557  *   array[idx] = 3; // warning suppressed
    558  *   foo(array, 5);  // warning suppressed
    559  *   __unsafe_buffer_usage_end
    560  *
    561  * These pragmas are NOT a way to mass-annotate functions with the attribute
    562  * __unsafe_buffer_usage. Functions declared within the pragma range
    563  * do NOT get annotated automatically. In some rare situations it makes sense
    564  * to do all three: put the attribute on the function, put pragmas inside
    565  * the body of the function, and put pragmas around some call sites.
    566  */
    567 #if __has_cpp_attribute(clang::unsafe_buffer_usage)
    568 #define __has_safe_buffers 1
    569 #define __unsafe_buffer_usage [[clang::unsafe_buffer_usage]]
    570 #elif __has_attribute(unsafe_buffer_usage)
    571 #define __has_safe_buffers 1
    572 #define __unsafe_buffer_usage __attribute__((__unsafe_buffer_usage__))
    573 #else
    574 #define __has_safe_buffers 0
    575 #define __unsafe_buffer_usage
    576 #endif
    577 #if __has_safe_buffers
    578 #define __unsafe_buffer_usage_begin _Pragma("clang unsafe_buffer_usage begin")
    579 #define __unsafe_buffer_usage_end   _Pragma("clang unsafe_buffer_usage end")
    580 #else
    581 #define __unsafe_buffer_usage_begin
    582 #define __unsafe_buffer_usage_end
    583 #endif
    584 
    585 /*
    586  * COMPILATION ENVIRONMENTS -- see compat(5) for additional detail
    587  *
    588  * DEFAULT	By default newly complied code will get POSIX APIs plus
    589  *		Apple API extensions in scope.
    590  *
    591  *		Most users will use this compilation environment to avoid
    592  *		behavioral differences between 32 and 64 bit code.
    593  *
    594  * LEGACY	Defining _NONSTD_SOURCE will get pre-POSIX APIs plus Apple
    595  *		API extensions in scope.
    596  *
    597  *		This is generally equivalent to the Tiger release compilation
    598  *		environment, except that it cannot be applied to 64 bit code;
    599  *		its use is discouraged.
    600  *
    601  *		We expect this environment to be deprecated in the future.
    602  *
    603  * STRICT	Defining _POSIX_C_SOURCE or _XOPEN_SOURCE restricts the
    604  *		available APIs to exactly the set of APIs defined by the
    605  *		corresponding standard, based on the value defined.
    606  *
    607  *		A correct, portable definition for _POSIX_C_SOURCE is 200112L.
    608  *		A correct, portable definition for _XOPEN_SOURCE is 600L.
    609  *
    610  *		Apple API extensions are not visible in this environment,
    611  *		which can cause Apple specific code to fail to compile,
    612  *		or behave incorrectly if prototypes are not in scope or
    613  *		warnings about missing prototypes are not enabled or ignored.
    614  *
    615  * In any compilation environment, for correct symbol resolution to occur,
    616  * function prototypes must be in scope.  It is recommended that all Apple
    617  * tools users add either the "-Wall" or "-Wimplicit-function-declaration"
    618  * compiler flags to their projects to be warned when a function is being
    619  * used without a prototype in scope.
    620  */
    621 
    622 /* These settings are particular to each product. */
    623 /* Platform: MacOSX */
    624 #if defined(__i386__)
    625 #define __DARWIN_ONLY_64_BIT_INO_T      0
    626 #define __DARWIN_ONLY_UNIX_CONFORMANCE  0
    627 #define __DARWIN_ONLY_VERS_1050         0
    628 #elif defined(__x86_64__)
    629 #define __DARWIN_ONLY_64_BIT_INO_T      0
    630 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
    631 #define __DARWIN_ONLY_VERS_1050         0
    632 #else
    633 #define __DARWIN_ONLY_64_BIT_INO_T      1
    634 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
    635 #define __DARWIN_ONLY_VERS_1050         1
    636 #endif
    637 
    638 /*
    639  * The __DARWIN_ALIAS macros are used to do symbol renaming; they allow
    640  * legacy code to use the old symbol, thus maintaining binary compatibility
    641  * while new code can use a standards compliant version of the same function.
    642  *
    643  * __DARWIN_ALIAS is used by itself if the function signature has not
    644  * changed, it is used along with a #ifdef check for __DARWIN_UNIX03
    645  * if the signature has changed.  Because the __LP64__ environment
    646  * only supports UNIX03 semantics it causes __DARWIN_UNIX03 to be
    647  * defined, but causes __DARWIN_ALIAS to do no symbol mangling.
    648  *
    649  * As a special case, when XCode is used to target a specific version of the
    650  * OS, the manifest constant __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
    651  * will be defined by the compiler, with the digits representing major version
    652  * time 100 + minor version times 10 (e.g. 10.5 := 1050).  If we are targeting
    653  * pre-10.5, and it is the default compilation environment, revert the
    654  * compilation environment to pre-__DARWIN_UNIX03.
    655  */
    656 #if !defined(__DARWIN_UNIX03)
    657 #  if   __DARWIN_ONLY_UNIX_CONFORMANCE
    658 #    if defined(_NONSTD_SOURCE)
    659 #      error "Can't define _NONSTD_SOURCE when only UNIX conformance is available."
    660 #    endif /* _NONSTD_SOURCE */
    661 #    define __DARWIN_UNIX03     1
    662 #  elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1040)
    663 #    define __DARWIN_UNIX03     0
    664 #  elif defined(_DARWIN_C_SOURCE) || defined(_XOPEN_SOURCE) || defined(_POSIX_C_SOURCE)
    665 #    if defined(_NONSTD_SOURCE)
    666 #      error "Can't define both _NONSTD_SOURCE and any of _DARWIN_C_SOURCE, _XOPEN_SOURCE or _POSIX_C_SOURCE."
    667 #    endif /* _NONSTD_SOURCE */
    668 #    define __DARWIN_UNIX03     1
    669 #  elif defined(_NONSTD_SOURCE)
    670 #    define __DARWIN_UNIX03     0
    671 #  else /* default */
    672 #    if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1050)
    673 #      define __DARWIN_UNIX03   0
    674 #    else /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 */
    675 #      define __DARWIN_UNIX03   1
    676 #    endif /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 */
    677 #  endif /* _DARWIN_C_SOURCE || _XOPEN_SOURCE || _POSIX_C_SOURCE || __LP64__ */
    678 #endif /* !__DARWIN_UNIX03 */
    679 
    680 #if !defined(__DARWIN_64_BIT_INO_T)
    681 #  if   defined(_DARWIN_USE_64_BIT_INODE)
    682 #    if defined(_DARWIN_NO_64_BIT_INODE)
    683 #      error "Can't define both _DARWIN_USE_64_BIT_INODE and _DARWIN_NO_64_BIT_INODE."
    684 #    endif /* _DARWIN_NO_64_BIT_INODE */
    685 #    define __DARWIN_64_BIT_INO_T 1
    686 #  elif defined(_DARWIN_NO_64_BIT_INODE)
    687 #    if __DARWIN_ONLY_64_BIT_INO_T
    688 #      error "Can't define _DARWIN_NO_64_BIT_INODE when only 64-bit inodes are available."
    689 #    endif /* __DARWIN_ONLY_64_BIT_INO_T */
    690 #    define __DARWIN_64_BIT_INO_T 0
    691 #  else /* default */
    692 #    if __DARWIN_ONLY_64_BIT_INO_T
    693 #      define __DARWIN_64_BIT_INO_T 1
    694 #    elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1060) || __DARWIN_UNIX03 == 0
    695 #      define __DARWIN_64_BIT_INO_T 0
    696 #    else /* default */
    697 #      define __DARWIN_64_BIT_INO_T 1
    698 #    endif /* __DARWIN_ONLY_64_BIT_INO_T */
    699 #  endif
    700 #endif /* !__DARWIN_64_BIT_INO_T */
    701 
    702 #if !defined(__DARWIN_VERS_1050)
    703 #  if   __DARWIN_ONLY_VERS_1050
    704 #    define __DARWIN_VERS_1050 1
    705 #  elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1050) || __DARWIN_UNIX03 == 0
    706 #    define __DARWIN_VERS_1050 0
    707 #  else /* default */
    708 #    define __DARWIN_VERS_1050 1
    709 #  endif
    710 #endif /* !__DARWIN_VERS_1050 */
    711 
    712 #if !defined(__DARWIN_NON_CANCELABLE)
    713 #    define __DARWIN_NON_CANCELABLE 0
    714 #endif /* !__DARWIN_NON_CANCELABLE */
    715 
    716 /*
    717  * symbol suffixes used for symbol versioning
    718  */
    719 #if __DARWIN_UNIX03
    720 #  if __DARWIN_ONLY_UNIX_CONFORMANCE
    721 #    define __DARWIN_SUF_UNIX03         /* nothing */
    722 #  else /* !__DARWIN_ONLY_UNIX_CONFORMANCE */
    723 #    define __DARWIN_SUF_UNIX03         "$UNIX2003"
    724 #  endif /* __DARWIN_ONLY_UNIX_CONFORMANCE */
    725 
    726 #  if __DARWIN_64_BIT_INO_T
    727 #    if __DARWIN_ONLY_64_BIT_INO_T
    728 #      define __DARWIN_SUF_64_BIT_INO_T /* nothing */
    729 #    else /* !__DARWIN_ONLY_64_BIT_INO_T */
    730 #      define __DARWIN_SUF_64_BIT_INO_T "$INODE64"
    731 #    endif /* __DARWIN_ONLY_64_BIT_INO_T */
    732 #  else /* !__DARWIN_64_BIT_INO_T */
    733 #    define __DARWIN_SUF_64_BIT_INO_T   /* nothing */
    734 #  endif /* __DARWIN_64_BIT_INO_T */
    735 
    736 #  if __DARWIN_VERS_1050
    737 #    if __DARWIN_ONLY_VERS_1050
    738 #      define __DARWIN_SUF_1050         /* nothing */
    739 #    else /* !__DARWIN_ONLY_VERS_1050 */
    740 #      define __DARWIN_SUF_1050         "$1050"
    741 #    endif /* __DARWIN_ONLY_VERS_1050 */
    742 #  else /* !__DARWIN_VERS_1050 */
    743 #    define __DARWIN_SUF_1050           /* nothing */
    744 #  endif /* __DARWIN_VERS_1050 */
    745 
    746 #  if __DARWIN_NON_CANCELABLE
    747 #    define __DARWIN_SUF_NON_CANCELABLE "$NOCANCEL"
    748 #  else /* !__DARWIN_NON_CANCELABLE */
    749 #    define __DARWIN_SUF_NON_CANCELABLE /* nothing */
    750 #  endif /* __DARWIN_NON_CANCELABLE */
    751 
    752 #else /* !__DARWIN_UNIX03 */
    753 #  define __DARWIN_SUF_UNIX03           /* nothing */
    754 #  define __DARWIN_SUF_64_BIT_INO_T     /* nothing */
    755 #  define __DARWIN_SUF_NON_CANCELABLE   /* nothing */
    756 #  define __DARWIN_SUF_1050             /* nothing */
    757 #endif /* __DARWIN_UNIX03 */
    758 
    759 #define __DARWIN_SUF_EXTSN              "$DARWIN_EXTSN"
    760 
    761 /*
    762  * symbol versioning macros
    763  */
    764 #define __DARWIN_ALIAS(sym)             __asm("_" __STRING(sym) __DARWIN_SUF_UNIX03)
    765 #define __DARWIN_ALIAS_C(sym)           __asm("_" __STRING(sym) __DARWIN_SUF_NON_CANCELABLE __DARWIN_SUF_UNIX03)
    766 #define __DARWIN_ALIAS_I(sym)           __asm("_" __STRING(sym) __DARWIN_SUF_64_BIT_INO_T __DARWIN_SUF_UNIX03)
    767 #define __DARWIN_NOCANCEL(sym)          __asm("_" __STRING(sym) __DARWIN_SUF_NON_CANCELABLE)
    768 #define __DARWIN_INODE64(sym)           __asm("_" __STRING(sym) __DARWIN_SUF_64_BIT_INO_T)
    769 
    770 #define __DARWIN_1050(sym)              __asm("_" __STRING(sym) __DARWIN_SUF_1050)
    771 #define __DARWIN_1050ALIAS(sym)         __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_UNIX03)
    772 #define __DARWIN_1050ALIAS_C(sym)       __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_NON_CANCELABLE __DARWIN_SUF_UNIX03)
    773 #define __DARWIN_1050ALIAS_I(sym)       __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_64_BIT_INO_T __DARWIN_SUF_UNIX03)
    774 #define __DARWIN_1050INODE64(sym)       __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_64_BIT_INO_T)
    775 
    776 #define __DARWIN_EXTSN(sym)             __asm("_" __STRING(sym) __DARWIN_SUF_EXTSN)
    777 #define __DARWIN_EXTSN_C(sym)           __asm("_" __STRING(sym) __DARWIN_SUF_EXTSN __DARWIN_SUF_NON_CANCELABLE)
    778 
    779 /*
    780  * symbol release macros
    781  */
    782 #include <sys/_symbol_aliasing.h>
    783 
    784 #if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
    785 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x)   __DARWIN_ALIAS_STARTING_IPHONE_##_iphone(x)
    786 #elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
    787 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x)   __DARWIN_ALIAS_STARTING_MAC_##_mac(x)
    788 #else
    789 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x)   x
    790 #endif
    791 
    792 
    793 /*
    794  * POSIX.1 requires that the macros we test be defined before any standard
    795  * header file is included.  This permits us to convert values for feature
    796  * testing, as necessary, using only _POSIX_C_SOURCE.
    797  *
    798  * Here's a quick run-down of the versions:
    799  *  defined(_POSIX_SOURCE)		1003.1-1988
    800  *  _POSIX_C_SOURCE == 1L		1003.1-1990
    801  *  _POSIX_C_SOURCE == 2L		1003.2-1992 C Language Binding Option
    802  *  _POSIX_C_SOURCE == 199309L		1003.1b-1993
    803  *  _POSIX_C_SOURCE == 199506L		1003.1c-1995, 1003.1i-1995,
    804  *					and the omnibus ISO/IEC 9945-1: 1996
    805  *  _POSIX_C_SOURCE == 200112L		1003.1-2001
    806  *  _POSIX_C_SOURCE == 200809L		1003.1-2008
    807  *
    808  * In addition, the X/Open Portability Guide, which is now the Single UNIX
    809  * Specification, defines a feature-test macro which indicates the version of
    810  * that specification, and which subsumes _POSIX_C_SOURCE.
    811  */
    812 
    813 /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1L. */
    814 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1L
    815 #undef _POSIX_C_SOURCE
    816 #define _POSIX_C_SOURCE         199009L
    817 #endif
    818 
    819 /* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2L. */
    820 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2L
    821 #undef _POSIX_C_SOURCE
    822 #define _POSIX_C_SOURCE         199209L
    823 #endif
    824 
    825 /* Deal with various X/Open Portability Guides and Single UNIX Spec. */
    826 #ifdef _XOPEN_SOURCE
    827 #if _XOPEN_SOURCE - 0L >= 700L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 200809L)
    828 #undef _POSIX_C_SOURCE
    829 #define _POSIX_C_SOURCE         200809L
    830 #elif _XOPEN_SOURCE - 0L >= 600L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 200112L)
    831 #undef _POSIX_C_SOURCE
    832 #define _POSIX_C_SOURCE         200112L
    833 #elif _XOPEN_SOURCE - 0L >= 500L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 199506L)
    834 #undef _POSIX_C_SOURCE
    835 #define _POSIX_C_SOURCE         199506L
    836 #endif
    837 #endif
    838 
    839 /*
    840  * Deal with all versions of POSIX.  The ordering relative to the tests above is
    841  * important.
    842  */
    843 #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
    844 #define _POSIX_C_SOURCE         198808L
    845 #endif
    846 
    847 /* POSIX C deprecation macros */
    848 #include <sys/_posix_availability.h>
    849 
    850 #define __POSIX_C_DEPRECATED(ver) ___POSIX_C_DEPRECATED_STARTING_##ver
    851 
    852 /*
    853  * Set a single macro which will always be defined and can be used to determine
    854  * the appropriate namespace.  For POSIX, these values will correspond to
    855  * _POSIX_C_SOURCE value.  Currently there are two additional levels corresponding
    856  * to ANSI (_ANSI_SOURCE) and Darwin extensions (_DARWIN_C_SOURCE)
    857  */
    858 #define __DARWIN_C_ANSI         010000L
    859 #define __DARWIN_C_FULL         900000L
    860 
    861 #if   defined(_ANSI_SOURCE)
    862 #define __DARWIN_C_LEVEL        __DARWIN_C_ANSI
    863 #elif defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE) && !defined(_NONSTD_SOURCE)
    864 #define __DARWIN_C_LEVEL        _POSIX_C_SOURCE
    865 #else
    866 #define __DARWIN_C_LEVEL        __DARWIN_C_FULL
    867 #endif
    868 
    869 /* If the developer has neither requested a strict language mode nor a version
    870  * of POSIX, turn on functionality provided by __STDC_WANT_LIB_EXT1__ as part
    871  * of __DARWIN_C_FULL.
    872  */
    873 #if !defined(__STDC_WANT_LIB_EXT1__) && !defined(__STRICT_ANSI__) && __DARWIN_C_LEVEL >= __DARWIN_C_FULL
    874 #define __STDC_WANT_LIB_EXT1__ 1
    875 #endif
    876 
    877 /*
    878  * long long is not supported in c89 (__STRICT_ANSI__), but g++ -ansi and
    879  * c99 still want long longs.  While not perfect, we allow long longs for
    880  * g++.
    881  */
    882 #if (defined(__STRICT_ANSI__) && (__STDC_VERSION__ - 0 < 199901L) && !defined(__GNUG__))
    883 #define __DARWIN_NO_LONG_LONG 1
    884 #else
    885 #define __DARWIN_NO_LONG_LONG 0
    886 #endif
    887 
    888 /*****************************************
    889 *  Public darwin-specific feature macros
    890 *****************************************/
    891 
    892 /*
    893  * _DARWIN_FEATURE_64_BIT_INODE indicates that the ino_t type is 64-bit, and
    894  * structures modified for 64-bit inodes (like struct stat) will be used.
    895  */
    896 #if __DARWIN_64_BIT_INO_T
    897 #define _DARWIN_FEATURE_64_BIT_INODE            1
    898 #endif
    899 
    900 /*
    901  * _DARWIN_FEATURE_64_ONLY_BIT_INODE indicates that the ino_t type may only
    902  * be 64-bit; there is no support for 32-bit ino_t when this macro is defined
    903  * (and non-zero).  There is no struct stat64 either, as the regular
    904  * struct stat will already be the 64-bit version.
    905  */
    906 #if __DARWIN_ONLY_64_BIT_INO_T
    907 #define _DARWIN_FEATURE_ONLY_64_BIT_INODE       1
    908 #endif
    909 
    910 /*
    911  * _DARWIN_FEATURE_ONLY_VERS_1050 indicates that only those APIs updated
    912  * in 10.5 exists; no pre-10.5 variants are available.
    913  */
    914 #if __DARWIN_ONLY_VERS_1050
    915 #define _DARWIN_FEATURE_ONLY_VERS_1050          1
    916 #endif
    917 
    918 /*
    919  * _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE indicates only UNIX conforming API
    920  * are available (the legacy BSD APIs are not available)
    921  */
    922 #if __DARWIN_ONLY_UNIX_CONFORMANCE
    923 #define _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE   1
    924 #endif
    925 
    926 /*
    927  * _DARWIN_FEATURE_UNIX_CONFORMANCE indicates whether UNIX conformance is on,
    928  * and specifies the conformance level (3 is SUSv3)
    929  */
    930 #if __DARWIN_UNIX03
    931 #define _DARWIN_FEATURE_UNIX_CONFORMANCE        3
    932 #endif
    933 
    934 
    935 /*
    936  * This macro casts away the qualifier from the variable
    937  *
    938  * Note: use at your own risk, removing qualifiers can result in
    939  * catastrophic run-time failures.
    940  */
    941 #ifndef __CAST_AWAY_QUALIFIER
    942 /*
    943  * XXX: this shouldn't ignore anything more than -Wcast-qual,
    944  * but the old implementation made it an almighty cast that
    945  * ignored everything, so things break left and right if you
    946  * make it only ignore -Wcast-qual.
    947  */
    948 #define __CAST_AWAY_QUALIFIER(variable, qualifier, type) \
    949 	_Pragma("GCC diagnostic push") \
    950 	_Pragma("GCC diagnostic ignored \"-Wcast-qual\"") \
    951 	_Pragma("GCC diagnostic ignored \"-Wcast-align\"") \
    952 	_Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"") \
    953 	((type)(variable)) \
    954 	_Pragma("GCC diagnostic pop")
    955 #endif
    956 
    957 /*
    958  * __XNU_PRIVATE_EXTERN is a linkage decoration indicating that a symbol can be
    959  * used from other compilation units, but not other libraries or executables.
    960  */
    961 #ifndef __XNU_PRIVATE_EXTERN
    962 #define __XNU_PRIVATE_EXTERN __attribute__((visibility("hidden")))
    963 #endif
    964 
    965 #if __has_include(<ptrcheck.h>)
    966 #include <ptrcheck.h>
    967 #else
    968 #if __has_feature(bounds_safety)
    969 #error -fbounds-safety is enabled, but <ptrcheck.h> is missing. \
    970         This will lead to difficult-to-diagnose compilation errors.
    971 #endif /* __has_feature(bounds_safety) */
    972 
    973 /*
    974  * We intentionally define to nothing pointer attributes which do not have an
    975  * impact on the ABI. __indexable and __bidi_indexable are not defined because
    976  * of the ABI incompatibility that makes the diagnostic preferable.
    977  */
    978 #define __has_ptrcheck 0
    979 #define __single
    980 #define __unsafe_indexable
    981 #define __counted_by(N)
    982 #define __counted_by_or_null(N)
    983 #define __sized_by(N)
    984 #define __sized_by_or_null(N)
    985 #define __ended_by(E)
    986 #define __terminated_by(T)
    987 #define __null_terminated
    988 
    989 /*
    990  * Similarly, we intentionally define to nothing the
    991  * __ptrcheck_abi_assume_single and __ptrcheck_abi_assume_unsafe_indexable
    992  * macros because they do not lead to an ABI incompatibility. However, we do not
    993  * define the indexable and unsafe_indexable ones because the diagnostic is
    994  * better than the silent ABI break.
    995  */
    996 #define __ptrcheck_abi_assume_single()
    997 #define __ptrcheck_abi_assume_unsafe_indexable()
    998 
    999 /* __unsafe_forge intrinsics are defined as regular C casts. */
   1000 #define __unsafe_forge_bidi_indexable(T, P, S) ((T)(P))
   1001 #define __unsafe_forge_single(T, P) ((T)(P))
   1002 #define __unsafe_forge_terminated_by(T, P, E) ((T)(P))
   1003 #define __unsafe_forge_null_terminated(T, P) ((T)(P))
   1004 #define __terminated_by_to_indexable(P) (P)
   1005 #define __unsafe_terminated_by_to_indexable(P) (P)
   1006 #define __null_terminated_to_indexable(P) (P)
   1007 #define __unsafe_null_terminated_to_indexable(P) (P)
   1008 #define __unsafe_terminated_by_from_indexable(T, P, ...) (P)
   1009 #define __unsafe_null_terminated_from_indexable(P, ...) (P)
   1010 
   1011 /* decay operates normally; attribute is meaningless without pointer checks. */
   1012 #define __array_decay_dicards_count_in_parameters
   1013 
   1014 /* this is a write-once variable; not useful without pointer checks. */
   1015 #define __unsafe_late_const
   1016 
   1017 #define __ptrcheck_unavailable
   1018 #define __ptrcheck_unavailable_r(REPLACEMENT)
   1019 
   1020 #endif /* !__has_include(<ptrcheck.h>) */
   1021 
   1022 
   1023 #define __ASSUME_PTR_ABI_SINGLE_BEGIN       __ptrcheck_abi_assume_single()
   1024 #define __ASSUME_PTR_ABI_SINGLE_END         __ptrcheck_abi_assume_unsafe_indexable()
   1025 
   1026 #if __has_ptrcheck
   1027 #define __header_indexable                  __indexable
   1028 #define __header_bidi_indexable             __bidi_indexable
   1029 #else
   1030 #define __header_indexable
   1031 #define __header_bidi_indexable
   1032 #endif
   1033 
   1034 /*
   1035  * Architecture validation for current SDK
   1036  */
   1037 #if !defined(__sys_cdefs_arch_unknown__) && defined(__i386__)
   1038 #elif !defined(__sys_cdefs_arch_unknown__) && defined(__x86_64__)
   1039 #elif !defined(__sys_cdefs_arch_unknown__) && defined(__arm__)
   1040 #elif !defined(__sys_cdefs_arch_unknown__) && defined(__arm64__)
   1041 #else
   1042 #error Unsupported architecture
   1043 #endif
   1044 
   1045 
   1046 
   1047 #define __compiler_barrier() __asm__ __volatile__("" ::: "memory")
   1048 
   1049 #if __has_attribute(enum_extensibility)
   1050 #define __enum_open __attribute__((__enum_extensibility__(open)))
   1051 #define __enum_closed __attribute__((__enum_extensibility__(closed)))
   1052 #else
   1053 #define __enum_open
   1054 #define __enum_closed
   1055 #endif // __has_attribute(enum_extensibility)
   1056 
   1057 #if __has_attribute(flag_enum)
   1058 #define __enum_options __attribute__((__flag_enum__))
   1059 #else
   1060 #define __enum_options
   1061 #endif
   1062 
   1063 /*
   1064  * Similar to OS_ENUM/OS_CLOSED_ENUM/OS_OPTIONS/OS_CLOSED_OPTIONS
   1065  *
   1066  * This provides more advanced type checking on compilers supporting
   1067  * the proper extensions, even in C.
   1068  */
   1069 #if __has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum) || \
   1070         __has_extension(cxx_strong_enums)
   1071 #define __enum_decl(_name, _type, ...) \
   1072 	        typedef enum : _type __VA_ARGS__ __enum_open _name
   1073 #define __enum_closed_decl(_name, _type, ...) \
   1074 	        typedef enum : _type __VA_ARGS__ __enum_closed _name
   1075 #define __options_decl(_name, _type, ...) \
   1076 	        typedef enum : _type __VA_ARGS__ __enum_open __enum_options _name
   1077 #define __options_closed_decl(_name, _type, ...) \
   1078 	        typedef enum : _type __VA_ARGS__ __enum_closed __enum_options _name
   1079 #else
   1080 #define __enum_decl(_name, _type, ...) \
   1081 	        typedef _type _name; enum __VA_ARGS__ __enum_open
   1082 #define __enum_closed_decl(_name, _type, ...) \
   1083 	        typedef _type _name; enum __VA_ARGS__ __enum_closed
   1084 #define __options_decl(_name, _type, ...) \
   1085 	        typedef _type _name; enum __VA_ARGS__ __enum_open __enum_options
   1086 #define __options_closed_decl(_name, _type, ...) \
   1087 	        typedef _type _name; enum __VA_ARGS__ __enum_closed __enum_options
   1088 #endif
   1089 
   1090 
   1091 
   1092 #define __kernel_ptr_semantics
   1093 #define __kernel_data_semantics
   1094 #define __kernel_dual_semantics
   1095 
   1096 
   1097 
   1098 #if defined(KERNEL_PRIVATE) && \
   1099         __has_attribute(xnu_data_size) && \
   1100         __has_attribute(xnu_returns_data_pointer)
   1101 /*
   1102  * Annotate function parameters to specify that they semantically
   1103  * represent the size of a data-only backing storage.
   1104  */
   1105 # define __xnu_data_size __attribute__((xnu_data_size))
   1106 /*
   1107  * Annotate function declarations to specify that the pointer they return
   1108  * points to a data-only backing storage.
   1109  */
   1110 # define __xnu_returns_data_pointer __attribute__((xnu_returns_data_pointer))
   1111 #else
   1112 # define __xnu_data_size
   1113 # define __xnu_returns_data_pointer
   1114 #endif
   1115 
   1116 
   1117 #endif /* !_CDEFS_H_ */