Added Windows on ARM support to SystemSnapshot::CPUVendor

Bug: crashpad:297
Change-Id: I1430f86986efdd7bc3c5494ce1838653c64524d6
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1647167
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Istvan Romai 2019-07-24 15:19:03 +02:00 committed by Commit Bot
parent e163efb372
commit 63782c8333
4 changed files with 78 additions and 22 deletions

View File

@ -28,6 +28,7 @@
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "util/win/module_version.h"
#include "util/win/scoped_registry_key.h"
namespace crashpad {
@ -76,11 +77,9 @@ SystemSnapshotWin::SystemSnapshotWin()
os_version_minor_(0),
os_version_bugfix_(0),
os_server_(false),
initialized_() {
}
initialized_() {}
SystemSnapshotWin::~SystemSnapshotWin() {
}
SystemSnapshotWin::~SystemSnapshotWin() {}
void SystemSnapshotWin::Initialize(ProcessReaderWin* process_reader) {
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
@ -191,9 +190,38 @@ std::string SystemSnapshotWin::CPUVendor() const {
*reinterpret_cast<int*>(vendor + 8) = cpu_info[2];
return std::string(vendor, sizeof(vendor));
#elif defined(ARCH_CPU_ARM64)
// TODO(jperaza): do this. https://crashpad.chromium.org/bug/30
// This is the same as SystemSnapshotLinux::CPURevision.
return std::string();
HKEY key;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
0,
KEY_QUERY_VALUE,
&key) != ERROR_SUCCESS) {
return std::string();
}
crashpad::ScopedRegistryKey scoped_key(key);
DWORD type;
wchar_t vendor_identifier[1024];
DWORD vendor_identifier_size = sizeof(vendor_identifier);
if (RegQueryValueEx(key,
L"VendorIdentifier",
nullptr,
&type,
reinterpret_cast<BYTE*>(vendor_identifier),
&vendor_identifier_size) != ERROR_SUCCESS ||
type != REG_SZ) {
return std::string();
}
std::string return_value;
DCHECK_EQ(vendor_identifier_size % sizeof(wchar_t), 0u);
base::UTF16ToUTF8(vendor_identifier,
vendor_identifier_size / sizeof(wchar_t),
&return_value);
return return_value.c_str();
#else
#error Unsupported Windows Arch
#endif

View File

@ -17,6 +17,7 @@
#include <sys/time.h>
#include <time.h>
#include <regex>
#include <string>
#include "build/build_config.h"
@ -73,10 +74,14 @@ TEST_F(SystemSnapshotWinTest, CPUCount) {
TEST_F(SystemSnapshotWinTest, CPUVendor) {
std::string cpu_vendor = system_snapshot().CPUVendor();
// There are a variety of other values, but we don't expect to run our tests
// on them.
#if defined(ARCH_CPU_X86_FAMILY)
EXPECT_TRUE(cpu_vendor == "GenuineIntel" || cpu_vendor == "AuthenticAMD");
#elif defined(ARCH_CPU_ARM64)
std::regex cpu_vendor_regex("[a-zA-Z0-9 \\-.]+");
EXPECT_TRUE(std::regex_match(cpu_vendor, cpu_vendor_regex));
#else
#error Unsupported Windows Arch
#endif
}
#if defined(ARCH_CPU_X86_FAMILY)

View File

@ -38,6 +38,7 @@
#include "util/win/get_function.h"
#include "util/win/handle.h"
#include "util/win/scoped_handle.h"
#include "util/win/scoped_registry_key.h"
namespace crashpad {
namespace test {
@ -528,18 +529,6 @@ TEST(ProcessInfo, ReadableRanges) {
&bytes_read));
}
struct ScopedRegistryKeyCloseTraits {
static HKEY InvalidValue() {
return nullptr;
}
static void Free(HKEY key) {
RegCloseKey(key);
}
};
using ScopedRegistryKey =
base::ScopedGeneric<HKEY, ScopedRegistryKeyCloseTraits>;
TEST(ProcessInfo, Handles) {
ScopedTempDir temp_dir;

View File

@ -0,0 +1,34 @@
// Copyright 2019 The Crashpad Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef CRASHPAD_UTIL_WIN_SCOPED_REGISTRY_KEY_H_
#define CRASHPAD_UTIL_WIN_SCOPED_REGISTRY_KEY_H_
#include <windows.h>
#include "base/scoped_generic.h"
namespace crashpad {
struct ScopedRegistryKeyCloseTraits {
static HKEY InvalidValue() { return nullptr; }
static void Free(HKEY key) { RegCloseKey(key); }
};
using ScopedRegistryKey =
base::ScopedGeneric<HKEY, ScopedRegistryKeyCloseTraits>;
} // namespace crashpad
#endif // CRASHPAD_UTIL_WIN_SCOPED_REGISTRY_KEY_H_