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 3 // found in the LICENSE file. 4 5 #include "base/win/windows_version.h" 6 7 #include <windows.h> 8 9 #include "base/logging.h" 10 11 namespace base { 12 namespace win { 13 14 // static GetInstance()15OSInfo* OSInfo::GetInstance() { 16 return Singleton<OSInfo>::get(); 17 } 18 OSInfo()19OSInfo::OSInfo() 20 : version_(VERSION_PRE_XP), 21 architecture_(OTHER_ARCHITECTURE), 22 wow64_status_(GetWOW64StatusForProcess(GetCurrentProcess())) { 23 OSVERSIONINFOEX version_info = { sizeof version_info }; 24 GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info)); 25 version_number_.major = version_info.dwMajorVersion; 26 version_number_.minor = version_info.dwMinorVersion; 27 version_number_.build = version_info.dwBuildNumber; 28 if ((version_number_.major == 5) && (version_number_.minor > 0)) { 29 version_ = (version_number_.minor == 1) ? VERSION_XP : VERSION_SERVER_2003; 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; 37 } 38 service_pack_.major = version_info.wServicePackMajor; 39 service_pack_.minor = version_info.wServicePackMinor; 40 41 SYSTEM_INFO system_info = { 0 }; 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; 50 } 51 ~OSInfo()52OSInfo::~OSInfo() { 53 } 54 55 // static GetWOW64StatusForProcess(HANDLE process_handle)56OSInfo::WOW64Status OSInfo::GetWOW64StatusForProcess(HANDLE process_handle) { 57 typedef BOOL (WINAPI* IsWow64ProcessFunc)(HANDLE, PBOOL); 58 IsWow64ProcessFunc is_wow64_process = reinterpret_cast<IsWow64ProcessFunc>( 59 GetProcAddress(GetModuleHandle(L"kernel32.dll"), "IsWow64Process")); 60 if (!is_wow64_process) 61 return WOW64_DISABLED; 62 BOOL is_wow64 = FALSE; 63 if (!(*is_wow64_process)(process_handle, &is_wow64)) 64 return WOW64_UNKNOWN; 65 return is_wow64 ? WOW64_ENABLED : WOW64_DISABLED; 66 } 67 GetVersion()68Version GetVersion() { 69 return OSInfo::GetInstance()->version(); 70 } 71 72 } // namespace win 73 } // namespace base 74