]> git.saurik.com Git - apple/libc.git/commitdiff
Libc-1272.250.1.tar.gz macos-10144 macos-10145 macos-10146 v1272.250.1
authorApple <opensource@apple.com>
Tue, 18 Jun 2019 01:06:10 +0000 (01:06 +0000)
committerApple <opensource@apple.com>
Tue, 18 Jun 2019 01:06:10 +0000 (01:06 +0000)
Libc.xcodeproj/project.pbxproj
libdarwin/AppleFactoryVariant.plist [new file with mode: 0644]
libdarwin/variant.c
os/variant_private.h
tests/Makefile
tests/os_variant.c

index 862e3a9e4c86330dfe80eaabb225e5fc8a07049b..b0eedf208bee08092071178364feb135d2ba5d00 100644 (file)
                                926F738F1E03E2A3001E049D /* Frameworks */,
                                3F55A4D72062412800C15893 /* Create public header path (safe to remove once we start installing public headers) */,
                                926F73901E03E2A3001E049D /* Headers */,
-                               9280EA241E5A5D6F007A6F58 /* Copy AppleInternalVariant.plist */,
+                               9280EA241E5A5D6F007A6F58 /* Copy AppleFooVariant.plists */,
                        );
                        buildRules = (
                        );
                        shellPath = /bin/bash;
                        shellScript = ". \"${SCRIPT_INPUT_FILE_0}\"";
                };
-               9280EA241E5A5D6F007A6F58 /* Copy AppleInternalVariant.plist */ = {
+               9280EA241E5A5D6F007A6F58 /* Copy AppleFooVariant.plists */ = {
                        isa = PBXShellScriptBuildPhase;
                        buildActionMask = 8;
                        files = (
                        );
                        inputPaths = (
                        );
-                       name = "Copy AppleInternalVariant.plist";
+                       name = "Copy AppleFooVariant.plists";
                        outputPaths = (
                        );
                        runOnlyForDeploymentPostprocessing = 1;
                        shellPath = /bin/sh;
-                       shellScript = "set -ex\nINSTALL_PATH=${DSTROOT}/System/Library/CoreServices\n\nif [ \"${PLATFORM_NAME}\" = \"macosx\" ]; then\ninstall -d ${INSTALL_PATH}\ninstall -m 0444 ${SRCROOT}/libdarwin/AppleInternalVariant.plist ${INSTALL_PATH}\nfi";
+                       shellScript = "set -ex\nINSTALL_PATH=${DSTROOT}/System/Library/CoreServices\n\nif [ \"${PLATFORM_NAME}\" = \"macosx\" ]; then\ninstall -d ${INSTALL_PATH}\ninstall -m 0444 ${SRCROOT}/libdarwin/AppleInternalVariant.plist ${INSTALL_PATH}\ninstall -m 0444 ${SRCROOT}/libdarwin/AppleFactoryVariant.plist ${INSTALL_PATH}\nfi\n";
                        showEnvVarsInLog = 0;
                };
                B122F0E81432B8E600AF95D0 /* Generate libc-features.h */ = {
                                        "$(inherited)",
                                        "_LIBC_NO_FEATURE_VERIFICATION=1",
                                        "DARWIN_BUILDING_LIBSYSTEM_DARWIN=1",
+                                       OS_CRASH_ENABLE_EXPERIMENTAL_LIBTRACE,
                                );
                                GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
                                GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
                                        "$(inherited)",
                                        "_LIBC_NO_FEATURE_VERIFICATION=1",
                                        "DARWIN_BUILDING_LIBSYSTEM_DARWIN=1",
+                                       OS_CRASH_ENABLE_EXPERIMENTAL_LIBTRACE,
                                );
                                GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
                                GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
diff --git a/libdarwin/AppleFactoryVariant.plist b/libdarwin/AppleFactoryVariant.plist
new file mode 100644 (file)
index 0000000..dcf7008
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+       <key>AppleInternal-Factory</key>
+       <true/>
+</dict>
+</plist>
index f08b7875efe55e85a66d22ef53d5fbe461d8b9e0..745a0ceb155319f5d875457f38e270f8a01d4bef 100644 (file)
 #include <System/machine/cpu_capabilities.h>
 
 #include <os/assumes.h>
+#include <os/stdlib.h>
 #include <os/variant_private.h>
 
