blob: 1ad319e4ccffebfb7fb2f68d9809ce4773b79f31 [file] [log] [blame]
henrika3ca48a62018-05-21 13:34:51 +02001/*
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>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
henrika3ca48a62018-05-21 13:34:51 +020016#include <string>
17
Steve Anton10542f22019-01-11 09:11:00 -080018#include "rtc_base/constructor_magic.h"
henrika3ca48a62018-05-21 13:34:51 +020019
20typedef void* HANDLE;
21
22namespace rtc {
23namespace 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.
32enum 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.
55enum 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.
67class 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
106 Version version() const { return version_; }
107 VersionNumber version_number() const { return version_number_; }
108 VersionType version_type() const { return version_type_; }
109 ServicePack service_pack() const { return service_pack_; }
110 std::string service_pack_str() const { return service_pack_str_; }
111 WindowsArchitecture architecture() const { return architecture_; }
112 int processors() const { return processors_; }
113 size_t allocation_granularity() const { return allocation_granularity_; }
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.
145Version GetVersion();
146
147} // namespace rtc_win
148} // namespace rtc
149
150#endif // RTC_BASE_WIN_WINDOWS_VERSION_H_