mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-20 10:43:46 +00:00
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:
parent
cd0b7c2cd4
commit
0bebda66a8
@ -22,9 +22,11 @@
|
|||||||
#include "build/build_config.h"
|
#include "build/build_config.h"
|
||||||
#include "client/length_delimited_ring_buffer.h"
|
#include "client/length_delimited_ring_buffer.h"
|
||||||
#import "test/ios/host/cptest_shared_object.h"
|
#import "test/ios/host/cptest_shared_object.h"
|
||||||
|
#include "util/mac/sysctl.h"
|
||||||
#include "util/mach/exception_types.h"
|
#include "util/mach/exception_types.h"
|
||||||
#include "util/mach/mach_extensions.h"
|
#include "util/mach/mach_extensions.h"
|
||||||
|
|
||||||
|
namespace crashpad {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
#if TARGET_OS_SIMULATOR
|
#if TARGET_OS_SIMULATOR
|
||||||
@ -36,22 +38,13 @@ bool IsMacOSVersion143OrGreaterAndiOS16OrLess() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t buf_len;
|
std::string build = crashpad::ReadStringSysctlByName("kern.osversion", false);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::stoi(build.substr(0, 2)) > 22;
|
return std::stoi(build.substr(0, 2)) > 22;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
} // namespace crashpad
|
||||||
|
|
||||||
@interface CPTestTestCase : XCTestCase {
|
@interface CPTestTestCase : XCTestCase {
|
||||||
XCUIApplication* app_;
|
XCUIApplication* app_;
|
||||||
@ -352,7 +345,7 @@ bool IsMacOSVersion143OrGreaterAndiOS16OrLess() {
|
|||||||
#if TARGET_OS_SIMULATOR
|
#if TARGET_OS_SIMULATOR
|
||||||
// This test will fail on older (<iOS17 simulators) when running on macOS 14.3
|
// 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
|
// or newer due to a bug in Simulator. crbug.com/328282286
|
||||||
if (IsMacOSVersion143OrGreaterAndiOS16OrLess()) {
|
if (crashpad::IsMacOSVersion143OrGreaterAndiOS16OrLess()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -313,6 +313,8 @@ crashpad_static_library("util") {
|
|||||||
|
|
||||||
if (crashpad_is_apple) {
|
if (crashpad_is_apple) {
|
||||||
sources += [
|
sources += [
|
||||||
|
"mac/sysctl.cc",
|
||||||
|
"mac/sysctl.h",
|
||||||
"mac/xattr.cc",
|
"mac/xattr.cc",
|
||||||
"mac/xattr.h",
|
"mac/xattr.h",
|
||||||
"mach/composite_mach_message_server.cc",
|
"mach/composite_mach_message_server.cc",
|
||||||
@ -349,8 +351,6 @@ crashpad_static_library("util") {
|
|||||||
"mac/mac_util.h",
|
"mac/mac_util.h",
|
||||||
"mac/service_management.cc",
|
"mac/service_management.cc",
|
||||||
"mac/service_management.h",
|
"mac/service_management.h",
|
||||||
"mac/sysctl.cc",
|
|
||||||
"mac/sysctl.h",
|
|
||||||
"mach/bootstrap.cc",
|
"mach/bootstrap.cc",
|
||||||
"mach/bootstrap.h",
|
"mach/bootstrap.h",
|
||||||
"mach/child_port_handshake.cc",
|
"mach/child_port_handshake.cc",
|
||||||
|
@ -27,30 +27,11 @@
|
|||||||
#include "base/strings/stringprintf.h"
|
#include "base/strings/stringprintf.h"
|
||||||
#include "base/strings/sys_string_conversions.h"
|
#include "base/strings/sys_string_conversions.h"
|
||||||
#include "build/build_config.h"
|
#include "build/build_config.h"
|
||||||
|
#include "util/mac/sysctl.h"
|
||||||
#include "util/misc/clock.h"
|
#include "util/misc/clock.h"
|
||||||
|
|
||||||
namespace {
|
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)>
|
template <typename T, void (T::*M)(void)>
|
||||||
void AddObserver(CFStringRef notification_name, T* observer) {
|
void AddObserver(CFStringRef notification_name, T* observer) {
|
||||||
CFNotificationCenterAddObserver(
|
CFNotificationCenterAddObserver(
|
||||||
@ -97,7 +78,7 @@ IOSSystemDataCollector::IOSSystemDataCollector()
|
|||||||
patch_version_ = base::saturated_cast<int>(version.patchVersion);
|
patch_version_ = base::saturated_cast<int>(version.patchVersion);
|
||||||
processor_count_ =
|
processor_count_ =
|
||||||
base::saturated_cast<int>([[NSProcessInfo processInfo] processorCount]);
|
base::saturated_cast<int>([[NSProcessInfo processInfo] processorCount]);
|
||||||
build_ = ReadStringSysctlByName("kern.osversion");
|
build_ = ReadStringSysctlByName("kern.osversion", false);
|
||||||
bundle_identifier_ =
|
bundle_identifier_ =
|
||||||
base::SysNSStringToUTF8([[NSBundle mainBundle] bundleIdentifier]);
|
base::SysNSStringToUTF8([[NSBundle mainBundle] bundleIdentifier]);
|
||||||
// If CRASHPAD_IS_IOS_APP_EXTENSION is defined, then the code is compiled with
|
// If CRASHPAD_IS_IOS_APP_EXTENSION is defined, then the code is compiled with
|
||||||
@ -110,7 +91,7 @@ IOSSystemDataCollector::IOSSystemDataCollector()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ARCH_CPU_X86_64)
|
#if defined(ARCH_CPU_X86_64)
|
||||||
cpu_vendor_ = ReadStringSysctlByName("machdep.cpu.vendor");
|
cpu_vendor_ = ReadStringSysctlByName("machdep.cpu.vendor", false);
|
||||||
#endif
|
#endif
|
||||||
uint32_t addressable_bits = 0;
|
uint32_t addressable_bits = 0;
|
||||||
size_t len = sizeof(uint32_t);
|
size_t len = sizeof(uint32_t);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user