+/*
+ * Lists all properties overridden by an empty file
+ */
+#define ALL_OVERRIDES_STR "content,diagnostics,ui,security"
+
 enum variant_property {
-       VP_ALL = 0,
        VP_CONTENT,
        VP_DIAGNOSTICS,
        VP_UI,
@@ -83,6 +88,7 @@ status2bool(enum check_status status) {
 #define INTERNAL_SETTINGS_PATH "/AppleInternal/Library/PreferenceBundles/Internal Settings.bundle"
 #else
 #define INTERNAL_DIAGS_PROFILE_PATH "/var/db/ConfigurationProfiles/Settings/com.apple.InternalDiagnostics.plist"
+#define FACTORY_CONTENT_PATH "/System/Library/CoreServices/AppleFactoryVariant.plist"
 #endif
 
 #if !TARGET_OS_SIMULATOR
@@ -156,8 +162,10 @@ static enum check_status internal_content = S_UNKNOWN;
 static enum check_status can_has_debugger = S_UNKNOWN;
 #if TARGET_OS_IPHONE
 static enum check_status internal_release_type = S_UNKNOWN;
+static enum check_status factory_release_type = S_UNKNOWN;
 #else // TARGET_OS_IPHONE
 static enum check_status internal_diags_profile = S_UNKNOWN;
+static enum check_status factory_content = S_UNKNOWN;
 #endif // TARGET_OS_IPHONE
 #endif // !TARGET_OS_SIMULATOR
 
@@ -174,10 +182,10 @@ static void _parse_disabled_status(char *test_string)
 
        if (test_string != NULL) {
                /* used for unit tests */
-               override_str = strdup(test_string);
+               override_str = os_strdup(test_string);
        } else {
                if (access(VAR_FILE_LEGACY, F_OK) == 0) {
-                       goto disable_all;
+                       override_str = os_strdup(ALL_OVERRIDES_STR);
                } else if (access(VAR_FILE_OVERRIDE, F_OK) != 0) {
                        return;
                }
@@ -185,7 +193,9 @@ static void _parse_disabled_status(char *test_string)
                override_str = _read_file(VAR_FILE_OVERRIDE, NULL);
        }
 
-       if (override_str == NULL) goto disable_all;
+       if (override_str == NULL) {
+               override_str = os_strdup(ALL_OVERRIDES_STR);
+       }
 
        char *token, *string = override_str;
        while ((token = strsep(&string, ",\n")) != NULL) {
@@ -202,11 +212,6 @@ static void _parse_disabled_status(char *test_string)
 
        free(override_str);
        return;
-
-disable_all:
-       for (int i = 0; i < VP_MAX; i++) {
-               disabled_status[i] = true;
-       }
 #endif //!TARGET_OS_SIMULATOR
 }
 
@@ -285,8 +290,55 @@ static bool _check_internal_content(void)
 }
 #endif // !TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
 
+#if TARGET_OS_OSX
+static bool _check_factory_content(void)
+{
+       if (factory_content == S_UNKNOWN) {
+               const char * path = FACTORY_CONTENT_PATH;
+               factory_content = (access(path, F_OK) == 0) ? S_YES : S_NO;
+       }
+       return status2bool(factory_content);
+}
+#endif // TARGET_OS_OSX
+
 #if TARGET_OS_IPHONE
 
+#if !TARGET_OS_SIMULATOR
+static bool _parse_system_version_plist(void)
+{
+       xpc_object_t system_version_plist = read_plist(SYSTEM_VERSION_PLIST_PATH);
+       if (!system_version_plist) {
+               return false;
+       }
+
+       const char *release_type =
+                       xpc_dictionary_get_string(system_version_plist,
+                                       SYSTEM_VERSION_PLIST_KEY);
+
+       if (release_type == NULL) {
+               /*
+                * Confusingly, customer images are just completely missing this key.
+                */
+               internal_release_type = S_NO;
+               factory_release_type = S_NO;
+       } else if (strcmp(release_type, "Internal") == 0 ||
+                       strcmp(release_type, "Lite Internal") == 0) {
+               internal_release_type = S_YES;
+               factory_release_type = S_NO;
+       } else if (strcmp(release_type, "NonUI") == 0) {
+               internal_release_type = S_YES;
+               factory_release_type = S_YES;
+       } else {
+               internal_release_type = S_NO;
+               factory_release_type = S_NO;
+       }
+
+       xpc_release(system_version_plist);
+
+       return true;
+}
+#endif //!TARGET_OS_SIMULATOR
+
 /*
  * This set of criteria was taken from copyInternalBuild in MobileGestalt.c
  */
@@ -296,27 +348,7 @@ static bool _check_internal_release_type(void)
        return _check_internal_content();
 #else // TARGET_OS_SIMULATOR
        if (internal_release_type == S_UNKNOWN) {
-               xpc_object_t system_version_plist = read_plist(SYSTEM_VERSION_PLIST_PATH);
-               if (system_version_plist) {
-                       const char *release_type =
-                                       xpc_dictionary_get_string(system_version_plist,
-                                                       SYSTEM_VERSION_PLIST_KEY);
-
-                       if (release_type == NULL) {
-                               /*
-                                * Confusingly, customer images are just completely missing this key.
-                                */
-                               internal_release_type = S_NO;
-                       } else if (strcmp(release_type, "Internal") == 0 ||
-                                       strcmp(release_type, "Lite Internal") == 0 ||
-                                       strcmp(release_type, "NonUI") == 0) {
-                               internal_release_type = S_YES;
-                       } else {
-                               internal_release_type = S_NO;
-                       }
-
-                       xpc_release(system_version_plist);
-               } else {
+               if (!_parse_system_version_plist()) {
                        internal_release_type = (access(INTERNAL_SETTINGS_PATH, F_OK) == 0) ? S_YES : S_NO;
                }
        }
@@ -325,6 +357,21 @@ static bool _check_internal_release_type(void)
 #endif // TARGET_OS_SIMULATOR
 }
 
+static bool _check_factory_release_type(void)
+{
+#if TARGET_OS_SIMULATOR
+       return false;
+#else // TARGET_OS_SIMULATOR
+       if (factory_release_type == S_UNKNOWN) {
+               if (!_parse_system_version_plist()) {
+                       factory_release_type = S_NO;
+               }
+       }
+
+       return status2bool(factory_release_type);
+#endif // TARGET_OS_SIMULATOR
+}
+
 #else
 
 static bool _check_internal_diags_profile(void)
@@ -421,6 +468,16 @@ os_variant_allows_internal_security_policies(const char * __unused subsystem)
        return _check_can_has_debugger();
 }
 
