From 0bebda66a86228d517a835399f9a177e67c83197 Mon Sep 17 00:00:00 2001 From: Justin Cohen Date: Tue, 4 Jun 2024 12:07:20 -0400 Subject: [PATCH] ios: Remove duplicate implementations of ReadStringSysctlByName Bug: crashpad: 480 Change-Id: Ie37c557d2170f6d96968ec4922ec52bfc6ad8136 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5580854 Reviewed-by: Mark Mentovai --- test/ios/crash_type_xctest.mm | 17 +++++------------ util/BUILD.gn | 4 ++-- util/ios/ios_system_data_collector.mm | 25 +++---------------------- 3 files changed, 10 insertions(+), 36 deletions(-) diff --git a/test/ios/crash_type_xctest.mm b/test/ios/crash_type_xctest.mm index a76f686e..646c9dfd 100644 --- a/test/ios/crash_type_xctest.mm +++ b/test/ios/crash_type_xctest.mm @@ -22,9 +22,11 @@ #include "build/build_config.h" #include "client/length_delimited_ring_buffer.h" #import "test/ios/host/cptest_shared_object.h" +#include "util/mac/sysctl.h" #include "util/mach/exception_types.h" #include "util/mach/mach_extensions.h" +namespace crashpad { namespace { #if TARGET_OS_SIMULATOR @@ -36,22 +38,13 @@ bool IsMacOSVersion143OrGreaterAndiOS16OrLess() { return false; } - size_t buf_len; - static constexpr char name[] = "kern.osversion"; - if (sysctlbyname(name, nullptr, &buf_len, nullptr, 0) != 0) { - return false; - } - - std::string build(buf_len - 1, '\0'); - if (sysctlbyname(name, &build[0], &buf_len, nullptr, 0) != 0) { - return false; - } - + std::string build = crashpad::ReadStringSysctlByName("kern.osversion", false); return std::stoi(build.substr(0, 2)) > 22; } #endif } // namespace +} // namespace crashpad @interface CPTestTestCase : XCTestCase { XCUIApplication* app_; @@ -352,7 +345,7 @@ bool IsMacOSVersion143OrGreaterAndiOS16OrLess() { #if TARGET_OS_SIMULATOR // This test will fail on older ( void AddObserver(CFStringRef notification_name, T* observer) { CFNotificationCenterAddObserver( @@ -97,7 +78,7 @@ IOSSystemDataCollector::IOSSystemDataCollector() patch_version_ = base::saturated_cast(version.patchVersion); processor_count_ = base::saturated_cast([[NSProcessInfo processInfo] processorCount]); - build_ = ReadStringSysctlByName("kern.osversion"); + build_ = ReadStringSysctlByName("kern.osversion", false); bundle_identifier_ = base::SysNSStringToUTF8([[NSBundle mainBundle] bundleIdentifier]); // If CRASHPAD_IS_IOS_APP_EXTENSION is defined, then the code is compiled with @@ -110,7 +91,7 @@ IOSSystemDataCollector::IOSSystemDataCollector() #endif #if defined(ARCH_CPU_X86_64) - cpu_vendor_ = ReadStringSysctlByName("machdep.cpu.vendor"); + cpu_vendor_ = ReadStringSysctlByName("machdep.cpu.vendor", false); #endif uint32_t addressable_bits = 0; size_t len = sizeof(uint32_t);