1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_WIN_WINDOWS_VERSION_H_ 6 #define BASE_WIN_WINDOWS_VERSION_H_ 7 8 #include <stddef.h> 9 10 #include <string> 11 12 #include "base/base_export.h" 13 #include "base/gtest_prod_util.h" 14 #include "base/macros.h" 15 #include "base/version.h" 16 17 using HANDLE = void*; 18 struct _OSVERSIONINFOEXW; 19 struct _SYSTEM_INFO; 20 21 namespace base { 22 namespace test { 23 class ScopedOSInfoOverride; 24 } // namespace test 25 } // namespace base 26 27 namespace base { 28 namespace win { 29 30 // The running version of Windows. This is declared outside OSInfo for 31 // syntactic sugar reasons; see the declaration of GetVersion() below. 32 // NOTE: Keep these in order so callers can do things like 33 // "if (base::win::GetVersion() >= base::win::Version::VISTA) ...". 34 // 35 // This enum is used in metrics histograms, so they shouldn't be reordered or 36 // removed. New values can be added before Version::WIN_LAST. 37 enum class Version { 38 PRE_XP = 0, // Not supported. 39 XP = 1, 40 SERVER_2003 = 2, // Also includes XP Pro x64 and Server 2003 R2. 41 VISTA = 3, // Also includes Windows Server 2008. 42 WIN7 = 4, // Also includes Windows Server 2008 R2. 43 WIN8 = 5, // Also includes Windows Server 2012. 44 WIN8_1 = 6, // Also includes Windows Server 2012 R2. 45 WIN10 = 7, // Threshold 1: Version 1507, Build 10240. 46 WIN10_TH2 = 8, // Threshold 2: Version 1511, Build 10586. 47 WIN10_RS1 = 9, // Redstone 1: Version 1607, Build 14393. 48 WIN10_RS2 = 10, // Redstone 2: Version 1703, Build 15063. 49 WIN10_RS3 = 11, // Redstone 3: Version 1709, Build 16299. 50 WIN10_RS4 = 12, // Redstone 4: Version 1803, Build 17134. 51 WIN10_RS5 = 13, // Redstone 5: Version 1809, Build 17763. 52 WIN10_19H1 = 14, // 19H1: Version 1903, Build 18362. 53 WIN10_20H1 = 15, // 20H1: Version 2004, Build 19041. 54 // On edit, update tools\metrics\histograms\enums.xml "WindowsVersion" and 55 // "GpuBlacklistFeatureTestResultsWindows2". 56 WIN_LAST, // Indicates error condition. 57 }; 58 59 // A rough bucketing of the available types of versions of Windows. This is used 60 // to distinguish enterprise enabled versions from home versions and potentially 61 // server versions. Keep these values in the same order, since they are used as 62 // is for metrics histogram ids. 63 enum VersionType { 64 SUITE_HOME = 0, 65 SUITE_PROFESSIONAL, 66 SUITE_SERVER, 67 SUITE_ENTERPRISE, 68 SUITE_EDUCATION, 69 SUITE_LAST, 70 }; 71 72 // A singleton that can be used to query various pieces of information about the 73 // OS and process state. Note that this doesn't use the base Singleton class, so 74 // it can be used without an AtExitManager. 75 class BASE_EXPORT OSInfo { 76 public: 77 struct VersionNumber { 78 int major; 79 int minor; 80 int build; 81 int patch; 82 }; 83 84 struct ServicePack { 85 int major; 86 int minor; 87 }; 88 89 // The processor architecture this copy of Windows natively uses. For 90 // example, given an x64-capable processor, we have three possibilities: 91 // 32-bit Chrome running on 32-bit Windows: X86_ARCHITECTURE 92 // 32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE 93 // 64-bit Chrome running on 64-bit Windows: X64_ARCHITECTURE 94 enum WindowsArchitecture { 95 X86_ARCHITECTURE, 96 X64_ARCHITECTURE, 97 IA64_ARCHITECTURE, 98 ARM64_ARCHITECTURE, 99 OTHER_ARCHITECTURE, 100 }; 101 102 // Whether a process is running under WOW64 (the wrapper that allows 32-bit 103 // processes to run on 64-bit versions of Windows). This will return 104 // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit 105 // Chrome on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g. 106 // the process does not have sufficient access rights to determine this. 107 enum WOW64Status { 108 WOW64_DISABLED, 109 WOW64_ENABLED, 110 WOW64_UNKNOWN, 111 }; 112 113 static OSInfo* GetInstance(); 114 115 // Separate from the rest of OSInfo so it can be used during early process 116 // initialization. 117 static WindowsArchitecture GetArchitecture(); 118 119 // Like wow64_status(), but for the supplied handle instead of the current 120 // process. This doesn't touch member state, so you can bypass the singleton. 121 static WOW64Status GetWOW64StatusForProcess(HANDLE process_handle); 122 version()123 const Version& version() const { return version_; } 124 Version Kernel32Version() const; 125 Version UcrtVersion() const; 126 base::Version Kernel32BaseVersion() const; 127 // The next two functions return arrays of values, [major, minor(, build)]. version_number()128 const VersionNumber& version_number() const { return version_number_; } version_type()129 const VersionType& version_type() const { return version_type_; } service_pack()130 const ServicePack& service_pack() const { return service_pack_; } service_pack_str()131 const std::string& service_pack_str() const { return service_pack_str_; } processors()132 const int& processors() const { return processors_; } allocation_granularity()133 const size_t& allocation_granularity() const { 134 return allocation_granularity_; 135 } wow64_status()136 const WOW64Status& wow64_status() const { return wow64_status_; } 137 std::string processor_model_name(); release_id()138 const std::string& release_id() const { return release_id_; } 139 140 private: 141 friend class base::test::ScopedOSInfoOverride; 142 FRIEND_TEST_ALL_PREFIXES(OSInfo, MajorMinorBuildToVersion); 143 static OSInfo** GetInstanceStorage(); 144 145 OSInfo(const _OSVERSIONINFOEXW& version_info, 146 const _SYSTEM_INFO& system_info, 147 int os_type); 148 ~OSInfo(); 149 150 // Returns a Version value for a given OS version tuple. 151 static Version MajorMinorBuildToVersion(int major, int minor, int build); 152 153 Version version_; 154 VersionNumber version_number_; 155 VersionType version_type_; 156 ServicePack service_pack_; 157 158 // Represents the version of the OS associated to a release of 159 // Windows 10. Each version may have different releases (such as patch 160 // updates). This is the identifier of the release. 161 // Example: 162 // Windows 10 Version 1809 (OS build 17763) has multiple releases 163 // (i.e. build 17763.1, build 17763.195, build 17763.379, ...). 164 // See https://docs.microsoft.com/en-us/windows/windows-10/release-information 165 // for more information. 166 std::string release_id_; 167 168 // A string, such as "Service Pack 3", that indicates the latest Service Pack 169 // installed on the system. If no Service Pack has been installed, the string 170 // is empty. 171 std::string service_pack_str_; 172 int processors_; 173 size_t allocation_granularity_; 174 WOW64Status wow64_status_; 175 std::string processor_model_name_; 176 177 DISALLOW_COPY_AND_ASSIGN(OSInfo); 178 }; 179 180 // Because this is by far the most commonly-requested value from the above 181 // singleton, we add a global-scope accessor here as syntactic sugar. 182 BASE_EXPORT Version GetVersion(); 183 184 } // namespace win 185 } // namespace base 186 187 #endif // BASE_WIN_WINDOWS_VERSION_H_ 188