windows_version.h 5.5 KB

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