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 <mark@chromium.org>
This commit is contained in:
Justin Cohen 2024-06-04 12:07:20 -04:00
parent cd0b7c2cd4
commit 0bebda66a8
3 changed files with 10 additions and 36 deletions

View File

@ -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 (<iOS17 simulators) when running on macOS 14.3
// or newer due to a bug in Simulator. crbug.com/328282286
if (IsMacOSVersion143OrGreaterAndiOS16OrLess()) {
if (crashpad::IsMacOSVersion143OrGreaterAndiOS16OrLess()) {
return;
}
#endif

View File

@ -313,6 +313,8 @@ crashpad_static_library("util") {
if (crashpad_is_apple) {
sources += [
"mac/sysctl.cc",
"mac/sysctl.h",
"mac/xattr.cc",
"mac/xattr.h",
"mach/composite_mach_message_server.cc",
@ -349,8 +351,6 @@ crashpad_static_library("util") {
"mac/mac_util.h",
"mac/service_management.cc",
"mac/service_management.h",
"mac/sysctl.cc",
"mac/sysctl.h",
"mach/bootstrap.cc",
"mach/bootstrap.h",
"mach/child_port_handshake.cc",

View File

@ -27,30 +27,11 @@
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h"
#include "build/build_config.h"
#include "util/mac/sysctl.h"
#include "util/misc/clock.h"
namespace {
std::string ReadStringSysctlByName(const char* name) {
size_t buf_len;
if (sysctlbyname(name, nullptr, &buf_len, nullptr, 0) != 0) {
PLOG(WARNING) << "sysctlbyname (size) " << name;
return std::string();
}
if (buf_len == 0) {
return std::string();
}
std::string value(buf_len - 1, '\0');
if (sysctlbyname(name, &value[0], &buf_len, nullptr, 0) != 0) {
PLOG(WARNING) << "sysctlbyname " << name;
return std::string();
}
return value;
}
template <typename T, void (T::*M)(void)>
void AddObserver(CFStringRef notification_name, T* observer) {
CFNotificationCenterAddObserver(
@ -97,7 +78,7 @@ IOSSystemDataCollector::IOSSystemDataCollector()
patch_version_ = base::saturated_cast<int>(version.patchVersion);
processor_count_ =
base::saturated_cast<int>([[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);