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