| 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 #include "base/win/windows_version.h" | 5 #include "base/win/windows_version.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 namespace win { | 12 namespace win { |
| 13 | 13 |
| 14 Version GetVersion() { | 14 // static |
| 15 static bool checked_version = false; | 15 OSInfo* OSInfo::GetInstance() { |
| 16 static Version win_version = VERSION_PRE_2000; | 16 return Singleton<OSInfo>::get(); |
| 17 if (!checked_version) { | |
| 18 OSVERSIONINFOEX version_info; | |
| 19 version_info.dwOSVersionInfoSize = sizeof version_info; | |
| 20 GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info)); | |
| 21 if (version_info.dwMajorVersion == 5) { | |
| 22 switch (version_info.dwMinorVersion) { | |
| 23 case 0: | |
| 24 win_version = VERSION_2000; | |
| 25 break; | |
| 26 case 1: | |
| 27 win_version = VERSION_XP; | |
| 28 break; | |
| 29 case 2: | |
| 30 default: | |
| 31 win_version = VERSION_SERVER_2003; | |
| 32 break; | |
| 33 } | |
| 34 } else if (version_info.dwMajorVersion == 6) { | |
| 35 if (version_info.wProductType != VER_NT_WORKSTATION) { | |
| 36 // 2008 is 6.0, and 2008 R2 is 6.1. | |
| 37 win_version = VERSION_2008; | |
| 38 } else { | |
| 39 if (version_info.dwMinorVersion == 0) { | |
| 40 win_version = VERSION_VISTA; | |
| 41 } else { | |
| 42 win_version = VERSION_WIN7; | |
| 43 } | |
| 44 } | |
| 45 } else if (version_info.dwMajorVersion > 6) { | |
| 46 win_version = VERSION_WIN7; | |
| 47 } | |
| 48 checked_version = true; | |
| 49 } | |
| 50 return win_version; | |
| 51 } | 17 } |
| 52 | 18 |
| 53 void GetServicePackLevel(int* major, int* minor) { | 19 OSInfo::OSInfo() |
| 54 DCHECK(major && minor); | 20 : version_(VERSION_PRE_XP), |
| 55 static bool checked_version = false; | 21 architecture_(OTHER_ARCHITECTURE), |
| 56 static int service_pack_major = -1; | 22 wow64_status_(GetWOW64StatusForProcess(GetCurrentProcess())) { |
| 57 static int service_pack_minor = -1; | 23 OSVERSIONINFOEX version_info = { sizeof version_info }; |
| 58 if (!checked_version) { | 24 GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info)); |
| 59 OSVERSIONINFOEX version_info = {0}; | 25 version_number_.major = version_info.dwMajorVersion; |
| 60 version_info.dwOSVersionInfoSize = sizeof(version_info); | 26 version_number_.minor = version_info.dwMinorVersion; |
| 61 GetVersionEx(reinterpret_cast<OSVERSIONINFOW*>(&version_info)); | 27 version_number_.build = version_info.dwBuildNumber; |
| 62 service_pack_major = version_info.wServicePackMajor; | 28 if ((version_number_.major == 5) && (version_number_.minor > 0)) { |
| 63 service_pack_minor = version_info.wServicePackMinor; | 29 version_ = (version_number_.minor == 1) ? VERSION_XP : VERSION_SERVER_2003; |
| 64 checked_version = true; | 30 } else if (version_number_.major == 6) { |
| 31 if (version_info.wProductType == VER_NT_WORKSTATION) |
| 32 version_ = (version_number_.minor == 0) ? VERSION_VISTA : VERSION_WIN7; |
| 33 else |
| 34 version_ = VERSION_SERVER_2008; |
| 35 } else if (version_number_.major > 6) { |
| 36 version_ = VERSION_WIN7; |
| 65 } | 37 } |
| 38 service_pack_.major = version_info.wServicePackMajor; |
| 39 service_pack_.minor = version_info.wServicePackMinor; |
| 66 | 40 |
| 67 *major = service_pack_major; | 41 SYSTEM_INFO system_info = { 0 }; |
| 68 *minor = service_pack_minor; | 42 GetNativeSystemInfo(&system_info); |
| 43 switch (system_info.wProcessorArchitecture) { |
| 44 case PROCESSOR_ARCHITECTURE_INTEL: architecture_ = X86_ARCHITECTURE; break; |
| 45 case PROCESSOR_ARCHITECTURE_AMD64: architecture_ = X64_ARCHITECTURE; break; |
| 46 case PROCESSOR_ARCHITECTURE_IA64: architecture_ = IA64_ARCHITECTURE; break; |
| 47 } |
| 48 processors_ = system_info.dwNumberOfProcessors; |
| 49 allocation_granularity_ = system_info.dwAllocationGranularity; |
| 69 } | 50 } |
| 70 | 51 |
| 71 WindowsArchitecture GetWindowsArchitecture() { | 52 OSInfo::~OSInfo() { |
| 72 SYSTEM_INFO system_info; | |
| 73 GetNativeSystemInfo(&system_info); | |
| 74 switch (system_info.wProcessorArchitecture) { | |
| 75 case PROCESSOR_ARCHITECTURE_INTEL: return X86_ARCHITECTURE; | |
| 76 case PROCESSOR_ARCHITECTURE_AMD64: return X64_ARCHITECTURE; | |
| 77 case PROCESSOR_ARCHITECTURE_IA64: return IA64_ARCHITECTURE; | |
| 78 default: return OTHER_ARCHITECTURE; | |
| 79 } | |
| 80 } | 53 } |
| 81 | 54 |
| 82 WOW64Status GetWOW64Status() { | 55 // static |
| 83 static WOW64Status wow64_status = | 56 OSInfo::WOW64Status OSInfo::GetWOW64StatusForProcess(HANDLE process_handle) { |
| 84 GetWOW64StatusForProcess(GetCurrentProcess()); | |
| 85 return wow64_status; | |
| 86 } | |
| 87 | |
| 88 WOW64Status GetWOW64StatusForProcess(HANDLE process_handle) { | |
| 89 typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL); | 57 typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL); |
| 90 IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>( | 58 IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>( |
| 91 GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process")); | 59 GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process")); |
| 92 if (!is_wow64_process) | 60 if (!is_wow64_process) |
| 93 return WOW64_DISABLED; | 61 return WOW64_DISABLED; |
| 94 BOOL is_wow64 = FALSE; | 62 BOOL is_wow64 = FALSE; |
| 95 if (!(*is_wow64_process)(process_handle, &is_wow64)) | 63 if (!(*is_wow64_process)(process_handle, &is_wow64)) |
| 96 return WOW64_UNKNOWN; | 64 return WOW64_UNKNOWN; |
| 97 return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED; | 65 return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED; |
| 98 } | 66 } |
| 99 | 67 |
| 68 Version GetVersion() { |
| 69 return OSInfo::GetInstance()->version(); |
| 70 } |
| 71 |
| 100 } // namespace win | 72 } // namespace win |
| 101 } // namespace base | 73 } // namespace base |
| OLD | NEW |