xref: /xnu-8796.101.5/bsd/sys/cdefs.h (revision aca3beaa3dfbd42498b42c5e5ce20a938e6554e5)
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_extension
101 #define __has_extension(x) 0
102 #endif
103 
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)
112 #define __P(protos)     protos          /* full-blown ANSI C */
113 #define __CONCAT(x, y)   x ## y
114 #define __STRING(x)     #x
115 
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 */
121 #else
122 #ifndef __GNUC__
123 #define __inline                        /* delete GCC keyword */
124 #endif /* !__GNUC__ */
125 #endif /* !__cplusplus */
126 
127 #else   /* !(__STDC__ || __cplusplus) */
128 #define __P(protos)     ()              /* traditional C preprocessor */
129 #define __CONCAT(x, y)   x /**/ y
130 #define __STRING(x)     "x"
131 
132 #ifndef __GNUC__
133 #define __const                         /* delete pseudo-ANSI C keywords */
134 #define __inline
135 #define __signed
136 #define __volatile
137 #endif  /* !__GNUC__ */
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  */
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) */
154 
155 /*
156  * __pure2 can be used for functions that are only a function of their scalar
157  * arguments (meaning they can't dereference pointers).
158  *
159  * __stateful_pure can be used for functions that have no side effects,
160  * but depend on the state of the memory.
161  */
162 #define __dead2         __attribute__((__noreturn__))
163 #define __pure2         __attribute__((__const__))
164 #define __stateful_pure __attribute__((__pure__))
165 
166 /* __unused denotes variables and functions that may not be used, preventing
167  * the compiler from warning about it if not used.
168  */
169 #define __unused        __attribute__((__unused__))
170 
171 /* __used forces variables and functions to be included even if it appears
172  * to the compiler that they are not used (and would thust be discarded).
173  */
174 #define __used          __attribute__((__used__))
175 
176 /* __cold marks code used for debugging or that is rarely taken
177  * and tells the compiler to optimize for size and outline code.
178  */
179 #if __has_attribute(cold)
180 #define __cold          __attribute__((__cold__))
181 #else
182 #define __cold
183 #endif
184 
185 /* __returns_nonnull marks functions that return a non-null pointer. */
186 #if __has_attribute(returns_nonnull)
187 #define __returns_nonnull __attribute((returns_nonnull))
188 #else
189 #define __returns_nonnull
190 #endif
191 
192 /* __exported denotes symbols that should be exported even when symbols
193  * are hidden by default.
194  * __exported_push/_exported_pop are pragmas used to delimit a range of
195  *  symbols that should be exported even when symbols are hidden by default.
196  */
197 #define __exported      __attribute__((__visibility__("default")))
198 #define __exported_push _Pragma("GCC visibility push(default)")
199 #define __exported_pop  _Pragma("GCC visibility pop")
200 
201 /* __deprecated causes the compiler to produce a warning when encountering
202  * code using the deprecated functionality.
203  * __deprecated_msg() does the same, and compilers that support it will print
204  * a message along with the deprecation warning.
205  * This may require turning on such warning with the -Wdeprecated flag.
206  * __deprecated_enum_msg() should be used on enums, and compilers that support
207  * it will print the deprecation warning.
208  * __kpi_deprecated() specifically indicates deprecation of kernel programming
209  * interfaces in Kernel.framework used by KEXTs.
210  */
211 #define __deprecated    __attribute__((__deprecated__))
212 
213 #if __has_extension(attribute_deprecated_with_message) || \
214         (defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5))))
215 	#define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
216 #else
217 	#define __deprecated_msg(_msg) __attribute__((__deprecated__))
218 #endif
219 
220 #if __has_extension(enumerator_attributes)
221 	#define __deprecated_enum_msg(_msg) __deprecated_msg(_msg)
222 #else
223 	#define __deprecated_enum_msg(_msg)
224 #endif
225 
226 #if defined(KERNEL) && !defined(KERNEL_PRIVATE)
227 #define __kpi_deprecated(_msg) __deprecated_msg(_msg)
228 #else /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */
229 #define __kpi_deprecated(_msg)
230 #endif /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */
231 
232 /* __unavailable causes the compiler to error out when encountering
233  * code using the tagged function
234  */
235 #if __has_attribute(unavailable)
236 #define __unavailable __attribute__((__unavailable__))
237 #else
238 #define __unavailable
239 #endif
240 
241 #if defined(KERNEL) && !defined(KERNEL_PRIVATE)
242 #define __kpi_unavailable __unavailable
243 #else /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */
244 #define __kpi_unavailable
245 #endif /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */
246 
247 #if XNU_KERNEL_PRIVATE
248 /* This macro is meant to be used for kpi deprecated to x86 3rd parties
249  * but should be marked as unavailable for arm macOS devices.
250  * XNU:                         nothing (API is still available)
251  * 1st party kexts:             __deprecated
252  * 3rd party kexts macOS x86:   __deprecated
253  * 3rd party kexts macOS arm:   __unavailable
254  */
255 #define __kpi_deprecated_arm64_macos_unavailable
256 #elif !KERNEL || !XNU_PLATFORM_MacOSX
257 #define __kpi_deprecated_arm64_macos_unavailable
258 #elif KERNEL_PRIVATE
259 #define __kpi_deprecated_arm64_macos_unavailable __deprecated
260 #elif defined(__arm64__)
261 #define __kpi_deprecated_arm64_macos_unavailable __unavailable
262 #else
263 #define __kpi_deprecated_arm64_macos_unavailable __deprecated
264 #endif /* XNU_KERNEL_PRIVATE */
265 
266 /* Delete pseudo-keywords wherever they are not available or needed. */
267 #ifndef __dead
268 #define __dead
269 #define __pure
270 #endif
271 
272 /*
273  * We use `__restrict' as a way to define the `restrict' type qualifier
274  * without disturbing older software that is unaware of C99 keywords.
275  */
276 #if __STDC_VERSION__ < 199901
277 #define __restrict
278 #else
279 #define __restrict      restrict
280 #endif
281 
282 /* Compatibility with compilers and environments that don't support the
283  * nullability feature.
284  */
285 
286 #if !__has_feature(nullability)
287 #ifndef __nullable
288 #define __nullable
289 #endif
290 #ifndef __nonnull
291 #define __nonnull
292 #endif
293 #ifndef __null_unspecified
294 #define __null_unspecified
295 #endif
296 #ifndef _Nullable
297 #define _Nullable
298 #endif
299 #ifndef _Nonnull
300 #define _Nonnull
301 #endif
302 #ifndef _Null_unspecified
303 #define _Null_unspecified
304 #endif
305 #endif
306 
307 /*
308  * __disable_tail_calls causes the compiler to not perform tail call
309  * optimization inside the marked function.
310  */
311 #if __has_attribute(disable_tail_calls)
312 #define __disable_tail_calls    __attribute__((__disable_tail_calls__))
313 #else
314 #define __disable_tail_calls
315 #endif
316 
317 /*
318  * __not_tail_called causes the compiler to prevent tail call optimization
319  * on statically bound calls to the function.  It has no effect on indirect
320  * calls.  Virtual functions, objective-c methods, and functions marked as
321  * "always_inline" cannot be marked as __not_tail_called.
322  */
323 #if __has_attribute(not_tail_called)
324 #define __not_tail_called       __attribute__((__not_tail_called__))
325 #else
326 #define __not_tail_called
327 #endif
328 
329 /*
330  * __result_use_check warns callers of a function that not using the function
331  * return value is a bug, i.e. dismissing malloc() return value results in a
332  * memory leak.
333  */
334 #if __has_attribute(warn_unused_result)
335 #define __result_use_check __attribute__((__warn_unused_result__))
336 #else
337 #define __result_use_check
338 #endif
339 
340 /*
341  * __swift_unavailable causes the compiler to mark a symbol as specifically
342  * unavailable in Swift, regardless of any other availability in C.
343  */
344 #if __has_feature(attribute_availability_swift)
345 #define __swift_unavailable(_msg)       __attribute__((__availability__(swift, unavailable, message=_msg)))
346 #else
347 #define __swift_unavailable(_msg)
348 #endif
349 
350 /*
351  * __abortlike is the attribute to put on functions like abort() that are
352  * typically used to mark assertions. These optimize the codegen
353  * for outlining while still maintaining debugability.
354  */
355 #ifndef __abortlike
356 #define __abortlike __dead2 __cold __not_tail_called
357 #endif
358 
359 /* Declaring inline functions within headers is error-prone due to differences
360  * across various versions of the C language and extensions.  __header_inline
361  * can be used to declare inline functions within system headers.  In cases
362  * where you want to force inlining instead of letting the compiler make
363  * the decision, you can use __header_always_inline.
364  *
365  * Be aware that using inline for functions which compilers may also provide
366  * builtins can behave differently under various compilers.  If you intend to
367  * provide an inline version of such a function, you may want to use a macro
368  * instead.
369  *
370  * The check for !__GNUC__ || __clang__ is because gcc doesn't correctly
371  * support c99 inline in some cases:
372  * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55965
373  */
374 
375 #if defined(__cplusplus) || \
376         (__STDC_VERSION__ >= 199901L && \
377         !defined(__GNUC_GNU_INLINE__) && \
378         (!defined(__GNUC__) || defined(__clang__)))
379 # define __header_inline           inline
380 #elif defined(__GNUC__) && defined(__GNUC_STDC_INLINE__)
381 # define __header_inline           extern __inline __attribute__((__gnu_inline__))
382 #elif defined(__GNUC__)
383 # define __header_inline           extern __inline
384 #else
385 /* If we land here, we've encountered an unsupported compiler,
386  * so hopefully it understands static __inline as a fallback.
387  */
388 # define __header_inline           static __inline
389 #endif
390 
391 #ifdef __GNUC__
392 # define __header_always_inline    __header_inline __attribute__ ((__always_inline__))
393 #else
394 /* Unfortunately, we're using a compiler that we don't know how to force to
395  * inline.  Oh well.
396  */
397 # define __header_always_inline    __header_inline
398 #endif
399 
400 /*
401  * Compiler-dependent macros that bracket portions of code where the
402  * "-Wunreachable-code" warning should be ignored. Please use sparingly.
403  */
404 #if defined(__clang__)
405 # define __unreachable_ok_push \
406 	 _Pragma("clang diagnostic push") \
407 	 _Pragma("clang diagnostic ignored \"-Wunreachable-code\"")
408 # define __unreachable_ok_pop \
409 	 _Pragma("clang diagnostic pop")
410 #elif defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
411 # define __unreachable_ok_push \
412 	 _Pragma("GCC diagnostic push") \
413 	 _Pragma("GCC diagnostic ignored \"-Wunreachable-code\"")
414 # define __unreachable_ok_pop \
415 	 _Pragma("GCC diagnostic pop")
416 #else
417 # define __unreachable_ok_push
418 # define __unreachable_ok_pop
419 #endif
420 
421 /*
422  * Compiler-dependent macros to declare that functions take printf-like
423  * or scanf-like arguments.  They are null except for versions of gcc
424  * that are known to support the features properly.  Functions declared
425  * with these attributes will cause compilation warnings if there is a
426  * mismatch between the format string and subsequent function parameter
427  * types.
428  */
429 #define __printflike(fmtarg, firstvararg) \
430 	__attribute__((__format__ (__printf__, fmtarg, firstvararg)))
431 #define __printf0like(fmtarg, firstvararg) \
432 	__attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
433 #define __scanflike(fmtarg, firstvararg) \
434 	__attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
435 #define __osloglike(fmtarg, firstvararg) \
436 	__attribute__((__format__ (__os_log__, fmtarg, firstvararg)))
437 
438 #define __IDSTRING(name, string) static const char name[] __used = string
439 
440 #ifndef __COPYRIGHT
441 #define __COPYRIGHT(s) __IDSTRING(copyright,s)
442 #endif
443 
444 #ifndef __RCSID
445 #define __RCSID(s) __IDSTRING(rcsid,s)
446 #endif
447 
448 #ifndef __SCCSID
449 #define __SCCSID(s) __IDSTRING(sccsid,s)
450 #endif
451 
452 #ifndef __PROJECT_VERSION
453 #define __PROJECT_VERSION(s) __IDSTRING(project_version,s)
454 #endif
455 
456 /* Source compatibility only, ID string not emitted in object file */
457 #ifndef __FBSDID
458 #define __FBSDID(s)
459 #endif
460 
461 #ifndef __DECONST
462 #define __DECONST(type, var)    __CAST_AWAY_QUALIFIER(var, const, type)
463 #endif
464 
465 #ifndef __DEVOLATILE
466 #define __DEVOLATILE(type, var) __CAST_AWAY_QUALIFIER(var, volatile, type)
467 #endif
468 
469 #ifndef __DEQUALIFY
470 #define __DEQUALIFY(type, var)  __CAST_AWAY_QUALIFIER(var, const volatile, type)
471 #endif
472 
473 /*
474  * __alloc_size can be used to label function arguments that represent the
475  * size of memory that the function allocates and returns. The one-argument
476  * form labels a single argument that gives the allocation size (where the
477  * arguments are numbered from 1):
478  *
479  * void	*malloc(size_t __size) __alloc_size(1);
480  *
481  * The two-argument form handles the case where the size is calculated as the
482  * product of two arguments:
483  *
484  * void	*calloc(size_t __count, size_t __size) __alloc_size(1,2);
485  */
486 #ifndef __alloc_size
487 #if __has_attribute(alloc_size)
488 #define __alloc_size(...) __attribute__((alloc_size(__VA_ARGS__)))
489 #else
490 #define __alloc_size(...)
491 #endif
492 #endif // __alloc_size
493 
494 /*
495  * COMPILATION ENVIRONMENTS -- see compat(5) for additional detail
496  *
497  * DEFAULT	By default newly complied code will get POSIX APIs plus
498  *		Apple API extensions in scope.
499  *
500  *		Most users will use this compilation environment to avoid
501  *		behavioral differences between 32 and 64 bit code.
502  *
503  * LEGACY	Defining _NONSTD_SOURCE will get pre-POSIX APIs plus Apple
504  *		API extensions in scope.
505  *
506  *		This is generally equivalent to the Tiger release compilation
507  *		environment, except that it cannot be applied to 64 bit code;
508  *		its use is discouraged.
509  *
510  *		We expect this environment to be deprecated in the future.
511  *
512  * STRICT	Defining _POSIX_C_SOURCE or _XOPEN_SOURCE restricts the
513  *		available APIs to exactly the set of APIs defined by the
514  *		corresponding standard, based on the value defined.
515  *
516  *		A correct, portable definition for _POSIX_C_SOURCE is 200112L.
517  *		A correct, portable definition for _XOPEN_SOURCE is 600L.
518  *
519  *		Apple API extensions are not visible in this environment,
520  *		which can cause Apple specific code to fail to compile,
521  *		or behave incorrectly if prototypes are not in scope or
522  *		warnings about missing prototypes are not enabled or ignored.
523  *
524  * In any compilation environment, for correct symbol resolution to occur,
525  * function prototypes must be in scope.  It is recommended that all Apple
526  * tools users add either the "-Wall" or "-Wimplicit-function-declaration"
527  * compiler flags to their projects to be warned when a function is being
528  * used without a prototype in scope.
529  */
530 
531 /* These settings are particular to each product. */
532 #ifdef KERNEL
533 #define __DARWIN_ONLY_64_BIT_INO_T      0
534 #define __DARWIN_ONLY_UNIX_CONFORMANCE  0
535 #define __DARWIN_ONLY_VERS_1050         0
536 #if defined(__x86_64__)
537 #define __DARWIN_SUF_DARWIN14   "_darwin14"
538 #define __DARWIN14_ALIAS(sym)   __asm("_" __STRING(sym) __DARWIN_SUF_DARWIN14)
539 #else
540 #define __DARWIN14_ALIAS(sym)
541 #endif
542 #else /* !KERNEL */
543 #ifdef XNU_PLATFORM_iPhoneOS
544 /* Platform: iPhoneOS */
545 #define __DARWIN_ONLY_64_BIT_INO_T      1
546 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
547 #define __DARWIN_ONLY_VERS_1050         1
548 #endif /* XNU_PLATFORM_iPhoneOS */
549 #ifdef XNU_PLATFORM_iPhoneSimulator
550 /* Platform: iPhoneSimulator */
551 #define __DARWIN_ONLY_64_BIT_INO_T      1
552 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
553 #define __DARWIN_ONLY_VERS_1050         1
554 #endif /* XNU_PLATFORM_iPhoneSimulator */
555 #ifdef XNU_PLATFORM_tvOS
556 /* Platform: tvOS */
557 #define __DARWIN_ONLY_64_BIT_INO_T      1
558 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
559 #define __DARWIN_ONLY_VERS_1050         1
560 #endif /* XNU_PLATFORM_tvOS */
561 #ifdef XNU_PLATFORM_AppleTVOS
562 /* Platform: AppleTVOS */
563 #define __DARWIN_ONLY_64_BIT_INO_T      1
564 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
565 #define __DARWIN_ONLY_VERS_1050         1
566 #endif /* XNU_PLATFORM_AppleTVOS */
567 #ifdef XNU_PLATFORM_tvSimulator
568 /* Platform: tvSimulator */
569 #define __DARWIN_ONLY_64_BIT_INO_T      1
570 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
571 #define __DARWIN_ONLY_VERS_1050         1
572 #endif /* XNU_PLATFORM_tvSimulator */
573 #ifdef XNU_PLATFORM_AppleTVSimulator
574 /* Platform: AppleTVSimulator */
575 #define __DARWIN_ONLY_64_BIT_INO_T      1
576 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
577 #define __DARWIN_ONLY_VERS_1050         1
578 #endif /* XNU_PLATFORM_AppleTVSimulator */
579 #ifdef XNU_PLATFORM_iPhoneOSNano
580 /* Platform: iPhoneOSNano */
581 #define __DARWIN_ONLY_64_BIT_INO_T      1
582 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
583 #define __DARWIN_ONLY_VERS_1050         1
584 #endif /* XNU_PLATFORM_iPhoneOSNano */
585 #ifdef XNU_PLATFORM_iPhoneNanoSimulator
586 /* Platform: iPhoneNanoSimulator */
587 #define __DARWIN_ONLY_64_BIT_INO_T      1
588 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
589 #define __DARWIN_ONLY_VERS_1050         1
590 #endif /* XNU_PLATFORM_iPhoneNanoSimulator */
591 #ifdef XNU_PLATFORM_WatchOS
592 /* Platform: WatchOS */
593 #define __DARWIN_ONLY_64_BIT_INO_T      1
594 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
595 #define __DARWIN_ONLY_VERS_1050         1
596 #endif /* XNU_PLATFORM_WatchOS */
597 #ifdef XNU_PLATFORM_WatchSimulator
598 /* Platform: WatchSimulator */
599 #define __DARWIN_ONLY_64_BIT_INO_T      1
600 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
601 #define __DARWIN_ONLY_VERS_1050         1
602 #endif /* XNU_PLATFORM_WatchSimulator */
603 #ifdef XNU_PLATFORM_BridgeOS
604 /* Platform: BridgeOS */
605 #define __DARWIN_ONLY_64_BIT_INO_T      1
606 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
607 #define __DARWIN_ONLY_VERS_1050         1
608 #endif /* XNU_PLATFORM_BridgeOS */
609 #ifdef XNU_PLATFORM_DriverKit
610 /* Platform: DriverKit */
611 #define __DARWIN_ONLY_64_BIT_INO_T      1
612 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
613 #define __DARWIN_ONLY_VERS_1050         1
614 #endif /* XNU_PLATFORM_DriverKit */
615 #ifdef XNU_PLATFORM_MacOSX
616 /* Platform: MacOSX */
617 #if defined(__i386__)
618 #define __DARWIN_ONLY_64_BIT_INO_T      0
619 #define __DARWIN_ONLY_UNIX_CONFORMANCE  0
620 #define __DARWIN_ONLY_VERS_1050         0
621 #elif defined(__x86_64__)
622 #define __DARWIN_ONLY_64_BIT_INO_T      0
623 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
624 #define __DARWIN_ONLY_VERS_1050         0
625 #else
626 #define __DARWIN_ONLY_64_BIT_INO_T      1
627 #define __DARWIN_ONLY_UNIX_CONFORMANCE  1
628 #define __DARWIN_ONLY_VERS_1050         1
629 #endif
630 #endif /* XNU_PLATFORM_MacOSX */
631 #endif /* KERNEL */
632 
633 /*
634  * The __DARWIN_ALIAS macros are used to do symbol renaming; they allow
635  * legacy code to use the old symbol, thus maintaining binary compatibility
636  * while new code can use a standards compliant version of the same function.
637  *
638  * __DARWIN_ALIAS is used by itself if the function signature has not
639  * changed, it is used along with a #ifdef check for __DARWIN_UNIX03
640  * if the signature has changed.  Because the __LP64__ environment
641  * only supports UNIX03 semantics it causes __DARWIN_UNIX03 to be
642  * defined, but causes __DARWIN_ALIAS to do no symbol mangling.
643  *
644  * As a special case, when XCode is used to target a specific version of the
645  * OS, the manifest constant __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
646  * will be defined by the compiler, with the digits representing major version
647  * time 100 + minor version times 10 (e.g. 10.5 := 1050).  If we are targeting
648  * pre-10.5, and it is the default compilation environment, revert the
649  * compilation environment to pre-__DARWIN_UNIX03.
650  */
651 #if !defined(__DARWIN_UNIX03)
652 #  if defined(KERNEL)
653 #    define __DARWIN_UNIX03     0
654 #  elif __DARWIN_ONLY_UNIX_CONFORMANCE
655 #    if defined(_NONSTD_SOURCE)
656 #      error "Can't define _NONSTD_SOURCE when only UNIX conformance is available."
657 #    endif /* _NONSTD_SOURCE */
658 #    define __DARWIN_UNIX03     1
659 #  elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1040)
660 #    define __DARWIN_UNIX03     0
661 #  elif defined(_DARWIN_C_SOURCE) || defined(_XOPEN_SOURCE) || defined(_POSIX_C_SOURCE)
662 #    if defined(_NONSTD_SOURCE)
663 #      error "Can't define both _NONSTD_SOURCE and any of _DARWIN_C_SOURCE, _XOPEN_SOURCE or _POSIX_C_SOURCE."
664 #    endif /* _NONSTD_SOURCE */
665 #    define __DARWIN_UNIX03     1
666 #  elif defined(_NONSTD_SOURCE)
667 #    define __DARWIN_UNIX03     0
668 #  else /* default */
669 #    if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1050)
670 #      define __DARWIN_UNIX03   0
671 #    else /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 */
672 #      define __DARWIN_UNIX03   1
673 #    endif /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 */
674 #  endif /* _DARWIN_C_SOURCE || _XOPEN_SOURCE || _POSIX_C_SOURCE || __LP64__ */
675 #endif /* !__DARWIN_UNIX03 */
676 
677 #if !defined(__DARWIN_64_BIT_INO_T)
678 #  if defined(KERNEL)
679 #    define __DARWIN_64_BIT_INO_T 0
680 #  elif defined(_DARWIN_USE_64_BIT_INODE)
681 #    if defined(_DARWIN_NO_64_BIT_INODE)
682 #      error "Can't define both _DARWIN_USE_64_BIT_INODE and _DARWIN_NO_64_BIT_INODE."
683 #    endif /* _DARWIN_NO_64_BIT_INODE */
684 #    define __DARWIN_64_BIT_INO_T 1
685 #  elif defined(_DARWIN_NO_64_BIT_INODE)
686 #    if __DARWIN_ONLY_64_BIT_INO_T
687 #      error "Can't define _DARWIN_NO_64_BIT_INODE when only 64-bit inodes are available."
688 #    endif /* __DARWIN_ONLY_64_BIT_INO_T */
689 #    define __DARWIN_64_BIT_INO_T 0
690 #  else /* default */
691 #    if __DARWIN_ONLY_64_BIT_INO_T
692 #      define __DARWIN_64_BIT_INO_T 1
693 #    elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1060) || __DARWIN_UNIX03 == 0
694 #      define __DARWIN_64_BIT_INO_T 0
695 #    else /* default */
696 #      define __DARWIN_64_BIT_INO_T 1
697 #    endif /* __DARWIN_ONLY_64_BIT_INO_T */
698 #  endif
699 #endif /* !__DARWIN_64_BIT_INO_T */
700 
701 #if !defined(__DARWIN_VERS_1050)
702 #  if defined(KERNEL)
703 #    define __DARWIN_VERS_1050 0
704 #  elif __DARWIN_ONLY_VERS_1050
705 #    define __DARWIN_VERS_1050 1
706 #  elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1050) || __DARWIN_UNIX03 == 0
707 #    define __DARWIN_VERS_1050 0
708 #  else /* default */
709 #    define __DARWIN_VERS_1050 1
710 #  endif
711 #endif /* !__DARWIN_VERS_1050 */
712 
713 #if !defined(__DARWIN_NON_CANCELABLE)
714 #  if defined(KERNEL)
715 #    define __DARWIN_NON_CANCELABLE 0
716 #  else /* default */
717 #    define __DARWIN_NON_CANCELABLE 0
718 #  endif
719 #endif /* !__DARWIN_NON_CANCELABLE */
720 
721 /*
722  * symbol suffixes used for symbol versioning
723  */
724 #if __DARWIN_UNIX03
725 #  if __DARWIN_ONLY_UNIX_CONFORMANCE
726 #    define __DARWIN_SUF_UNIX03         /* nothing */
727 #  else /* !__DARWIN_ONLY_UNIX_CONFORMANCE */
728 #    define __DARWIN_SUF_UNIX03         "$UNIX2003"
729 #  endif /* __DARWIN_ONLY_UNIX_CONFORMANCE */
730 
731 #  if __DARWIN_64_BIT_INO_T
732 #    if __DARWIN_ONLY_64_BIT_INO_T
733 #      define __DARWIN_SUF_64_BIT_INO_T /* nothing */
734 #    else /* !__DARWIN_ONLY_64_BIT_INO_T */
735 #      define __DARWIN_SUF_64_BIT_INO_T "$INODE64"
736 #    endif /* __DARWIN_ONLY_64_BIT_INO_T */
737 #  else /* !__DARWIN_64_BIT_INO_T */
738 #    define __DARWIN_SUF_64_BIT_INO_T   /* nothing */
739 #  endif /* __DARWIN_64_BIT_INO_T */
740 
741 #  if __DARWIN_VERS_1050
742 #    if __DARWIN_ONLY_VERS_1050
743 #      define __DARWIN_SUF_1050         /* nothing */
744 #    else /* !__DARWIN_ONLY_VERS_1050 */
745 #      define __DARWIN_SUF_1050         "$1050"
746 #    endif /* __DARWIN_ONLY_VERS_1050 */
747 #  else /* !__DARWIN_VERS_1050 */
748 #    define __DARWIN_SUF_1050           /* nothing */
749 #  endif /* __DARWIN_VERS_1050 */
750 
751 #  if __DARWIN_NON_CANCELABLE
752 #    define __DARWIN_SUF_NON_CANCELABLE "$NOCANCEL"
753 #  else /* !__DARWIN_NON_CANCELABLE */
754 #    define __DARWIN_SUF_NON_CANCELABLE /* nothing */
755 #  endif /* __DARWIN_NON_CANCELABLE */
756 
757 #else /* !__DARWIN_UNIX03 */
758 #  define __DARWIN_SUF_UNIX03           /* nothing */
759 #  define __DARWIN_SUF_64_BIT_INO_T     /* nothing */
760 #  define __DARWIN_SUF_NON_CANCELABLE   /* nothing */
761 #  define __DARWIN_SUF_1050             /* nothing */
762 #endif /* __DARWIN_UNIX03 */
763 
764 #define __DARWIN_SUF_EXTSN              "$DARWIN_EXTSN"
765 
766 /*
767  * symbol versioning macros
768  */
769 #define __DARWIN_ALIAS(sym)             __asm("_" __STRING(sym) __DARWIN_SUF_UNIX03)
770 #define __DARWIN_ALIAS_C(sym)           __asm("_" __STRING(sym) __DARWIN_SUF_NON_CANCELABLE __DARWIN_SUF_UNIX03)
771 #define __DARWIN_ALIAS_I(sym)           __asm("_" __STRING(sym) __DARWIN_SUF_64_BIT_INO_T __DARWIN_SUF_UNIX03)
772 #define __DARWIN_NOCANCEL(sym)          __asm("_" __STRING(sym) __DARWIN_SUF_NON_CANCELABLE)
773 #define __DARWIN_INODE64(sym)           __asm("_" __STRING(sym) __DARWIN_SUF_64_BIT_INO_T)
774 
775 #define __DARWIN_1050(sym)              __asm("_" __STRING(sym) __DARWIN_SUF_1050)
776 #define __DARWIN_1050ALIAS(sym)         __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_UNIX03)
777 #define __DARWIN_1050ALIAS_C(sym)       __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_NON_CANCELABLE __DARWIN_SUF_UNIX03)
778 #define __DARWIN_1050ALIAS_I(sym)       __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_64_BIT_INO_T __DARWIN_SUF_UNIX03)
779 #define __DARWIN_1050INODE64(sym)       __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_64_BIT_INO_T)
780 
781 #define __DARWIN_EXTSN(sym)             __asm("_" __STRING(sym) __DARWIN_SUF_EXTSN)
782 #define __DARWIN_EXTSN_C(sym)           __asm("_" __STRING(sym) __DARWIN_SUF_EXTSN __DARWIN_SUF_NON_CANCELABLE)
783 #if XNU_KERNEL_PRIVATE
784 #define __XNU_INTERNAL(sym)             __asm("_" __STRING(sym) "$XNU_INTERNAL") __attribute__((used))
785 #endif
786 
787 /*
788  * symbol release macros
789  */
790 #ifdef KERNEL
791 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x)
792 #else
793 #include <sys/_symbol_aliasing.h>
794 
795 #if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
796 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x)   __DARWIN_ALIAS_STARTING_IPHONE_##_iphone(x)
797 #elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
798 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x)   __DARWIN_ALIAS_STARTING_MAC_##_mac(x)
799 #else
800 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x)   x
801 #endif
802 #endif /* KERNEL */
803 
804 
805 /*
806  * POSIX.1 requires that the macros we test be defined before any standard
807  * header file is included.  This permits us to convert values for feature
808  * testing, as necessary, using only _POSIX_C_SOURCE.
809  *
810  * Here's a quick run-down of the versions:
811  *  defined(_POSIX_SOURCE)		1003.1-1988
812  *  _POSIX_C_SOURCE == 1L		1003.1-1990
813  *  _POSIX_C_SOURCE == 2L		1003.2-1992 C Language Binding Option
814  *  _POSIX_C_SOURCE == 199309L		1003.1b-1993
815  *  _POSIX_C_SOURCE == 199506L		1003.1c-1995, 1003.1i-1995,
816  *					and the omnibus ISO/IEC 9945-1: 1996
817  *  _POSIX_C_SOURCE == 200112L		1003.1-2001
818  *  _POSIX_C_SOURCE == 200809L		1003.1-2008
819  *
820  * In addition, the X/Open Portability Guide, which is now the Single UNIX
821  * Specification, defines a feature-test macro which indicates the version of
822  * that specification, and which subsumes _POSIX_C_SOURCE.
823  */
824 
825 /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1L. */
826 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1L
827 #undef _POSIX_C_SOURCE
828 #define _POSIX_C_SOURCE         199009L
829 #endif
830 
831 /* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2L. */
832 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2L
833 #undef _POSIX_C_SOURCE
834 #define _POSIX_C_SOURCE         199209L
835 #endif
836 
837 /* Deal with various X/Open Portability Guides and Single UNIX Spec. */
838 #ifdef _XOPEN_SOURCE
839 #if _XOPEN_SOURCE - 0L >= 700L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 200809L)
840 #undef _POSIX_C_SOURCE
841 #define _POSIX_C_SOURCE         200809L
842 #elif _XOPEN_SOURCE - 0L >= 600L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 200112L)
843 #undef _POSIX_C_SOURCE
844 #define _POSIX_C_SOURCE         200112L
845 #elif _XOPEN_SOURCE - 0L >= 500L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 199506L)
846 #undef _POSIX_C_SOURCE
847 #define _POSIX_C_SOURCE         199506L
848 #endif
849 #endif
850 
851 /*
852  * Deal with all versions of POSIX.  The ordering relative to the tests above is
853  * important.
854  */
855 #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
856 #define _POSIX_C_SOURCE         198808L
857 #endif
858 
859 /* POSIX C deprecation macros */
860 #ifdef KERNEL
861 #define __POSIX_C_DEPRECATED(ver)
862 #else
863 #include <sys/_posix_availability.h>
864 
865 #define __POSIX_C_DEPRECATED(ver) ___POSIX_C_DEPRECATED_STARTING_##ver
866 #endif
867 
868 /*
869  * Set a single macro which will always be defined and can be used to determine
870  * the appropriate namespace.  For POSIX, these values will correspond to
871  * _POSIX_C_SOURCE value.  Currently there are two additional levels corresponding
872  * to ANSI (_ANSI_SOURCE) and Darwin extensions (_DARWIN_C_SOURCE)
873  */
874 #define __DARWIN_C_ANSI         010000L
875 #define __DARWIN_C_FULL         900000L
876 
877 #if   defined(_ANSI_SOURCE)
878 #define __DARWIN_C_LEVEL        __DARWIN_C_ANSI
879 #elif defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE) && !defined(_NONSTD_SOURCE)
880 #define __DARWIN_C_LEVEL        _POSIX_C_SOURCE
881 #else
882 #define __DARWIN_C_LEVEL        __DARWIN_C_FULL
883 #endif
884 
885 /* If the developer has neither requested a strict language mode nor a version
886  * of POSIX, turn on functionality provided by __STDC_WANT_LIB_EXT1__ as part
887  * of __DARWIN_C_FULL.
888  */
889 #if !defined(__STDC_WANT_LIB_EXT1__) && !defined(__STRICT_ANSI__) && __DARWIN_C_LEVEL >= __DARWIN_C_FULL
890 #define __STDC_WANT_LIB_EXT1__ 1
891 #endif
892 
893 /*
894  * long long is not supported in c89 (__STRICT_ANSI__), but g++ -ansi and
895  * c99 still want long longs.  While not perfect, we allow long longs for
896  * g++.
897  */
898 #if (defined(__STRICT_ANSI__) && (__STDC_VERSION__ - 0 < 199901L) && !defined(__GNUG__))
899 #define __DARWIN_NO_LONG_LONG 1
900 #else
901 #define __DARWIN_NO_LONG_LONG 0
902 #endif
903 
904 /*****************************************
905 *  Public darwin-specific feature macros
906 *****************************************/
907 
908 /*
909  * _DARWIN_FEATURE_64_BIT_INODE indicates that the ino_t type is 64-bit, and
910  * structures modified for 64-bit inodes (like struct stat) will be used.
911  */
912 #if __DARWIN_64_BIT_INO_T
913 #define _DARWIN_FEATURE_64_BIT_INODE            1
914 #endif
915 
916 /*
917  * _DARWIN_FEATURE_64_ONLY_BIT_INODE indicates that the ino_t type may only
918  * be 64-bit; there is no support for 32-bit ino_t when this macro is defined
919  * (and non-zero).  There is no struct stat64 either, as the regular
920  * struct stat will already be the 64-bit version.
921  */
922 #if __DARWIN_ONLY_64_BIT_INO_T
923 #define _DARWIN_FEATURE_ONLY_64_BIT_INODE       1
924 #endif
925 
926 /*
927  * _DARWIN_FEATURE_ONLY_VERS_1050 indicates that only those APIs updated
928  * in 10.5 exists; no pre-10.5 variants are available.
929  */
930 #if __DARWIN_ONLY_VERS_1050
931 #define _DARWIN_FEATURE_ONLY_VERS_1050          1
932 #endif
933 
934 /*
935  * _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE indicates only UNIX conforming API
936  * are available (the legacy BSD APIs are not available)
937  */
938 #if __DARWIN_ONLY_UNIX_CONFORMANCE
939 #define _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE   1
940 #endif
941 
942 /*
943  * _DARWIN_FEATURE_UNIX_CONFORMANCE indicates whether UNIX conformance is on,
944  * and specifies the conformance level (3 is SUSv3)
945  */
946 #if __DARWIN_UNIX03
947 #define _DARWIN_FEATURE_UNIX_CONFORMANCE        3
948 #endif
949 
950 #if defined(DRIVERKIT) && !defined(KERNEL)
951 /*
952  * __DRIVERKIT_LIBC__ indicates to the C++ standard library headers and
953  * similar components that only the restricted set of standard C library
954  * functionality and headers for the DriverKit userspace driver environment
955  * are available.
956  */
957 #define __DRIVERKIT_LIBC__                      1
958 #endif /* defined(DRIVERKIT) && !defined(KERNEL) */
959 
960 /*
961  * This macro casts away the qualifier from the variable
962  *
963  * Note: use at your own risk, removing qualifiers can result in
964  * catastrophic run-time failures.
965  */
966 #ifndef __CAST_AWAY_QUALIFIER
967 /*
968  * XXX: this shouldn't ignore anything more than -Wcast-qual,
969  * but the old implementation made it an almighty cast that
970  * ignored everything, so things break left and right if you
971  * make it only ignore -Wcast-qual.
972  */
973 #define __CAST_AWAY_QUALIFIER(variable, qualifier, type) \
974 	_Pragma("GCC diagnostic push") \
975 	_Pragma("GCC diagnostic ignored \"-Wcast-qual\"") \
976 	_Pragma("GCC diagnostic ignored \"-Wcast-align\"") \
977 	_Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"") \
978 	((type)(variable)) \
979 	_Pragma("GCC diagnostic pop")
980 #endif
981 
982 /*
983  * __XNU_PRIVATE_EXTERN is a linkage decoration indicating that a symbol can be
984  * used from other compilation units, but not other libraries or executables.
985  */
986 #ifndef __XNU_PRIVATE_EXTERN
987 #define __XNU_PRIVATE_EXTERN __attribute__((visibility("hidden")))
988 #endif
989 
990 #if __has_include(<ptrcheck.h>)
991 #include <ptrcheck.h>
992 #else
993 /*
994  * We intentionally define to nothing pointer attributes which do not have an
995  * impact on the ABI. __indexable and __bidi_indexable are not defined because
996  * of the ABI incompatibility that makes the diagnostic preferable.
997  */
998 #define __has_ptrcheck 0
999 #define __single
1000 #define __unsafe_indexable
1001 #define __counted_by(N)
1002 #define __sized_by(N)
1003 #define __ended_by(E)
1004 #define __terminated_by(T)
1005 #define __null_terminated
1006 
1007 /*
1008  * Similarly, we intentionally define to nothing the
1009  * __ptrcheck_abi_assume_single and __ptrcheck_abi_assume_unsafe_indexable
1010  * macros because they do not lead to an ABI incompatibility. However, we do not
1011  * define the indexable and unsafe_indexable ones because the diagnostic is
1012  * better than the silent ABI break.
1013  */
1014 #define __ptrcheck_abi_assume_single()
1015 #define __ptrcheck_abi_assume_unsafe_indexable()
1016 
1017 /* __unsafe_forge intrinsics are defined as regular C casts. */
1018 #define __unsafe_forge_bidi_indexable(T, P, S) ((T)(P))
1019 #define __unsafe_forge_single(T, P) ((T)(P))
1020 #define __terminated_by_to_indexable(P) (P)
1021 #define __unsafe_terminated_by_to_indexable(P) (P)
1022 #define __null_terminated_to_indexable(P) (P)
1023 #define __unsafe_null_terminated_to_indexable(P) (P)
1024 #define __unsafe_terminated_by_from_indexable(T, P, ...) (P)
1025 #define __unsafe_null_terminated_from_indexable(P, ...) (P)
1026 
1027 /* decay operates normally; attribute is meaningless without pointer checks. */
1028 #define __array_decay_dicards_count_in_parameters
1029 
1030 /* this is a write-once variable; not useful without pointer checks. */
1031 #define __unsafe_late_const
1032 #endif /* !__has_include(<ptrcheck.h>) */
1033 
1034 #if KERNEL && !BOUND_CHECKS && !__has_ptrcheck
1035 /*
1036  * With pointer checks disabled, we define __indexable to allow source to still
1037  * contain these annotations. This is safe in builds which _uniformly_ disable
1038  * pointer checks (but not in builds which inconsistently have them enabled).
1039  */
1040 
1041 #define __indexable
1042 #define __bidi_indexable
1043 #endif
1044 
1045 #define __ASSUME_PTR_ABI_SINGLE_BEGIN       __ptrcheck_abi_assume_single()
1046 #define __ASSUME_PTR_ABI_SINGLE_END         __ptrcheck_abi_assume_unsafe_indexable()
1047 
1048 #if __has_ptrcheck
1049 #define __header_indexable                  __indexable
1050 #define __header_bidi_indexable             __bidi_indexable
1051 #else
1052 #define __header_indexable
1053 #define __header_bidi_indexable
1054 #endif
1055 
1056 /*
1057  * Architecture validation for current SDK
1058  */
1059 #if !defined(__sys_cdefs_arch_unknown__) && defined(__i386__)
1060 #elif !defined(__sys_cdefs_arch_unknown__) && defined(__x86_64__)
1061 #elif !defined(__sys_cdefs_arch_unknown__) && defined(__arm__)
1062 #elif !defined(__sys_cdefs_arch_unknown__) && defined(__arm64__)
1063 #else
1064 #error Unsupported architecture
1065 #endif
1066 
1067 #ifdef XNU_KERNEL_PRIVATE
1068 /*
1069  * Selectively ignore cast alignment warnings
1070  */
1071 #define __IGNORE_WCASTALIGN(x) _Pragma("clang diagnostic push")                     \
1072 	                       _Pragma("clang diagnostic ignored \"-Wcast-align\"") \
1073 	                       x                                                    \
1074 	                       _Pragma("clang diagnostic pop")
1075 #endif
1076 
1077 #if defined(PRIVATE) || defined(KERNEL)
1078 /*
1079  * Check if __probable and __improbable have already been defined elsewhere.
1080  * These macros inform the compiler (and humans) about which branches are likely
1081  * to be taken.
1082  */
1083 #if !defined(__probable) && !defined(__improbable)
1084 #define __probable(x)   __builtin_expect(!!(x), 1)
1085 #define __improbable(x) __builtin_expect(!!(x), 0)
1086 #endif /* !defined(__probable) && !defined(__improbable) */
1087 
1088 #define __container_of(ptr, type_t, field) __extension__({ \
1089 	const __typeof__(((type_t *)NULL)->field) *__ptr = (ptr);               \
1090 	uintptr_t __result = (uintptr_t)__ptr - offsetof(type_t, field);        \
1091 	if (__ptr) __builtin_assume(__result != 0);                             \
1092 	__unsafe_forge_single(type_t *, __result);                              \
1093 })
1094 
1095 #define __container_of_safe(ptr, type_t, field) __extension__({ \
1096 	const __typeof__(((type_t *)NULL)->field) *__ptr_or_null = (ptr);       \
1097 	__ptr_or_null ? __container_of(__ptr_or_null, type_t, field) : NULL;    \
1098 })
1099 
1100 /*
1101  * This forces the optimizer to materialize the specified variable value,
1102  * and prevents any reordering of operations done to it.
1103  */
1104 #define __compiler_materialize_and_prevent_reordering_on(var) \
1105 	__asm__ ("" : "=r"(var) : "0"(var))
1106 
1107 #endif /* KERNEL || PRIVATE */
1108 
1109 #define __compiler_barrier() __asm__ __volatile__("" ::: "memory")
1110 
1111 #if __has_attribute(enum_extensibility)
1112 #define __enum_open __attribute__((__enum_extensibility__(open)))
1113 #define __enum_closed __attribute__((__enum_extensibility__(closed)))
1114 #else
1115 #define __enum_open
1116 #define __enum_closed
1117 #endif // __has_attribute(enum_extensibility)
1118 
1119 #if __has_attribute(flag_enum)
1120 #define __enum_options __attribute__((__flag_enum__))
1121 #else
1122 #define __enum_options
1123 #endif
1124 
1125 /*
1126  * Similar to OS_ENUM/OS_CLOSED_ENUM/OS_OPTIONS/OS_CLOSED_OPTIONS
1127  *
1128  * This provides more advanced type checking on compilers supporting
1129  * the proper extensions, even in C.
1130  */
1131 #if __has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum) || \
1132         __has_extension(cxx_strong_enums)
1133 #define __enum_decl(_name, _type, ...) \
1134 	        typedef enum : _type __VA_ARGS__ __enum_open _name
1135 #define __enum_closed_decl(_name, _type, ...) \
1136 	        typedef enum : _type __VA_ARGS__ __enum_closed _name
1137 #define __options_decl(_name, _type, ...) \
1138 	        typedef enum : _type __VA_ARGS__ __enum_open __enum_options _name
1139 #define __options_closed_decl(_name, _type, ...) \
1140 	        typedef enum : _type __VA_ARGS__ __enum_closed __enum_options _name
1141 #else
1142 #define __enum_decl(_name, _type, ...) \
1143 	        typedef _type _name; enum __VA_ARGS__ __enum_open
1144 #define __enum_closed_decl(_name, _type, ...) \
1145 	        typedef _type _name; enum __VA_ARGS__ __enum_closed
1146 #define __options_decl(_name, _type, ...) \
1147 	        typedef _type _name; enum __VA_ARGS__ __enum_open __enum_options
1148 #define __options_closed_decl(_name, _type, ...) \
1149 	        typedef _type _name; enum __VA_ARGS__ __enum_closed __enum_options
1150 #endif
1151 
1152 #if XNU_KERNEL_PRIVATE
1153 /*
1154  * __xnu_struct_group() can be used to declare a set of fields to be grouped
1155  * together logically in order to perform safer memory operations
1156  * (assignment, zeroing, ...) on them.
1157  */
1158 #ifdef __cplusplus
1159 #define __xnu_struct_group(group_type, group_name, ...) \
1160 	struct group_type __VA_ARGS__; \
1161 	union { \
1162 	    struct __VA_ARGS__; \
1163 	    struct group_type group_name; \
1164 	}
1165 #else
1166 #define __xnu_struct_group(group_type, group_name, ...) \
1167 	union { \
1168 	    struct __VA_ARGS__; \
1169 	    struct group_type __VA_ARGS__ group_name; \
1170 	}
1171 #endif
1172 #endif /* XNU_KERNEL_PRIVATE */
1173 
1174 #if defined(KERNEL) && __has_attribute(xnu_usage_semantics)
1175 /*
1176  * These macros can be used to annotate type definitions or scalar structure
1177  * fields to inform the compiler about which semantic they have with regards
1178  * to the content of the underlying memory represented by such type or field.
1179  *
1180  * This information is used in the analysis of the types performed by the
1181  * signature based type segregation implemented in kalloc.
1182  */
1183 #define __kernel_ptr_semantics __attribute__((xnu_usage_semantics("pointer")))
1184 #define __kernel_data_semantics __attribute__((xnu_usage_semantics("data")))
1185 #define __kernel_dual_semantics __attribute__((xnu_usage_semantics("pointer", "data")))
1186 
1187 #else  /* defined(KERNEL) && __has_attribute(xnu_usage_semantics) */
1188 
1189 #define __kernel_ptr_semantics
1190 #define __kernel_data_semantics
1191 #define __kernel_dual_semantics
1192 
1193 #endif /* defined(KERNEL) && __has_attribute(xnu_usage_semantics) */
1194 
1195 #if XNU_KERNEL_PRIVATE
1196 /*
1197  * Compiler-dependent macros that bracket portions of code where the
1198  * "-Wxnu-typed-allocators" warning should be ignored.
1199  */
1200 #if defined(__clang__)
1201 # define __typed_allocators_ignore_push \
1202 	 _Pragma("clang diagnostic push") \
1203 	 _Pragma("clang diagnostic ignored \"-Wxnu-typed-allocators\"")
1204 # define __typed_allocators_ignore_pop \
1205 	 _Pragma("clang diagnostic pop")
1206 # define __typed_allocators_ignore(x) __typed_allocators_ignore_push \
1207 	                              x                              \
1208 	                              __typed_allocators_ignore_pop
1209 #else
1210 # define __typed_allocators_ignore_push
1211 # define __typed_allocators_ignore_push
1212 # define __typed_allocators_ignore(x) x
1213 #endif /* __clang */
1214 #endif /* XNU_KERNEL_PRIVATE */
1215 
1216 #endif /* !_CDEFS_H_ */
1217