From 9a5a789123d7528d1c1cb71e66134fe0d7a9d37a Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Wed, 9 Sep 2020 22:35:13 -0400 Subject: [PATCH] mac: Fix MacOSVersionNumber for 10.12.0 < version < 10.13.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In 5412beb63386, I asserted (via my code) that the kern.osproductversion sysctl was introduced in 10.12.0, but this was utterly wrong. It’s not available until 10.13.4. Compare 10.13.3 xnu-4570.41.2/bsd/kern/kern_sysctl.c to 10.13.4 xnu-4570.51.1/bsd/kern/kern_sysctl.c, look for osproductversion. https://pbs.twimg.com/media/EU0GDTVU4AY73KC.jpg Failures appeared starting at https://ci.chromium.org/p/chromium/builders/ci/Mac10.12%20Tests/37499 (https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8869605548532164608/+/steps/crashpad_tests_on_Intel_GPU_on_Mac_on_Mac-10.12.6/0/stdout). This fixes expectations to not require kern.osproductversion to exist until 10.13.4. VM-tested on 10.12.6, 10.13.3, 10.13.4, and 10.14.0. Bug: crashpad:347 Test: crashpad_util_test MacUtil.MacOSVersionNumber Change-Id: Ic58d8ca8f04394d41c691dd2d946c59497ee71d5 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2402248 Reviewed-by: Robert Sesek Commit-Queue: Mark Mentovai --- compat/mac/AvailabilityVersions.h | 4 ++++ snapshot/mac/system_snapshot_mac_test.cc | 2 +- util/mac/mac_util.cc | 24 ++++++++++++------------ util/mac/mac_util.h | 2 +- util/mac/mac_util_test.mm | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/compat/mac/AvailabilityVersions.h b/compat/mac/AvailabilityVersions.h index 8e932c57..0bedb3d2 100644 --- a/compat/mac/AvailabilityVersions.h +++ b/compat/mac/AvailabilityVersions.h @@ -61,6 +61,10 @@ #define __MAC_10_13 101300 #endif +#ifndef __MAC_10_13_4 +#define __MAC_10_13_4 101304 +#endif + // 10.14 SDK #ifndef __MAC_10_14 diff --git a/snapshot/mac/system_snapshot_mac_test.cc b/snapshot/mac/system_snapshot_mac_test.cc index 3b796cd2..bdbc2962 100644 --- a/snapshot/mac/system_snapshot_mac_test.cc +++ b/snapshot/mac/system_snapshot_mac_test.cc @@ -119,7 +119,7 @@ TEST_F(SystemSnapshotMacTest, OSVersion) { const int macos_version_number = MacOSVersionNumber(); EXPECT_EQ(major * 1'00'00 + minor * 1'00 + - (macos_version_number >= 10'12'00 ? bugfix : 0), + (macos_version_number >= 10'13'04 ? bugfix : 0), macos_version_number); EXPECT_FALSE(build.empty()); } diff --git a/util/mac/mac_util.cc b/util/mac/mac_util.cc index cd6669c4..10e7aad1 100644 --- a/util/mac/mac_util.cc +++ b/util/mac/mac_util.cc @@ -61,7 +61,7 @@ extern const CFStringRef _kCFSystemVersionBuildVersionKey WEAK_IMPORT; namespace { -#if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_12 +#if __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_13_4 // Returns the running system’s Darwin major version. Don’t call this, it’s an // implementation detail and its result is meant to be cached by // MacOSVersionNumber(). @@ -98,7 +98,7 @@ int DarwinMajorVersion() { return darwin_major_version; } -#endif // DT < 10.12 +#endif // DT < 10.13.4 // Helpers for the weak-imported private CoreFoundation internals. @@ -192,10 +192,10 @@ int MacOSVersionNumber() { static int macos_version_number = []() { // kern.osproductversion is a lightweight way to get the operating system // version from the kernel without having to open any files or spin up any - // threads, but it’s only available in macOS 10.12 and later. - std::string macos_version_number_string = - ReadStringSysctlByName("kern.osproductversion", - __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_12); + // threads, but it’s only available in macOS 10.13.4 and later. + std::string macos_version_number_string = ReadStringSysctlByName( + "kern.osproductversion", + __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_13_4); if (!macos_version_number_string.empty()) { int major; int minor; @@ -212,12 +212,12 @@ int MacOSVersionNumber() { } } -#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_12 - // On macOS 10.12 and later, the sysctlbyname above should have been +#if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_13_4 + // On macOS 10.13.4 and later, the sysctlbyname above should have been // successful. NOTREACHED(); return -1; -#else // DT >= 10.12 +#else // DT >= 10.13.4 // The Darwin major version is always 4 greater than the macOS minor version // for Darwin versions beginning with 6, corresponding to Mac OS X 10.2, // through Darwin 19, corresponding to macOS 10.15. @@ -227,12 +227,12 @@ int MacOSVersionNumber() { int macos_version_number = 10'00'00 + (darwin_major_version - 4) * 1'00; - // On macOS 10.12 and later, the sysctlbyname above should have been + // On macOS 10.13.4 and later, the sysctlbyname above should have been // successful. - DCHECK_LT(macos_version_number, 10'12'00); + DCHECK_LT(macos_version_number, 10'13'04); return macos_version_number; -#endif // DT >= 10.12 +#endif // DT >= 10.13.4 }(); return macos_version_number; diff --git a/util/mac/mac_util.h b/util/mac/mac_util.h index b6f9bd97..c94e2332 100644 --- a/util/mac/mac_util.h +++ b/util/mac/mac_util.h @@ -28,7 +28,7 @@ namespace crashpad { //! `__MAC_OS_X_VERSION_MIN_REQUIRED`, `__MAC_OS_X_VERSION_MAX_ALLOWED`, and //! per-version `__MAC_*` macros, for versions since OS X 10.10. //! -//! On macOS 10.12 and later, this function will return the major, minor, and +//! On macOS 10.13.4 and later, this function will return the major, minor, and //! bugfix components combined into a single number. On older OS versions, only //! the major and minor components will be returned, and the bugfix component //! will always be reported as 0. By contrast, MacOSVersionComponents() always diff --git a/util/mac/mac_util_test.mm b/util/mac/mac_util_test.mm index 8cef8b2b..aa188e36 100644 --- a/util/mac/mac_util_test.mm +++ b/util/mac/mac_util_test.mm @@ -134,7 +134,7 @@ TEST(MacUtil, MacOSVersionNumber) { EXPECT_EQ(macos_version_number, major * 1'00'00 + minor * 1'00 + - (macos_version_number >= 10'12'00 ? bugfix : 0)); + (macos_version_number >= 10'13'04 ? bugfix : 0)); } TEST(MacUtil, MacModelAndBoard) {