+bool
+os_variant_has_factory_content(const char * __unused subsystem)
+{
+#if TARGET_OS_IPHONE
+       return _check_factory_release_type();
+#else
+       return _check_factory_content();
+#endif
+}
+
 #endif // VARIANT_SKIP_EXPORTED
 
 #define STATUS_INITIAL_BITS 0x70000000F0000000ULL
@@ -432,7 +489,9 @@ enum status_flags_positions {
        SFP_INTERNAL_CONTENT = 0,
        SFP_CAN_HAS_DEBUGGER = 1,
        SFP_INTERNAL_RELEASE_TYPE = 2,
-       SFP_INTERNAL_DIAGS_PROFILE = 3
+       SFP_INTERNAL_DIAGS_PROFILE = 3,
+       SFP_FACTORY_CONTENT = 4,
+       SFP_FACTORY_RELEASE_TYPE = 5,
 };
 
 #if !TARGET_OS_SIMULATOR
@@ -454,10 +513,18 @@ static uint64_t _get_cached_check_status(void)
        _check_internal_release_type();
        if (internal_release_type != S_UNKNOWN)
                res |= internal_release_type << SFP_INTERNAL_RELEASE_TYPE * STATUS_BIT_WIDTH;
+
+       _check_factory_release_type();
+       if (factory_release_type != S_UNKNOWN)
+               res |= factory_release_type << SFP_FACTORY_RELEASE_TYPE * STATUS_BIT_WIDTH;
 #else
        _check_internal_diags_profile();
        if (internal_diags_profile != S_UNKNOWN)
                res |= internal_diags_profile << SFP_INTERNAL_DIAGS_PROFILE * STATUS_BIT_WIDTH;
+
+       _check_factory_content();
+       if (factory_content != S_UNKNOWN)
+               res |= factory_content << SFP_FACTORY_CONTENT * STATUS_BIT_WIDTH;
 #endif
 
        _parse_disabled_status(NULL);
@@ -476,14 +543,22 @@ static void _restore_cached_check_status(uint64_t status)
        if ((status >> (SFP_INTERNAL_CONTENT * STATUS_BIT_WIDTH)) & STATUS_SET)
                internal_content = (status >> (SFP_INTERNAL_CONTENT * STATUS_BIT_WIDTH)) & STATUS_MASK;
 #endif
+
        if ((status >> (SFP_CAN_HAS_DEBUGGER * STATUS_BIT_WIDTH)) & STATUS_SET)
                can_has_debugger = (status >> (SFP_CAN_HAS_DEBUGGER * STATUS_BIT_WIDTH)) & STATUS_MASK;
+
 #if TARGET_OS_IPHONE
        if ((status >> (SFP_INTERNAL_RELEASE_TYPE * STATUS_BIT_WIDTH)) & STATUS_SET)
                internal_release_type = (status >> (SFP_INTERNAL_RELEASE_TYPE * STATUS_BIT_WIDTH)) & STATUS_MASK;
