OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 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 "minidump/minidump_system_info_writer.h" | 15 #include "minidump/minidump_system_info_writer.h" |
16 | 16 |
17 #include <string.h> | 17 #include <string.h> |
18 #include <sys/types.h> | 18 #include <sys/types.h> |
19 | 19 |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "minidump/minidump_string_writer.h" | 21 #include "minidump/minidump_string_writer.h" |
| 22 #include "snapshot/system_snapshot.h" |
22 #include "util/file/file_writer.h" | 23 #include "util/file/file_writer.h" |
23 | 24 |
24 namespace crashpad { | 25 namespace crashpad { |
25 | 26 |
| 27 namespace { |
| 28 |
| 29 uint64_t AMD64FeaturesFromSystemSnapshot( |
| 30 const SystemSnapshot* system_snapshot) { |
| 31 #define ADD_FEATURE(minidump_bit) (UINT64_C(1) << (minidump_bit)) |
| 32 |
| 33 // Features for which no cpuid bits are present, but that always exist on |
| 34 // x86_64. cmpxchg is supported on 486 and later. |
| 35 uint64_t minidump_features = ADD_FEATURE(PF_COMPARE_EXCHANGE_DOUBLE); |
| 36 |
| 37 #define MAP_FEATURE(features, cpuid_bit, minidump_bit) \ |
| 38 do { \ |
| 39 if ((features) & (static_cast<decltype(features)>(1) << (cpuid_bit))) { \ |
| 40 minidump_features |= ADD_FEATURE(minidump_bit); \ |
| 41 } \ |
| 42 } while (false) |
| 43 |
| 44 #define F_TSC 4 |
| 45 #define F_PAE 6 |
| 46 #define F_MMX 23 |
| 47 #define F_SSE 25 |
| 48 #define F_SSE2 26 |
| 49 #define F_SSE3 32 |
| 50 #define F_CX16 45 |
| 51 #define F_XSAVE 58 |
| 52 #define F_RDRAND 62 |
| 53 |
| 54 uint64_t cpuid_features = system_snapshot->CPUX86Features(); |
| 55 |
| 56 MAP_FEATURE(cpuid_features, F_TSC, PF_RDTSC_INSTRUCTION_AVAILABLE); |
| 57 MAP_FEATURE(cpuid_features, F_PAE, PF_PAE_ENABLED); |
| 58 MAP_FEATURE(cpuid_features, F_MMX, PF_MMX_INSTRUCTIONS_AVAILABLE); |
| 59 MAP_FEATURE(cpuid_features, F_SSE, PF_XMMI_INSTRUCTIONS_AVAILABLE); |
| 60 MAP_FEATURE(cpuid_features, F_SSE2, PF_XMMI64_INSTRUCTIONS_AVAILABLE); |
| 61 MAP_FEATURE(cpuid_features, F_SSE3, PF_SSE3_INSTRUCTIONS_AVAILABLE); |
| 62 MAP_FEATURE(cpuid_features, F_CX16, PF_COMPARE_EXCHANGE128); |
| 63 MAP_FEATURE(cpuid_features, F_XSAVE, PF_XSAVE_ENABLED); |
| 64 MAP_FEATURE(cpuid_features, F_RDRAND, PF_RDRAND_INSTRUCTION_AVAILABLE); |
| 65 |
| 66 #define FX_XD 20 |
| 67 #define FX_3DNOW 31 |
| 68 |
| 69 uint64_t extended_features = system_snapshot->CPUX86ExtendedFeatures(); |
| 70 |
| 71 MAP_FEATURE(extended_features, FX_3DNOW, PF_3DNOW_INSTRUCTIONS_AVAILABLE); |
| 72 |
| 73 #define F7_FSGSBASE 0 |
| 74 |
| 75 uint32_t leaf7_features = system_snapshot->CPUX86Leaf7Features(); |
| 76 |
| 77 MAP_FEATURE(leaf7_features, F7_FSGSBASE, PF_RDWRFSGSBASE_AVAILABLE); |
| 78 |
| 79 // This feature bit should be set if NX (XD, DEP) is enabled, not just if |
| 80 // it’s available on the CPU as indicated by the XF_XD bit. |
| 81 if (system_snapshot->NXEnabled()) { |
| 82 minidump_features |= ADD_FEATURE(PF_NX_ENABLED); |
| 83 } |
| 84 |
| 85 if (system_snapshot->CPUX86SupportsDAZ()) { |
| 86 minidump_features |= ADD_FEATURE(PF_SSE_DAZ_MODE_AVAILABLE); |
| 87 } |
| 88 |
| 89 // PF_SECOND_LEVEL_ADDRESS_TRANSLATION can’t be determined without |
| 90 // consulting model-specific registers, a privileged operation. The exact |
| 91 // use of PF_VIRT_FIRMWARE_ENABLED is unknown. PF_FASTFAIL_AVAILABLE is |
| 92 // irrelevant outside of Windows. |
| 93 |
| 94 #undef MAP_FEATURE |
| 95 #undef ADD_FEATURE |
| 96 |
| 97 return minidump_features; |
| 98 } |
| 99 |
| 100 } // namespace |
| 101 |
26 MinidumpSystemInfoWriter::MinidumpSystemInfoWriter() | 102 MinidumpSystemInfoWriter::MinidumpSystemInfoWriter() |
27 : MinidumpStreamWriter(), system_info_(), csd_version_() { | 103 : MinidumpStreamWriter(), system_info_(), csd_version_() { |
28 system_info_.ProcessorArchitecture = kMinidumpCPUArchitectureUnknown; | 104 system_info_.ProcessorArchitecture = kMinidumpCPUArchitectureUnknown; |
29 } | 105 } |
30 | 106 |
31 MinidumpSystemInfoWriter::~MinidumpSystemInfoWriter() { | 107 MinidumpSystemInfoWriter::~MinidumpSystemInfoWriter() { |
32 } | 108 } |
33 | 109 |
| 110 void MinidumpSystemInfoWriter::InitializeFromSnapshot( |
| 111 const SystemSnapshot* system_snapshot) { |
| 112 DCHECK_EQ(state(), kStateMutable); |
| 113 DCHECK(!csd_version_); |
| 114 |
| 115 MinidumpCPUArchitecture cpu_architecture; |
| 116 switch (system_snapshot->GetCPUArchitecture()) { |
| 117 case kCPUArchitectureX86: |
| 118 cpu_architecture = kMinidumpCPUArchitectureX86; |
| 119 break; |
| 120 case kCPUArchitectureX86_64: |
| 121 cpu_architecture = kMinidumpCPUArchitectureAMD64; |
| 122 break; |
| 123 default: |
| 124 NOTREACHED(); |
| 125 cpu_architecture = kMinidumpCPUArchitectureUnknown; |
| 126 break; |
| 127 } |
| 128 SetCPUArchitecture(cpu_architecture); |
| 129 |
| 130 uint32_t cpu_revision = system_snapshot->CPURevision(); |
| 131 SetCPULevelAndRevision( |
| 132 (cpu_revision & 0xffff0000) >> 16, cpu_revision & 0x0000ffff); |
| 133 SetCPUCount(system_snapshot->CPUCount()); |
| 134 |
| 135 if (cpu_architecture == kMinidumpCPUArchitectureX86) { |
| 136 std::string cpu_vendor = system_snapshot->CPUVendor(); |
| 137 SetCPUX86VendorString(cpu_vendor); |
| 138 |
| 139 // The minidump file format only has room for the bottom 32 bits of CPU |
| 140 // features and extended CPU features. |
| 141 SetCPUX86VersionAndFeatures(system_snapshot->CPUX86Signature(), |
| 142 system_snapshot->CPUX86Features() & 0xffffffff); |
| 143 |
| 144 if (cpu_vendor == "AuthenticAMD") { |
| 145 SetCPUX86AMDExtendedFeatures( |
| 146 system_snapshot->CPUX86ExtendedFeatures() & 0xffffffff); |
| 147 } |
| 148 } else if (cpu_architecture == kMinidumpCPUArchitectureAMD64) { |
| 149 SetCPUOtherFeatures(AMD64FeaturesFromSystemSnapshot(system_snapshot), 0); |
| 150 } |
| 151 |
| 152 MinidumpOS operating_system; |
| 153 switch (system_snapshot->GetOperatingSystem()) { |
| 154 case SystemSnapshot::kOperatingSystemMacOSX: |
| 155 operating_system = kMinidumpOSMacOSX; |
| 156 break; |
| 157 default: |
| 158 NOTREACHED(); |
| 159 operating_system = kMinidumpOSUnknown; |
| 160 break; |
| 161 } |
| 162 SetOS(operating_system); |
| 163 |
| 164 SetOSType(system_snapshot->OSServer() ? kMinidumpOSTypeServer |
| 165 : kMinidumpOSTypeWorkstation); |
| 166 |
| 167 int major; |
| 168 int minor; |
| 169 int bugfix; |
| 170 std::string build; |
| 171 system_snapshot->OSVersion(&major, &minor, &bugfix, &build); |
| 172 SetOSVersion(major, minor, bugfix); |
| 173 SetCSDVersion(build); |
| 174 } |
| 175 |
34 void MinidumpSystemInfoWriter::SetCSDVersion(const std::string& csd_version) { | 176 void MinidumpSystemInfoWriter::SetCSDVersion(const std::string& csd_version) { |
35 DCHECK_EQ(state(), kStateMutable); | 177 DCHECK_EQ(state(), kStateMutable); |
36 | 178 |
37 if (!csd_version_) { | 179 if (!csd_version_) { |
38 csd_version_.reset(new internal::MinidumpUTF16StringWriter()); | 180 csd_version_.reset(new internal::MinidumpUTF16StringWriter()); |
39 } | 181 } |
40 | 182 |
41 csd_version_->SetUTF8(csd_version); | 183 csd_version_->SetUTF8(csd_version); |
42 } | 184 } |
43 | 185 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 DCHECK_EQ(state(), kStateWritable); | 287 DCHECK_EQ(state(), kStateWritable); |
146 | 288 |
147 return file_writer->Write(&system_info_, sizeof(system_info_)); | 289 return file_writer->Write(&system_info_, sizeof(system_info_)); |
148 } | 290 } |
149 | 291 |
150 MinidumpStreamType MinidumpSystemInfoWriter::StreamType() const { | 292 MinidumpStreamType MinidumpSystemInfoWriter::StreamType() const { |
151 return kMinidumpStreamTypeSystemInfo; | 293 return kMinidumpStreamTypeSystemInfo; |
152 } | 294 } |
153 | 295 |
154 } // namespace crashpad | 296 } // namespace crashpad |
OLD | NEW |