1 // Copyright 2017 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_X86_CPUID_READER_H_
16 #define CRASHPAD_SNAPSHOT_X86_CPUID_READER_H_
17 
18 #include <stdint.h>
19 
20 #include <string>
21 
22 #include "build/build_config.h"
23 
24 #if defined(ARCH_CPU_X86_FAMILY)
25 
26 namespace crashpad {
27 namespace internal {
28 
29 //! \brief Reads x86-family CPU information by calling `cpuid`.
30 class CpuidReader {
31  public:
32   CpuidReader();
33   ~CpuidReader();
34 
35   //! \see SystemSnapshot::CPURevision
36   uint32_t Revision() const;
37 
38   //! \see SystemSnapshot::CPUVendor
Vendor()39   std::string Vendor() const { return vendor_; }
40 
41   //! \see SystemSnapshot::CPUX86Signature
Signature()42   uint32_t Signature() const { return signature_; }
43 
44   //! \see SystemSnapshot::CPUX86Features
Features()45   uint64_t Features() const { return features_; }
46 
47   //! \see SystemSnapshot::CPUX86ExtendedFeatures
ExtendedFeatures()48   uint64_t ExtendedFeatures() const { return extended_features_; }
49 
50   //! \see SystemSnapshot::CPUX86Leaf7Features
51   uint32_t Leaf7Features() const;
52 
53   //! \see SystemSnapshot::NXEnabled
NXEnabled()54   bool NXEnabled() const { return (ExtendedFeatures() & (1 << 20)) != 0; }
55 
56   //! \see SystemSnapshot::CPUX86SupportsDAZ
57   bool SupportsDAZ() const;
58 
59  private:
60   void Cpuid(uint32_t cpuinfo[4], uint32_t leaf) const;
61 
62   uint64_t features_;
63   uint64_t extended_features_;
64   std::string vendor_;
65   uint32_t max_leaf_;
66   uint32_t signature_;
67 };
68 
69 }  // namespace internal
70 }  // namespace crashpad
71 
72 #endif  // ARCH_CPU_X86_FAMILY
73 
74 #endif  // CRASHPAD_SNAPSHOT_X86_CPUID_READER_H_
75