Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Side by Side Diff: snapshot/win/system_snapshot_win.cc

Issue 1126273003: win: Retrieve module version/type information (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@thread-context-fixes
Patch Set: rebase Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « snapshot/win/module_snapshot_win.cc ('k') | util/util.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "snapshot/win/system_snapshot_win.h" 15 #include "snapshot/win/system_snapshot_win.h"
16 16
17 #include <intrin.h> 17 #include <intrin.h>
18 #include <powrprof.h> 18 #include <powrprof.h>
19 #include <windows.h> 19 #include <windows.h>
20 #include <winnt.h> 20 #include <winnt.h>
21 21
22 #include <algorithm> 22 #include <algorithm>
23 #include <utility> 23 #include <utility>
24 #include <vector> 24 #include <vector>
25 25
26 #include "base/memory/scoped_ptr.h"
27 #include "base/numerics/safe_conversions.h" 26 #include "base/numerics/safe_conversions.h"
28 #include "base/strings/stringprintf.h" 27 #include "base/strings/stringprintf.h"
29 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
29 #include "util/win/module_version.h"
30 30
31 namespace crashpad { 31 namespace crashpad {
32 32
33 namespace { 33 namespace {
34 34
35 //! \brief Gets a string representation for a VS_FIXEDFILEINFO.dwFileFlags 35 //! \brief Gets a string representation for a VS_FIXEDFILEINFO.dwFileFlags
36 //! value. 36 //! value.
37 std::string GetStringForFileFlags(uint32_t file_flags) { 37 std::string GetStringForFileFlags(uint32_t file_flags) {
38 std::string result; 38 std::string result;
39 DCHECK_EQ(file_flags & VS_FF_INFOINFERRED, 0u); 39 DCHECK_EQ(file_flags & VS_FF_INFOINFERRED, 0u);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 // We use both GetVersionEx and VerQueryValue. GetVersionEx is not trustworthy 89 // We use both GetVersionEx and VerQueryValue. GetVersionEx is not trustworthy
90 // after Windows 8 (depending on the application manifest) so its data is used 90 // after Windows 8 (depending on the application manifest) so its data is used
91 // only to fill the os_server_ field, and the rest comes from the version 91 // only to fill the os_server_ field, and the rest comes from the version
92 // information stamped on kernel32.dll. 92 // information stamped on kernel32.dll.
93 OSVERSIONINFOEX version_info = {sizeof(version_info)}; 93 OSVERSIONINFOEX version_info = {sizeof(version_info)};
94 if (!GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info))) { 94 if (!GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info))) {
95 PLOG(WARNING) << "GetVersionEx"; 95 PLOG(WARNING) << "GetVersionEx";
96 } else { 96 } else {
97 const wchar_t kSystemDll[] = L"kernel32.dll"; 97 const wchar_t kSystemDll[] = L"kernel32.dll";
98 DWORD size = GetFileVersionInfoSize(kSystemDll, nullptr); 98 VS_FIXEDFILEINFO ffi;
99 if (!size) { 99 if (GetModuleVersionAndType(base::FilePath(kSystemDll), &ffi)) {
100 PLOG(WARNING) << "GetFileVersionInfoSize"; 100 std::string flags_string = GetStringForFileFlags(ffi.dwFileFlags);
101 } else { 101 os_server_ = version_info.wProductType != VER_NT_WORKSTATION;
102 scoped_ptr<uint8_t[]> data(new uint8_t[size]); 102 std::string os_name = GetStringForFileOS(ffi.dwFileOS);
103 if (!GetFileVersionInfo(kSystemDll, 0, size, data.get())) { 103 os_version_major_ = ffi.dwFileVersionMS >> 16;
104 PLOG(WARNING) << "GetFileVersionInfo"; 104 os_version_minor_ = ffi.dwFileVersionMS & 0xffff;
105 } else { 105 os_version_bugfix_ = ffi.dwFileVersionLS >> 16;
106 VS_FIXEDFILEINFO* fixed_file_info; 106 os_version_build_ =
107 UINT size; 107 base::StringPrintf("%d", ffi.dwFileVersionLS & 0xffff);
108 if (!VerQueryValue(data.get(), 108 os_version_full_ = base::StringPrintf(
109 L"\\", 109 "%s %d.%d.%d.%s%s",
110 reinterpret_cast<void**>(&fixed_file_info), 110 os_name.c_str(),
111 &size)) { 111 os_version_major_,
112 PLOG(WARNING) << "VerQueryValue"; 112 os_version_minor_,
113 } else { 113 os_version_bugfix_,
114 uint32_t valid_flags = 114 os_version_build_.c_str(),
115 fixed_file_info->dwFileFlags & fixed_file_info->dwFileFlagsMask; 115 flags_string.empty() ? "" : (std::string(" (") + flags_string + ")")
116 std::string flags_string = GetStringForFileFlags(valid_flags); 116 .c_str());
117 os_version_major_ =
118 (fixed_file_info->dwFileVersionMS & 0xffff0000) >> 16;
119 os_version_minor_ = fixed_file_info->dwFileVersionMS & 0xffff;
120 os_version_bugfix_ =
121 (fixed_file_info->dwFileVersionLS & 0xffff0000) >> 16;
122 os_version_build_ = base::StringPrintf(
123 "%d", fixed_file_info->dwFileVersionLS & 0xffff);
124 os_server_ = version_info.wProductType != VER_NT_WORKSTATION;
125 std::string os_name = GetStringForFileOS(fixed_file_info->dwFileOS);
126 os_version_full_ = base::StringPrintf(
127 "%s %d.%d.%d.%s%s",
128 os_name.c_str(),
129 os_version_major_,
130 os_version_minor_,
131 os_version_bugfix_,
132 os_version_build_.c_str(),
133 flags_string.empty() ? "" : (std::string(" (") + flags_string +
134 ")").c_str());
135 }
136 }
137 } 117 }
138 } 118 }
139 119
140 INITIALIZATION_STATE_SET_VALID(initialized_); 120 INITIALIZATION_STATE_SET_VALID(initialized_);
141 } 121 }
142 122
143 CPUArchitecture SystemSnapshotWin::GetCPUArchitecture() const { 123 CPUArchitecture SystemSnapshotWin::GetCPUArchitecture() const {
144 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 124 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
145 125
146 return process_reader_->Is64Bit() ? kCPUArchitectureX86_64 126 return process_reader_->Is64Bit() ? kCPUArchitectureX86_64
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 *standard_offset_seconds = 327 *standard_offset_seconds =
348 (time_zone_information.Bias + time_zone_information.StandardBias) * -60; 328 (time_zone_information.Bias + time_zone_information.StandardBias) * -60;
349 *daylight_offset_seconds = 329 *daylight_offset_seconds =
350 (time_zone_information.Bias + time_zone_information.DaylightBias) * -60; 330 (time_zone_information.Bias + time_zone_information.DaylightBias) * -60;
351 *standard_name = base::UTF16ToUTF8(time_zone_information.StandardName); 331 *standard_name = base::UTF16ToUTF8(time_zone_information.StandardName);
352 *daylight_name = base::UTF16ToUTF8(time_zone_information.DaylightName); 332 *daylight_name = base::UTF16ToUTF8(time_zone_information.DaylightName);
353 } 333 }
354 334
355 } // namespace internal 335 } // namespace internal
356 } // namespace crashpad 336 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/win/module_snapshot_win.cc ('k') | util/util.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698