Mercurial > hg > graal-compiler
comparison src/os/windows/vm/os_windows.cpp @ 20629:09259e52a610
8059803: Update use of GetVersionEx to get correct Windows version in hs_err files
Summary: Update use of GetVersionEx to get correct Windows version in hs_err files
Reviewed-by: dcubed, gtriantafill
author | ctornqvi |
---|---|
date | Tue, 11 Nov 2014 10:46:07 -0800 |
parents | aef17e6b4abf |
children | 7848fc12602b |
comparison
equal
deleted
inserted
replaced
20628:80260967f994 | 20629:09259e52a610 |
---|---|
1648 os::win32::print_windows_version(st); | 1648 os::win32::print_windows_version(st); |
1649 } | 1649 } |
1650 | 1650 |
1651 void os::win32::print_windows_version(outputStream* st) { | 1651 void os::win32::print_windows_version(outputStream* st) { |
1652 OSVERSIONINFOEX osvi; | 1652 OSVERSIONINFOEX osvi; |
1653 SYSTEM_INFO si; | 1653 VS_FIXEDFILEINFO *file_info; |
1654 | 1654 TCHAR kernel32_path[MAX_PATH]; |
1655 UINT len, ret; | |
1656 | |
1657 // Use the GetVersionEx information to see if we're on a server or | |
1658 // workstation edition of Windows. Starting with Windows 8.1 we can't | |
1659 // trust the OS version information returned by this API. | |
1655 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); | 1660 ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); |
1656 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); | 1661 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
1657 | |
1658 if (!GetVersionEx((OSVERSIONINFO *)&osvi)) { | 1662 if (!GetVersionEx((OSVERSIONINFO *)&osvi)) { |
1659 st->print_cr("N/A"); | 1663 st->print_cr("Call to GetVersionEx failed"); |
1660 return; | 1664 return; |
1661 } | 1665 } |
1662 | 1666 bool is_workstation = (osvi.wProductType == VER_NT_WORKSTATION); |
1663 int os_vers = osvi.dwMajorVersion * 1000 + osvi.dwMinorVersion; | 1667 |
1664 | 1668 // Get the full path to \Windows\System32\kernel32.dll and use that for |
1669 // determining what version of Windows we're running on. | |
1670 len = MAX_PATH - (UINT)strlen("\\kernel32.dll") - 1; | |
1671 ret = GetSystemDirectory(kernel32_path, len); | |
1672 if (ret == 0 || ret > len) { | |
1673 st->print_cr("Call to GetSystemDirectory failed"); | |
1674 return; | |
1675 } | |
1676 strncat(kernel32_path, "\\kernel32.dll", MAX_PATH - ret); | |
1677 | |
1678 DWORD version_size = GetFileVersionInfoSize(kernel32_path, NULL); | |
1679 if (version_size == 0) { | |
1680 st->print_cr("Call to GetFileVersionInfoSize failed"); | |
1681 return; | |
1682 } | |
1683 | |
1684 LPTSTR version_info = (LPTSTR)os::malloc(version_size, mtInternal); | |
1685 if (version_info == NULL) { | |
1686 st->print_cr("Failed to allocate version_info"); | |
1687 return; | |
1688 } | |
1689 | |
1690 if (!GetFileVersionInfo(kernel32_path, NULL, version_size, version_info)) { | |
1691 os::free(version_info); | |
1692 st->print_cr("Call to GetFileVersionInfo failed"); | |
1693 return; | |
1694 } | |
1695 | |
1696 if (!VerQueryValue(version_info, TEXT("\\"), (LPVOID*)&file_info, &len)) { | |
1697 os::free(version_info); | |
1698 st->print_cr("Call to VerQueryValue failed"); | |
1699 return; | |
1700 } | |
1701 | |
1702 int major_version = HIWORD(file_info->dwProductVersionMS); | |
1703 int minor_version = LOWORD(file_info->dwProductVersionMS); | |
1704 int build_number = HIWORD(file_info->dwProductVersionLS); | |
1705 int build_minor = LOWORD(file_info->dwProductVersionLS); | |
1706 int os_vers = major_version * 1000 + minor_version; | |
1707 os::free(version_info); | |
1708 | |
1709 st->print(" Windows "); | |
1710 switch (os_vers) { | |
1711 | |
1712 case 6000: | |
1713 if (is_workstation) { | |
1714 st->print("Vista"); | |
1715 } else { | |
1716 st->print("Server 2008"); | |
1717 } | |
1718 break; | |
1719 | |
1720 case 6001: | |
1721 if (is_workstation) { | |
1722 st->print("7"); | |
1723 } else { | |
1724 st->print("Server 2008 R2"); | |
1725 } | |
1726 break; | |
1727 | |
1728 case 6002: | |
1729 if (is_workstation) { | |
1730 st->print("8"); | |
1731 } else { | |
1732 st->print("Server 2012"); | |
1733 } | |
1734 break; | |
1735 | |
1736 case 6003: | |
1737 if (is_workstation) { | |
1738 st->print("8.1"); | |
1739 } else { | |
1740 st->print("Server 2012 R2"); | |
1741 } | |
1742 break; | |
1743 | |
1744 case 6004: | |
1745 if (is_workstation) { | |
1746 st->print("10"); | |
1747 } else { | |
1748 // The server version name of Windows 10 is not known at this time | |
1749 st->print("%d.%d", major_version, minor_version); | |
1750 } | |
1751 break; | |
1752 | |
1753 default: | |
1754 // Unrecognized windows, print out its major and minor versions | |
1755 st->print("%d.%d", major_version, minor_version); | |
1756 break; | |
1757 } | |
1758 | |
1759 // Retrieve SYSTEM_INFO from GetNativeSystemInfo call so that we could | |
1760 // find out whether we are running on 64 bit processor or not | |
1761 SYSTEM_INFO si; | |
1665 ZeroMemory(&si, sizeof(SYSTEM_INFO)); | 1762 ZeroMemory(&si, sizeof(SYSTEM_INFO)); |
1666 if (os_vers >= 5002) { | 1763 os::Kernel32Dll::GetNativeSystemInfo(&si); |
1667 // Retrieve SYSTEM_INFO from GetNativeSystemInfo call so that we could | 1764 if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { |
1668 // find out whether we are running on 64 bit processor or not. | |
1669 if (os::Kernel32Dll::GetNativeSystemInfoAvailable()) { | |
1670 os::Kernel32Dll::GetNativeSystemInfo(&si); | |
1671 } else { | |
1672 GetSystemInfo(&si); | |
1673 } | |
1674 } | |
1675 | |
1676 if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) { | |
1677 switch (os_vers) { | |
1678 case 3051: st->print(" Windows NT 3.51"); break; | |
1679 case 4000: st->print(" Windows NT 4.0"); break; | |
1680 case 5000: st->print(" Windows 2000"); break; | |
1681 case 5001: st->print(" Windows XP"); break; | |
1682 case 5002: | |
1683 if (osvi.wProductType == VER_NT_WORKSTATION && | |
1684 si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { | |
1685 st->print(" Windows XP x64 Edition"); | |
1686 } else { | |
1687 st->print(" Windows Server 2003 family"); | |
1688 } | |
1689 break; | |
1690 | |
1691 case 6000: | |
1692 if (osvi.wProductType == VER_NT_WORKSTATION) { | |
1693 st->print(" Windows Vista"); | |
1694 } else { | |
1695 st->print(" Windows Server 2008"); | |
1696 } | |
1697 break; | |
1698 | |
1699 case 6001: | |
1700 if (osvi.wProductType == VER_NT_WORKSTATION) { | |
1701 st->print(" Windows 7"); | |
1702 } else { | |
1703 st->print(" Windows Server 2008 R2"); | |
1704 } | |
1705 break; | |
1706 | |
1707 case 6002: | |
1708 if (osvi.wProductType == VER_NT_WORKSTATION) { | |
1709 st->print(" Windows 8"); | |
1710 } else { | |
1711 st->print(" Windows Server 2012"); | |
1712 } | |
1713 break; | |
1714 | |
1715 case 6003: | |
1716 if (osvi.wProductType == VER_NT_WORKSTATION) { | |
1717 st->print(" Windows 8.1"); | |
1718 } else { | |
1719 st->print(" Windows Server 2012 R2"); | |
1720 } | |
1721 break; | |
1722 | |
1723 default: // future os | |
1724 // Unrecognized windows, print out its major and minor versions | |
1725 st->print(" Windows NT %d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion); | |
1726 } | |
1727 } else { | |
1728 switch (os_vers) { | |
1729 case 4000: st->print(" Windows 95"); break; | |
1730 case 4010: st->print(" Windows 98"); break; | |
1731 case 4090: st->print(" Windows Me"); break; | |
1732 default: // future windows, print out its major and minor versions | |
1733 st->print(" Windows %d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion); | |
1734 } | |
1735 } | |
1736 | |
1737 if (os_vers >= 6000 && si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { | |
1738 st->print(" , 64 bit"); | 1765 st->print(" , 64 bit"); |
1739 } | 1766 } |
1740 | 1767 |
1741 st->print(" Build %d", osvi.dwBuildNumber); | 1768 st->print(" Build %d", build_number); |
1742 st->print(" %s", osvi.szCSDVersion); // service pack | 1769 st->print(" (%d.%d.%d.%d)", major_version, minor_version, build_number, build_minor); |
1743 st->cr(); | 1770 st->cr(); |
1744 } | 1771 } |
1745 | 1772 |
1746 void os::pd_print_cpu_info(outputStream* st) { | 1773 void os::pd_print_cpu_info(outputStream* st) { |
1747 // Nothing to do for now. | 1774 // Nothing to do for now. |
5348 | 5375 |
5349 inline BOOL os::Kernel32Dll::Module32Next(HANDLE hSnapshot,LPMODULEENTRY32 lpme) { | 5376 inline BOOL os::Kernel32Dll::Module32Next(HANDLE hSnapshot,LPMODULEENTRY32 lpme) { |
5350 return ::Module32Next(hSnapshot, lpme); | 5377 return ::Module32Next(hSnapshot, lpme); |
5351 } | 5378 } |
5352 | 5379 |
5353 | |
5354 inline BOOL os::Kernel32Dll::GetNativeSystemInfoAvailable() { | |
5355 return true; | |
5356 } | |
5357 | |
5358 inline void os::Kernel32Dll::GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) { | 5380 inline void os::Kernel32Dll::GetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo) { |
5359 ::GetNativeSystemInfo(lpSystemInfo); | 5381 ::GetNativeSystemInfo(lpSystemInfo); |
5360 } | 5382 } |
5361 | 5383 |
5362 // PSAPI API | 5384 // PSAPI API |