]>
git.saurik.com Git - apple/xnu.git/blob - bsd/sys/cdefs.h
2 * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright 1995 NeXT Computer, Inc. All rights reserved. */
30 * Copyright (c) 1991, 1993
31 * The Regents of the University of California. All rights reserved.
33 * This code is derived from software contributed to Berkeley by
34 * Berkeley Software Design, Inc.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
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.
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
64 * @(#)cdefs.h 8.8 (Berkeley) 1/9/95
70 #if defined(__cplusplus)
71 #define __BEGIN_DECLS extern "C" {
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"
85 * Compatibility with compilers and environments that don't support compiler
86 * feature checking function-like macros.
89 #define __has_builtin(x) 0
92 #define __has_include(x) 0
95 #define __has_feature(x) 0
97 #ifndef __has_attribute
98 #define __has_attribute(x) 0
100 #ifndef __has_extension
101 #define __has_extension(x) 0
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.
111 #if defined(__STDC__) || defined(__cplusplus)
112 #define __P(protos) protos /* full-blown ANSI C */
113 #define __CONCAT(x, y) x ## y
114 #define __STRING(x) #x
116 #define __const const /* define reserved names to standard */
117 #define __signed signed
118 #define __volatile volatile
119 #if defined(__cplusplus)
120 #define __inline inline /* convert to C++ keyword */
123 #define __inline /* delete GCC keyword */
124 #endif /* !__GNUC__ */
125 #endif /* !__cplusplus */
127 #else /* !(__STDC__ || __cplusplus) */
128 #define __P(protos) () /* traditional C preprocessor */
129 #define __CONCAT(x, y) x /**/ y
130 #define __STRING(x) "x"
133 #define __const /* delete pseudo-ANSI C keywords */
137 #endif /* !__GNUC__ */
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.
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
152 #endif /* !NO_ANSI_KEYWORDS */
153 #endif /* !(__STDC__ || __cplusplus) */
155 #define __dead2 __attribute__((__noreturn__))
156 #define __pure2 __attribute__((__const__))
158 /* __unused denotes variables and functions that may not be used, preventing
159 * the compiler from warning about it if not used.
161 #define __unused __attribute__((__unused__))
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).
166 #define __used __attribute__((__used__))
168 /* __cold marks code used for debugging or that is rarely taken
169 * and tells the compiler to optimize for size and outline code.
171 #if __has_attribute(cold)
172 #define __cold __attribute__((__cold__))
177 /* __deprecated causes the compiler to produce a warning when encountering
178 * code using the deprecated functionality.
179 * __deprecated_msg() does the same, and compilers that support it will print
180 * a message along with the deprecation warning.
181 * This may require turning on such warning with the -Wdeprecated flag.
182 * __deprecated_enum_msg() should be used on enums, and compilers that support
183 * it will print the deprecation warning.
184 * __kpi_deprecated() specifically indicates deprecation of kernel programming
185 * interfaces in Kernel.framework used by KEXTs.
187 #define __deprecated __attribute__((__deprecated__))
189 #if __has_extension(attribute_deprecated_with_message) || \
190 (defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5))))
191 #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
193 #define __deprecated_msg(_msg) __attribute__((__deprecated__))
196 #if __has_extension(enumerator_attributes)
197 #define __deprecated_enum_msg(_msg) __deprecated_msg(_msg)
199 #define __deprecated_enum_msg(_msg)
202 #if defined(KERNEL) && !defined(KERNEL_PRIVATE)
203 #define __kpi_deprecated(_msg) __deprecated_msg(_msg)
204 #else /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */
205 #define __kpi_deprecated(_msg)
206 #endif /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */
208 /* __unavailable causes the compiler to error out when encountering
209 * code using the tagged function of variable.
211 #define __unavailable __attribute__((__unavailable__))
213 /* Delete pseudo-keywords wherever they are not available or needed. */
220 * We use `__restrict' as a way to define the `restrict' type qualifier
221 * without disturbing older software that is unaware of C99 keywords.
223 #if __STDC_VERSION__ < 199901
226 #define __restrict restrict
229 /* Compatibility with compilers and environments that don't support the
230 * nullability feature.
233 #if !__has_feature(nullability)
240 #ifndef __null_unspecified
241 #define __null_unspecified
249 #ifndef _Null_unspecified
250 #define _Null_unspecified
255 * __disable_tail_calls causes the compiler to not perform tail call
256 * optimization inside the marked function.
258 #if __has_attribute(disable_tail_calls)
259 #define __disable_tail_calls __attribute__((__disable_tail_calls__))
261 #define __disable_tail_calls
265 * __not_tail_called causes the compiler to prevent tail call optimization
266 * on statically bound calls to the function. It has no effect on indirect
267 * calls. Virtual functions, objective-c methods, and functions marked as
268 * "always_inline" cannot be marked as __not_tail_called.
270 #if __has_attribute(not_tail_called)
271 #define __not_tail_called __attribute__((__not_tail_called__))
273 #define __not_tail_called
277 * __result_use_check warns callers of a function that not using the function
278 * return value is a bug, i.e. dismissing malloc() return value results in a
281 #if __has_attribute(warn_unused_result)
282 #define __result_use_check __attribute__((__warn_unused_result__))
284 #define __result_use_check
288 * __swift_unavailable causes the compiler to mark a symbol as specifically
289 * unavailable in Swift, regardless of any other availability in C.
291 #if __has_feature(attribute_availability_swift)
292 #define __swift_unavailable(_msg) __attribute__((__availability__(swift, unavailable, message=_msg)))
294 #define __swift_unavailable(_msg)
298 * __abortlike is the attribute to put on functions like abort() that are
299 * typically used to mark assertions. These optimize the codegen
300 * for outlining while still maintaining debugability.
303 #define __abortlike __dead2 __cold __not_tail_called
306 /* Declaring inline functions within headers is error-prone due to differences
307 * across various versions of the C language and extensions. __header_inline
308 * can be used to declare inline functions within system headers. In cases
309 * where you want to force inlining instead of letting the compiler make
310 * the decision, you can use __header_always_inline.
312 * Be aware that using inline for functions which compilers may also provide
313 * builtins can behave differently under various compilers. If you intend to
314 * provide an inline version of such a function, you may want to use a macro
317 * The check for !__GNUC__ || __clang__ is because gcc doesn't correctly
318 * support c99 inline in some cases:
319 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55965
322 #if defined(__cplusplus) || \
323 (__STDC_VERSION__ >= 199901L && \
324 !defined(__GNUC_GNU_INLINE__) && \
325 (!defined(__GNUC__) || defined(__clang__)))
326 # define __header_inline inline
327 #elif defined(__GNUC__) && defined(__GNUC_STDC_INLINE__)
328 # define __header_inline extern __inline __attribute__((__gnu_inline__))
329 #elif defined(__GNUC__)
330 # define __header_inline extern __inline
332 /* If we land here, we've encountered an unsupported compiler,
333 * so hopefully it understands static __inline as a fallback.
335 # define __header_inline static __inline
339 # define __header_always_inline __header_inline __attribute__ ((__always_inline__))
341 /* Unfortunately, we're using a compiler that we don't know how to force to
344 # define __header_always_inline __header_inline
348 * Compiler-dependent macros that bracket portions of code where the
349 * "-Wunreachable-code" warning should be ignored. Please use sparingly.
351 #if defined(__clang__)
352 # define __unreachable_ok_push \
353 _Pragma("clang diagnostic push") \
354 _Pragma("clang diagnostic ignored \"-Wunreachable-code\"")
355 # define __unreachable_ok_pop \
356 _Pragma("clang diagnostic pop")
357 #elif defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
358 # define __unreachable_ok_push \
359 _Pragma("GCC diagnostic push") \
360 _Pragma("GCC diagnostic ignored \"-Wunreachable-code\"")
361 # define __unreachable_ok_pop \
362 _Pragma("GCC diagnostic pop")
364 # define __unreachable_ok_push
365 # define __unreachable_ok_pop
369 * Compiler-dependent macros to declare that functions take printf-like
370 * or scanf-like arguments. They are null except for versions of gcc
371 * that are known to support the features properly. Functions declared
372 * with these attributes will cause compilation warnings if there is a
373 * mismatch between the format string and subsequent function parameter
376 #define __printflike(fmtarg, firstvararg) \
377 __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
378 #define __printf0like(fmtarg, firstvararg) \
379 __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
380 #define __scanflike(fmtarg, firstvararg) \
381 __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
383 #define __IDSTRING(name, string) static const char name[] __used = string
386 #define __COPYRIGHT(s) __IDSTRING(copyright,s)
390 #define __RCSID(s) __IDSTRING(rcsid,s)
394 #define __SCCSID(s) __IDSTRING(sccsid,s)
397 #ifndef __PROJECT_VERSION
398 #define __PROJECT_VERSION(s) __IDSTRING(project_version,s)
401 /* Source compatibility only, ID string not emitted in object file */
407 #define __DECONST(type, var) __CAST_AWAY_QUALIFIER(var, const, type)
411 #define __DEVOLATILE(type, var) __CAST_AWAY_QUALIFIER(var, volatile, type)
415 #define __DEQUALIFY(type, var) __CAST_AWAY_QUALIFIER(var, const volatile, type)
419 * __alloc_size can be used to label function arguments that represent the
420 * size of memory that the function allocates and returns. The one-argument
421 * form labels a single argument that gives the allocation size (where the
422 * arguments are numbered from 1):
424 * void *malloc(size_t __size) __alloc_size(1);
426 * The two-argument form handles the case where the size is calculated as the
427 * product of two arguments:
429 * void *calloc(size_t __count, size_t __size) __alloc_size(1,2);
432 #if __has_attribute(alloc_size)
433 #define __alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
435 #define __alloc_size(...)
437 #endif // __alloc_size
440 * COMPILATION ENVIRONMENTS -- see compat(5) for additional detail
442 * DEFAULT By default newly complied code will get POSIX APIs plus
443 * Apple API extensions in scope.
445 * Most users will use this compilation environment to avoid
446 * behavioral differences between 32 and 64 bit code.
448 * LEGACY Defining _NONSTD_SOURCE will get pre-POSIX APIs plus Apple
449 * API extensions in scope.
451 * This is generally equivalent to the Tiger release compilation
452 * environment, except that it cannot be applied to 64 bit code;
453 * its use is discouraged.
455 * We expect this environment to be deprecated in the future.
457 * STRICT Defining _POSIX_C_SOURCE or _XOPEN_SOURCE restricts the
458 * available APIs to exactly the set of APIs defined by the
459 * corresponding standard, based on the value defined.
461 * A correct, portable definition for _POSIX_C_SOURCE is 200112L.
462 * A correct, portable definition for _XOPEN_SOURCE is 600L.
464 * Apple API extensions are not visible in this environment,
465 * which can cause Apple specific code to fail to compile,
466 * or behave incorrectly if prototypes are not in scope or
467 * warnings about missing prototypes are not enabled or ignored.
469 * In any compilation environment, for correct symbol resolution to occur,
470 * function prototypes must be in scope. It is recommended that all Apple
471 * tools users add either the "-Wall" or "-Wimplicit-function-declaration"
472 * compiler flags to their projects to be warned when a function is being
473 * used without a prototype in scope.
476 /* These settings are particular to each product. */
478 #define __DARWIN_ONLY_64_BIT_INO_T 0
479 #define __DARWIN_ONLY_UNIX_CONFORMANCE 0
480 #define __DARWIN_ONLY_VERS_1050 0
481 #if defined(__x86_64__)
482 #define __DARWIN_SUF_DARWIN14 "_darwin14"
483 #define __DARWIN14_ALIAS(sym) __asm("_" __STRING(sym) __DARWIN_SUF_DARWIN14)
485 #define __DARWIN14_ALIAS(sym)
488 #ifdef PLATFORM_iPhoneOS
489 /* Platform: iPhoneOS */
490 #define __DARWIN_ONLY_64_BIT_INO_T 1
491 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1
492 #define __DARWIN_ONLY_VERS_1050 1
493 #endif /* PLATFORM_iPhoneOS */
494 #ifdef PLATFORM_iPhoneSimulator
495 /* Platform: iPhoneSimulator */
496 #define __DARWIN_ONLY_64_BIT_INO_T 1
497 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1
498 #define __DARWIN_ONLY_VERS_1050 1
499 #endif /* PLATFORM_iPhoneSimulator */
502 #define __DARWIN_ONLY_64_BIT_INO_T 1
503 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1
504 #define __DARWIN_ONLY_VERS_1050 1
505 #endif /* PLATFORM_tvOS */
506 #ifdef PLATFORM_AppleTVOS
507 /* Platform: AppleTVOS */
508 #define __DARWIN_ONLY_64_BIT_INO_T 1
509 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1
510 #define __DARWIN_ONLY_VERS_1050 1
511 #endif /* PLATFORM_AppleTVOS */
512 #ifdef PLATFORM_tvSimulator
513 /* Platform: tvSimulator */
514 #define __DARWIN_ONLY_64_BIT_INO_T 1
515 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1
516 #define __DARWIN_ONLY_VERS_1050 1
517 #endif /* PLATFORM_tvSimulator */
518 #ifdef PLATFORM_AppleTVSimulator
519 /* Platform: AppleTVSimulator */
520 #define __DARWIN_ONLY_64_BIT_INO_T 1
521 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1
522 #define __DARWIN_ONLY_VERS_1050 1
523 #endif /* PLATFORM_AppleTVSimulator */
524 #ifdef PLATFORM_iPhoneOSNano
525 /* Platform: iPhoneOSNano */
526 #define __DARWIN_ONLY_64_BIT_INO_T 1
527 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1
528 #define __DARWIN_ONLY_VERS_1050 1
529 #endif /* PLATFORM_iPhoneOSNano */
530 #ifdef PLATFORM_iPhoneNanoSimulator
531 /* Platform: iPhoneNanoSimulator */
532 #define __DARWIN_ONLY_64_BIT_INO_T 1
533 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1
534 #define __DARWIN_ONLY_VERS_1050 1
535 #endif /* PLATFORM_iPhoneNanoSimulator */
536 #ifdef PLATFORM_WatchOS
537 /* Platform: WatchOS */
538 #define __DARWIN_ONLY_64_BIT_INO_T 1
539 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1
540 #define __DARWIN_ONLY_VERS_1050 1
541 #endif /* PLATFORM_WatchOS */
542 #ifdef PLATFORM_WatchSimulator
543 /* Platform: WatchSimulator */
544 #define __DARWIN_ONLY_64_BIT_INO_T 1
545 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1
546 #define __DARWIN_ONLY_VERS_1050 1
547 #endif /* PLATFORM_WatchSimulator */
548 #ifdef PLATFORM_BridgeOS
549 /* Platform: BridgeOS */
550 #define __DARWIN_ONLY_64_BIT_INO_T 1
551 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1
552 #define __DARWIN_ONLY_VERS_1050 1
553 #endif /* PLATFORM_BridgeOS */
554 #ifdef PLATFORM_DriverKit
555 /* Platform: DriverKit */
556 #define __DARWIN_ONLY_64_BIT_INO_T 1
557 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1
558 #define __DARWIN_ONLY_VERS_1050 1
559 #endif /* PLATFORM_DriverKit */
560 #ifdef PLATFORM_MacOSX
561 /* Platform: MacOSX */
562 #define __DARWIN_ONLY_64_BIT_INO_T 0
563 /* #undef __DARWIN_ONLY_UNIX_CONFORMANCE (automatically set for 64-bit) */
564 #define __DARWIN_ONLY_VERS_1050 0
565 #endif /* PLATFORM_MacOSX */
569 * The __DARWIN_ALIAS macros are used to do symbol renaming; they allow
570 * legacy code to use the old symbol, thus maintaining binary compatibility
571 * while new code can use a standards compliant version of the same function.
573 * __DARWIN_ALIAS is used by itself if the function signature has not
574 * changed, it is used along with a #ifdef check for __DARWIN_UNIX03
575 * if the signature has changed. Because the __LP64__ environment
576 * only supports UNIX03 semantics it causes __DARWIN_UNIX03 to be
577 * defined, but causes __DARWIN_ALIAS to do no symbol mangling.
579 * As a special case, when XCode is used to target a specific version of the
580 * OS, the manifest constant __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
581 * will be defined by the compiler, with the digits representing major version
582 * time 100 + minor version times 10 (e.g. 10.5 := 1050). If we are targeting
583 * pre-10.5, and it is the default compilation environment, revert the
584 * compilation environment to pre-__DARWIN_UNIX03.
586 #if !defined(__DARWIN_ONLY_UNIX_CONFORMANCE)
587 # if defined(__LP64__)
588 # define __DARWIN_ONLY_UNIX_CONFORMANCE 1
589 # else /* !__LP64__ */
590 # define __DARWIN_ONLY_UNIX_CONFORMANCE 0
591 # endif /* __LP64__ */
592 #endif /* !__DARWIN_ONLY_UNIX_CONFORMANCE */
594 #if !defined(__DARWIN_UNIX03)
596 # define __DARWIN_UNIX03 0
597 # elif __DARWIN_ONLY_UNIX_CONFORMANCE
598 # if defined(_NONSTD_SOURCE)
599 # error "Can't define _NONSTD_SOURCE when only UNIX conformance is available."
600 # endif /* _NONSTD_SOURCE */
601 # define __DARWIN_UNIX03 1
602 # elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1040)
603 # define __DARWIN_UNIX03 0
604 # elif defined(_DARWIN_C_SOURCE) || defined(_XOPEN_SOURCE) || defined(_POSIX_C_SOURCE)
605 # if defined(_NONSTD_SOURCE)
606 # error "Can't define both _NONSTD_SOURCE and any of _DARWIN_C_SOURCE, _XOPEN_SOURCE or _POSIX_C_SOURCE."
607 # endif /* _NONSTD_SOURCE */
608 # define __DARWIN_UNIX03 1
609 # elif defined(_NONSTD_SOURCE)
610 # define __DARWIN_UNIX03 0
612 # if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1050)
613 # define __DARWIN_UNIX03 0
614 # else /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 */
615 # define __DARWIN_UNIX03 1
616 # endif /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 */
617 # endif /* _DARWIN_C_SOURCE || _XOPEN_SOURCE || _POSIX_C_SOURCE || __LP64__ */
618 #endif /* !__DARWIN_UNIX03 */
620 #if !defined(__DARWIN_64_BIT_INO_T)
622 # define __DARWIN_64_BIT_INO_T 0
623 # elif defined(_DARWIN_USE_64_BIT_INODE)
624 # if defined(_DARWIN_NO_64_BIT_INODE)
625 # error "Can't define both _DARWIN_USE_64_BIT_INODE and _DARWIN_NO_64_BIT_INODE."
626 # endif /* _DARWIN_NO_64_BIT_INODE */
627 # define __DARWIN_64_BIT_INO_T 1
628 # elif defined(_DARWIN_NO_64_BIT_INODE)
629 # if __DARWIN_ONLY_64_BIT_INO_T
630 # error "Can't define _DARWIN_NO_64_BIT_INODE when only 64-bit inodes are available."
631 # endif /* __DARWIN_ONLY_64_BIT_INO_T */
632 # define __DARWIN_64_BIT_INO_T 0
634 # if __DARWIN_ONLY_64_BIT_INO_T
635 # define __DARWIN_64_BIT_INO_T 1
636 # elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1060) || __DARWIN_UNIX03 == 0
637 # define __DARWIN_64_BIT_INO_T 0
639 # define __DARWIN_64_BIT_INO_T 1
640 # endif /* __DARWIN_ONLY_64_BIT_INO_T */
642 #endif /* !__DARWIN_64_BIT_INO_T */
644 #if !defined(__DARWIN_VERS_1050)
646 # define __DARWIN_VERS_1050 0
647 # elif __DARWIN_ONLY_VERS_1050
648 # define __DARWIN_VERS_1050 1
649 # elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1050) || __DARWIN_UNIX03 == 0
650 # define __DARWIN_VERS_1050 0
652 # define __DARWIN_VERS_1050 1
654 #endif /* !__DARWIN_VERS_1050 */
656 #if !defined(__DARWIN_NON_CANCELABLE)
658 # define __DARWIN_NON_CANCELABLE 0
660 # define __DARWIN_NON_CANCELABLE 0
662 #endif /* !__DARWIN_NON_CANCELABLE */
665 * symbol suffixes used for symbol versioning
668 # if __DARWIN_ONLY_UNIX_CONFORMANCE
669 # define __DARWIN_SUF_UNIX03 /* nothing */
670 # else /* !__DARWIN_ONLY_UNIX_CONFORMANCE */
671 # define __DARWIN_SUF_UNIX03 "$UNIX2003"
672 # endif /* __DARWIN_ONLY_UNIX_CONFORMANCE */
674 # if __DARWIN_64_BIT_INO_T
675 # if __DARWIN_ONLY_64_BIT_INO_T
676 # define __DARWIN_SUF_64_BIT_INO_T /* nothing */
677 # else /* !__DARWIN_ONLY_64_BIT_INO_T */
678 # define __DARWIN_SUF_64_BIT_INO_T "$INODE64"
679 # endif /* __DARWIN_ONLY_64_BIT_INO_T */
680 # else /* !__DARWIN_64_BIT_INO_T */
681 # define __DARWIN_SUF_64_BIT_INO_T /* nothing */
682 # endif /* __DARWIN_64_BIT_INO_T */
684 # if __DARWIN_VERS_1050
685 # if __DARWIN_ONLY_VERS_1050
686 # define __DARWIN_SUF_1050 /* nothing */
687 # else /* !__DARWIN_ONLY_VERS_1050 */
688 # define __DARWIN_SUF_1050 "$1050"
689 # endif /* __DARWIN_ONLY_VERS_1050 */
690 # else /* !__DARWIN_VERS_1050 */
691 # define __DARWIN_SUF_1050 /* nothing */
692 # endif /* __DARWIN_VERS_1050 */
694 # if __DARWIN_NON_CANCELABLE
695 # define __DARWIN_SUF_NON_CANCELABLE "$NOCANCEL"
696 # else /* !__DARWIN_NON_CANCELABLE */
697 # define __DARWIN_SUF_NON_CANCELABLE /* nothing */
698 # endif /* __DARWIN_NON_CANCELABLE */
700 #else /* !__DARWIN_UNIX03 */
701 # define __DARWIN_SUF_UNIX03 /* nothing */
702 # define __DARWIN_SUF_64_BIT_INO_T /* nothing */
703 # define __DARWIN_SUF_NON_CANCELABLE /* nothing */
704 # define __DARWIN_SUF_1050 /* nothing */
705 #endif /* __DARWIN_UNIX03 */
707 #define __DARWIN_SUF_EXTSN "$DARWIN_EXTSN"
710 * symbol versioning macros
712 #define __DARWIN_ALIAS(sym) __asm("_" __STRING(sym) __DARWIN_SUF_UNIX03)
713 #define __DARWIN_ALIAS_C(sym) __asm("_" __STRING(sym) __DARWIN_SUF_NON_CANCELABLE __DARWIN_SUF_UNIX03)
714 #define __DARWIN_ALIAS_I(sym) __asm("_" __STRING(sym) __DARWIN_SUF_64_BIT_INO_T __DARWIN_SUF_UNIX03)
715 #define __DARWIN_NOCANCEL(sym) __asm("_" __STRING(sym) __DARWIN_SUF_NON_CANCELABLE)
716 #define __DARWIN_INODE64(sym) __asm("_" __STRING(sym) __DARWIN_SUF_64_BIT_INO_T)
718 #define __DARWIN_1050(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050)
719 #define __DARWIN_1050ALIAS(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_UNIX03)
720 #define __DARWIN_1050ALIAS_C(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_NON_CANCELABLE __DARWIN_SUF_UNIX03)
721 #define __DARWIN_1050ALIAS_I(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_64_BIT_INO_T __DARWIN_SUF_UNIX03)
722 #define __DARWIN_1050INODE64(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_64_BIT_INO_T)
724 #define __DARWIN_EXTSN(sym) __asm("_" __STRING(sym) __DARWIN_SUF_EXTSN)
725 #define __DARWIN_EXTSN_C(sym) __asm("_" __STRING(sym) __DARWIN_SUF_EXTSN __DARWIN_SUF_NON_CANCELABLE)
726 #if XNU_KERNEL_PRIVATE
727 #define __XNU_INTERNAL(sym) __asm("_" __STRING(sym) "$XNU_INTERNAL")
731 * symbol release macros
734 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x)
736 #include <sys/_symbol_aliasing.h>
738 #if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
739 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) __DARWIN_ALIAS_STARTING_IPHONE_##_iphone(x)
740 #elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
741 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) __DARWIN_ALIAS_STARTING_MAC_##_mac(x)
743 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) x
749 * POSIX.1 requires that the macros we test be defined before any standard
750 * header file is included. This permits us to convert values for feature
751 * testing, as necessary, using only _POSIX_C_SOURCE.
753 * Here's a quick run-down of the versions:
754 * defined(_POSIX_SOURCE) 1003.1-1988
755 * _POSIX_C_SOURCE == 1L 1003.1-1990
756 * _POSIX_C_SOURCE == 2L 1003.2-1992 C Language Binding Option
757 * _POSIX_C_SOURCE == 199309L 1003.1b-1993
758 * _POSIX_C_SOURCE == 199506L 1003.1c-1995, 1003.1i-1995,
759 * and the omnibus ISO/IEC 9945-1: 1996
760 * _POSIX_C_SOURCE == 200112L 1003.1-2001
761 * _POSIX_C_SOURCE == 200809L 1003.1-2008
763 * In addition, the X/Open Portability Guide, which is now the Single UNIX
764 * Specification, defines a feature-test macro which indicates the version of
765 * that specification, and which subsumes _POSIX_C_SOURCE.
768 /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1L. */
769 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1L
770 #undef _POSIX_C_SOURCE
771 #define _POSIX_C_SOURCE 199009L
774 /* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2L. */
775 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2L
776 #undef _POSIX_C_SOURCE
777 #define _POSIX_C_SOURCE 199209L
780 /* Deal with various X/Open Portability Guides and Single UNIX Spec. */
782 #if _XOPEN_SOURCE - 0L >= 700L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 200809L)
783 #undef _POSIX_C_SOURCE
784 #define _POSIX_C_SOURCE 200809L
785 #elif _XOPEN_SOURCE - 0L >= 600L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 200112L)
786 #undef _POSIX_C_SOURCE
787 #define _POSIX_C_SOURCE 200112L
788 #elif _XOPEN_SOURCE - 0L >= 500L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 199506L)
789 #undef _POSIX_C_SOURCE
790 #define _POSIX_C_SOURCE 199506L
795 * Deal with all versions of POSIX. The ordering relative to the tests above is
798 #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
799 #define _POSIX_C_SOURCE 198808L
802 /* POSIX C deprecation macros */
804 #define __POSIX_C_DEPRECATED(ver)
806 #include <sys/_posix_availability.h>
808 #define __POSIX_C_DEPRECATED(ver) ___POSIX_C_DEPRECATED_STARTING_##ver
812 * Set a single macro which will always be defined and can be used to determine
813 * the appropriate namespace. For POSIX, these values will correspond to
814 * _POSIX_C_SOURCE value. Currently there are two additional levels corresponding
815 * to ANSI (_ANSI_SOURCE) and Darwin extensions (_DARWIN_C_SOURCE)
817 #define __DARWIN_C_ANSI 010000L
818 #define __DARWIN_C_FULL 900000L
820 #if defined(_ANSI_SOURCE)
821 #define __DARWIN_C_LEVEL __DARWIN_C_ANSI
822 #elif defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE) && !defined(_NONSTD_SOURCE)
823 #define __DARWIN_C_LEVEL _POSIX_C_SOURCE
825 #define __DARWIN_C_LEVEL __DARWIN_C_FULL
828 /* If the developer has neither requested a strict language mode nor a version
829 * of POSIX, turn on functionality provided by __STDC_WANT_LIB_EXT1__ as part
830 * of __DARWIN_C_FULL.
832 #if !defined(__STDC_WANT_LIB_EXT1__) && !defined(__STRICT_ANSI__) && __DARWIN_C_LEVEL >= __DARWIN_C_FULL
833 #define __STDC_WANT_LIB_EXT1__ 1
837 * long long is not supported in c89 (__STRICT_ANSI__), but g++ -ansi and
838 * c99 still want long longs. While not perfect, we allow long longs for
841 #if (defined(__STRICT_ANSI__) && (__STDC_VERSION__ - 0 < 199901L) && !defined(__GNUG__))
842 #define __DARWIN_NO_LONG_LONG 1
844 #define __DARWIN_NO_LONG_LONG 0
847 /*****************************************
848 * Public darwin-specific feature macros
849 *****************************************/
852 * _DARWIN_FEATURE_64_BIT_INODE indicates that the ino_t type is 64-bit, and
853 * structures modified for 64-bit inodes (like struct stat) will be used.
855 #if __DARWIN_64_BIT_INO_T
856 #define _DARWIN_FEATURE_64_BIT_INODE 1
860 * _DARWIN_FEATURE_64_ONLY_BIT_INODE indicates that the ino_t type may only
861 * be 64-bit; there is no support for 32-bit ino_t when this macro is defined
862 * (and non-zero). There is no struct stat64 either, as the regular
863 * struct stat will already be the 64-bit version.
865 #if __DARWIN_ONLY_64_BIT_INO_T
866 #define _DARWIN_FEATURE_ONLY_64_BIT_INODE 1
870 * _DARWIN_FEATURE_ONLY_VERS_1050 indicates that only those APIs updated
871 * in 10.5 exists; no pre-10.5 variants are available.
873 #if __DARWIN_ONLY_VERS_1050
874 #define _DARWIN_FEATURE_ONLY_VERS_1050 1
878 * _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE indicates only UNIX conforming API
879 * are available (the legacy BSD APIs are not available)
881 #if __DARWIN_ONLY_UNIX_CONFORMANCE
882 #define _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE 1
886 * _DARWIN_FEATURE_UNIX_CONFORMANCE indicates whether UNIX conformance is on,
887 * and specifies the conformance level (3 is SUSv3)
890 #define _DARWIN_FEATURE_UNIX_CONFORMANCE 3
893 #if defined(DRIVERKIT) && !defined(KERNEL)
895 * __DRIVERKIT_LIBC__ indicates to the C++ standard library headers and
896 * similar components that only the restricted set of standard C library
897 * functionality and headers for the DriverKit userspace driver environment
900 #define __DRIVERKIT_LIBC__ 1
901 #endif /* defined(DRIVERKIT) && !defined(KERNEL) */
904 * This macro casts away the qualifier from the variable
906 * Note: use at your own risk, removing qualifiers can result in
907 * catastrophic run-time failures.
909 #ifndef __CAST_AWAY_QUALIFIER
910 #define __CAST_AWAY_QUALIFIER(variable, qualifier, type) (type) (long)(variable)
914 * __XNU_PRIVATE_EXTERN is a linkage decoration indicating that a symbol can be
915 * used from other compilation units, but not other libraries or executables.
917 #ifndef __XNU_PRIVATE_EXTERN
918 #define __XNU_PRIVATE_EXTERN __attribute__((visibility("hidden")))
922 * Architecture validation for current SDK
924 #if !defined(__sys_cdefs_arch_unknown__) && defined(__i386__)
925 #elif !defined(__sys_cdefs_arch_unknown__) && defined(__x86_64__)
926 #elif !defined(__sys_cdefs_arch_unknown__) && defined(__arm__)
927 #elif !defined(__sys_cdefs_arch_unknown__) && defined(__arm64__)
929 #error Unsupported architecture
932 #ifdef XNU_KERNEL_PRIVATE
934 * Selectively ignore cast alignment warnings
936 #define __IGNORE_WCASTALIGN(x) _Pragma("clang diagnostic push") \
937 _Pragma("clang diagnostic ignored \"-Wcast-align\"") \
939 _Pragma("clang diagnostic pop")
942 #if defined(PRIVATE) || defined(KERNEL)
944 * Check if __probable and __improbable have already been defined elsewhere.
945 * These macros inform the compiler (and humans) about which branches are likely
948 #if !defined(__probable) && !defined(__improbable)
949 #define __probable(x) __builtin_expect(!!(x), 1)
950 #define __improbable(x) __builtin_expect(!!(x), 0)
951 #endif /* !defined(__probable) && !defined(__improbable) */
953 #if defined(__cplusplus)
954 #define __container_of(ptr, type, field) __extension__({ \
955 const typeof(((type *)nullptr)->field) *__ptr = (ptr); \
956 (type *)((uintptr_t)__ptr - offsetof(type, field)); \
959 #define __container_of(ptr, type, field) __extension__({ \
960 const typeof(((type *)NULL)->field) *__ptr = (ptr); \
961 (type *)((uintptr_t)__ptr - offsetof(type, field)); \
965 #endif /* KERNEL || PRIVATE */
967 #define __compiler_barrier() __asm__ __volatile__("" ::: "memory")
969 #if __has_attribute(enum_extensibility)
970 #define __enum_open __attribute__((__enum_extensibility__(open)))
971 #define __enum_closed __attribute__((__enum_extensibility__(closed)))
974 #define __enum_closed
975 #endif // __has_attribute(enum_extensibility)
977 #if __has_attribute(flag_enum)
978 #define __enum_options __attribute__((__flag_enum__))
980 #define __enum_options
984 * Similar to OS_ENUM/OS_CLOSED_ENUM/OS_OPTIONS/OS_CLOSED_OPTIONS
986 * This provides more advanced type checking on compilers supporting
987 * the proper extensions, even in C.
989 #if __has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum) || \
990 __has_extension(cxx_strong_enums)
991 #define __enum_decl(_name, _type, ...) \
992 typedef enum : _type __VA_ARGS__ __enum_open _name
993 #define __enum_closed_decl(_name, _type, ...) \
994 typedef enum : _type __VA_ARGS__ __enum_closed _name
995 #define __options_decl(_name, _type, ...) \
996 typedef enum : _type __VA_ARGS__ __enum_open __enum_options _name
997 #define __options_closed_decl(_name, _type, ...) \
998 typedef enum : _type __VA_ARGS__ __enum_closed __enum_options _name
1000 #define __enum_decl(_name, _type, ...) \
1001 typedef _type _name; enum __VA_ARGS__ __enum_open
1002 #define __enum_closed_decl(_name, _type, ...) \
1003 typedef _type _name; enum __VA_ARGS__ __enum_closed
1004 #define __options_decl(_name, _type, ...) \
1005 typedef _type _name; enum __VA_ARGS__ __enum_open __enum_options
1006 #define __options_closed_decl(_name, _type, ...) \
1007 typedef _type _name; enum __VA_ARGS__ __enum_closed __enum_options
1010 #endif /* !_CDEFS_H_ */