]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/cdefs.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / bsd / sys / cdefs.h
CommitLineData
1c79356b 1/*
d9a64523 2 * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
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.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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
0a7de745
A
67#ifndef _CDEFS_H_
68#define _CDEFS_H_
1c79356b
A
69
70#if defined(__cplusplus)
0a7de745
A
71#define __BEGIN_DECLS extern "C" {
72#define __END_DECLS }
1c79356b 73#else
0a7de745
A
74#define __BEGIN_DECLS
75#define __END_DECLS
1c79356b
A
76#endif
77
316670eb
A
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
3e170ce0
A
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_extension
101#define __has_extension(x) 0
102#endif
103
1c79356b
A
104/*
105 * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
106 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
107 * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
108 * in between its arguments. __CONCAT can also concatenate double-quoted
109 * strings produced by the __STRING macro, but this only works with ANSI C.
110 */
111#if defined(__STDC__) || defined(__cplusplus)
0a7de745
A
112#define __P(protos) protos /* full-blown ANSI C */
113#define __CONCAT(x, y) x ## y
114#define __STRING(x) #x
1c79356b 115
0a7de745
A
116#define __const const /* define reserved names to standard */
117#define __signed signed
118#define __volatile volatile
1c79356b 119#if defined(__cplusplus)
0a7de745 120#define __inline inline /* convert to C++ keyword */
1c79356b
A
121#else
122#ifndef __GNUC__
0a7de745 123#define __inline /* delete GCC keyword */
1c79356b
A
124#endif /* !__GNUC__ */
125#endif /* !__cplusplus */
126
0a7de745
A
127#else /* !(__STDC__ || __cplusplus) */
128#define __P(protos) () /* traditional C preprocessor */
129#define __CONCAT(x, y) x /**/ y
130#define __STRING(x) "x"
1c79356b
A
131
132#ifndef __GNUC__
0a7de745
A
133#define __const /* delete pseudo-ANSI C keywords */
134#define __inline
135#define __signed
136#define __volatile
137#endif /* !__GNUC__ */
1c79356b
A
138
139/*
140 * In non-ANSI C environments, new programs will want ANSI-only C keywords
141 * deleted from the program and old programs will want them left alone.
142 * When using a compiler other than gcc, programs using the ANSI C keywords
143 * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
144 * When using "gcc -traditional", we assume that this is the intent; if
145 * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
146 */
0a7de745
A
147#ifndef NO_ANSI_KEYWORDS
148#define const __const /* convert ANSI C keywords */
149#define inline __inline
150#define signed __signed
151#define volatile __volatile
1c79356b
A
152#endif /* !NO_ANSI_KEYWORDS */
153#endif /* !(__STDC__ || __cplusplus) */
154
cb323159
A
155#define __dead2 __attribute__((__noreturn__))
156#define __pure2 __attribute__((__const__))
316670eb
A
157
158/* __unused denotes variables and functions that may not be used, preventing
159 * the compiler from warning about it if not used.
1c79356b 160 */
cb323159 161#define __unused __attribute__((__unused__))
316670eb
A
162
163/* __used forces variables and functions to be included even if it appears
164 * to the compiler that they are not used (and would thust be discarded).
165 */
cb323159
A
166#define __used __attribute__((__used__))
167
168/* __cold marks code used for debugging or that is rarely taken
169 * and tells the compiler to optimize for size and outline code.
170 */
171#if __has_attribute(cold)
172#define __cold __attribute__((__cold__))
173#else
174#define __cold
175#endif
316670eb 176
f427ee49
A
177/* __exported denotes symbols that should be exported even when symbols
178 * are hidden by default.
179 * __exported_push/_exported_pop are pragmas used to delimit a range of
180 * symbols that should be exported even when symbols are hidden by default.
181 */
182#define __exported __attribute__((__visibility__("default")))
183#define __exported_push _Pragma("GCC visibility push(default)")
184#define __exported_pop _Pragma("GCC visibility pop")
185
316670eb 186/* __deprecated causes the compiler to produce a warning when encountering
39236c6e
A
187 * code using the deprecated functionality.
188 * __deprecated_msg() does the same, and compilers that support it will print
189 * a message along with the deprecation warning.
190 * This may require turning on such warning with the -Wdeprecated flag.
191 * __deprecated_enum_msg() should be used on enums, and compilers that support
192 * it will print the deprecation warning.
cb323159
A
193 * __kpi_deprecated() specifically indicates deprecation of kernel programming
194 * interfaces in Kernel.framework used by KEXTs.
316670eb 195 */
cb323159 196#define __deprecated __attribute__((__deprecated__))
316670eb 197
3e170ce0 198#if __has_extension(attribute_deprecated_with_message) || \
0a7de745 199 (defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5))))
cb323159 200 #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
39236c6e 201#else
cb323159 202 #define __deprecated_msg(_msg) __attribute__((__deprecated__))
39236c6e
A
203#endif
204
3e170ce0
A
205#if __has_extension(enumerator_attributes)
206 #define __deprecated_enum_msg(_msg) __deprecated_msg(_msg)
39236c6e 207#else
3e170ce0 208 #define __deprecated_enum_msg(_msg)
39236c6e
A
209#endif
210
cb323159
A
211#if defined(KERNEL) && !defined(KERNEL_PRIVATE)
212#define __kpi_deprecated(_msg) __deprecated_msg(_msg)
213#else /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */
214#define __kpi_deprecated(_msg)
215#endif /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */
216
316670eb 217/* __unavailable causes the compiler to error out when encountering
f427ee49
A
218 * code using the tagged function
219 */
220#if __has_attribute(unavailable)
221#define __unavailable __attribute__((__unavailable__))
222#else
223#define __unavailable
224#endif
225
226#if defined(KERNEL) && !defined(KERNEL_PRIVATE)
227#define __kpi_unavailable __unavailable
228#else /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */
229#define __kpi_unavailable
230#endif /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */
231
232#if defined(KERNEL)
233#if defined(XNU_KERNEL_PRIVATE)
234/* This macro is meant to be used for kpi deprecated to x86 3rd parties
235 * but should be marked as unavailable for arm macOS devices.
236 * XNU: nothing (API is still available)
237 * 1st party kexts: __deprecated
238 * 3rd party kexts macOS x86: __deprecated
239 * 3rd party kexts macOS arm: __unavailable
316670eb 240 */
f427ee49
A
241#define __kpi_deprecated_arm64_macos_unavailable
242#elif defined(KERNEL_PRIVATE)
243#define __kpi_deprecated_arm64_macos_unavailable __deprecated
244#else /* !defined(XNU_KERNEL_PRIVATE) */
245#if TARGET_OS_OSX && defined(__arm64__)
246#define __kpi_deprecated_arm64_macos_unavailable __unavailable
247#else /* !TARGET_OS_OSX || !defined(__arm64__) */
248#define __kpi_deprecated_arm64_macos_unavailable __deprecated
249#endif /* !TARGET_OS_OSX || !defined(__arm64__) */
250#endif /* !defined(XNU_KERNEL_PRIVATE) */
251#else /* !defined(KERNEL) */
252#define __kpi_deprecated_arm64_macos_unavailable
253#endif /* !defined(KERNEL) */
1c79356b
A
254
255/* Delete pseudo-keywords wherever they are not available or needed. */
256#ifndef __dead
0a7de745
A
257#define __dead
258#define __pure
1c79356b 259#endif
6d2010ae 260
91447636 261/*
316670eb
A
262 * We use `__restrict' as a way to define the `restrict' type qualifier
263 * without disturbing older software that is unaware of C99 keywords.
91447636 264 */
91447636
A
265#if __STDC_VERSION__ < 199901
266#define __restrict
267#else
0a7de745 268#define __restrict restrict
91447636 269#endif
91447636 270
3e170ce0
A
271/* Compatibility with compilers and environments that don't support the
272 * nullability feature.
273 */
274
275#if !__has_feature(nullability)
276#ifndef __nullable
277#define __nullable
278#endif
279#ifndef __nonnull
280#define __nonnull
281#endif
282#ifndef __null_unspecified
283#define __null_unspecified
284#endif
39037602
A
285#ifndef _Nullable
286#define _Nullable
287#endif
288#ifndef _Nonnull
289#define _Nonnull
290#endif
291#ifndef _Null_unspecified
292#define _Null_unspecified
293#endif
294#endif
295
296/*
297 * __disable_tail_calls causes the compiler to not perform tail call
298 * optimization inside the marked function.
299 */
300#if __has_attribute(disable_tail_calls)
0a7de745 301#define __disable_tail_calls __attribute__((__disable_tail_calls__))
39037602
A
302#else
303#define __disable_tail_calls
304#endif
305
306/*
307 * __not_tail_called causes the compiler to prevent tail call optimization
308 * on statically bound calls to the function. It has no effect on indirect
309 * calls. Virtual functions, objective-c methods, and functions marked as
310 * "always_inline" cannot be marked as __not_tail_called.
311 */
312#if __has_attribute(not_tail_called)
0a7de745 313#define __not_tail_called __attribute__((__not_tail_called__))
39037602
A
314#else
315#define __not_tail_called
316#endif
317
318/*
319 * __result_use_check warns callers of a function that not using the function
320 * return value is a bug, i.e. dismissing malloc() return value results in a
321 * memory leak.
322 */
323#if __has_attribute(warn_unused_result)
324#define __result_use_check __attribute__((__warn_unused_result__))
325#else
326#define __result_use_check
327#endif
328
329/*
330 * __swift_unavailable causes the compiler to mark a symbol as specifically
331 * unavailable in Swift, regardless of any other availability in C.
332 */
333#if __has_feature(attribute_availability_swift)
0a7de745 334#define __swift_unavailable(_msg) __attribute__((__availability__(swift, unavailable, message=_msg)))
39037602
A
335#else
336#define __swift_unavailable(_msg)
3e170ce0
A
337#endif
338
cb323159
A
339/*
340 * __abortlike is the attribute to put on functions like abort() that are
341 * typically used to mark assertions. These optimize the codegen
342 * for outlining while still maintaining debugability.
343 */
344#ifndef __abortlike
345#define __abortlike __dead2 __cold __not_tail_called
346#endif
347
39236c6e
A
348/* Declaring inline functions within headers is error-prone due to differences
349 * across various versions of the C language and extensions. __header_inline
350 * can be used to declare inline functions within system headers. In cases
351 * where you want to force inlining instead of letting the compiler make
352 * the decision, you can use __header_always_inline.
353 *
354 * Be aware that using inline for functions which compilers may also provide
355 * builtins can behave differently under various compilers. If you intend to
356 * provide an inline version of such a function, you may want to use a macro
357 * instead.
358 *
359 * The check for !__GNUC__ || __clang__ is because gcc doesn't correctly
360 * support c99 inline in some cases:
361 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55965
362 */
363
15129b1c 364#if defined(__cplusplus) || \
0a7de745
A
365 (__STDC_VERSION__ >= 199901L && \
366 !defined(__GNUC_GNU_INLINE__) && \
367 (!defined(__GNUC__) || defined(__clang__)))
39236c6e
A
368# define __header_inline inline
369#elif defined(__GNUC__) && defined(__GNUC_STDC_INLINE__)
370# define __header_inline extern __inline __attribute__((__gnu_inline__))
371#elif defined(__GNUC__)
372# define __header_inline extern __inline
373#else
0a7de745
A
374/* If we land here, we've encountered an unsupported compiler,
375 * so hopefully it understands static __inline as a fallback.
376 */
39236c6e
A
377# define __header_inline static __inline
378#endif
379
380#ifdef __GNUC__
381# define __header_always_inline __header_inline __attribute__ ((__always_inline__))
382#else
0a7de745
A
383/* Unfortunately, we're using a compiler that we don't know how to force to
384 * inline. Oh well.
385 */
39236c6e
A
386# define __header_always_inline __header_inline
387#endif
388
fe8ab488
A
389/*
390 * Compiler-dependent macros that bracket portions of code where the
391 * "-Wunreachable-code" warning should be ignored. Please use sparingly.
392 */
393#if defined(__clang__)
394# define __unreachable_ok_push \
0a7de745
A
395 _Pragma("clang diagnostic push") \
396 _Pragma("clang diagnostic ignored \"-Wunreachable-code\"")
fe8ab488 397# define __unreachable_ok_pop \
0a7de745 398 _Pragma("clang diagnostic pop")
fe8ab488
A
399#elif defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
400# define __unreachable_ok_push \
0a7de745
A
401 _Pragma("GCC diagnostic push") \
402 _Pragma("GCC diagnostic ignored \"-Wunreachable-code\"")
fe8ab488 403# define __unreachable_ok_pop \
0a7de745 404 _Pragma("GCC diagnostic pop")
fe8ab488
A
405#else
406# define __unreachable_ok_push
407# define __unreachable_ok_pop
408#endif
409
91447636
A
410/*
411 * Compiler-dependent macros to declare that functions take printf-like
412 * or scanf-like arguments. They are null except for versions of gcc
413 * that are known to support the features properly. Functions declared
414 * with these attributes will cause compilation warnings if there is a
415 * mismatch between the format string and subsequent function parameter
416 * types.
417 */
91447636 418#define __printflike(fmtarg, firstvararg) \
0a7de745 419 __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
39037602 420#define __printf0like(fmtarg, firstvararg) \
0a7de745 421 __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
91447636 422#define __scanflike(fmtarg, firstvararg) \
0a7de745 423 __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
91447636 424
0a7de745 425#define __IDSTRING(name, string) static const char name[] __used = string
1c79356b
A
426
427#ifndef __COPYRIGHT
428#define __COPYRIGHT(s) __IDSTRING(copyright,s)
429#endif
430
431#ifndef __RCSID
432#define __RCSID(s) __IDSTRING(rcsid,s)
433#endif
434
435#ifndef __SCCSID
436#define __SCCSID(s) __IDSTRING(sccsid,s)
437#endif
438
439#ifndef __PROJECT_VERSION
440#define __PROJECT_VERSION(s) __IDSTRING(project_version,s)
441#endif
442
316670eb
A
443/* Source compatibility only, ID string not emitted in object file */
444#ifndef __FBSDID
0a7de745 445#define __FBSDID(s)
316670eb
A
446#endif
447
0a7de745
A
448#ifndef __DECONST
449#define __DECONST(type, var) __CAST_AWAY_QUALIFIER(var, const, type)
39236c6e
A
450#endif
451
0a7de745
A
452#ifndef __DEVOLATILE
453#define __DEVOLATILE(type, var) __CAST_AWAY_QUALIFIER(var, volatile, type)
39236c6e
A
454#endif
455
0a7de745
A
456#ifndef __DEQUALIFY
457#define __DEQUALIFY(type, var) __CAST_AWAY_QUALIFIER(var, const volatile, type)
39236c6e 458#endif
316670eb 459
d9a64523
A
460/*
461 * __alloc_size can be used to label function arguments that represent the
462 * size of memory that the function allocates and returns. The one-argument
463 * form labels a single argument that gives the allocation size (where the
464 * arguments are numbered from 1):
465 *
466 * void *malloc(size_t __size) __alloc_size(1);
467 *
468 * The two-argument form handles the case where the size is calculated as the
469 * product of two arguments:
470 *
471 * void *calloc(size_t __count, size_t __size) __alloc_size(1,2);
472 */
473#ifndef __alloc_size
474#if __has_attribute(alloc_size)
475#define __alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
476#else
477#define __alloc_size(...)
478#endif
479#endif // __alloc_size
480
91447636 481/*
6d2010ae 482 * COMPILATION ENVIRONMENTS -- see compat(5) for additional detail
2d21ac55
A
483 *
484 * DEFAULT By default newly complied code will get POSIX APIs plus
485 * Apple API extensions in scope.
486 *
487 * Most users will use this compilation environment to avoid
b0d623f7 488 * behavioral differences between 32 and 64 bit code.
2d21ac55
A
489 *
490 * LEGACY Defining _NONSTD_SOURCE will get pre-POSIX APIs plus Apple
491 * API extensions in scope.
492 *
493 * This is generally equivalent to the Tiger release compilation
494 * environment, except that it cannot be applied to 64 bit code;
495 * its use is discouraged.
496 *
497 * We expect this environment to be deprecated in the future.
498 *
499 * STRICT Defining _POSIX_C_SOURCE or _XOPEN_SOURCE restricts the
500 * available APIs to exactly the set of APIs defined by the
501 * corresponding standard, based on the value defined.
91447636 502 *
2d21ac55
A
503 * A correct, portable definition for _POSIX_C_SOURCE is 200112L.
504 * A correct, portable definition for _XOPEN_SOURCE is 600L.
505 *
506 * Apple API extensions are not visible in this environment,
507 * which can cause Apple specific code to fail to compile,
508 * or behave incorrectly if prototypes are not in scope or
509 * warnings about missing prototypes are not enabled or ignored.
510 *
511 * In any compilation environment, for correct symbol resolution to occur,
512 * function prototypes must be in scope. It is recommended that all Apple
b0d623f7 513 * tools users add either the "-Wall" or "-Wimplicit-function-declaration"
2d21ac55
A
514 * compiler flags to their projects to be warned when a function is being
515 * used without a prototype in scope.
516 */
517
593a1d5f
A
518/* These settings are particular to each product. */
519#ifdef KERNEL
0a7de745
A
520#define __DARWIN_ONLY_64_BIT_INO_T 0
521#define __DARWIN_ONLY_UNIX_CONFORMANCE 0
522#define __DARWIN_ONLY_VERS_1050 0
fe8ab488 523#if defined(__x86_64__)
0a7de745
A
524#define __DARWIN_SUF_DARWIN14 "_darwin14"
525#define __DARWIN14_ALIAS(sym) __asm("_" __STRING(sym) __DARWIN_SUF_DARWIN14)
fe8ab488 526#else
0a7de745 527#define __DARWIN14_ALIAS(sym)
fe8ab488 528#endif
593a1d5f 529#else /* !KERNEL */
6d2010ae
A
530#ifdef PLATFORM_iPhoneOS
531/* Platform: iPhoneOS */
0a7de745
A
532#define __DARWIN_ONLY_64_BIT_INO_T 1
533#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
534#define __DARWIN_ONLY_VERS_1050 1
6d2010ae
A
535#endif /* PLATFORM_iPhoneOS */
536#ifdef PLATFORM_iPhoneSimulator
537/* Platform: iPhoneSimulator */
0a7de745
A
538#define __DARWIN_ONLY_64_BIT_INO_T 1
539#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
540#define __DARWIN_ONLY_VERS_1050 1
6d2010ae 541#endif /* PLATFORM_iPhoneSimulator */
3e170ce0
A
542#ifdef PLATFORM_tvOS
543/* Platform: tvOS */
0a7de745
A
544#define __DARWIN_ONLY_64_BIT_INO_T 1
545#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
546#define __DARWIN_ONLY_VERS_1050 1
3e170ce0
A
547#endif /* PLATFORM_tvOS */
548#ifdef PLATFORM_AppleTVOS
549/* Platform: AppleTVOS */
0a7de745
A
550#define __DARWIN_ONLY_64_BIT_INO_T 1
551#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
552#define __DARWIN_ONLY_VERS_1050 1
3e170ce0
A
553#endif /* PLATFORM_AppleTVOS */
554#ifdef PLATFORM_tvSimulator
555/* Platform: tvSimulator */
0a7de745
A
556#define __DARWIN_ONLY_64_BIT_INO_T 1
557#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
558#define __DARWIN_ONLY_VERS_1050 1
3e170ce0
A
559#endif /* PLATFORM_tvSimulator */
560#ifdef PLATFORM_AppleTVSimulator
561/* Platform: AppleTVSimulator */
0a7de745
A
562#define __DARWIN_ONLY_64_BIT_INO_T 1
563#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
564#define __DARWIN_ONLY_VERS_1050 1
3e170ce0 565#endif /* PLATFORM_AppleTVSimulator */
fe8ab488
A
566#ifdef PLATFORM_iPhoneOSNano
567/* Platform: iPhoneOSNano */
0a7de745
A
568#define __DARWIN_ONLY_64_BIT_INO_T 1
569#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
570#define __DARWIN_ONLY_VERS_1050 1
fe8ab488
A
571#endif /* PLATFORM_iPhoneOSNano */
572#ifdef PLATFORM_iPhoneNanoSimulator
573/* Platform: iPhoneNanoSimulator */
0a7de745
A
574#define __DARWIN_ONLY_64_BIT_INO_T 1
575#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
576#define __DARWIN_ONLY_VERS_1050 1
fe8ab488 577#endif /* PLATFORM_iPhoneNanoSimulator */
3e170ce0
A
578#ifdef PLATFORM_WatchOS
579/* Platform: WatchOS */
0a7de745
A
580#define __DARWIN_ONLY_64_BIT_INO_T 1
581#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
582#define __DARWIN_ONLY_VERS_1050 1
3e170ce0
A
583#endif /* PLATFORM_WatchOS */
584#ifdef PLATFORM_WatchSimulator
585/* Platform: WatchSimulator */
0a7de745
A
586#define __DARWIN_ONLY_64_BIT_INO_T 1
587#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
588#define __DARWIN_ONLY_VERS_1050 1
3e170ce0 589#endif /* PLATFORM_WatchSimulator */
5ba3f43e
A
590#ifdef PLATFORM_BridgeOS
591/* Platform: BridgeOS */
0a7de745
A
592#define __DARWIN_ONLY_64_BIT_INO_T 1
593#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
594#define __DARWIN_ONLY_VERS_1050 1
5ba3f43e 595#endif /* PLATFORM_BridgeOS */
cb323159
A
596#ifdef PLATFORM_DriverKit
597/* Platform: DriverKit */
598#define __DARWIN_ONLY_64_BIT_INO_T 1
599#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
600#define __DARWIN_ONLY_VERS_1050 1
601#endif /* PLATFORM_DriverKit */
6d2010ae
A
602#ifdef PLATFORM_MacOSX
603/* Platform: MacOSX */
f427ee49 604#if defined(__i386__)
0a7de745 605#define __DARWIN_ONLY_64_BIT_INO_T 0
f427ee49 606#define __DARWIN_ONLY_UNIX_CONFORMANCE 0
0a7de745 607#define __DARWIN_ONLY_VERS_1050 0
f427ee49
A
608#elif defined(__x86_64__)
609#define __DARWIN_ONLY_64_BIT_INO_T 0
610#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
611#define __DARWIN_ONLY_VERS_1050 0
612#else
613#define __DARWIN_ONLY_64_BIT_INO_T 1
614#define __DARWIN_ONLY_UNIX_CONFORMANCE 1
615#define __DARWIN_ONLY_VERS_1050 1
616#endif
6d2010ae 617#endif /* PLATFORM_MacOSX */
593a1d5f
A
618#endif /* KERNEL */
619
2d21ac55
A
620/*
621 * The __DARWIN_ALIAS macros are used to do symbol renaming; they allow
b0d623f7 622 * legacy code to use the old symbol, thus maintaining binary compatibility
2d21ac55 623 * while new code can use a standards compliant version of the same function.
91447636
A
624 *
625 * __DARWIN_ALIAS is used by itself if the function signature has not
626 * changed, it is used along with a #ifdef check for __DARWIN_UNIX03
b0d623f7
A
627 * if the signature has changed. Because the __LP64__ environment
628 * only supports UNIX03 semantics it causes __DARWIN_UNIX03 to be
91447636 629 * defined, but causes __DARWIN_ALIAS to do no symbol mangling.
2d21ac55
A
630 *
631 * As a special case, when XCode is used to target a specific version of the
632 * OS, the manifest constant __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
633 * will be defined by the compiler, with the digits representing major version
b0d623f7 634 * time 100 + minor version times 10 (e.g. 10.5 := 1050). If we are targeting
2d21ac55
A
635 * pre-10.5, and it is the default compilation environment, revert the
636 * compilation environment to pre-__DARWIN_UNIX03.
91447636 637 */
91447636 638#if !defined(__DARWIN_UNIX03)
593a1d5f 639# if defined(KERNEL)
0a7de745 640# define __DARWIN_UNIX03 0
593a1d5f 641# elif __DARWIN_ONLY_UNIX_CONFORMANCE
2d21ac55 642# if defined(_NONSTD_SOURCE)
593a1d5f 643# error "Can't define _NONSTD_SOURCE when only UNIX conformance is available."
2d21ac55 644# endif /* _NONSTD_SOURCE */
0a7de745
A
645# define __DARWIN_UNIX03 1
646# elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1040)
647# define __DARWIN_UNIX03 0
593a1d5f
A
648# elif defined(_DARWIN_C_SOURCE) || defined(_XOPEN_SOURCE) || defined(_POSIX_C_SOURCE)
649# if defined(_NONSTD_SOURCE)
650# error "Can't define both _NONSTD_SOURCE and any of _DARWIN_C_SOURCE, _XOPEN_SOURCE or _POSIX_C_SOURCE."
651# endif /* _NONSTD_SOURCE */
0a7de745 652# define __DARWIN_UNIX03 1
593a1d5f 653# elif defined(_NONSTD_SOURCE)
0a7de745 654# define __DARWIN_UNIX03 0
2d21ac55 655# else /* default */
0a7de745
A
656# if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1050)
657# define __DARWIN_UNIX03 0
2d21ac55 658# else /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 */
0a7de745 659# define __DARWIN_UNIX03 1
2d21ac55
A
660# endif /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 */
661# endif /* _DARWIN_C_SOURCE || _XOPEN_SOURCE || _POSIX_C_SOURCE || __LP64__ */
91447636
A
662#endif /* !__DARWIN_UNIX03 */
663
2d21ac55 664#if !defined(__DARWIN_64_BIT_INO_T)
593a1d5f
A
665# if defined(KERNEL)
666# define __DARWIN_64_BIT_INO_T 0
667# elif defined(_DARWIN_USE_64_BIT_INODE)
668# if defined(_DARWIN_NO_64_BIT_INODE)
669# error "Can't define both _DARWIN_USE_64_BIT_INODE and _DARWIN_NO_64_BIT_INODE."
670# endif /* _DARWIN_NO_64_BIT_INODE */
2d21ac55 671# define __DARWIN_64_BIT_INO_T 1
593a1d5f
A
672# elif defined(_DARWIN_NO_64_BIT_INODE)
673# if __DARWIN_ONLY_64_BIT_INO_T
674# error "Can't define _DARWIN_NO_64_BIT_INODE when only 64-bit inodes are available."
675# endif /* __DARWIN_ONLY_64_BIT_INO_T */
2d21ac55
A
676# define __DARWIN_64_BIT_INO_T 0
677# else /* default */
593a1d5f
A
678# if __DARWIN_ONLY_64_BIT_INO_T
679# define __DARWIN_64_BIT_INO_T 1
0a7de745 680# elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1060) || __DARWIN_UNIX03 == 0
593a1d5f 681# define __DARWIN_64_BIT_INO_T 0
b0d623f7
A
682# else /* default */
683# define __DARWIN_64_BIT_INO_T 1
593a1d5f 684# endif /* __DARWIN_ONLY_64_BIT_INO_T */
2d21ac55
A
685# endif
686#endif /* !__DARWIN_64_BIT_INO_T */
687
593a1d5f 688#if !defined(__DARWIN_VERS_1050)
2d21ac55 689# if defined(KERNEL)
593a1d5f
A
690# define __DARWIN_VERS_1050 0
691# elif __DARWIN_ONLY_VERS_1050
692# define __DARWIN_VERS_1050 1
0a7de745 693# elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1050) || __DARWIN_UNIX03 == 0
593a1d5f 694# define __DARWIN_VERS_1050 0
b0d623f7
A
695# else /* default */
696# define __DARWIN_VERS_1050 1
2d21ac55 697# endif
593a1d5f 698#endif /* !__DARWIN_VERS_1050 */
2d21ac55 699
593a1d5f
A
700#if !defined(__DARWIN_NON_CANCELABLE)
701# if defined(KERNEL)
702# define __DARWIN_NON_CANCELABLE 0
2d21ac55 703# else /* default */
593a1d5f 704# define __DARWIN_NON_CANCELABLE 0
2d21ac55
A
705# endif
706#endif /* !__DARWIN_NON_CANCELABLE */
707
708/*
709 * symbol suffixes used for symbol versioning
710 */
711#if __DARWIN_UNIX03
593a1d5f 712# if __DARWIN_ONLY_UNIX_CONFORMANCE
0a7de745 713# define __DARWIN_SUF_UNIX03 /* nothing */
593a1d5f 714# else /* !__DARWIN_ONLY_UNIX_CONFORMANCE */
0a7de745 715# define __DARWIN_SUF_UNIX03 "$UNIX2003"
593a1d5f 716# endif /* __DARWIN_ONLY_UNIX_CONFORMANCE */
2d21ac55
A
717
718# if __DARWIN_64_BIT_INO_T
593a1d5f 719# if __DARWIN_ONLY_64_BIT_INO_T
0a7de745 720# define __DARWIN_SUF_64_BIT_INO_T /* nothing */
593a1d5f 721# else /* !__DARWIN_ONLY_64_BIT_INO_T */
0a7de745 722# define __DARWIN_SUF_64_BIT_INO_T "$INODE64"
593a1d5f 723# endif /* __DARWIN_ONLY_64_BIT_INO_T */
2d21ac55 724# else /* !__DARWIN_64_BIT_INO_T */
0a7de745 725# define __DARWIN_SUF_64_BIT_INO_T /* nothing */
593a1d5f
A
726# endif /* __DARWIN_64_BIT_INO_T */
727
728# if __DARWIN_VERS_1050
729# if __DARWIN_ONLY_VERS_1050
0a7de745 730# define __DARWIN_SUF_1050 /* nothing */
593a1d5f 731# else /* !__DARWIN_ONLY_VERS_1050 */
0a7de745 732# define __DARWIN_SUF_1050 "$1050"
593a1d5f
A
733# endif /* __DARWIN_ONLY_VERS_1050 */
734# else /* !__DARWIN_VERS_1050 */
0a7de745 735# define __DARWIN_SUF_1050 /* nothing */
593a1d5f 736# endif /* __DARWIN_VERS_1050 */
2d21ac55
A
737
738# if __DARWIN_NON_CANCELABLE
0a7de745 739# define __DARWIN_SUF_NON_CANCELABLE "$NOCANCEL"
2d21ac55 740# else /* !__DARWIN_NON_CANCELABLE */
0a7de745 741# define __DARWIN_SUF_NON_CANCELABLE /* nothing */
2d21ac55
A
742# endif /* __DARWIN_NON_CANCELABLE */
743
2d21ac55 744#else /* !__DARWIN_UNIX03 */
0a7de745
A
745# define __DARWIN_SUF_UNIX03 /* nothing */
746# define __DARWIN_SUF_64_BIT_INO_T /* nothing */
747# define __DARWIN_SUF_NON_CANCELABLE /* nothing */
748# define __DARWIN_SUF_1050 /* nothing */
2d21ac55
A
749#endif /* __DARWIN_UNIX03 */
750
0a7de745 751#define __DARWIN_SUF_EXTSN "$DARWIN_EXTSN"
2d21ac55
A
752
753/*
754 * symbol versioning macros
755 */
0a7de745
A
756#define __DARWIN_ALIAS(sym) __asm("_" __STRING(sym) __DARWIN_SUF_UNIX03)
757#define __DARWIN_ALIAS_C(sym) __asm("_" __STRING(sym) __DARWIN_SUF_NON_CANCELABLE __DARWIN_SUF_UNIX03)
758#define __DARWIN_ALIAS_I(sym) __asm("_" __STRING(sym) __DARWIN_SUF_64_BIT_INO_T __DARWIN_SUF_UNIX03)
759#define __DARWIN_NOCANCEL(sym) __asm("_" __STRING(sym) __DARWIN_SUF_NON_CANCELABLE)
760#define __DARWIN_INODE64(sym) __asm("_" __STRING(sym) __DARWIN_SUF_64_BIT_INO_T)
2d21ac55 761
0a7de745
A
762#define __DARWIN_1050(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050)
763#define __DARWIN_1050ALIAS(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_UNIX03)
764#define __DARWIN_1050ALIAS_C(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_NON_CANCELABLE __DARWIN_SUF_UNIX03)
765#define __DARWIN_1050ALIAS_I(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_64_BIT_INO_T __DARWIN_SUF_UNIX03)
766#define __DARWIN_1050INODE64(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_64_BIT_INO_T)
2d21ac55 767
0a7de745
A
768#define __DARWIN_EXTSN(sym) __asm("_" __STRING(sym) __DARWIN_SUF_EXTSN)
769#define __DARWIN_EXTSN_C(sym) __asm("_" __STRING(sym) __DARWIN_SUF_EXTSN __DARWIN_SUF_NON_CANCELABLE)
cb323159
A
770#if XNU_KERNEL_PRIVATE
771#define __XNU_INTERNAL(sym) __asm("_" __STRING(sym) "$XNU_INTERNAL")
772#endif
91447636 773
b0d623f7
A
774/*
775 * symbol release macros
776 */
6d2010ae
A
777#ifdef KERNEL
778#define __DARWIN_ALIAS_STARTING(_mac, _iphone, x)
779#else
780#include <sys/_symbol_aliasing.h>
781
316670eb 782#if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
6d2010ae
A
783#define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) __DARWIN_ALIAS_STARTING_IPHONE_##_iphone(x)
784#elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
785#define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) __DARWIN_ALIAS_STARTING_MAC_##_mac(x)
786#else
3e170ce0 787#define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) x
b0d623f7 788#endif
6d2010ae 789#endif /* KERNEL */
b0d623f7 790
91447636
A
791
792/*
793 * POSIX.1 requires that the macros we test be defined before any standard
794 * header file is included. This permits us to convert values for feature
795 * testing, as necessary, using only _POSIX_C_SOURCE.
796 *
797 * Here's a quick run-down of the versions:
798 * defined(_POSIX_SOURCE) 1003.1-1988
799 * _POSIX_C_SOURCE == 1L 1003.1-1990
800 * _POSIX_C_SOURCE == 2L 1003.2-1992 C Language Binding Option
801 * _POSIX_C_SOURCE == 199309L 1003.1b-1993
802 * _POSIX_C_SOURCE == 199506L 1003.1c-1995, 1003.1i-1995,
803 * and the omnibus ISO/IEC 9945-1: 1996
804 * _POSIX_C_SOURCE == 200112L 1003.1-2001
6d2010ae 805 * _POSIX_C_SOURCE == 200809L 1003.1-2008
91447636
A
806 *
807 * In addition, the X/Open Portability Guide, which is now the Single UNIX
808 * Specification, defines a feature-test macro which indicates the version of
809 * that specification, and which subsumes _POSIX_C_SOURCE.
810 */
811
812/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1L. */
813#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1L
814#undef _POSIX_C_SOURCE
0a7de745 815#define _POSIX_C_SOURCE 199009L
91447636
A
816#endif
817
818/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2L. */
819#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2L
820#undef _POSIX_C_SOURCE
0a7de745 821#define _POSIX_C_SOURCE 199209L
91447636
A
822#endif
823
824/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
825#ifdef _XOPEN_SOURCE
6d2010ae
A
826#if _XOPEN_SOURCE - 0L >= 700L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 200809L)
827#undef _POSIX_C_SOURCE
828#define _POSIX_C_SOURCE 200809L
829#elif _XOPEN_SOURCE - 0L >= 600L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 200112L)
91447636 830#undef _POSIX_C_SOURCE
0a7de745 831#define _POSIX_C_SOURCE 200112L
6d2010ae 832#elif _XOPEN_SOURCE - 0L >= 500L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 199506L)
91447636 833#undef _POSIX_C_SOURCE
0a7de745 834#define _POSIX_C_SOURCE 199506L
91447636
A
835#endif
836#endif
837
838/*
839 * Deal with all versions of POSIX. The ordering relative to the tests above is
840 * important.
841 */
842#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
843#define _POSIX_C_SOURCE 198808L
844#endif
845
6d2010ae
A
846/* POSIX C deprecation macros */
847#ifdef KERNEL
848#define __POSIX_C_DEPRECATED(ver)
849#else
850#include <sys/_posix_availability.h>
851
852#define __POSIX_C_DEPRECATED(ver) ___POSIX_C_DEPRECATED_STARTING_##ver
853#endif
854
855/*
856 * Set a single macro which will always be defined and can be used to determine
857 * the appropriate namespace. For POSIX, these values will correspond to
858 * _POSIX_C_SOURCE value. Currently there are two additional levels corresponding
859 * to ANSI (_ANSI_SOURCE) and Darwin extensions (_DARWIN_C_SOURCE)
860 */
861#define __DARWIN_C_ANSI 010000L
862#define __DARWIN_C_FULL 900000L
863
864#if defined(_ANSI_SOURCE)
865#define __DARWIN_C_LEVEL __DARWIN_C_ANSI
866#elif defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE) && !defined(_NONSTD_SOURCE)
867#define __DARWIN_C_LEVEL _POSIX_C_SOURCE
868#else
869#define __DARWIN_C_LEVEL __DARWIN_C_FULL
870#endif
871
39236c6e
A
872/* If the developer has neither requested a strict language mode nor a version
873 * of POSIX, turn on functionality provided by __STDC_WANT_LIB_EXT1__ as part
874 * of __DARWIN_C_FULL.
875 */
876#if !defined(__STDC_WANT_LIB_EXT1__) && !defined(__STRICT_ANSI__) && __DARWIN_C_LEVEL >= __DARWIN_C_FULL
877#define __STDC_WANT_LIB_EXT1__ 1
878#endif
6d2010ae 879
91447636
A
880/*
881 * long long is not supported in c89 (__STRICT_ANSI__), but g++ -ansi and
882 * c99 still want long longs. While not perfect, we allow long longs for
883 * g++.
884 */
0a7de745 885#if (defined(__STRICT_ANSI__) && (__STDC_VERSION__ - 0 < 199901L) && !defined(__GNUG__))
a39ff7e2
A
886#define __DARWIN_NO_LONG_LONG 1
887#else
888#define __DARWIN_NO_LONG_LONG 0
889#endif
91447636 890
2d21ac55 891/*****************************************
0a7de745
A
892* Public darwin-specific feature macros
893*****************************************/
2d21ac55 894
593a1d5f
A
895/*
896 * _DARWIN_FEATURE_64_BIT_INODE indicates that the ino_t type is 64-bit, and
897 * structures modified for 64-bit inodes (like struct stat) will be used.
898 */
899#if __DARWIN_64_BIT_INO_T
0a7de745 900#define _DARWIN_FEATURE_64_BIT_INODE 1
593a1d5f
A
901#endif
902
2d21ac55 903/*
593a1d5f
A
904 * _DARWIN_FEATURE_64_ONLY_BIT_INODE indicates that the ino_t type may only
905 * be 64-bit; there is no support for 32-bit ino_t when this macro is defined
906 * (and non-zero). There is no struct stat64 either, as the regular
907 * struct stat will already be the 64-bit version.
2d21ac55 908 */
593a1d5f 909#if __DARWIN_ONLY_64_BIT_INO_T
0a7de745 910#define _DARWIN_FEATURE_ONLY_64_BIT_INODE 1
2d21ac55
A
911#endif
912
913/*
593a1d5f
A
914 * _DARWIN_FEATURE_ONLY_VERS_1050 indicates that only those APIs updated
915 * in 10.5 exists; no pre-10.5 variants are available.
2d21ac55 916 */
593a1d5f 917#if __DARWIN_ONLY_VERS_1050
0a7de745 918#define _DARWIN_FEATURE_ONLY_VERS_1050 1
593a1d5f
A
919#endif
920
921/*
922 * _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE indicates only UNIX conforming API
923 * are available (the legacy BSD APIs are not available)
924 */
925#if __DARWIN_ONLY_UNIX_CONFORMANCE
0a7de745 926#define _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE 1
593a1d5f
A
927#endif
928
929/*
930 * _DARWIN_FEATURE_UNIX_CONFORMANCE indicates whether UNIX conformance is on,
931 * and specifies the conformance level (3 is SUSv3)
932 */
933#if __DARWIN_UNIX03
0a7de745 934#define _DARWIN_FEATURE_UNIX_CONFORMANCE 3
2d21ac55
A
935#endif
936
cb323159
A
937#if defined(DRIVERKIT) && !defined(KERNEL)
938/*
939 * __DRIVERKIT_LIBC__ indicates to the C++ standard library headers and
940 * similar components that only the restricted set of standard C library
941 * functionality and headers for the DriverKit userspace driver environment
942 * are available.
943 */
944#define __DRIVERKIT_LIBC__ 1
945#endif /* defined(DRIVERKIT) && !defined(KERNEL) */
946
0a7de745 947/*
b0d623f7
A
948 * This macro casts away the qualifier from the variable
949 *
950 * Note: use at your own risk, removing qualifiers can result in
951 * catastrophic run-time failures.
952 */
953#ifndef __CAST_AWAY_QUALIFIER
6d2010ae 954#define __CAST_AWAY_QUALIFIER(variable, qualifier, type) (type) (long)(variable)
b0d623f7
A
955#endif
956
39236c6e
A
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/*
966 * Architecture validation for current SDK
967 */
968#if !defined(__sys_cdefs_arch_unknown__) && defined(__i386__)
969#elif !defined(__sys_cdefs_arch_unknown__) && defined(__x86_64__)
5ba3f43e
A
970#elif !defined(__sys_cdefs_arch_unknown__) && defined(__arm__)
971#elif !defined(__sys_cdefs_arch_unknown__) && defined(__arm64__)
39236c6e
A
972#else
973#error Unsupported architecture
974#endif
975
3e170ce0
A
976#ifdef XNU_KERNEL_PRIVATE
977/*
978 * Selectively ignore cast alignment warnings
979 */
980#define __IGNORE_WCASTALIGN(x) _Pragma("clang diagnostic push") \
0a7de745
A
981 _Pragma("clang diagnostic ignored \"-Wcast-align\"") \
982 x; \
983 _Pragma("clang diagnostic pop")
3e170ce0
A
984#endif
985
d9a64523
A
986#if defined(PRIVATE) || defined(KERNEL)
987/*
988 * Check if __probable and __improbable have already been defined elsewhere.
989 * These macros inform the compiler (and humans) about which branches are likely
990 * to be taken.
991 */
992#if !defined(__probable) && !defined(__improbable)
0a7de745
A
993#define __probable(x) __builtin_expect(!!(x), 1)
994#define __improbable(x) __builtin_expect(!!(x), 0)
d9a64523
A
995#endif /* !defined(__probable) && !defined(__improbable) */
996
cb323159
A
997#if defined(__cplusplus)
998#define __container_of(ptr, type, field) __extension__({ \
f427ee49 999 const __typeof__(((type *)nullptr)->field) *__ptr = (ptr); \
cb323159
A
1000 (type *)((uintptr_t)__ptr - offsetof(type, field)); \
1001 })
1002#else
1003#define __container_of(ptr, type, field) __extension__({ \
f427ee49 1004 const __typeof__(((type *)NULL)->field) *__ptr = (ptr); \
0a7de745 1005 (type *)((uintptr_t)__ptr - offsetof(type, field)); \
d9a64523 1006 })
cb323159 1007#endif
d9a64523
A
1008
1009#endif /* KERNEL || PRIVATE */
1010
1011#define __compiler_barrier() __asm__ __volatile__("" ::: "memory")
1012
cb323159
A
1013#if __has_attribute(enum_extensibility)
1014#define __enum_open __attribute__((__enum_extensibility__(open)))
1015#define __enum_closed __attribute__((__enum_extensibility__(closed)))
1016#else
1017#define __enum_open
1018#define __enum_closed
1019#endif // __has_attribute(enum_extensibility)
1020
1021#if __has_attribute(flag_enum)
1022#define __enum_options __attribute__((__flag_enum__))
1023#else
1024#define __enum_options
1025#endif
1026
1027/*
1028 * Similar to OS_ENUM/OS_CLOSED_ENUM/OS_OPTIONS/OS_CLOSED_OPTIONS
1029 *
1030 * This provides more advanced type checking on compilers supporting
1031 * the proper extensions, even in C.
1032 */
1033#if __has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum) || \
1034 __has_extension(cxx_strong_enums)
1035#define __enum_decl(_name, _type, ...) \
1036 typedef enum : _type __VA_ARGS__ __enum_open _name
1037#define __enum_closed_decl(_name, _type, ...) \
1038 typedef enum : _type __VA_ARGS__ __enum_closed _name
1039#define __options_decl(_name, _type, ...) \
1040 typedef enum : _type __VA_ARGS__ __enum_open __enum_options _name
1041#define __options_closed_decl(_name, _type, ...) \
1042 typedef enum : _type __VA_ARGS__ __enum_closed __enum_options _name
1043#else
1044#define __enum_decl(_name, _type, ...) \
1045 typedef _type _name; enum __VA_ARGS__ __enum_open
1046#define __enum_closed_decl(_name, _type, ...) \
1047 typedef _type _name; enum __VA_ARGS__ __enum_closed
1048#define __options_decl(_name, _type, ...) \
1049 typedef _type _name; enum __VA_ARGS__ __enum_open __enum_options
1050#define __options_closed_decl(_name, _type, ...) \
1051 typedef _type _name; enum __VA_ARGS__ __enum_closed __enum_options
1052#endif
1053
1c79356b 1054#endif /* !_CDEFS_H_ */