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