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_align can be used to label function arguments that represent the 475 * alignment of the returned pointer. 476 */ 477 #ifndef __alloc_align 478 #if __has_attribute(alloc_align) 479 #define __alloc_align(n) __attribute__((alloc_align(n))) 480 #else 481 #define __alloc_align(n) 482 #endif 483 #endif // __alloc_align 484 485 /* 486 * __alloc_size can be used to label function arguments that represent the 487 * size of memory that the function allocates and returns. The one-argument 488 * form labels a single argument that gives the allocation size (where the 489 * arguments are numbered from 1): 490 * 491 * void *malloc(size_t __size) __alloc_size(1); 492 * 493 * The two-argument form handles the case where the size is calculated as the 494 * product of two arguments: 495 * 496 * void *calloc(size_t __count, size_t __size) __alloc_size(1,2); 497 */ 498 #ifndef __alloc_size 499 #if __has_attribute(alloc_size) 500 #define __alloc_size(...) __attribute__((alloc_size(__VA_ARGS__))) 501 #else 502 #define __alloc_size(...) 503 #endif 504 #endif // __alloc_size 505 506 /* 507 * COMPILATION ENVIRONMENTS -- see compat(5) for additional detail 508 * 509 * DEFAULT By default newly complied code will get POSIX APIs plus 510 * Apple API extensions in scope. 511 * 512 * Most users will use this compilation environment to avoid 513 * behavioral differences between 32 and 64 bit code. 514 * 515 * LEGACY Defining _NONSTD_SOURCE will get pre-POSIX APIs plus Apple 516 * API extensions in scope. 517 * 518 * This is generally equivalent to the Tiger release compilation 519 * environment, except that it cannot be applied to 64 bit code; 520 * its use is discouraged. 521 * 522 * We expect this environment to be deprecated in the future. 523 * 524 * STRICT Defining _POSIX_C_SOURCE or _XOPEN_SOURCE restricts the 525 * available APIs to exactly the set of APIs defined by the 526 * corresponding standard, based on the value defined. 527 * 528 * A correct, portable definition for _POSIX_C_SOURCE is 200112L. 529 * A correct, portable definition for _XOPEN_SOURCE is 600L. 530 * 531 * Apple API extensions are not visible in this environment, 532 * which can cause Apple specific code to fail to compile, 533 * or behave incorrectly if prototypes are not in scope or 534 * warnings about missing prototypes are not enabled or ignored. 535 * 536 * In any compilation environment, for correct symbol resolution to occur, 537 * function prototypes must be in scope. It is recommended that all Apple 538 * tools users add either the "-Wall" or "-Wimplicit-function-declaration" 539 * compiler flags to their projects to be warned when a function is being 540 * used without a prototype in scope. 541 */ 542 543 /* These settings are particular to each product. */ 544 #ifdef KERNEL 545 #define __DARWIN_ONLY_64_BIT_INO_T 0 546 #define __DARWIN_ONLY_UNIX_CONFORMANCE 0 547 #define __DARWIN_ONLY_VERS_1050 0 548 #if defined(__x86_64__) 549 #define __DARWIN_SUF_DARWIN14 "_darwin14" 550 #define __DARWIN14_ALIAS(sym) __asm("_" __STRING(sym) __DARWIN_SUF_DARWIN14) 551 #else 552 #define __DARWIN14_ALIAS(sym) 553 #endif 554 #else /* !KERNEL */ 555 #ifdef XNU_PLATFORM_iPhoneOS 556 /* Platform: iPhoneOS */ 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_iPhoneOS */ 561 #ifdef XNU_PLATFORM_iPhoneSimulator 562 /* Platform: iPhoneSimulator */ 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_iPhoneSimulator */ 567 #ifdef XNU_PLATFORM_tvOS 568 /* Platform: tvOS */ 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_tvOS */ 573 #ifdef XNU_PLATFORM_AppleTVOS 574 /* Platform: AppleTVOS */ 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_AppleTVOS */ 579 #ifdef XNU_PLATFORM_tvSimulator 580 /* Platform: tvSimulator */ 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_tvSimulator */ 585 #ifdef XNU_PLATFORM_AppleTVSimulator 586 /* Platform: AppleTVSimulator */ 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_AppleTVSimulator */ 591 #ifdef XNU_PLATFORM_iPhoneOSNano 592 /* Platform: iPhoneOSNano */ 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_iPhoneOSNano */ 597 #ifdef XNU_PLATFORM_iPhoneNanoSimulator 598 /* Platform: iPhoneNanoSimulator */ 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_iPhoneNanoSimulator */ 603 #ifdef XNU_PLATFORM_WatchOS 604 /* Platform: WatchOS */ 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_WatchOS */ 609 #ifdef XNU_PLATFORM_WatchSimulator 610 /* Platform: WatchSimulator */ 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_WatchSimulator */ 615 #ifdef XNU_PLATFORM_BridgeOS 616 /* Platform: BridgeOS */ 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 /* XNU_PLATFORM_BridgeOS */ 621 #ifdef XNU_PLATFORM_DriverKit 622 /* Platform: DriverKit */ 623 #define __DARWIN_ONLY_64_BIT_INO_T 1 624 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 625 #define __DARWIN_ONLY_VERS_1050 1 626 #endif /* XNU_PLATFORM_DriverKit */ 627 #ifdef XNU_PLATFORM_MacOSX 628 /* Platform: MacOSX */ 629 #if defined(__i386__) 630 #define __DARWIN_ONLY_64_BIT_INO_T 0 631 #define __DARWIN_ONLY_UNIX_CONFORMANCE 0 632 #define __DARWIN_ONLY_VERS_1050 0 633 #elif defined(__x86_64__) 634 #define __DARWIN_ONLY_64_BIT_INO_T 0 635 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 636 #define __DARWIN_ONLY_VERS_1050 0 637 #else 638 #define __DARWIN_ONLY_64_BIT_INO_T 1 639 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 640 #define __DARWIN_ONLY_VERS_1050 1 641 #endif 642 #endif /* XNU_PLATFORM_MacOSX */ 643 #endif /* KERNEL */ 644 645 /* 646 * The __DARWIN_ALIAS macros are used to do symbol renaming; they allow 647 * legacy code to use the old symbol, thus maintaining binary compatibility 648 * while new code can use a standards compliant version of the same function. 649 * 650 * __DARWIN_ALIAS is used by itself if the function signature has not 651 * changed, it is used along with a #ifdef check for __DARWIN_UNIX03 652 * if the signature has changed. Because the __LP64__ environment 653 * only supports UNIX03 semantics it causes __DARWIN_UNIX03 to be 654 * defined, but causes __DARWIN_ALIAS to do no symbol mangling. 655 * 656 * As a special case, when XCode is used to target a specific version of the 657 * OS, the manifest constant __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ 658 * will be defined by the compiler, with the digits representing major version 659 * time 100 + minor version times 10 (e.g. 10.5 := 1050). If we are targeting 660 * pre-10.5, and it is the default compilation environment, revert the 661 * compilation environment to pre-__DARWIN_UNIX03. 662 */ 663 #if !defined(__DARWIN_UNIX03) 664 # if defined(KERNEL) 665 # define __DARWIN_UNIX03 0 666 # elif __DARWIN_ONLY_UNIX_CONFORMANCE 667 # if defined(_NONSTD_SOURCE) 668 # error "Can't define _NONSTD_SOURCE when only UNIX conformance is available." 669 # endif /* _NONSTD_SOURCE */ 670 # define __DARWIN_UNIX03 1 671 # elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1040) 672 # define __DARWIN_UNIX03 0 673 # elif defined(_DARWIN_C_SOURCE) || defined(_XOPEN_SOURCE) || defined(_POSIX_C_SOURCE) 674 # if defined(_NONSTD_SOURCE) 675 # error "Can't define both _NONSTD_SOURCE and any of _DARWIN_C_SOURCE, _XOPEN_SOURCE or _POSIX_C_SOURCE." 676 # endif /* _NONSTD_SOURCE */ 677 # define __DARWIN_UNIX03 1 678 # elif defined(_NONSTD_SOURCE) 679 # define __DARWIN_UNIX03 0 680 # else /* default */ 681 # if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1050) 682 # define __DARWIN_UNIX03 0 683 # else /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 */ 684 # define __DARWIN_UNIX03 1 685 # endif /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 */ 686 # endif /* _DARWIN_C_SOURCE || _XOPEN_SOURCE || _POSIX_C_SOURCE || __LP64__ */ 687 #endif /* !__DARWIN_UNIX03 */ 688 689 #if !defined(__DARWIN_64_BIT_INO_T) 690 # if defined(KERNEL) 691 # define __DARWIN_64_BIT_INO_T 0 692 # elif defined(_DARWIN_USE_64_BIT_INODE) 693 # if defined(_DARWIN_NO_64_BIT_INODE) 694 # error "Can't define both _DARWIN_USE_64_BIT_INODE and _DARWIN_NO_64_BIT_INODE." 695 # endif /* _DARWIN_NO_64_BIT_INODE */ 696 # define __DARWIN_64_BIT_INO_T 1 697 # elif defined(_DARWIN_NO_64_BIT_INODE) 698 # if __DARWIN_ONLY_64_BIT_INO_T 699 # error "Can't define _DARWIN_NO_64_BIT_INODE when only 64-bit inodes are available." 700 # endif /* __DARWIN_ONLY_64_BIT_INO_T */ 701 # define __DARWIN_64_BIT_INO_T 0 702 # else /* default */ 703 # if __DARWIN_ONLY_64_BIT_INO_T 704 # define __DARWIN_64_BIT_INO_T 1 705 # elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1060) || __DARWIN_UNIX03 == 0 706 # define __DARWIN_64_BIT_INO_T 0 707 # else /* default */ 708 # define __DARWIN_64_BIT_INO_T 1 709 # endif /* __DARWIN_ONLY_64_BIT_INO_T */ 710 # endif 711 #endif /* !__DARWIN_64_BIT_INO_T */ 712 713 #if !defined(__DARWIN_VERS_1050) 714 # if defined(KERNEL) 715 # define __DARWIN_VERS_1050 0 716 # elif __DARWIN_ONLY_VERS_1050 717 # define __DARWIN_VERS_1050 1 718 # elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1050) || __DARWIN_UNIX03 == 0 719 # define __DARWIN_VERS_1050 0 720 # else /* default */ 721 # define __DARWIN_VERS_1050 1 722 # endif 723 #endif /* !__DARWIN_VERS_1050 */ 724 725 #if !defined(__DARWIN_NON_CANCELABLE) 726 # if defined(KERNEL) 727 # define __DARWIN_NON_CANCELABLE 0 728 # else /* default */ 729 # define __DARWIN_NON_CANCELABLE 0 730 # endif 731 #endif /* !__DARWIN_NON_CANCELABLE */ 732 733 /* 734 * symbol suffixes used for symbol versioning 735 */ 736 #if __DARWIN_UNIX03 737 # if __DARWIN_ONLY_UNIX_CONFORMANCE 738 # define __DARWIN_SUF_UNIX03 /* nothing */ 739 # else /* !__DARWIN_ONLY_UNIX_CONFORMANCE */ 740 # define __DARWIN_SUF_UNIX03 "$UNIX2003" 741 # endif /* __DARWIN_ONLY_UNIX_CONFORMANCE */ 742 743 # if __DARWIN_64_BIT_INO_T 744 # if __DARWIN_ONLY_64_BIT_INO_T 745 # define __DARWIN_SUF_64_BIT_INO_T /* nothing */ 746 # else /* !__DARWIN_ONLY_64_BIT_INO_T */ 747 # define __DARWIN_SUF_64_BIT_INO_T "$INODE64" 748 # endif /* __DARWIN_ONLY_64_BIT_INO_T */ 749 # else /* !__DARWIN_64_BIT_INO_T */ 750 # define __DARWIN_SUF_64_BIT_INO_T /* nothing */ 751 # endif /* __DARWIN_64_BIT_INO_T */ 752 753 # if __DARWIN_VERS_1050 754 # if __DARWIN_ONLY_VERS_1050 755 # define __DARWIN_SUF_1050 /* nothing */ 756 # else /* !__DARWIN_ONLY_VERS_1050 */ 757 # define __DARWIN_SUF_1050 "$1050" 758 # endif /* __DARWIN_ONLY_VERS_1050 */ 759 # else /* !__DARWIN_VERS_1050 */ 760 # define __DARWIN_SUF_1050 /* nothing */ 761 # endif /* __DARWIN_VERS_1050 */ 762 763 # if __DARWIN_NON_CANCELABLE 764 # define __DARWIN_SUF_NON_CANCELABLE "$NOCANCEL" 765 # else /* !__DARWIN_NON_CANCELABLE */ 766 # define __DARWIN_SUF_NON_CANCELABLE /* nothing */ 767 # endif /* __DARWIN_NON_CANCELABLE */ 768 769 #else /* !__DARWIN_UNIX03 */ 770 # define __DARWIN_SUF_UNIX03 /* nothing */ 771 # define __DARWIN_SUF_64_BIT_INO_T /* nothing */ 772 # define __DARWIN_SUF_NON_CANCELABLE /* nothing */ 773 # define __DARWIN_SUF_1050 /* nothing */ 774 #endif /* __DARWIN_UNIX03 */ 775 776 #define __DARWIN_SUF_EXTSN "$DARWIN_EXTSN" 777 778 /* 779 * symbol versioning macros 780 */ 781 #define __DARWIN_ALIAS(sym) __asm("_" __STRING(sym) __DARWIN_SUF_UNIX03) 782 #define __DARWIN_ALIAS_C(sym) __asm("_" __STRING(sym) __DARWIN_SUF_NON_CANCELABLE __DARWIN_SUF_UNIX03) 783 #define __DARWIN_ALIAS_I(sym) __asm("_" __STRING(sym) __DARWIN_SUF_64_BIT_INO_T __DARWIN_SUF_UNIX03) 784 #define __DARWIN_NOCANCEL(sym) __asm("_" __STRING(sym) __DARWIN_SUF_NON_CANCELABLE) 785 #define __DARWIN_INODE64(sym) __asm("_" __STRING(sym) __DARWIN_SUF_64_BIT_INO_T) 786 787 #define __DARWIN_1050(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050) 788 #define __DARWIN_1050ALIAS(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_UNIX03) 789 #define __DARWIN_1050ALIAS_C(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_NON_CANCELABLE __DARWIN_SUF_UNIX03) 790 #define __DARWIN_1050ALIAS_I(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_64_BIT_INO_T __DARWIN_SUF_UNIX03) 791 #define __DARWIN_1050INODE64(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_64_BIT_INO_T) 792 793 #define __DARWIN_EXTSN(sym) __asm("_" __STRING(sym) __DARWIN_SUF_EXTSN) 794 #define __DARWIN_EXTSN_C(sym) __asm("_" __STRING(sym) __DARWIN_SUF_EXTSN __DARWIN_SUF_NON_CANCELABLE) 795 #if XNU_KERNEL_PRIVATE 796 #define __XNU_INTERNAL(sym) __asm("_" __STRING(sym) "$XNU_INTERNAL") __attribute__((used)) 797 #endif 798 799 /* 800 * symbol release macros 801 */ 802 #ifdef KERNEL 803 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) 804 #else 805 #include <sys/_symbol_aliasing.h> 806 807 #if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) 808 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) __DARWIN_ALIAS_STARTING_IPHONE_##_iphone(x) 809 #elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) 810 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) __DARWIN_ALIAS_STARTING_MAC_##_mac(x) 811 #else 812 #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) x 813 #endif 814 #endif /* KERNEL */ 815 816 817 /* 818 * POSIX.1 requires that the macros we test be defined before any standard 819 * header file is included. This permits us to convert values for feature 820 * testing, as necessary, using only _POSIX_C_SOURCE. 821 * 822 * Here's a quick run-down of the versions: 823 * defined(_POSIX_SOURCE) 1003.1-1988 824 * _POSIX_C_SOURCE == 1L 1003.1-1990 825 * _POSIX_C_SOURCE == 2L 1003.2-1992 C Language Binding Option 826 * _POSIX_C_SOURCE == 199309L 1003.1b-1993 827 * _POSIX_C_SOURCE == 199506L 1003.1c-1995, 1003.1i-1995, 828 * and the omnibus ISO/IEC 9945-1: 1996 829 * _POSIX_C_SOURCE == 200112L 1003.1-2001 830 * _POSIX_C_SOURCE == 200809L 1003.1-2008 831 * 832 * In addition, the X/Open Portability Guide, which is now the Single UNIX 833 * Specification, defines a feature-test macro which indicates the version of 834 * that specification, and which subsumes _POSIX_C_SOURCE. 835 */ 836 837 /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1L. */ 838 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1L 839 #undef _POSIX_C_SOURCE 840 #define _POSIX_C_SOURCE 199009L 841 #endif 842 843 /* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2L. */ 844 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2L 845 #undef _POSIX_C_SOURCE 846 #define _POSIX_C_SOURCE 199209L 847 #endif 848 849 /* Deal with various X/Open Portability Guides and Single UNIX Spec. */ 850 #ifdef _XOPEN_SOURCE 851 #if _XOPEN_SOURCE - 0L >= 700L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 200809L) 852 #undef _POSIX_C_SOURCE 853 #define _POSIX_C_SOURCE 200809L 854 #elif _XOPEN_SOURCE - 0L >= 600L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 200112L) 855 #undef _POSIX_C_SOURCE 856 #define _POSIX_C_SOURCE 200112L 857 #elif _XOPEN_SOURCE - 0L >= 500L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 199506L) 858 #undef _POSIX_C_SOURCE 859 #define _POSIX_C_SOURCE 199506L 860 #endif 861 #endif 862 863 /* 864 * Deal with all versions of POSIX. The ordering relative to the tests above is 865 * important. 866 */ 867 #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) 868 #define _POSIX_C_SOURCE 198808L 869 #endif 870 871 /* POSIX C deprecation macros */ 872 #ifdef KERNEL 873 #define __POSIX_C_DEPRECATED(ver) 874 #else 875 #include <sys/_posix_availability.h> 876 877 #define __POSIX_C_DEPRECATED(ver) ___POSIX_C_DEPRECATED_STARTING_##ver 878 #endif 879 880 /* 881 * Set a single macro which will always be defined and can be used to determine 882 * the appropriate namespace. For POSIX, these values will correspond to 883 * _POSIX_C_SOURCE value. Currently there are two additional levels corresponding 884 * to ANSI (_ANSI_SOURCE) and Darwin extensions (_DARWIN_C_SOURCE) 885 */ 886 #define __DARWIN_C_ANSI 010000L 887 #define __DARWIN_C_FULL 900000L 888 889 #if defined(_ANSI_SOURCE) 890 #define __DARWIN_C_LEVEL __DARWIN_C_ANSI 891 #elif defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE) && !defined(_NONSTD_SOURCE) 892 #define __DARWIN_C_LEVEL _POSIX_C_SOURCE 893 #else 894 #define __DARWIN_C_LEVEL __DARWIN_C_FULL 895 #endif 896 897 /* If the developer has neither requested a strict language mode nor a version 898 * of POSIX, turn on functionality provided by __STDC_WANT_LIB_EXT1__ as part 899 * of __DARWIN_C_FULL. 900 */ 901 #if !defined(__STDC_WANT_LIB_EXT1__) && !defined(__STRICT_ANSI__) && __DARWIN_C_LEVEL >= __DARWIN_C_FULL 902 #define __STDC_WANT_LIB_EXT1__ 1 903 #endif 904 905 /* 906 * long long is not supported in c89 (__STRICT_ANSI__), but g++ -ansi and 907 * c99 still want long longs. While not perfect, we allow long longs for 908 * g++. 909 */ 910 #if (defined(__STRICT_ANSI__) && (__STDC_VERSION__ - 0 < 199901L) && !defined(__GNUG__)) 911 #define __DARWIN_NO_LONG_LONG 1 912 #else 913 #define __DARWIN_NO_LONG_LONG 0 914 #endif 915 916 /***************************************** 917 * Public darwin-specific feature macros 918 *****************************************/ 919 920 /* 921 * _DARWIN_FEATURE_64_BIT_INODE indicates that the ino_t type is 64-bit, and 922 * structures modified for 64-bit inodes (like struct stat) will be used. 923 */ 924 #if __DARWIN_64_BIT_INO_T 925 #define _DARWIN_FEATURE_64_BIT_INODE 1 926 #endif 927 928 /* 929 * _DARWIN_FEATURE_64_ONLY_BIT_INODE indicates that the ino_t type may only 930 * be 64-bit; there is no support for 32-bit ino_t when this macro is defined 931 * (and non-zero). There is no struct stat64 either, as the regular 932 * struct stat will already be the 64-bit version. 933 */ 934 #if __DARWIN_ONLY_64_BIT_INO_T 935 #define _DARWIN_FEATURE_ONLY_64_BIT_INODE 1 936 #endif 937 938 /* 939 * _DARWIN_FEATURE_ONLY_VERS_1050 indicates that only those APIs updated 940 * in 10.5 exists; no pre-10.5 variants are available. 941 */ 942 #if __DARWIN_ONLY_VERS_1050 943 #define _DARWIN_FEATURE_ONLY_VERS_1050 1 944 #endif 945 946 /* 947 * _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE indicates only UNIX conforming API 948 * are available (the legacy BSD APIs are not available) 949 */ 950 #if __DARWIN_ONLY_UNIX_CONFORMANCE 951 #define _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE 1 952 #endif 953 954 /* 955 * _DARWIN_FEATURE_UNIX_CONFORMANCE indicates whether UNIX conformance is on, 956 * and specifies the conformance level (3 is SUSv3) 957 */ 958 #if __DARWIN_UNIX03 959 #define _DARWIN_FEATURE_UNIX_CONFORMANCE 3 960 #endif 961 962 #if defined(DRIVERKIT) && !defined(KERNEL) 963 /* 964 * __DRIVERKIT_LIBC__ indicates to the C++ standard library headers and 965 * similar components that only the restricted set of standard C library 966 * functionality and headers for the DriverKit userspace driver environment 967 * are available. 968 */ 969 #define __DRIVERKIT_LIBC__ 1 970 #endif /* defined(DRIVERKIT) && !defined(KERNEL) */ 971 972 /* 973 * This macro casts away the qualifier from the variable 974 * 975 * Note: use at your own risk, removing qualifiers can result in 976 * catastrophic run-time failures. 977 */ 978 #ifndef __CAST_AWAY_QUALIFIER 979 /* 980 * XXX: this shouldn't ignore anything more than -Wcast-qual, 981 * but the old implementation made it an almighty cast that 982 * ignored everything, so things break left and right if you 983 * make it only ignore -Wcast-qual. 984 */ 985 #define __CAST_AWAY_QUALIFIER(variable, qualifier, type) \ 986 _Pragma("GCC diagnostic push") \ 987 _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") \ 988 _Pragma("GCC diagnostic ignored \"-Wcast-align\"") \ 989 _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"") \ 990 ((type)(variable)) \ 991 _Pragma("GCC diagnostic pop") 992 #endif 993 994 /* 995 * __XNU_PRIVATE_EXTERN is a linkage decoration indicating that a symbol can be 996 * used from other compilation units, but not other libraries or executables. 997 */ 998 #ifndef __XNU_PRIVATE_EXTERN 999 #define __XNU_PRIVATE_EXTERN __attribute__((visibility("hidden"))) 1000 #endif 1001 1002 #if __has_include(<ptrcheck.h>) 1003 #include <ptrcheck.h> 1004 #else 1005 /* 1006 * We intentionally define to nothing pointer attributes which do not have an 1007 * impact on the ABI. __indexable and __bidi_indexable are not defined because 1008 * of the ABI incompatibility that makes the diagnostic preferable. 1009 */ 1010 #define __has_ptrcheck 0 1011 #define __single 1012 #define __unsafe_indexable 1013 #define __counted_by(N) 1014 #define __sized_by(N) 1015 #define __ended_by(E) 1016 #define __terminated_by(T) 1017 #define __null_terminated 1018 1019 /* 1020 * Similarly, we intentionally define to nothing the 1021 * __ptrcheck_abi_assume_single and __ptrcheck_abi_assume_unsafe_indexable 1022 * macros because they do not lead to an ABI incompatibility. However, we do not 1023 * define the indexable and unsafe_indexable ones because the diagnostic is 1024 * better than the silent ABI break. 1025 */ 1026 #define __ptrcheck_abi_assume_single() 1027 #define __ptrcheck_abi_assume_unsafe_indexable() 1028 1029 /* __unsafe_forge intrinsics are defined as regular C casts. */ 1030 #define __unsafe_forge_bidi_indexable(T, P, S) ((T)(P)) 1031 #define __unsafe_forge_single(T, P) ((T)(P)) 1032 #define __terminated_by_to_indexable(P) (P) 1033 #define __unsafe_terminated_by_to_indexable(P) (P) 1034 #define __null_terminated_to_indexable(P) (P) 1035 #define __unsafe_null_terminated_to_indexable(P) (P) 1036 #define __unsafe_terminated_by_from_indexable(T, P, ...) (P) 1037 #define __unsafe_null_terminated_from_indexable(P, ...) (P) 1038 1039 /* decay operates normally; attribute is meaningless without pointer checks. */ 1040 #define __array_decay_dicards_count_in_parameters 1041 1042 /* this is a write-once variable; not useful without pointer checks. */ 1043 #define __unsafe_late_const 1044 #endif /* !__has_include(<ptrcheck.h>) */ 1045 1046 #if KERNEL && !BOUND_CHECKS && !__has_ptrcheck 1047 /* 1048 * With pointer checks disabled, we define __indexable to allow source to still 1049 * contain these annotations. This is safe in builds which _uniformly_ disable 1050 * pointer checks (but not in builds which inconsistently have them enabled). 1051 */ 1052 1053 #define __indexable 1054 #define __bidi_indexable 1055 #endif 1056 1057 #define __ASSUME_PTR_ABI_SINGLE_BEGIN __ptrcheck_abi_assume_single() 1058 #define __ASSUME_PTR_ABI_SINGLE_END __ptrcheck_abi_assume_unsafe_indexable() 1059 1060 #if __has_ptrcheck 1061 #define __header_indexable __indexable 1062 #define __header_bidi_indexable __bidi_indexable 1063 #else 1064 #define __header_indexable 1065 #define __header_bidi_indexable 1066 #endif 1067 1068 /* 1069 * Architecture validation for current SDK 1070 */ 1071 #if !defined(__sys_cdefs_arch_unknown__) && defined(__i386__) 1072 #elif !defined(__sys_cdefs_arch_unknown__) && defined(__x86_64__) 1073 #elif !defined(__sys_cdefs_arch_unknown__) && defined(__arm__) 1074 #elif !defined(__sys_cdefs_arch_unknown__) && defined(__arm64__) 1075 #else 1076 #error Unsupported architecture 1077 #endif 1078 1079 #ifdef XNU_KERNEL_PRIVATE 1080 /* 1081 * Selectively ignore cast alignment warnings 1082 */ 1083 #define __IGNORE_WCASTALIGN(x) _Pragma("clang diagnostic push") \ 1084 _Pragma("clang diagnostic ignored \"-Wcast-align\"") \ 1085 x \ 1086 _Pragma("clang diagnostic pop") 1087 #endif 1088 1089 #if defined(PRIVATE) || defined(KERNEL) 1090 /* 1091 * Check if __probable and __improbable have already been defined elsewhere. 1092 * These macros inform the compiler (and humans) about which branches are likely 1093 * to be taken. 1094 */ 1095 #if !defined(__probable) && !defined(__improbable) 1096 #define __probable(x) __builtin_expect(!!(x), 1) 1097 #define __improbable(x) __builtin_expect(!!(x), 0) 1098 #endif /* !defined(__probable) && !defined(__improbable) */ 1099 1100 #define __container_of(ptr, type_t, field) __extension__({ \ 1101 const __typeof__(((type_t *)NULL)->field) *__ptr = (ptr); \ 1102 uintptr_t __result = (uintptr_t)__ptr - offsetof(type_t, field); \ 1103 if (__ptr) __builtin_assume(__result != 0); \ 1104 __unsafe_forge_single(type_t *, __result); \ 1105 }) 1106 1107 #define __container_of_safe(ptr, type_t, field) __extension__({ \ 1108 const __typeof__(((type_t *)NULL)->field) *__ptr_or_null = (ptr); \ 1109 __ptr_or_null ? __container_of(__ptr_or_null, type_t, field) : NULL; \ 1110 }) 1111 1112 /* 1113 * This forces the optimizer to materialize the specified variable value, 1114 * and prevents any reordering of operations done to it. 1115 */ 1116 #define __compiler_materialize_and_prevent_reordering_on(var) \ 1117 __asm__ ("" : "=r"(var) : "0"(var)) 1118 1119 #endif /* KERNEL || PRIVATE */ 1120 1121 #define __compiler_barrier() __asm__ __volatile__("" ::: "memory") 1122 1123 #if __has_attribute(enum_extensibility) 1124 #define __enum_open __attribute__((__enum_extensibility__(open))) 1125 #define __enum_closed __attribute__((__enum_extensibility__(closed))) 1126 #else 1127 #define __enum_open 1128 #define __enum_closed 1129 #endif // __has_attribute(enum_extensibility) 1130 1131 #if __has_attribute(flag_enum) 1132 #define __enum_options __attribute__((__flag_enum__)) 1133 #else 1134 #define __enum_options 1135 #endif 1136 1137 /* 1138 * Similar to OS_ENUM/OS_CLOSED_ENUM/OS_OPTIONS/OS_CLOSED_OPTIONS 1139 * 1140 * This provides more advanced type checking on compilers supporting 1141 * the proper extensions, even in C. 1142 */ 1143 #if __has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum) || \ 1144 __has_extension(cxx_strong_enums) 1145 #define __enum_decl(_name, _type, ...) \ 1146 typedef enum : _type __VA_ARGS__ __enum_open _name 1147 #define __enum_closed_decl(_name, _type, ...) \ 1148 typedef enum : _type __VA_ARGS__ __enum_closed _name 1149 #define __options_decl(_name, _type, ...) \ 1150 typedef enum : _type __VA_ARGS__ __enum_open __enum_options _name 1151 #define __options_closed_decl(_name, _type, ...) \ 1152 typedef enum : _type __VA_ARGS__ __enum_closed __enum_options _name 1153 #else 1154 #define __enum_decl(_name, _type, ...) \ 1155 typedef _type _name; enum __VA_ARGS__ __enum_open 1156 #define __enum_closed_decl(_name, _type, ...) \ 1157 typedef _type _name; enum __VA_ARGS__ __enum_closed 1158 #define __options_decl(_name, _type, ...) \ 1159 typedef _type _name; enum __VA_ARGS__ __enum_open __enum_options 1160 #define __options_closed_decl(_name, _type, ...) \ 1161 typedef _type _name; enum __VA_ARGS__ __enum_closed __enum_options 1162 #endif 1163 1164 #if XNU_KERNEL_PRIVATE 1165 /* 1166 * __xnu_struct_group() can be used to declare a set of fields to be grouped 1167 * together logically in order to perform safer memory operations 1168 * (assignment, zeroing, ...) on them. 1169 */ 1170 #ifdef __cplusplus 1171 #define __xnu_struct_group(group_type, group_name, ...) \ 1172 struct group_type __VA_ARGS__; \ 1173 union { \ 1174 struct __VA_ARGS__; \ 1175 struct group_type group_name; \ 1176 } 1177 #else 1178 #define __xnu_struct_group(group_type, group_name, ...) \ 1179 union { \ 1180 struct __VA_ARGS__; \ 1181 struct group_type __VA_ARGS__ group_name; \ 1182 } 1183 #endif 1184 #endif /* XNU_KERNEL_PRIVATE */ 1185 1186 #if defined(KERNEL) && __has_attribute(xnu_usage_semantics) 1187 /* 1188 * These macros can be used to annotate type definitions or scalar structure 1189 * fields to inform the compiler about which semantic they have with regards 1190 * to the content of the underlying memory represented by such type or field. 1191 * 1192 * This information is used in the analysis of the types performed by the 1193 * signature based type segregation implemented in kalloc. 1194 */ 1195 #define __kernel_ptr_semantics __attribute__((xnu_usage_semantics("pointer"))) 1196 #define __kernel_data_semantics __attribute__((xnu_usage_semantics("data"))) 1197 #define __kernel_dual_semantics __attribute__((xnu_usage_semantics("pointer", "data"))) 1198 1199 #else /* defined(KERNEL) && __has_attribute(xnu_usage_semantics) */ 1200 1201 #define __kernel_ptr_semantics 1202 #define __kernel_data_semantics 1203 #define __kernel_dual_semantics 1204 1205 #endif /* defined(KERNEL) && __has_attribute(xnu_usage_semantics) */ 1206 1207 #if XNU_KERNEL_PRIVATE 1208 /* 1209 * Compiler-dependent macros that bracket portions of code where the 1210 * "-Wxnu-typed-allocators" warning should be ignored. 1211 */ 1212 #if defined(__clang__) 1213 # define __typed_allocators_ignore_push \ 1214 _Pragma("clang diagnostic push") \ 1215 _Pragma("clang diagnostic ignored \"-Wxnu-typed-allocators\"") 1216 # define __typed_allocators_ignore_pop \ 1217 _Pragma("clang diagnostic pop") 1218 # define __typed_allocators_ignore(x) __typed_allocators_ignore_push \ 1219 x \ 1220 __typed_allocators_ignore_pop 1221 #else 1222 # define __typed_allocators_ignore_push 1223 # define __typed_allocators_ignore_push 1224 # define __typed_allocators_ignore(x) x 1225 #endif /* __clang */ 1226 #endif /* XNU_KERNEL_PRIVATE */ 1227 1228 #endif /* !_CDEFS_H_ */ 1229