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