+
+       if ((status >> (SFP_FACTORY_RELEASE_TYPE * STATUS_BIT_WIDTH)) & STATUS_SET)
+               factory_release_type = (status >> (SFP_FACTORY_RELEASE_TYPE * STATUS_BIT_WIDTH)) & STATUS_MASK;
 #else
        if ((status >> (SFP_INTERNAL_DIAGS_PROFILE * STATUS_BIT_WIDTH)) & STATUS_SET)
                internal_diags_profile = (status >> (SFP_INTERNAL_DIAGS_PROFILE * STATUS_BIT_WIDTH)) & STATUS_MASK;
+
+       if ((status >> (SFP_FACTORY_CONTENT * STATUS_BIT_WIDTH)) & STATUS_SET)
+               factory_content = (status >> (SFP_FACTORY_CONTENT * STATUS_BIT_WIDTH)) & STATUS_MASK;
 #endif
 
        for (int i = 0; i < VP_MAX; i++) {
index f9826cd02b5db227d7a02a697fd3cd2fe5e4f9a5..bcbcefc1d3a51b331ad418fd4eec9f8c295e87a2 100644 (file)
@@ -140,6 +140,26 @@ OS_EXPORT OS_WARN_RESULT
 bool
 os_variant_allows_internal_security_policies(const char *subsystem);
 
+/*!
+ * @function os_variant_has_factory_content
+ *
+ * @abstract returns whether this system has factory diagnostics content
+ *
+ * @description
+ *
+ * On macOS, this checks for a AppleFactoryVariant.plist that is present in the
+ * factory diagnostics image.
+ *
+ * On embedded platforms, this will check for the NonUI variant.
+ *
+ * @result
+ * Returns true if this build has this property.  False otherwise or upon error.
+ */
+API_AVAILABLE(macosx(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+OS_EXPORT OS_WARN_RESULT
+bool
+os_variant_has_factory_content(const char *subsystem);
+
 __END_DECLS
 
 #endif // __os_variant_H__
index 2b2f5be6be36986f5f75446aa5259ae451142e56..493827433182cde2c93d30c555a92b5d9b16ad2e 100644 (file)
@@ -35,6 +35,7 @@ qsort_perf: OTHER_CFLAGS += -Wno-sign-compare -Wno-sign-conversion -Wno-cast-ali
 else
 EXCLUDED_SOURCES += qsort_perf.c
 endif
+os_variant: OTHER_CFLAGS += -DOS_CRASH_ENABLE_EXPERIMENTAL_LIBTRACE
 
 include $(DEVELOPER_DIR)/AppleInternal/Makefiles/darwintest/Makefile.targets
 
index 3717f6d7d14b0a9af515d4167bcb231a875f77a1..4890c51f6c1ef82bc9d15bc087c3b469ccd316de 100644 (file)
@@ -19,6 +19,9 @@ T_DECL(os_variant_basic, "Just calls all the APIs")
 
        T_MAYFAIL;
        T_EXPECT_TRUE(os_variant_allows_internal_security_policies("com.apple.Libc.tests"), NULL);
+
+       T_MAYFAIL;
+       T_EXPECT_FALSE(os_variant_has_factory_content("com.apple.Libc.tests"), NULL);
 }
 
 #define VARIANT_SKIP_EXPORTED
@@ -27,9 +30,6 @@ T_DECL(os_variant_basic, "Just calls all the APIs")
 
 T_DECL(os_variant_detailed, "Looks at individual checks")
 {
-       T_MAYFAIL;
-       T_EXPECT_FALSE(_check_disabled(VP_ALL), NULL);
-
        T_MAYFAIL;
        T_EXPECT_FALSE(_check_disabled(VP_CONTENT), NULL);
 
@@ -50,9 +50,15 @@ T_DECL(os_variant_detailed, "Looks at individual checks")
 #if TARGET_OS_IPHONE
        T_MAYFAIL;
        T_EXPECT_TRUE(_check_internal_release_type(), NULL);
+
+       T_MAYFAIL;
+       T_EXPECT_TRUE(_check_factory_release_type(), NULL);
 #else
        T_MAYFAIL;
        T_EXPECT_FALSE(_check_internal_diags_profile(), NULL);
+
+       T_MAYFAIL;
+       T_EXPECT_FALSE(_check_factory_content(), NULL);
 #endif
 
        T_MAYFAIL;
@@ -62,7 +68,7 @@ T_DECL(os_variant_detailed, "Looks at individual checks")
 T_DECL(os_variant_override_parse, "Checks the parsing of the override file")
 {
        // Warm up the dispatch_once
-       _check_disabled(VP_ALL);
+       _check_disabled(VP_CONTENT);
 
        T_LOG("Override: NULL"); // Live system
        _parse_disabled_status(NULL);