mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
mac: Fix MacOSVersionNumber for 10.12.0 < version < 10.13.4
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 <rsesek@chromium.org> Commit-Queue: Mark Mentovai <mark@chromium.org>
This commit is contained in:
parent
fc97e5cbb2
commit
9a5a789123
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user