Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 | /* * Copyright (c) 2000-2018 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* Copyright 1995 NeXT Computer, Inc. All rights reserved. */ /* * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Berkeley Software Design, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 */ #ifndef _CDEFS_H_ #define _CDEFS_H_ #if defined(__cplusplus) #define __BEGIN_DECLS extern "C" { #define __END_DECLS } #else #define __BEGIN_DECLS #define __END_DECLS #endif /* This SDK is designed to work with clang and specific versions of * gcc >= 4.0 with Apple's patch sets */ #if !defined(__GNUC__) || __GNUC__ < 4 #warning "Unsupported compiler detected" #endif /* * Compatibility with compilers and environments that don't support compiler * feature checking function-like macros. */ #ifndef __has_builtin #define __has_builtin(x) 0 #endif #ifndef __has_include #define __has_include(x) 0 #endif #ifndef __has_feature #define __has_feature(x) 0 #endif #ifndef __has_attribute #define __has_attribute(x) 0 #endif #ifndef __has_cpp_attribute #define __has_cpp_attribute(x) 0 #endif #ifndef __has_extension #define __has_extension(x) 0 #endif /* * The __CONCAT macro is used to concatenate parts of symbol names, e.g. * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. * The __CONCAT macro is a bit tricky -- make sure you don't put spaces * in between its arguments. __CONCAT can also concatenate double-quoted * strings produced by the __STRING macro, but this only works with ANSI C. */ #if defined(__STDC__) || defined(__cplusplus) #define __P(protos) protos /* full-blown ANSI C */ #define __CONCAT(x, y) x ## y #define __STRING(x) #x #define __const const /* define reserved names to standard */ #define __signed signed #define __volatile volatile #if defined(__cplusplus) #define __inline inline /* convert to C++ keyword */ #else #ifndef __GNUC__ #define __inline /* delete GCC keyword */ #endif /* !__GNUC__ */ #endif /* !__cplusplus */ #else /* !(__STDC__ || __cplusplus) */ #define __P(protos) () /* traditional C preprocessor */ #define __CONCAT(x, y) x /**/ y #define __STRING(x) "x" #ifndef __GNUC__ #define __const /* delete pseudo-ANSI C keywords */ #define __inline #define __signed #define __volatile #endif /* !__GNUC__ */ /* * In non-ANSI C environments, new programs will want ANSI-only C keywords * deleted from the program and old programs will want them left alone. * When using a compiler other than gcc, programs using the ANSI C keywords * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. * When using "gcc -traditional", we assume that this is the intent; if * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. */ #ifndef NO_ANSI_KEYWORDS #define const __const /* convert ANSI C keywords */ #define inline __inline #define signed __signed #define volatile __volatile #endif /* !NO_ANSI_KEYWORDS */ #endif /* !(__STDC__ || __cplusplus) */ /* * __pure2 can be used for functions that are only a function of their scalar * arguments (meaning they can't dereference pointers). * * __stateful_pure can be used for functions that have no side effects, * but depend on the state of the memory. */ #define __dead2 __attribute__((__noreturn__)) #define __pure2 __attribute__((__const__)) #define __stateful_pure __attribute__((__pure__)) /* __unused denotes variables and functions that may not be used, preventing * the compiler from warning about it if not used. */ #define __unused __attribute__((__unused__)) /* __used forces variables and functions to be included even if it appears * to the compiler that they are not used (and would thust be discarded). */ #define __used __attribute__((__used__)) /* __cold marks code used for debugging or that is rarely taken * and tells the compiler to optimize for size and outline code. */ #if __has_attribute(cold) #define __cold __attribute__((__cold__)) #else #define __cold #endif /* __returns_nonnull marks functions that return a non-null pointer. */ #if __has_attribute(returns_nonnull) #define __returns_nonnull __attribute((returns_nonnull)) #else #define __returns_nonnull #endif /* __exported denotes symbols that should be exported even when symbols * are hidden by default. * __exported_push/_exported_pop are pragmas used to delimit a range of * symbols that should be exported even when symbols are hidden by default. */ #define __exported __attribute__((__visibility__("default"))) #define __exported_push _Pragma("GCC visibility push(default)") #ifndef __BUILDING_XNU_LIBRARY__ #define __exported_push_hidden _Pragma("GCC visibility push(hidden)") #define __exported_pop _Pragma("GCC visibility pop") #define __exported_hidden __private_extern__ #else /* __BUILDING_XNU_LIBRARY__ */ /* Don't hide symbols that the might be need to be used from outside */ #define __exported_push_hidden #define __exported_pop #define __exported_hidden #endif /* __BUILDING_XNU_LIBRARY__ */ /* __deprecated causes the compiler to produce a warning when encountering * code using the deprecated functionality. * __deprecated_msg() does the same, and compilers that support it will print * a message along with the deprecation warning. * This may require turning on such warning with the -Wdeprecated flag. * __deprecated_enum_msg() should be used on enums, and compilers that support * it will print the deprecation warning. * __kpi_deprecated() specifically indicates deprecation of kernel programming * interfaces in Kernel.framework used by KEXTs. */ #define __deprecated __attribute__((__deprecated__)) #if __has_extension(attribute_deprecated_with_message) || \ (defined(__GNUC__) && ((__GNUC__ >= 5) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)))) #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg))) #else #define __deprecated_msg(_msg) __attribute__((__deprecated__)) #endif #if __has_extension(enumerator_attributes) #define __deprecated_enum_msg(_msg) __deprecated_msg(_msg) #else #define __deprecated_enum_msg(_msg) #endif #if defined(KERNEL) && !defined(KERNEL_PRIVATE) #define __kpi_deprecated(_msg) __deprecated_msg(_msg) #else /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */ #define __kpi_deprecated(_msg) #endif /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */ /* __unavailable causes the compiler to error out when encountering * code using the tagged function */ #if __has_attribute(unavailable) #define __unavailable __attribute__((__unavailable__)) #else #define __unavailable #endif #if defined(KERNEL) && !defined(KERNEL_PRIVATE) #define __kpi_unavailable __unavailable #else /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */ #define __kpi_unavailable #endif /* !defined(KERNEL) || defined(KERNEL_PRIVATE) */ #if XNU_KERNEL_PRIVATE /* This macro is meant to be used for kpi deprecated to x86 3rd parties * but should be marked as unavailable for arm macOS devices. * XNU: nothing (API is still available) * 1st party kexts: __deprecated * 3rd party kexts macOS x86: __deprecated * 3rd party kexts macOS arm: __unavailable */ #define __kpi_deprecated_arm64_macos_unavailable #elif !KERNEL || !XNU_PLATFORM_MacOSX #define __kpi_deprecated_arm64_macos_unavailable #elif KERNEL_PRIVATE #define __kpi_deprecated_arm64_macos_unavailable __deprecated #elif defined(__arm64__) #define __kpi_deprecated_arm64_macos_unavailable __unavailable #else #define __kpi_deprecated_arm64_macos_unavailable __deprecated #endif /* XNU_KERNEL_PRIVATE */ /* Delete pseudo-keywords wherever they are not available or needed. */ #ifndef __dead #define __dead #define __pure #endif /* * We use `__restrict' as a way to define the `restrict' type qualifier * without disturbing older software that is unaware of C99 keywords. */ #if __STDC_VERSION__ < 199901 #define __restrict #else #define __restrict restrict #endif /* Compatibility with compilers and environments that don't support the * nullability feature. */ #if !__has_feature(nullability) #ifndef __nullable #define __nullable #endif #ifndef __nonnull #define __nonnull #endif #ifndef __null_unspecified #define __null_unspecified #endif #ifndef _Nullable #define _Nullable #endif #ifndef _Nonnull #define _Nonnull #endif #ifndef _Null_unspecified #define _Null_unspecified #endif #endif /* * __disable_tail_calls causes the compiler to not perform tail call * optimization inside the marked function. */ #if __has_attribute(disable_tail_calls) #define __disable_tail_calls __attribute__((__disable_tail_calls__)) #else #define __disable_tail_calls #endif /* * __not_tail_called causes the compiler to prevent tail call optimization * on statically bound calls to the function. It has no effect on indirect * calls. Virtual functions, objective-c methods, and functions marked as * "always_inline" cannot be marked as __not_tail_called. */ #if __has_attribute(not_tail_called) #define __not_tail_called __attribute__((__not_tail_called__)) #else #define __not_tail_called #endif /* * __result_use_check warns callers of a function that not using the function * return value is a bug, i.e. dismissing malloc() return value results in a * memory leak. */ #if __has_attribute(warn_unused_result) #define __result_use_check __attribute__((__warn_unused_result__)) #else #define __result_use_check #endif /* * __swift_unavailable causes the compiler to mark a symbol as specifically * unavailable in Swift, regardless of any other availability in C. */ #if __has_feature(attribute_availability_swift) #define __swift_unavailable(_msg) __attribute__((__availability__(swift, unavailable, message=_msg))) #else #define __swift_unavailable(_msg) #endif /* * Attributes to support Swift concurrency. */ #if __has_attribute(__swift_attr__) #define __swift_unavailable_from_async(_msg) __attribute__((__swift_attr__("@_unavailableFromAsync(message: \"" _msg "\")"))) #define __swift_nonisolated __attribute__((__swift_attr__("nonisolated"))) #define __swift_nonisolated_unsafe __attribute__((__swift_attr__("nonisolated(unsafe)"))) #else #define __swift_unavailable_from_async(_msg) #define __swift_nonisolated #define __swift_nonisolated_unsafe #endif /* * __abortlike is the attribute to put on functions like abort() that are * typically used to mark assertions. These optimize the codegen * for outlining while still maintaining debugability. */ #ifndef __abortlike #define __abortlike __dead2 __cold __not_tail_called #endif /* Declaring inline functions within headers is error-prone due to differences * across various versions of the C language and extensions. __header_inline * can be used to declare inline functions within system headers. In cases * where you want to force inlining instead of letting the compiler make * the decision, you can use __header_always_inline. * * Be aware that using inline for functions which compilers may also provide * builtins can behave differently under various compilers. If you intend to * provide an inline version of such a function, you may want to use a macro * instead. * * The check for !__GNUC__ || __clang__ is because gcc doesn't correctly * support c99 inline in some cases: * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55965 */ #if defined(__cplusplus) || \ (__STDC_VERSION__ >= 199901L && \ !defined(__GNUC_GNU_INLINE__) && \ (!defined(__GNUC__) || defined(__clang__))) # define __header_inline inline #elif defined(__GNUC__) && defined(__GNUC_STDC_INLINE__) # define __header_inline extern __inline __attribute__((__gnu_inline__)) #elif defined(__GNUC__) # define __header_inline extern __inline #else /* If we land here, we've encountered an unsupported compiler, * so hopefully it understands static __inline as a fallback. */ # define __header_inline static __inline #endif #ifdef __GNUC__ # define __header_always_inline __header_inline __attribute__ ((__always_inline__)) #else /* Unfortunately, we're using a compiler that we don't know how to force to * inline. Oh well. */ # define __header_always_inline __header_inline #endif /* * Compiler-dependent macros that bracket portions of code where the * "-Wunreachable-code" warning should be ignored. Please use sparingly. */ #if defined(__clang__) # define __unreachable_ok_push \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Wunreachable-code\"") # define __unreachable_ok_pop \ _Pragma("clang diagnostic pop") #elif defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) # define __unreachable_ok_push \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wunreachable-code\"") # define __unreachable_ok_pop \ _Pragma("GCC diagnostic pop") #else # define __unreachable_ok_push # define __unreachable_ok_pop #endif /* * Compiler-dependent macros to declare that functions take printf-like * or scanf-like arguments. They are null except for versions of gcc * that are known to support the features properly. Functions declared * with these attributes will cause compilation warnings if there is a * mismatch between the format string and subsequent function parameter * types. */ #define __printflike(fmtarg, firstvararg) \ __attribute__((__format__ (__printf__, fmtarg, firstvararg))) #define __printf0like(fmtarg, firstvararg) \ __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) #define __scanflike(fmtarg, firstvararg) \ __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) #define __osloglike(fmtarg, firstvararg) \ __attribute__((__format__ (__os_log__, fmtarg, firstvararg))) #define __IDSTRING(name, string) static const char name[] __used = string #ifndef __COPYRIGHT #define __COPYRIGHT(s) __IDSTRING(copyright,s) #endif #ifndef __RCSID #define __RCSID(s) __IDSTRING(rcsid,s) #endif #ifndef __SCCSID #define __SCCSID(s) __IDSTRING(sccsid,s) #endif #ifndef __PROJECT_VERSION #define __PROJECT_VERSION(s) __IDSTRING(project_version,s) #endif /* Source compatibility only, ID string not emitted in object file */ #ifndef __FBSDID #define __FBSDID(s) #endif #ifndef __DECONST #define __DECONST(type, var) __CAST_AWAY_QUALIFIER(var, const, type) #endif #ifndef __DEVOLATILE #define __DEVOLATILE(type, var) __CAST_AWAY_QUALIFIER(var, volatile, type) #endif #ifndef __DEQUALIFY #define __DEQUALIFY(type, var) __CAST_AWAY_QUALIFIER(var, const volatile, type) #endif /* * __alloc_align can be used to label function arguments that represent the * alignment of the returned pointer. */ #ifndef __alloc_align #if __has_attribute(alloc_align) #define __alloc_align(n) __attribute__((alloc_align(n))) #else #define __alloc_align(n) #endif #endif // __alloc_align /* * __alloc_size can be used to label function arguments that represent the * size of memory that the function allocates and returns. The one-argument * form labels a single argument that gives the allocation size (where the * arguments are numbered from 1): * * void *malloc(size_t __size) __alloc_size(1); * * The two-argument form handles the case where the size is calculated as the * product of two arguments: * * void *calloc(size_t __count, size_t __size) __alloc_size(1,2); */ #ifndef __alloc_size #if __has_attribute(alloc_size) #define __alloc_size(...) __attribute__((alloc_size(__VA_ARGS__))) #else #define __alloc_size(...) #endif #endif // __alloc_size /* * Facilities below assist adoption of -Wunsafe-buffer-usage, an off-by-default * Clang compiler warning that helps the developer minimize unsafe, raw * buffer manipulation in the code that may lead to buffer overflow * vulnerabilities. * * They are primarily designed for modern C++ code where -Wunsafe-buffer-usage * comes with automatic fix-it hints that help the developer transform * their code to use modern C++ containers, which may be made bounds-safe by * linking against a version of the C++ standard library that offers * bounds-checked containers. * They can be used in plain C, but -fbounds-safety is the preferred solution * for plain C (see also <ptrcheck.h>). * * Attribute __unsafe_buffer_usage can be used to label functions that should be * avoided as they may perform or otherwise introduce unsafe buffer manipulation * operations. The attribute can also be attached to class/struct fields that * are used in unsafe buffer manipulations. * * Calls to attribute annotated functions are flagged by -Wunsafe-buffer-usage, similar to * how unchecked buffer manipulation operations are flagged when observed * by the compiler directly. Similarly, use of and assignment to the struct/class fields * that have the attribute also get flagged by the compiler. * * // An unsafe function that needs to be avoided. * __unsafe_buffer_usage * void foo(int *buf, size_t size); * * // A safe alternative to foo(). * void foo(std::span<int> buf); * * void bar(size_t idx) { * int array[5]; * * // Direct unsafe buffer manipulation through subscript operator: * array[idx] = 3; // warning: function introduces unsafe buffer manipulation [-Wunsafe-buffer-usage] * // Unsafe buffer manipulation through function foo(): * foo(array, 5); // warning: function introduces unsafe buffer manipulation [-Wunsafe-buffer-usage] * // Checked buffer manipulation, with bounds information automatically * // preserved for the purposes of runtime checks in standard library: * foo(array); // no warning * } * * struct Reader { * // Field involved in unsafe buffer manipulation * __unsafe_buffer_usage * void *ptr; * * __unsafe_buffer_usage * size_t sz, count; * }; * * void add_element(Reader rdr, int value) { * if(rdr.count < rdr.sz) { // warning: unsafe buffer access [-Wunsafe-buffer-usage] * rdr.ptr[rdr.count] = value; // warning: unsafe buffer access [-Wunsafe-buffer-usage] * rdr.count++; // warning: unsafe buffer access [-Wunsafe-buffer-usage] * } * } * * While annotating a function as __unsafe_buffer_usage has an effect similar * to annotating it as __deprecated, the __unsafe_buffer_usage attribute * should be used whenever the resulting warning needs to be controlled * by the -Wunsafe-buffer-usage flag (which is turned off in codebases that * don't attempt to achieve bounds safety this way) as opposed to -Wdeprecated * (enabled in most codebases). * * The attribute suppresses all -Wunsafe-buffer-usage warnings inside the * function's body as it is explictly marked as unsafe by the user and * introduces new warnings at each call site to help the developers avoid the * function entirely. Most of the time it does not make sense to annotate a * function as __unsafe_buffer_usage without providing the users with a safe * alternative. * * Pragmas __unsafe_buffer_usage_begin and __unsafe_buffer_usage_end * annotate a range of code as intentionally containing unsafe buffer * operations. They suppress -Wunsafe-buffer-usage warnings * for unsafe operations in range: * * __unsafe_buffer_usage_begin * array[idx] = 3; // warning suppressed * foo(array, 5); // warning suppressed * __unsafe_buffer_usage_end * * These pragmas are NOT a way to mass-annotate functions with the attribute * __unsafe_buffer_usage. Functions declared within the pragma range * do NOT get annotated automatically. */ #if __has_cpp_attribute(clang::unsafe_buffer_usage) #define __has_safe_buffers 1 #define __unsafe_buffer_usage [[clang::unsafe_buffer_usage]] #elif __has_attribute(unsafe_buffer_usage) #define __has_safe_buffers 1 #define __unsafe_buffer_usage __attribute__((__unsafe_buffer_usage__)) #else #define __has_safe_buffers 0 #define __unsafe_buffer_usage #endif #if __has_safe_buffers #define __unsafe_buffer_usage_begin _Pragma("clang unsafe_buffer_usage begin") #define __unsafe_buffer_usage_end _Pragma("clang unsafe_buffer_usage end") #else #define __unsafe_buffer_usage_begin #define __unsafe_buffer_usage_end #endif /* * COMPILATION ENVIRONMENTS -- see compat(5) for additional detail * * DEFAULT By default newly complied code will get POSIX APIs plus * Apple API extensions in scope. * * Most users will use this compilation environment to avoid * behavioral differences between 32 and 64 bit code. * * LEGACY Defining _NONSTD_SOURCE will get pre-POSIX APIs plus Apple * API extensions in scope. * * This is generally equivalent to the Tiger release compilation * environment, except that it cannot be applied to 64 bit code; * its use is discouraged. * * We expect this environment to be deprecated in the future. * * STRICT Defining _POSIX_C_SOURCE or _XOPEN_SOURCE restricts the * available APIs to exactly the set of APIs defined by the * corresponding standard, based on the value defined. * * A correct, portable definition for _POSIX_C_SOURCE is 200112L. * A correct, portable definition for _XOPEN_SOURCE is 600L. * * Apple API extensions are not visible in this environment, * which can cause Apple specific code to fail to compile, * or behave incorrectly if prototypes are not in scope or * warnings about missing prototypes are not enabled or ignored. * * In any compilation environment, for correct symbol resolution to occur, * function prototypes must be in scope. It is recommended that all Apple * tools users add either the "-Wall" or "-Wimplicit-function-declaration" * compiler flags to their projects to be warned when a function is being * used without a prototype in scope. */ /* These settings are particular to each product. */ #ifdef KERNEL #define __DARWIN_ONLY_64_BIT_INO_T 0 #define __DARWIN_ONLY_UNIX_CONFORMANCE 0 #define __DARWIN_ONLY_VERS_1050 0 #if defined(__x86_64__) #define __DARWIN_SUF_DARWIN14 "_darwin14" #define __DARWIN14_ALIAS(sym) __asm("_" __STRING(sym) __DARWIN_SUF_DARWIN14) #else #define __DARWIN14_ALIAS(sym) #endif #else /* !KERNEL */ #ifdef XNU_PLATFORM_iPhoneOS /* Platform: iPhoneOS */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_iPhoneOS */ #ifdef XNU_PLATFORM_iPhoneSimulator /* Platform: iPhoneSimulator */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_iPhoneSimulator */ #ifdef XNU_PLATFORM_tvOS /* Platform: tvOS */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_tvOS */ #ifdef XNU_PLATFORM_AppleTVOS /* Platform: AppleTVOS */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_AppleTVOS */ #ifdef XNU_PLATFORM_tvSimulator /* Platform: tvSimulator */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_tvSimulator */ #ifdef XNU_PLATFORM_AppleTVSimulator /* Platform: AppleTVSimulator */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_AppleTVSimulator */ #ifdef XNU_PLATFORM_iPhoneOSNano /* Platform: iPhoneOSNano */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_iPhoneOSNano */ #ifdef XNU_PLATFORM_iPhoneNanoSimulator /* Platform: iPhoneNanoSimulator */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_iPhoneNanoSimulator */ #ifdef XNU_PLATFORM_WatchOS /* Platform: WatchOS */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_WatchOS */ #ifdef XNU_PLATFORM_WatchSimulator /* Platform: WatchSimulator */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_WatchSimulator */ #ifdef XNU_PLATFORM_BridgeOS /* Platform: BridgeOS */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_BridgeOS */ #ifdef XNU_PLATFORM_DriverKit /* Platform: DriverKit */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_DriverKit */ #ifdef XNU_PLATFORM_MacOSX /* Platform: MacOSX */ #if defined(__i386__) #define __DARWIN_ONLY_64_BIT_INO_T 0 #define __DARWIN_ONLY_UNIX_CONFORMANCE 0 #define __DARWIN_ONLY_VERS_1050 0 #elif defined(__x86_64__) #define __DARWIN_ONLY_64_BIT_INO_T 0 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 0 #else #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif #endif /* XNU_PLATFORM_MacOSX */ #ifdef XNU_PLATFORM_XROS /* Platform: XROS */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_XROS */ #ifdef XNU_PLATFORM_XRSimulator /* Platform: XRSimulator */ #define __DARWIN_ONLY_64_BIT_INO_T 1 #define __DARWIN_ONLY_UNIX_CONFORMANCE 1 #define __DARWIN_ONLY_VERS_1050 1 #endif /* XNU_PLATFORM_XRSimulator */ #endif /* KERNEL */ /* * The __DARWIN_ALIAS macros are used to do symbol renaming; they allow * legacy code to use the old symbol, thus maintaining binary compatibility * while new code can use a standards compliant version of the same function. * * __DARWIN_ALIAS is used by itself if the function signature has not * changed, it is used along with a #ifdef check for __DARWIN_UNIX03 * if the signature has changed. Because the __LP64__ environment * only supports UNIX03 semantics it causes __DARWIN_UNIX03 to be * defined, but causes __DARWIN_ALIAS to do no symbol mangling. * * As a special case, when XCode is used to target a specific version of the * OS, the manifest constant __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ * will be defined by the compiler, with the digits representing major version * time 100 + minor version times 10 (e.g. 10.5 := 1050). If we are targeting * pre-10.5, and it is the default compilation environment, revert the * compilation environment to pre-__DARWIN_UNIX03. */ #if !defined(__DARWIN_UNIX03) # if defined(KERNEL) # define __DARWIN_UNIX03 0 # elif __DARWIN_ONLY_UNIX_CONFORMANCE # if defined(_NONSTD_SOURCE) # error "Can't define _NONSTD_SOURCE when only UNIX conformance is available." # endif /* _NONSTD_SOURCE */ # define __DARWIN_UNIX03 1 # elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1040) # define __DARWIN_UNIX03 0 # elif defined(_DARWIN_C_SOURCE) || defined(_XOPEN_SOURCE) || defined(_POSIX_C_SOURCE) # if defined(_NONSTD_SOURCE) # error "Can't define both _NONSTD_SOURCE and any of _DARWIN_C_SOURCE, _XOPEN_SOURCE or _POSIX_C_SOURCE." # endif /* _NONSTD_SOURCE */ # define __DARWIN_UNIX03 1 # elif defined(_NONSTD_SOURCE) # define __DARWIN_UNIX03 0 # else /* default */ # if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1050) # define __DARWIN_UNIX03 0 # else /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 */ # define __DARWIN_UNIX03 1 # endif /* __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050 */ # endif /* _DARWIN_C_SOURCE || _XOPEN_SOURCE || _POSIX_C_SOURCE || __LP64__ */ #endif /* !__DARWIN_UNIX03 */ #if !defined(__DARWIN_64_BIT_INO_T) # if defined(KERNEL) # define __DARWIN_64_BIT_INO_T 0 # elif defined(_DARWIN_USE_64_BIT_INODE) # if defined(_DARWIN_NO_64_BIT_INODE) # error "Can't define both _DARWIN_USE_64_BIT_INODE and _DARWIN_NO_64_BIT_INODE." # endif /* _DARWIN_NO_64_BIT_INODE */ # define __DARWIN_64_BIT_INO_T 1 # elif defined(_DARWIN_NO_64_BIT_INODE) # if __DARWIN_ONLY_64_BIT_INO_T # error "Can't define _DARWIN_NO_64_BIT_INODE when only 64-bit inodes are available." # endif /* __DARWIN_ONLY_64_BIT_INO_T */ # define __DARWIN_64_BIT_INO_T 0 # else /* default */ # if __DARWIN_ONLY_64_BIT_INO_T # define __DARWIN_64_BIT_INO_T 1 # elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1060) || __DARWIN_UNIX03 == 0 # define __DARWIN_64_BIT_INO_T 0 # else /* default */ # define __DARWIN_64_BIT_INO_T 1 # endif /* __DARWIN_ONLY_64_BIT_INO_T */ # endif #endif /* !__DARWIN_64_BIT_INO_T */ #if !defined(__DARWIN_VERS_1050) # if defined(KERNEL) # define __DARWIN_VERS_1050 0 # elif __DARWIN_ONLY_VERS_1050 # define __DARWIN_VERS_1050 1 # elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && ((__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ - 0) < 1050) || __DARWIN_UNIX03 == 0 # define __DARWIN_VERS_1050 0 # else /* default */ # define __DARWIN_VERS_1050 1 # endif #endif /* !__DARWIN_VERS_1050 */ #if !defined(__DARWIN_NON_CANCELABLE) # if defined(KERNEL) # define __DARWIN_NON_CANCELABLE 0 # else /* default */ # define __DARWIN_NON_CANCELABLE 0 # endif #endif /* !__DARWIN_NON_CANCELABLE */ /* * symbol suffixes used for symbol versioning */ #if __DARWIN_UNIX03 # if __DARWIN_ONLY_UNIX_CONFORMANCE # define __DARWIN_SUF_UNIX03 /* nothing */ # else /* !__DARWIN_ONLY_UNIX_CONFORMANCE */ # define __DARWIN_SUF_UNIX03 "$UNIX2003" # endif /* __DARWIN_ONLY_UNIX_CONFORMANCE */ # if __DARWIN_64_BIT_INO_T # if __DARWIN_ONLY_64_BIT_INO_T # define __DARWIN_SUF_64_BIT_INO_T /* nothing */ # else /* !__DARWIN_ONLY_64_BIT_INO_T */ # define __DARWIN_SUF_64_BIT_INO_T "$INODE64" # endif /* __DARWIN_ONLY_64_BIT_INO_T */ # else /* !__DARWIN_64_BIT_INO_T */ # define __DARWIN_SUF_64_BIT_INO_T /* nothing */ # endif /* __DARWIN_64_BIT_INO_T */ # if __DARWIN_VERS_1050 # if __DARWIN_ONLY_VERS_1050 # define __DARWIN_SUF_1050 /* nothing */ # else /* !__DARWIN_ONLY_VERS_1050 */ # define __DARWIN_SUF_1050 "$1050" # endif /* __DARWIN_ONLY_VERS_1050 */ # else /* !__DARWIN_VERS_1050 */ # define __DARWIN_SUF_1050 /* nothing */ # endif /* __DARWIN_VERS_1050 */ # if __DARWIN_NON_CANCELABLE # define __DARWIN_SUF_NON_CANCELABLE "$NOCANCEL" # else /* !__DARWIN_NON_CANCELABLE */ # define __DARWIN_SUF_NON_CANCELABLE /* nothing */ # endif /* __DARWIN_NON_CANCELABLE */ #else /* !__DARWIN_UNIX03 */ # define __DARWIN_SUF_UNIX03 /* nothing */ # define __DARWIN_SUF_64_BIT_INO_T /* nothing */ # define __DARWIN_SUF_NON_CANCELABLE /* nothing */ # define __DARWIN_SUF_1050 /* nothing */ #endif /* __DARWIN_UNIX03 */ #define __DARWIN_SUF_EXTSN "$DARWIN_EXTSN" /* * symbol versioning macros */ #define __DARWIN_ALIAS(sym) __asm("_" __STRING(sym) __DARWIN_SUF_UNIX03) #define __DARWIN_ALIAS_C(sym) __asm("_" __STRING(sym) __DARWIN_SUF_NON_CANCELABLE __DARWIN_SUF_UNIX03) #define __DARWIN_ALIAS_I(sym) __asm("_" __STRING(sym) __DARWIN_SUF_64_BIT_INO_T __DARWIN_SUF_UNIX03) #define __DARWIN_NOCANCEL(sym) __asm("_" __STRING(sym) __DARWIN_SUF_NON_CANCELABLE) #define __DARWIN_INODE64(sym) __asm("_" __STRING(sym) __DARWIN_SUF_64_BIT_INO_T) #define __DARWIN_1050(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050) #define __DARWIN_1050ALIAS(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_UNIX03) #define __DARWIN_1050ALIAS_C(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_NON_CANCELABLE __DARWIN_SUF_UNIX03) #define __DARWIN_1050ALIAS_I(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_64_BIT_INO_T __DARWIN_SUF_UNIX03) #define __DARWIN_1050INODE64(sym) __asm("_" __STRING(sym) __DARWIN_SUF_1050 __DARWIN_SUF_64_BIT_INO_T) #define __DARWIN_EXTSN(sym) __asm("_" __STRING(sym) __DARWIN_SUF_EXTSN) #define __DARWIN_EXTSN_C(sym) __asm("_" __STRING(sym) __DARWIN_SUF_EXTSN __DARWIN_SUF_NON_CANCELABLE) #if XNU_KERNEL_PRIVATE #define __XNU_INTERNAL(sym) __asm("_" __STRING(sym) "$XNU_INTERNAL") __attribute__((used)) #endif /* * symbol release macros */ #ifdef KERNEL #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) #else #include <sys/_symbol_aliasing.h> #if defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) __DARWIN_ALIAS_STARTING_IPHONE_##_iphone(x) #elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) __DARWIN_ALIAS_STARTING_MAC_##_mac(x) #else #define __DARWIN_ALIAS_STARTING(_mac, _iphone, x) x #endif #endif /* KERNEL */ /* * POSIX.1 requires that the macros we test be defined before any standard * header file is included. This permits us to convert values for feature * testing, as necessary, using only _POSIX_C_SOURCE. * * Here's a quick run-down of the versions: * defined(_POSIX_SOURCE) 1003.1-1988 * _POSIX_C_SOURCE == 1L 1003.1-1990 * _POSIX_C_SOURCE == 2L 1003.2-1992 C Language Binding Option * _POSIX_C_SOURCE == 199309L 1003.1b-1993 * _POSIX_C_SOURCE == 199506L 1003.1c-1995, 1003.1i-1995, * and the omnibus ISO/IEC 9945-1: 1996 * _POSIX_C_SOURCE == 200112L 1003.1-2001 * _POSIX_C_SOURCE == 200809L 1003.1-2008 * * In addition, the X/Open Portability Guide, which is now the Single UNIX * Specification, defines a feature-test macro which indicates the version of * that specification, and which subsumes _POSIX_C_SOURCE. */ /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1L. */ #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1L #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 199009L #endif /* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2L. */ #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2L #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 199209L #endif /* Deal with various X/Open Portability Guides and Single UNIX Spec. */ #ifdef _XOPEN_SOURCE #if _XOPEN_SOURCE - 0L >= 700L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 200809L) #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200809L #elif _XOPEN_SOURCE - 0L >= 600L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 200112L) #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200112L #elif _XOPEN_SOURCE - 0L >= 500L && (!defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE - 0L < 199506L) #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 199506L #endif #endif /* * Deal with all versions of POSIX. The ordering relative to the tests above is * important. */ #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) #define _POSIX_C_SOURCE 198808L #endif /* POSIX C deprecation macros */ #ifdef KERNEL #define __POSIX_C_DEPRECATED(ver) #else #include <sys/_posix_availability.h> #define __POSIX_C_DEPRECATED(ver) ___POSIX_C_DEPRECATED_STARTING_##ver #endif /* * Set a single macro which will always be defined and can be used to determine * the appropriate namespace. For POSIX, these values will correspond to * _POSIX_C_SOURCE value. Currently there are two additional levels corresponding * to ANSI (_ANSI_SOURCE) and Darwin extensions (_DARWIN_C_SOURCE) */ #define __DARWIN_C_ANSI 010000L #define __DARWIN_C_FULL 900000L #if defined(_ANSI_SOURCE) #define __DARWIN_C_LEVEL __DARWIN_C_ANSI #elif defined(_POSIX_C_SOURCE) && !defined(_DARWIN_C_SOURCE) && !defined(_NONSTD_SOURCE) #define __DARWIN_C_LEVEL _POSIX_C_SOURCE #else #define __DARWIN_C_LEVEL __DARWIN_C_FULL #endif /* If the developer has neither requested a strict language mode nor a version * of POSIX, turn on functionality provided by __STDC_WANT_LIB_EXT1__ as part * of __DARWIN_C_FULL. */ #if !defined(__STDC_WANT_LIB_EXT1__) && !defined(__STRICT_ANSI__) && __DARWIN_C_LEVEL >= __DARWIN_C_FULL #define __STDC_WANT_LIB_EXT1__ 1 #endif /* * long long is not supported in c89 (__STRICT_ANSI__), but g++ -ansi and * c99 still want long longs. While not perfect, we allow long longs for * g++. */ #if (defined(__STRICT_ANSI__) && (__STDC_VERSION__ - 0 < 199901L) && !defined(__GNUG__)) #define __DARWIN_NO_LONG_LONG 1 #else #define __DARWIN_NO_LONG_LONG 0 #endif /***************************************** * Public darwin-specific feature macros *****************************************/ /* * _DARWIN_FEATURE_64_BIT_INODE indicates that the ino_t type is 64-bit, and * structures modified for 64-bit inodes (like struct stat) will be used. */ #if __DARWIN_64_BIT_INO_T #define _DARWIN_FEATURE_64_BIT_INODE 1 #endif /* * _DARWIN_FEATURE_64_ONLY_BIT_INODE indicates that the ino_t type may only * be 64-bit; there is no support for 32-bit ino_t when this macro is defined * (and non-zero). There is no struct stat64 either, as the regular * struct stat will already be the 64-bit version. */ #if __DARWIN_ONLY_64_BIT_INO_T #define _DARWIN_FEATURE_ONLY_64_BIT_INODE 1 #endif /* * _DARWIN_FEATURE_ONLY_VERS_1050 indicates that only those APIs updated * in 10.5 exists; no pre-10.5 variants are available. */ #if __DARWIN_ONLY_VERS_1050 #define _DARWIN_FEATURE_ONLY_VERS_1050 1 #endif /* * _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE indicates only UNIX conforming API * are available (the legacy BSD APIs are not available) */ #if __DARWIN_ONLY_UNIX_CONFORMANCE #define _DARWIN_FEATURE_ONLY_UNIX_CONFORMANCE 1 #endif /* * _DARWIN_FEATURE_UNIX_CONFORMANCE indicates whether UNIX conformance is on, * and specifies the conformance level (3 is SUSv3) */ #if __DARWIN_UNIX03 #define _DARWIN_FEATURE_UNIX_CONFORMANCE 3 #endif #if defined(DRIVERKIT) && !defined(KERNEL) /* * __DRIVERKIT_LIBC__ indicates to the C++ standard library headers and * similar components that only the restricted set of standard C library * functionality and headers for the DriverKit userspace driver environment * are available. */ #define __DRIVERKIT_LIBC__ 1 #endif /* defined(DRIVERKIT) && !defined(KERNEL) */ /* * This macro casts away the qualifier from the variable * * Note: use at your own risk, removing qualifiers can result in * catastrophic run-time failures. */ #ifndef __CAST_AWAY_QUALIFIER /* * XXX: this shouldn't ignore anything more than -Wcast-qual, * but the old implementation made it an almighty cast that * ignored everything, so things break left and right if you * make it only ignore -Wcast-qual. */ #define __CAST_AWAY_QUALIFIER(variable, qualifier, type) \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") \ _Pragma("GCC diagnostic ignored \"-Wcast-align\"") \ _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"") \ ((type)(variable)) \ _Pragma("GCC diagnostic pop") #endif /* * __XNU_PRIVATE_EXTERN is a linkage decoration indicating that a symbol can be * used from other compilation units, but not other libraries or executables. */ #ifndef __XNU_PRIVATE_EXTERN #define __XNU_PRIVATE_EXTERN __attribute__((visibility("hidden"))) #endif #if __has_include(<ptrcheck.h>) #include <ptrcheck.h> #else #if __has_feature(bounds_safety) #error -fbounds-safety is enabled, but <ptrcheck.h> is missing. \ This will lead to difficult-to-diagnose compilation errors. #endif /* __has_feature(bounds_safety) */ /* * We intentionally define to nothing pointer attributes which do not have an * impact on the ABI. __indexable and __bidi_indexable are not defined because * of the ABI incompatibility that makes the diagnostic preferable. */ #define __has_ptrcheck 0 #define __single #define __unsafe_indexable #define __counted_by(N) #define __counted_by_or_null(N) #define __sized_by(N) #define __sized_by_or_null(N) #define __ended_by(E) #define __terminated_by(T) #define __null_terminated /* * Similarly, we intentionally define to nothing the * __ptrcheck_abi_assume_single and __ptrcheck_abi_assume_unsafe_indexable * macros because they do not lead to an ABI incompatibility. However, we do not * define the indexable and unsafe_indexable ones because the diagnostic is * better than the silent ABI break. */ #define __ptrcheck_abi_assume_single() #define __ptrcheck_abi_assume_unsafe_indexable() /* __unsafe_forge intrinsics are defined as regular C casts. */ #define __unsafe_forge_bidi_indexable(T, P, S) ((T)(P)) #define __unsafe_forge_single(T, P) ((T)(P)) #define __unsafe_forge_terminated_by(T, P, E) ((T)(P)) #define __unsafe_forge_null_terminated(T, P) ((T)(P)) #define __terminated_by_to_indexable(P) (P) #define __unsafe_terminated_by_to_indexable(P) (P) #define __null_terminated_to_indexable(P) (P) #define __unsafe_null_terminated_to_indexable(P) (P) #define __unsafe_terminated_by_from_indexable(T, P, ...) (P) #define __unsafe_null_terminated_from_indexable(P, ...) (P) /* decay operates normally; attribute is meaningless without pointer checks. */ #define __array_decay_dicards_count_in_parameters /* this is a write-once variable; not useful without pointer checks. */ #define __unsafe_late_const #define __ptrcheck_unavailable #define __ptrcheck_unavailable_r(REPLACEMENT) #endif /* !__has_include(<ptrcheck.h>) */ #if KERNEL && !BOUND_CHECKS && !__has_ptrcheck /* * With pointer checks disabled, we define __indexable to allow source to still * contain these annotations. This is safe in builds which _uniformly_ disable * pointer checks (but not in builds which inconsistently have them enabled). */ #define __indexable #define __bidi_indexable #endif #define __ASSUME_PTR_ABI_SINGLE_BEGIN __ptrcheck_abi_assume_single() #define __ASSUME_PTR_ABI_SINGLE_END __ptrcheck_abi_assume_unsafe_indexable() #if __has_ptrcheck #define __header_indexable __indexable #define __header_bidi_indexable __bidi_indexable #else #define __header_indexable #define __header_bidi_indexable #endif /* * Architecture validation for current SDK */ #if !defined(__sys_cdefs_arch_unknown__) && defined(__i386__) #elif !defined(__sys_cdefs_arch_unknown__) && defined(__x86_64__) #elif !defined(__sys_cdefs_arch_unknown__) && defined(__arm__) #elif !defined(__sys_cdefs_arch_unknown__) && defined(__arm64__) #else #error Unsupported architecture #endif #ifdef XNU_KERNEL_PRIVATE /* * Selectively ignore cast alignment warnings */ #define __IGNORE_WCASTALIGN(x) _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Wcast-align\"") \ x \ _Pragma("clang diagnostic pop") #endif #if defined(PRIVATE) || defined(KERNEL) /* * Check if __probable and __improbable have already been defined elsewhere. * These macros inform the compiler (and humans) about which branches are likely * to be taken. */ #if !defined(__probable) && !defined(__improbable) #define __probable(x) __builtin_expect(!!(x), 1) #define __improbable(x) __builtin_expect(!!(x), 0) #endif /* !defined(__probable) && !defined(__improbable) */ #define __container_of(ptr, type_t, field) __extension__({ \ const __typeof__(((type_t *)NULL)->field) *__ptr = (ptr); \ uintptr_t __result = (uintptr_t)__ptr - offsetof(type_t, field); \ if (__ptr) __builtin_assume(__result != 0); \ __unsafe_forge_single(type_t *, __result); \ }) #define __container_of_safe(ptr, type_t, field) __extension__({ \ const __typeof__(((type_t *)NULL)->field) *__ptr_or_null = (ptr); \ __ptr_or_null ? __container_of(__ptr_or_null, type_t, field) : NULL; \ }) /* * This forces the optimizer to materialize the specified variable value, * and prevents any reordering of operations done to it. */ #define __compiler_materialize_and_prevent_reordering_on(var) \ __asm__ ("" : "=r"(var) : "0"(var)) #endif /* KERNEL || PRIVATE */ #define __compiler_barrier() __asm__ __volatile__("" ::: "memory") #if __has_attribute(enum_extensibility) #define __enum_open __attribute__((__enum_extensibility__(open))) #define __enum_closed __attribute__((__enum_extensibility__(closed))) #else #define __enum_open #define __enum_closed #endif // __has_attribute(enum_extensibility) #if __has_attribute(flag_enum) #define __enum_options __attribute__((__flag_enum__)) #else #define __enum_options #endif /* * Similar to OS_ENUM/OS_CLOSED_ENUM/OS_OPTIONS/OS_CLOSED_OPTIONS * * This provides more advanced type checking on compilers supporting * the proper extensions, even in C. */ #if __has_feature(objc_fixed_enum) || __has_extension(cxx_fixed_enum) || \ __has_extension(cxx_strong_enums) #define __enum_decl(_name, _type, ...) \ typedef enum : _type __VA_ARGS__ __enum_open _name #define __enum_closed_decl(_name, _type, ...) \ typedef enum : _type __VA_ARGS__ __enum_closed _name #define __options_decl(_name, _type, ...) \ typedef enum : _type __VA_ARGS__ __enum_open __enum_options _name #define __options_closed_decl(_name, _type, ...) \ typedef enum : _type __VA_ARGS__ __enum_closed __enum_options _name #else #define __enum_decl(_name, _type, ...) \ typedef _type _name; enum __VA_ARGS__ __enum_open #define __enum_closed_decl(_name, _type, ...) \ typedef _type _name; enum __VA_ARGS__ __enum_closed #define __options_decl(_name, _type, ...) \ typedef _type _name; enum __VA_ARGS__ __enum_open __enum_options #define __options_closed_decl(_name, _type, ...) \ typedef _type _name; enum __VA_ARGS__ __enum_closed __enum_options #endif #if XNU_KERNEL_PRIVATE /* * __xnu_struct_group() can be used to declare a set of fields to be grouped * together logically in order to perform safer memory operations * (assignment, zeroing, ...) on them. */ #ifdef __cplusplus #define __xnu_struct_group(group_type, group_name, ...) \ struct group_type __VA_ARGS__; \ union { \ struct __VA_ARGS__; \ struct group_type group_name; \ } #else #define __xnu_struct_group(group_type, group_name, ...) \ union { \ struct __VA_ARGS__; \ struct group_type __VA_ARGS__ group_name; \ } #endif #endif /* XNU_KERNEL_PRIVATE */ #if defined(KERNEL) && __has_attribute(xnu_usage_semantics) /* * These macros can be used to annotate type definitions or scalar structure * fields to inform the compiler about which semantic they have with regards * to the content of the underlying memory represented by such type or field. * * This information is used in the analysis of the types performed by the * signature based type segregation implemented in kalloc. */ #define __kernel_ptr_semantics __attribute__((xnu_usage_semantics("pointer"))) #define __kernel_data_semantics __attribute__((xnu_usage_semantics("data"))) #define __kernel_dual_semantics __attribute__((xnu_usage_semantics("pointer", "data"))) #else /* defined(KERNEL) && __has_attribute(xnu_usage_semantics) */ #define __kernel_ptr_semantics #define __kernel_data_semantics #define __kernel_dual_semantics #endif /* defined(KERNEL) && __has_attribute(xnu_usage_semantics) */ #if XNU_KERNEL_PRIVATE /* * Compiler-dependent macros that bracket portions of code where the * "-Wxnu-typed-allocators" warning should be ignored. */ #if defined(__clang__) # define __typed_allocators_ignore_push \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Wxnu-typed-allocators\"") # define __typed_allocators_ignore_pop \ _Pragma("clang diagnostic pop") # define __typed_allocators_ignore(x) __typed_allocators_ignore_push \ x \ __typed_allocators_ignore_pop #else # define __typed_allocators_ignore_push # define __typed_allocators_ignore_pop # define __typed_allocators_ignore(x) x #endif /* __clang */ #endif /* XNU_KERNEL_PRIVATE */ #if defined(KERNEL_PRIVATE) && \ __has_attribute(xnu_data_size) && \ __has_attribute(xnu_returns_data_pointer) /* * Annotate function parameters to specify that they semantically * represent the size of a data-only backing storage. */ # define __xnu_data_size __attribute__((xnu_data_size)) /* * Annotate function declarations to specify that the pointer they return * points to a data-only backing storage. */ # define __xnu_returns_data_pointer __attribute__((xnu_returns_data_pointer)) #else # define __xnu_data_size # define __xnu_returns_data_pointer #endif #if XNU_KERNEL_PRIVATE /* * Macro pair which allows C code to, at build time, require that a function * will not use a stack frame/spill to the stack in RELEASE or DEVELOPMENT (i.e. * not DEBUG). * * This macro has no effect on non-optimizing/-O0 builds since we rely on the * existence of some basic optimizations in order to ensure that stack usage can * be avoided. Since non-optimizing builds should never be used in production, * we can relax the security properties of this macro and permit stack usage * without an error. * * When unsupported, this macro is ignored and stack usage will not generate an * error. As such, this macro should only be used when stack usage may pose a * security concern rather than a functional issue. * * In user-space compilation the function decorated with this calls into a mock * function and that uses the stack, so this needs to be disabled. */ #if __OPTIMIZE__ && !defined(__BUILDING_XNU_LIBRARY__) #define __SECURITY_STACK_DISALLOWED_PUSH \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic error \"-Wframe-larger-than\"") #define __SECURITY_STACK_DISALLOWED_POP \ _Pragma("clang diagnostic pop") #else #define __SECURITY_STACK_DISALLOWED_PUSH #define __SECURITY_STACK_DISALLOWED_POP #endif /* __clang */ #endif /* XNU_KERNEL_PRIVATE */ #endif /* !_CDEFS_H_ */ |