From: Apple Date: Tue, 18 Jun 2019 01:06:10 +0000 (+0000) Subject: Libc-1272.250.1.tar.gz X-Git-Tag: macos-10144^0 X-Git-Url: https://git.saurik.com/apple/libc.git/commitdiff_plain/6dccf0e0b5e80b7b6176e8d332e646175431bb3d Libc-1272.250.1.tar.gz --- diff --git a/Libc.xcodeproj/project.pbxproj b/Libc.xcodeproj/project.pbxproj index 862e3a9..b0eedf2 100644 --- a/Libc.xcodeproj/project.pbxproj +++ b/Libc.xcodeproj/project.pbxproj @@ -8983,7 +8983,7 @@ 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 = ( ); @@ -9413,19 +9413,19 @@ 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 */ = { @@ -15638,6 +15638,7 @@ "$(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; @@ -15684,6 +15685,7 @@ "$(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 index 0000000..dcf7008 --- /dev/null +++ b/libdarwin/AppleFactoryVariant.plist @@ -0,0 +1,8 @@ + + + + + AppleInternal-Factory + + + diff --git a/libdarwin/variant.c b/libdarwin/variant.c index f08b787..745a0ce 100644 --- a/libdarwin/variant.c +++ b/libdarwin/variant.c @@ -33,10 +33,15 @@ #include #include +#include #include +/* + * 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++) { diff --git a/os/variant_private.h b/os/variant_private.h index f9826cd..bcbcefc 100644 --- a/os/variant_private.h +++ b/os/variant_private.h @@ -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__ diff --git a/tests/Makefile b/tests/Makefile index 2b2f5be..4938274 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -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 diff --git a/tests/os_variant.c b/tests/os_variant.c index 3717f6d..4890c51 100644 --- a/tests/os_variant.c +++ b/tests/os_variant.c @@ -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);