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