1 /*
2  *  Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef RTC_BASE_WIN_WINDOWS_VERSION_H_
12 #define RTC_BASE_WIN_WINDOWS_VERSION_H_
13 
14 #include <stddef.h>
15 
16 #include <string>
17 
18 #include "rtc_base/constructor_magic.h"
19 
20 typedef void* HANDLE;
21 
22 namespace rtc {
23 namespace rtc_win {
24 
25 // The running version of Windows.  This is declared outside OSInfo for
26 // syntactic sugar reasons; see the declaration of GetVersion() below.
27 // NOTE: Keep these in order so callers can do things like
28 // "if (rtc_win::GetVersion() >= rtc_win::VERSION_VISTA) ...".
29 //
30 // This enum is used in metrics histograms, so they shouldn't be reordered or
31 // removed. New values can be added before VERSION_WIN_LAST.
32 enum Version {
33   VERSION_PRE_XP = 0,  // Not supported.
34   VERSION_XP = 1,
35   VERSION_SERVER_2003 = 2,  // Also includes XP Pro x64 and Server 2003 R2.
36   VERSION_VISTA = 3,        // Also includes Windows Server 2008.
37   VERSION_WIN7 = 4,         // Also includes Windows Server 2008 R2.
38   VERSION_WIN8 = 5,         // Also includes Windows Server 2012.
39   VERSION_WIN8_1 = 6,       // Also includes Windows Server 2012 R2.
40   VERSION_WIN10 = 7,        // Threshold 1: Version 1507, Build 10240.
41   VERSION_WIN10_TH2 = 8,    // Threshold 2: Version 1511, Build 10586.
42   VERSION_WIN10_RS1 = 9,    // Redstone 1: Version 1607, Build 14393.
43   VERSION_WIN10_RS2 = 10,   // Redstone 2: Version 1703, Build 15063.
44   VERSION_WIN10_RS3 = 11,   // Redstone 3: Version 1709, Build 16299.
45   VERSION_WIN10_RS4 = 12,   // Redstone 4: Version 1803, Build 17134.
46   // On edit, update tools\metrics\histograms\enums.xml "WindowsVersion" and
47   // "GpuBlacklistFeatureTestResultsWindows2".
48   VERSION_WIN_LAST,  // Indicates error condition.
49 };
50 
51 // A rough bucketing of the available types of versions of Windows. This is used
52 // to distinguish enterprise enabled versions from home versions and potentially
53 // server versions. Keep these values in the same order, since they are used as
54 // is for metrics histogram ids.
55 enum VersionType {
56   SUITE_HOME = 0,
57   SUITE_PROFESSIONAL,
58   SUITE_SERVER,
59   SUITE_ENTERPRISE,
60   SUITE_EDUCATION,
61   SUITE_LAST,
62 };
63 
64 // A singleton that can be used to query various pieces of information about the
65 // OS and process state. Note that this doesn't use the base Singleton class, so
66 // it can be used without an AtExitManager.
67 class OSInfo {
68  public:
69   struct VersionNumber {
70     int major;
71     int minor;
72     int build;
73     int patch;
74   };
75 
76   struct ServicePack {
77     int major;
78     int minor;
79   };
80 
81   // The processor architecture this copy of Windows natively uses.  For
82   // example, given an x64-capable processor, we have three possibilities:
83   //   32-bit Chrome running on 32-bit Windows:           X86_ARCHITECTURE
84   //   32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE
85   //   64-bit Chrome running on 64-bit Windows:           X64_ARCHITECTURE
86   enum WindowsArchitecture {
87     X86_ARCHITECTURE,
88     X64_ARCHITECTURE,
89     IA64_ARCHITECTURE,
90     OTHER_ARCHITECTURE,
91   };
92 
93   // Whether a process is running under WOW64 (the wrapper that allows 32-bit
94   // processes to run on 64-bit versions of Windows).  This will return
95   // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit
96   // Chrome on 64-bit Windows".  WOW64_UNKNOWN means "an error occurred", e.g.
97   // the process does not have sufficient access rights to determine this.
98   enum WOW64Status {
99     WOW64_DISABLED,
100     WOW64_ENABLED,
101     WOW64_UNKNOWN,
102   };
103 
104   static OSInfo* GetInstance();
105 
version()106   Version version() const { return version_; }
version_number()107   VersionNumber version_number() const { return version_number_; }
version_type()108   VersionType version_type() const { return version_type_; }
service_pack()109   ServicePack service_pack() const { return service_pack_; }
service_pack_str()110   std::string service_pack_str() const { return service_pack_str_; }
architecture()111   WindowsArchitecture architecture() const { return architecture_; }
processors()112   int processors() const { return processors_; }
allocation_granularity()113   size_t allocation_granularity() const { return allocation_granularity_; }
wow64_status()114   WOW64Status wow64_status() const { return wow64_status_; }
115   std::string processor_model_name();
116 
117   // Like wow64_status(), but for the supplied handle instead of the current
118   // process.  This doesn't touch member state, so you can bypass the singleton.
119   static WOW64Status GetWOW64StatusForProcess(HANDLE process_handle);
120 
121  private:
122   OSInfo();
123   ~OSInfo();
124 
125   Version version_;
126   VersionNumber version_number_;
127   VersionType version_type_;
128   ServicePack service_pack_;
129 
130   // A string, such as "Service Pack 3", that indicates the latest Service Pack
131   // installed on the system. If no Service Pack has been installed, the string
132   // is empty.
133   std::string service_pack_str_;
134   WindowsArchitecture architecture_;
135   int processors_;
136   size_t allocation_granularity_;
137   WOW64Status wow64_status_;
138   std::string processor_model_name_;
139 
140   RTC_DISALLOW_COPY_AND_ASSIGN(OSInfo);
141 };
142 
143 // Because this is by far the most commonly-requested value from the above
144 // singleton, we add a global-scope accessor here as syntactic sugar.
145 Version GetVersion();
146 
147 }  // namespace rtc_win
148 }  // namespace rtc
149 
150 #endif  // RTC_BASE_WIN_WINDOWS_VERSION_H_
151