OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_WIN_WINDOWS_VERSION_H_ | 5 #ifndef BASE_WIN_WINDOWS_VERSION_H_ |
6 #define BASE_WIN_WINDOWS_VERSION_H_ | 6 #define BASE_WIN_WINDOWS_VERSION_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/base_api.h" | 9 #include "base/base_api.h" |
| 10 #include "base/memory/singleton.h" |
10 | 11 |
11 typedef void* HANDLE; | 12 typedef void* HANDLE; |
12 | 13 |
13 namespace base { | 14 namespace base { |
14 namespace win { | 15 namespace win { |
15 | 16 |
| 17 // The running version of Windows. This is declared outside OSInfo for |
| 18 // syntactic sugar reasons; see the declaration of GetVersion() below. |
16 // NOTE: Keep these in order so callers can do things like | 19 // NOTE: Keep these in order so callers can do things like |
17 // "if (GetWinVersion() > WINVERSION_2000) ...". It's OK to change the values, | 20 // "if (base::win::OSInfo::GetInstance()->version() > |
18 // though. | 21 // base::win::OSInfo::VERSION_2000) ...". |
19 enum Version { | 22 enum Version { |
20 VERSION_PRE_2000 = 0, // Not supported | 23 VERSION_PRE_XP = 0, // Not supported. |
21 VERSION_2000 = 1, // Not supported | 24 VERSION_XP, |
22 VERSION_XP = 2, | 25 VERSION_SERVER_2003, // Also includes Windows XP Professional x64. |
23 VERSION_SERVER_2003 = 3, // Also includes Windows XP Professional x64 edition | 26 VERSION_VISTA, |
24 VERSION_VISTA = 4, | 27 VERSION_SERVER_2008, |
25 VERSION_2008 = 5, | 28 VERSION_WIN7, |
26 VERSION_WIN7 = 6, | |
27 }; | 29 }; |
28 | 30 |
29 // Returns the running version of Windows. | 31 // A Singleton that can be used to query various pieces of information about the |
30 BASE_API Version GetVersion(); | 32 // OS and process state. |
| 33 class BASE_API OSInfo { |
| 34 public: |
| 35 // The processor architecture this copy of Windows natively uses, which may |
| 36 // not be the same as the processor's "native architecture". For example, |
| 37 // given an x64-capable processor, we have three possibilities: |
| 38 // 32-bit Chrome running on 32-bit Windows: X86_ARCHITECTURE |
| 39 // 32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE |
| 40 // 64-bit Chrome running on 64-bit Windows: X64_ARCHITECTURE |
| 41 enum WindowsArchitecture { |
| 42 X86_ARCHITECTURE, |
| 43 X64_ARCHITECTURE, |
| 44 IA64_ARCHITECTURE, |
| 45 OTHER_ARCHITECTURE, |
| 46 }; |
31 | 47 |
32 // Returns the major and minor version of the service pack installed. | 48 // Whether a process is running under WOW64 (the wrapper that allows 32-bit |
33 BASE_API void GetServicePackLevel(int* major, int* minor); | 49 // processes to run on 64-bit versions of Windows). This will return |
| 50 // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit |
| 51 // Chrome on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g. |
| 52 // the process does not have sufficient access rights to determine this. |
| 53 enum WOW64Status { |
| 54 WOW64_DISABLED, |
| 55 WOW64_ENABLED, |
| 56 WOW64_UNKNOWN, |
| 57 }; |
34 | 58 |
35 enum WindowsArchitecture { | 59 static OSInfo* GetInstance(); |
36 X86_ARCHITECTURE, | 60 |
37 X64_ARCHITECTURE, | 61 Version version() const { return version_; } |
38 IA64_ARCHITECTURE, | 62 // The next two functions return arrays of values, [major, minor(, build)]. |
39 OTHER_ARCHITECTURE, | 63 const int* version_number() const { return version_number_; } |
| 64 const int* service_pack() const { return service_pack_; } |
| 65 WindowsArchitecture architecture() const { return architecture_; } |
| 66 int processors() const { return processors_; } |
| 67 size_t allocation_granularity() const { return allocation_granularity_; } |
| 68 WOW64Status wow64_status() const { return wow64_status_; } |
| 69 |
| 70 // Like wow64_status(), but for the supplied handle instead of the current |
| 71 // process. This doesn't touch member state, so you can bypass the singleton. |
| 72 static WOW64Status GetWOW64StatusForProcess(HANDLE process_handle); |
| 73 |
| 74 private: |
| 75 OSInfo(); |
| 76 ~OSInfo(); |
| 77 |
| 78 Version version_; |
| 79 int version_number_[3]; |
| 80 int service_pack_[2]; |
| 81 WindowsArchitecture architecture_; |
| 82 int processors_; |
| 83 size_t allocation_granularity_; |
| 84 WOW64Status wow64_status_; |
| 85 |
| 86 friend struct DefaultSingletonTraits<OSInfo>; |
| 87 DISALLOW_COPY_AND_ASSIGN(OSInfo); |
40 }; | 88 }; |
41 | 89 |
42 // Returns the processor architecture this copy of Windows natively uses. | 90 // Because this is by far the most commonly-requested value from the above |
43 // For example, given an x64-capable processor, we have three possibilities: | 91 // singleton, we add a global-scope accessor here as syntactic sugar. |
44 // 32-bit Chrome running on 32-bit Windows: X86_ARCHITECTURE | 92 BASE_API Version GetVersion(); |
45 // 32-bit Chrome running on 64-bit Windows via WOW64: X64_ARCHITECTURE | |
46 // 64-bit Chrome running on 64-bit Windows: X64_ARCHITECTURE | |
47 BASE_API WindowsArchitecture GetWindowsArchitecture(); | |
48 | |
49 enum WOW64Status { | |
50 WOW64_DISABLED, | |
51 WOW64_ENABLED, | |
52 WOW64_UNKNOWN, | |
53 }; | |
54 | |
55 // Returns whether this process is running under WOW64 (the wrapper that allows | |
56 // 32-bit processes to run on 64-bit versions of Windows). This will return | |
57 // WOW64_DISABLED for both "32-bit Chrome on 32-bit Windows" and "64-bit Chrome | |
58 // on 64-bit Windows". WOW64_UNKNOWN means "an error occurred", e.g. the | |
59 // process does not have sufficient access rights to determine this. | |
60 BASE_API WOW64Status GetWOW64Status(); | |
61 | |
62 // Like GetWOW64Status(), but for the supplied handle instead of the current | |
63 // process. | |
64 BASE_API WOW64Status GetWOW64StatusForProcess(HANDLE process_handle); | |
65 | 93 |
66 } // namespace win | 94 } // namespace win |
67 } // namespace base | 95 } // namespace base |
68 | 96 |
69 #endif // BASE_WIN_WINDOWS_VERSION_H_ | 97 #endif // BASE_WIN_WINDOWS_VERSION_H_ |
OLD | NEW |