1.1 --- a/src/os/windows/vm/os_windows.cpp Wed Nov 05 08:22:17 2014 -0800 1.2 +++ b/src/os/windows/vm/os_windows.cpp Tue Nov 11 10:46:07 2014 -0800 1.3 @@ -1650,96 +1650,123 @@ 1.4 1.5 void os::win32::print_windows_version(outputStream* st) { 1.6 OSVERSIONINFOEX osvi; 1.7 - SYSTEM_INFO si; 1.8 - 1.9 + VS_FIXEDFILEINFO *file_info; 1.10 + TCHAR kernel32_path[MAX_PATH]; 1.11 + UINT len, ret; 1.12 + 1.13 + // Use the GetVersionEx information to see if we're on a server or 1.14 + // workstation edition of Windows. Starting with Windows 8.1 we can't 1.15 + // trust the OS version information returned by this API. 1.16 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); 1.17 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 1.18 - 1.19 if (!GetVersionEx((OSVERSIONINFO *)&osvi)) { 1.20 - st->print_cr("N/A"); 1.21 + st->print_cr("Call to GetVersionEx failed"); 1.22 return; 1.23 } 1.24 - 1.25 - int os_vers = osvi.dwMajorVersion * 1000 + osvi.dwMinorVersion; 1.26 - 1.27 + bool is_workstation = (osvi.wProductType == VER_NT_WORKSTATION); 1.28 + 1.29 + // Get the full path to \Windows\System32\kernel32.dll and use that for 1.30 + // determining what version of Windows we're running on. 1.31 + len = MAX_PATH - (UINT)strlen("\\kernel32.dll") - 1; 1.32 + ret = GetSystemDirectory(kernel32_path, len); 1.33 + if (ret == 0 || ret > len) { 1.34 + st->print_cr("Call to GetSystemDirectory failed"); 1.35 + return; 1.36 + } 1.37 + strncat(kernel32_path, "\\kernel32.dll", MAX_PATH - ret); 1.38 + 1.39 + DWORD version_size = GetFileVersionInfoSize(kernel32_path, NULL); 1.40 + if (version_size == 0) { 1.41 + st->print_cr("Call to GetFileVersionInfoSize failed"); 1.42 + return; 1.43 + } 1.44 + 1.45 + LPTSTR version_info = (LPTSTR)os::malloc(version_size, mtInternal); 1.46 + if (version_info == NULL) { 1.47 + st->print_cr("Failed to allocate version_info"); 1.48 + return; 1.49 + } 1.50 + 1.51 + if (!GetFileVersionInfo(kernel32_path, NULL, version_size, version_info)) { 1.52 + os::free(version_info); 1.53 + st->print_cr("Call to GetFileVersionInfo failed"); 1.54 + return; 1.55 + } 1.56 + 1.57 + if (!VerQueryValue(version_info, TEXT("\\"), (LPVOID*)&file_info, &len)) { 1.58 + os::free(version_info); 1.59 + st->print_cr("Call to VerQueryValue failed"); 1.60 + return; 1.61 + } 1.62 + 1.63 + int major_version = HIWORD(file_info->dwProductVersionMS); 1.64 + int minor_version = LOWORD(file_info->dwProductVersionMS); 1.65 + int build_number = HIWORD(file_info->dwProductVersionLS); 1.66 + int build_minor = LOWORD(file_info->dwProductVersionLS); 1.67 + int os_vers = major_version * 1000 + minor_version; 1.68 + os::free(version_info); 1.69 + 1.70 + st->print(" Windows "); 1.71 + switch (os_vers) { 1.72 + 1.73 + case 6000: 1.74 + if (is_workstation) { 1.75 + st->print("Vista"); 1.76 + } else { 1.77 + st->print("Server 2008"); 1.78 + } 1.79 + break; 1.80 + 1.81 + case 6001: 1.82 + if (is_workstation) { 1.83 + st->print("7"); 1.84 + } else { 1.85 + st->print("Server 2008 R2"); 1.86 + } 1.87 + break; 1.88 + 1.89 + case 6002: 1.90 + if (is_workstation) { 1.91 + st->print("8"); 1.92 + } else { 1.93 + st->print("Server 2012"); 1.94 + } 1.95 + break; 1.96 + 1.97 + case 6003: 1.98 + if (is_workstation) { 1.99 + st->print("8.1"); 1.100 + } else { 1.101 + st->print("Server 2012 R2"); 1.102 + } 1.103 + break; 1.104 + 1.105 + case 6004: 1.106 + if (is_workstation) { 1.107 + st->print("10"); 1.108 + } else { 1.109 + // The server version name of Windows 10 is not known at this time 1.110 + st->print("%d.%d", major_version, minor_version); 1.111 + } 1.112 + break; 1.113 + 1.114 + default: 1.115 + // Unrecognized windows, print out its major and minor versions 1.116 + st->print("%d.%d", major_version, minor_version); 1.117 + break; 1.118 + } 1.119 + 1.120 + // Retrieve SYSTEM_INFO from GetNativeSystemInfo call so that we could 1.121 + // find out whether we are running on 64 bit processor or not 1.122 + SYSTEM_INFO si; 1.123 ZeroMemory(&si, sizeof(SYSTEM_INFO)); 1.124 - if (os_vers >= 5002) { 1.125 - // Retrieve SYSTEM_INFO from GetNativeSystemInfo call so that we could 1.126 - // find out whether we are running on 64 bit processor or not. 1.127 - if (os::Kernel32Dll::GetNativeSystemInfoAvailable()) { 1.128 - os::Kernel32Dll::GetNativeSystemInfo(&si); 1.129 - } else { 1.130 - GetSystemInfo(&si); 1.131 - } 1.132 - } 1.133 - 1.134 - if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) { 1.135 - switch (os_vers) { 1.136 - case 3051: st->print(" Windows NT 3.51"); break; 1.137 - case 4000: st->print(" Windows NT 4.0"); break; 1.138 - case 5000: st->print(" Windows 2000"); break; 1.139 - case 5001: st->print(" Windows XP"); break; 1.140 - case 5002: 1.141 - if (osvi.wProductType == VER_NT_WORKSTATION && 1.142 - si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { 1.143 - st->print(" Windows XP x64 Edition"); 1.144 - } else { 1.145 - st->print(" Windows Server 2003 family"); 1.146 - } 1.147 - break; 1.148 - 1.149 - case 6000: 1.150 - if (osvi.wProductType == VER_NT_WORKSTATION) { 1.151 - st->print(" Windows Vista"); 1.152 - } else { 1.153 - st->print(" Windows Server 2008"); 1.154 - } 1.155 - break; 1.156 - 1.157 - case 6001: 1.158 - if (osvi.wProductType == VER_NT_WORKSTATION) { 1.159 - st->print(" Windows 7"); 1.160 - } else { 1.161 - st->print(" Windows Server 2008 R2"); 1.162 - } 1.163 - break; 1.164 - 1.165 - case 6002: 1.166 - if (osvi.wProductType == VER_NT_WORKSTATION) { 1.167 - st->print(" Windows 8"); 1.168 - } else { 1.169 - st->print(" Windows Server 2012"); 1.170 - } 1.171 - break; 1.172 - 1.173 - case 6003: 1.174 - if (osvi.wProductType == VER_NT_WORKSTATION) { 1.175 - st->print(" Windows 8.1"); 1.176 - } else { 1.177 - st->print(" Windows Server 2012 R2"); 1.178 - } 1.179 - break; 1.180 - 1.181 - default: // future os 1.182 - // Unrecognized windows, print out its major and minor versions 1.183 - st->print(" Windows NT %d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion); 1.184 - } 1.185 - } else { 1.186 - switch (os_vers) { 1.187 - case 4000: st->print(" Windows 95"); break; 1.188 - case 4010: st->print(" Windows 98"); break; 1.189 - case 4090: st->print(" Windows Me"); break; 1.190 - default: // future windows, print out its major and minor versions 1.191 - st->print(" Windows %d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion); 1.192 - } 1.193 - } 1.194 - 1.195 - if (os_vers >= 6000 && si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { 1.196 + os::Kernel32Dll::GetNativeSystemInfo(&si); 1.197 + if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { 1.198 st->print(" , 64 bit"); 1.199 } 1.200 1.201 - st->print(" Build %d", osvi.dwBuildNumber); 1.202 - st->print(" %s", osvi.szCSDVersion); // service pack 1.203 + st->print(" Build %d", build_number); 1.204 + st->print(" (%d.%d.%d.%d)", major_version, minor_version, build_number, build_minor); 1.205 st->cr(); 1.206 } 1.207 1.208 @@ -5350,11 +5377,6 @@ 1.209 return ::Module32Next(hSnapshot, lpme); 1.210 } 1.211 1.212 - 1.213 -inline BOOL os::Kernel32Dll::GetNativeSystemInfoAvailable() { 1.214 - return true; 1.215 -} 1.216 - 1.217 inline void os::Kernel32Dll::GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) { 1.218 ::GetNativeSystemInfo(lpSystemInfo); 1.219 }