OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (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 |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 #ifndef CRASHPAD_SNAPSHOT_SYSTEM_SNAPSHOT_H_ |
| 16 #define CRASHPAD_SNAPSHOT_SYSTEM_SNAPSHOT_H_ |
| 17 |
| 18 #include <stdint.h> |
| 19 #include <sys/types.h> |
| 20 |
| 21 #include <string> |
| 22 |
| 23 #include "snapshot/cpu_architecture.h" |
| 24 |
| 25 namespace crashpad { |
| 26 |
| 27 //! \brief An abstract interface to a snapshot representing the state of a |
| 28 //! system, comprising an operating system, CPU architecture, and various |
| 29 //! other characteristics. |
| 30 class SystemSnapshot { |
| 31 public: |
| 32 //! \brief A system’s operating system family. |
| 33 enum OperatingSystem { |
| 34 //! \brief The snapshot system’s operating system is unknown. |
| 35 kOperatingSystemUnknown = 0, |
| 36 |
| 37 //! \brief Mac OS X. |
| 38 kOperatingSystemMacOSX, |
| 39 }; |
| 40 |
| 41 //! \brief A system’s daylight saving time status. |
| 42 //! |
| 43 //! The daylight saving time status is taken partially from the system’s |
| 44 //! locale configuration. This determines whether daylight saving time is |
| 45 //! ever observed on the system. If it is, the snapshot’s time |
| 46 //! (ProcessSnapshot::SnapshotTime()) is used to determine whether the system |
| 47 //! was observing daylight saving time at the time of the snapshot. |
| 48 enum DaylightSavingTimeStatus { |
| 49 //! \brief Daylight saving time is never observed on the snapshot system. |
| 50 kDoesNotObserveDaylightSavingTime = 0, |
| 51 |
| 52 //! \brief Daylight saving time is observed on the snapshot system when in |
| 53 //! effect, but standard time was in effect at the time of the snapshot. |
| 54 kObservingStandardTime, |
| 55 |
| 56 //! \brief Daylight saving time is observed on the snapshot system when in |
| 57 //! effect, and daylight saving time was in effect at the time of the |
| 58 //! snapshot. |
| 59 kObservingDaylightSavingTime, |
| 60 }; |
| 61 |
| 62 //! \brief Returns the snapshot system’s CPU architecture. |
| 63 //! |
| 64 //! In some cases, a system may be able to run processes of multiple specific |
| 65 //! architecture types. For example, systems based on 64-bit architectures |
| 66 //! such as x86_64 are often able to run 32-bit code of another architecture |
| 67 //! in the same family, such as 32-bit x86. On these systems, this method will |
| 68 //! return the architecture of the process that the snapshot is associated |
| 69 //! with, provided that the SystemSnapshot object was obtained from |
| 70 //! ProcessSnapshot::System(). This renders one aspect of this method’s return |
| 71 //! value a process attribute rather than a system attribute, but it’s defined |
| 72 //! here rather than in ProcessSnapshot because the CPU architecture is a |
| 73 //! better conceptual fit for the system abstraction alongside these other |
| 74 //! related methods. |
| 75 virtual CPUArchitecture GetCPUArchitecture() const = 0; |
| 76 |
| 77 //! \brief Returns the snapshot system’s CPU revision. |
| 78 //! |
| 79 //! For x86-family CPUs (including x86_64 and 32-bit x86), this is the CPU |
| 80 //! family ID value from `cpuid 1` `eax`, adjusted to take the extended family |
| 81 //! ID into account. |
| 82 //! |
| 83 //! \return A CPU architecture-specific value identifying the CPU revision. |
| 84 virtual uint32_t CPURevision() const = 0; |
| 85 |
| 86 //! \brief Returns the total number of CPUs present in the snapshot system. |
| 87 virtual uint8_t CPUCount() const = 0; |
| 88 |
| 89 //! \brief Returns the vendor of the snapshot system’s CPUs. |
| 90 //! |
| 91 //! For x86-family CPUs (including x86_64 and 32-bit x86), this is the CPU |
| 92 //! vendor identification string as encoded in `cpuid 0` `ebx`, `edx`, and |
| 93 //! `ecx`. |
| 94 //! |
| 95 //! \return A string identifying the vendor of the snapshot system’s CPUs. |
| 96 virtual std::string CPUVendor() const = 0; |
| 97 |
| 98 //! \brief Returns frequency information about the snapshot system’s CPUs in |
| 99 //! \current_hz and \a max_hz. |
| 100 //! |
| 101 //! \param[out] current_hz The snapshot system’s CPU clock frequency in Hz at |
| 102 //! the time of the snapshot. |
| 103 //! \param[out] max_hz The snapshot system’s maximum possible CPU clock |
| 104 //! frequency. |
| 105 virtual void CPUFrequency(uint64_t* current_hz, uint64_t* max_hz) const = 0; |
| 106 |
| 107 //! \brief Returns an x86-family snapshot system’s CPU signature. |
| 108 //! |
| 109 //! This is the family, model, and stepping ID values as encoded in `cpuid 1` |
| 110 //! `eax`. |
| 111 //! |
| 112 //! This method must only be called when GetCPUArchitecture() indicates an |
| 113 //! x86-family CPU architecture (#kCPUArchitectureX86 or |
| 114 //! #kCPUArchitectureX86_64). |
| 115 //! |
| 116 //! \return An x86 family-specific value identifying the CPU signature. |
| 117 virtual uint32_t CPUX86Signature() const = 0; |
| 118 |
| 119 //! \brief Returns an x86-family snapshot system’s CPU features. |
| 120 //! |
| 121 //! This is the feature information as encoded in `cpuid 1` `edx` and `ecx`. |
| 122 //! `edx` is placed in the low half of the return value, and `ecx` is placed |
| 123 //! in the high half. |
| 124 //! |
| 125 //! This method must only be called when GetCPUArchitecture() indicates an |
| 126 //! x86-family CPU architecture (#kCPUArchitectureX86 or |
| 127 //! #kCPUArchitectureX86_64). |
| 128 //! |
| 129 //! \return An x86 family-specific value identifying CPU features. |
| 130 //! |
| 131 //! \sa CPUX86ExtendedFeatures() |
| 132 //! \sa CPUX86Leaf7Features() |
| 133 virtual uint64_t CPUX86Features() const = 0; |
| 134 |
| 135 //! \brief Returns an x86-family snapshot system’s extended CPU features. |
| 136 //! |
| 137 //! This is the extended feature information as encoded in `cpuid 0x80000001` |
| 138 //! `edx` and `ecx`. `edx` is placed in the low half of the return value, and |
| 139 //! `ecx` is placed in the high half. |
| 140 //! |
| 141 //! This method must only be called when GetCPUArchitecture() indicates an |
| 142 //! x86-family CPU architecture (#kCPUArchitectureX86 or |
| 143 //! #kCPUArchitectureX86_64). |
| 144 //! |
| 145 //! \return An x86 family-specific value identifying extended CPU features. |
| 146 //! |
| 147 //! \sa CPUX86Features() |
| 148 //! \sa CPUX86Leaf7Features() |
| 149 virtual uint64_t CPUX86ExtendedFeatures() const = 0; |
| 150 |
| 151 //! \brief Returns an x86-family snapshot system’s “leaf 7” CPU features. |
| 152 //! |
| 153 //! This is the “leaf 7” feature information as encoded in `cpuid 7` `ebx`. If |
| 154 //! `cpuid 7` is not supported by the snapshot CPU, this returns `0`. |
| 155 //! |
| 156 //! This method must only be called when GetCPUArchitecture() indicates an |
| 157 //! x86-family CPU architecture (#kCPUArchitectureX86 or |
| 158 //! #kCPUArchitectureX86_64). |
| 159 //! |
| 160 //! \return An x86 family-specific value identifying “leaf 7” CPU features. |
| 161 //! |
| 162 //! \sa CPUX86Features() |
| 163 //! \sa CPUX86ExtendedFeatures() |
| 164 virtual uint32_t CPUX86Leaf7Features() const = 0; |
| 165 |
| 166 //! \brief Returns an x86-family snapshot system’s CPU’s support for the SSE |
| 167 //! DAZ (“denormals are zeros”) mode. |
| 168 //! |
| 169 //! This determines whether the CPU supports DAZ mode at all, not whether this |
| 170 //! mode is enabled for any particular thread. DAZ mode support is detected by |
| 171 //! examining the DAZ bit in the `mxcsr_mask` field of the floating-point |
| 172 //! context saved by `fxsave`. |
| 173 //! |
| 174 //! This method must only be called when GetCPUArchitecture() indicates an |
| 175 //! x86-family CPU architecture (#kCPUArchitectureX86 or |
| 176 //! #kCPUArchitectureX86_64). |
| 177 //! |
| 178 //! \return `true` if the snapshot system’s CPUs support the SSE DAZ mode, |
| 179 //! `false` if they do not. |
| 180 virtual bool CPUX86SupportsDAZ() const = 0; |
| 181 |
| 182 //! \brief Returns the snapshot system’s operating system family. |
| 183 virtual OperatingSystem GetOperatingSystem() const = 0; |
| 184 |
| 185 //! \brief Returns whether the snapshot system runs a server variant of its |
| 186 //! operating system. |
| 187 virtual bool OSServer() const = 0; |
| 188 |
| 189 //! \brief Returns the snapshot system’s operating system version information |
| 190 //! in \a major, \a minor, \a bugfix, and \a build. |
| 191 //! |
| 192 //! \param[out] major The snapshot system’s operating system’s first (major) |
| 193 //! version number component. This would be `10` for Mac OS X 10.9.5, and |
| 194 //! `6` for Windows 7 (NT 6.1) SP1 version 6.1.7601. |
| 195 //! \param[out] minor The snapshot system’s operating system’s second (minor) |
| 196 //! version number component. This would be `9` for Mac OS X 10.9.5, and |
| 197 //! `1` for Windows 7 (NT 6.1) SP1 version 6.1.7601. |
| 198 //! \param[out] bugfix The snapshot system’s operating system’s third (bugfix) |
| 199 //! version number component. This would be `5` for Mac OS X 10.9.5, and |
| 200 //! `7601` for Windows 7 (NT 6.1) SP1 version 6.1.7601. |
| 201 //! \param[out] build A string further identifying an operating system |
| 202 //! version. For Mac OS X 10.9.5, this would be `"13F34"`. For Windows, |
| 203 //! this would be `"Service Pack 1"` if that service pack was installed. |
| 204 //! For Linux and other Unix-like systems, this would be the kernel |
| 205 //! version from `uname -srvm`, possibly with additional information |
| 206 //! appended. On Android, the `ro.build.fingerprint` system property would |
| 207 //! be appended. |
| 208 virtual void OSVersion(int* major, |
| 209 int* minor, |
| 210 int* bugfix, |
| 211 std::string* build) const = 0; |
| 212 |
| 213 //! \brief Returns the snapshot system’s full operating system version |
| 214 //! information in string format. |
| 215 //! |
| 216 //! For Mac OS X, the string contains values from the operating system and |
| 217 //! kernel. A Mac OS X 10.9.5 snapshot system would be identified as `"Mac OS |
| 218 //! X 10.9.5 (13F34); Darwin 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 |
| 219 //! 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64"`. |
| 220 virtual std::string OSVersionFull() const = 0; |
| 221 |
| 222 //! \brief Returns a description of the snapshot system’s hardware in string |
| 223 //! format. |
| 224 //! |
| 225 //! For Mac OS X, the string contains the Mac model and board ID. A mid-2014 |
| 226 //! 15" MacBook Pro would be identified as `"MacBookPro11,3 |
| 227 //! (Mac-2BD1B31983FE1663)"`. |
| 228 virtual std::string MachineDescription() const = 0; |
| 229 |
| 230 //! \brief Returns the status of the NX (no-execute, or XD, execute-disable) |
| 231 //! feature on the snapshot system. |
| 232 //! |
| 233 //! This refers to a feature that allows mapped readable pages to be marked |
| 234 //! as non-executable. |
| 235 //! |
| 236 //! \return `true` if the snapshot system supports NX and it is enabled. |
| 237 virtual bool NXEnabled() const = 0; |
| 238 |
| 239 //! \brief Returns time zone information from the snapshot system, based on |
| 240 //! its locale configuration and real-time clock. |
| 241 //! |
| 242 //! \param[out] dst_status Whether the location observes daylight saving time, |
| 243 //! and if so, whether it or standard time is currently being observed. |
| 244 //! \param[out] standard_offset_seconds The number of seconds that the |
| 245 //! location’s time zone is east (ahead) of UTC during standard time. |
| 246 //! \param[out] daylight_offset_seconds The number of seconds that the |
| 247 //! location’s time zone is east (ahead) of UTC during daylight saving. |
| 248 //! time. |
| 249 //! \param[out] standard_name The name of the time zone while standard time is |
| 250 //! being observed. |
| 251 //! \param[out] daylight_name The name of the time zone while daylight saving |
| 252 //! time is being observed. |
| 253 virtual void TimeZone(DaylightSavingTimeStatus* observes_daylight, |
| 254 int* standard_offset_seconds, |
| 255 int* daylight_offset_seconds, |
| 256 std::string* standard_name, |
| 257 std::string* daylight_name) const = 0; |
| 258 |
| 259 protected: |
| 260 ~SystemSnapshot() {} |
| 261 }; |
| 262 |
| 263 } // namespace crashpad |
| 264 |
| 265 #endif // CRASHPAD_SNAPSHOT_SYSTEM_SNAPSHOT_H_ |
OLD | NEW |