Skip to content

Commit

Permalink
Better detection of Windows 10 in omrsysinfo_get_OS_type()
Browse files Browse the repository at this point in the history
If _WIN32_WINNT_WIN10 isn't defined, which it isn't for VS2013, use
deprected GetVersionEx() to detect Windows 10.

Issue eclipse-openj9/openj9#12260

Signed-off-by: Peter Shipton <[email protected]>
  • Loading branch information
pshipton committed Mar 23, 2021
1 parent f111a8b commit f842ddc
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions port/win32/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ WIN32_WINNT version constants :

if (NULL == PPG_si_osType) {
char *defaultTypeName = "Windows";
#if !defined(_WIN32_WINNT_WINBLUE) || (_WIN32_WINNT_MAXVER < _WIN32_WINNT_WINBLUE)
/* Windows 8 or earlier */
#if !defined(_WIN32_WINNT_WIN10) || (_WIN32_WINNT_MAXVER < _WIN32_WINNT_WIN10)
OSVERSIONINFOEX versionInfo;
#endif
#endif /* !defined(_WIN32_WINNT_WIN10) || (_WIN32_WINNT_MAXVER < _WIN32_WINNT_WIN10) */

PPG_si_osType = defaultTypeName; /* by default, use the "unrecognized version" string */
PPG_si_osTypeOnHeap = NULL;

Expand All @@ -323,6 +323,19 @@ WIN32_WINNT version constants :
PPG_si_osType = defaultTypeName;
isServerMajorVersion10 = TRUE;
} else
#else /* defined(_WIN32_WINNT_WIN10) && (_WIN32_WINNT_MAXVER >= _WIN32_WINNT_WIN10) */
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
/* GetVersionEx() is deprecated, but still needed when using older compilers. Suppress the warning. */
#pragma warning( suppress : 4996 )
if (GetVersionEx((OSVERSIONINFO *) &versionInfo)) {
if (10 <= versionInfo.dwMajorVersion) {
isServerMajorVersion10 = TRUE;
}
}
if (isServerMajorVersion10) {
PPG_si_osType = defaultTypeName;
/* Windows 10+ is detected, don't check the following cases. */
} else
#endif /* defined(_WIN32_WINNT_WIN10) && (_WIN32_WINNT_MAXVER >= _WIN32_WINNT_WIN10) */
if (IsWindows8Point1OrGreater()) {
PPG_si_osType = "Windows Server 2012 R2";
Expand All @@ -341,6 +354,28 @@ WIN32_WINNT version constants :
/* May need to check ReleaseId when next Windows version is released */
PPG_si_osType = "Windows 10";
} else
#else /* defined(_WIN32_WINNT_WIN10) && (_WIN32_WINNT_MAXVER >= _WIN32_WINNT_WIN10) */
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
/* GetVersionEx() is deprecated, but still needed when using older compilers. Suppress the warning. */
#pragma warning( suppress : 4996 )
if (GetVersionEx((OSVERSIONINFO *) &versionInfo)) {
if ((VER_PLATFORM_WIN32_NT == versionInfo.dwPlatformId) && (10 <= versionInfo.dwMajorVersion)) {
PPG_si_osType = NULL;
if (VER_NT_WORKSTATION == versionInfo.wProductType) {
if ((10 == versionInfo.dwMajorVersion) && (0 == versionInfo.dwMinorVersion)) {
PPG_si_osType = "Windows 10";
}
} else {
isServerMajorVersion10 = TRUE;
}
}
}
if ((PPG_si_osType != defaultTypeName) || isServerMajorVersion10) {
if (NULL == PPG_si_osType) {
PPG_si_osType = defaultTypeName;
}
/* Windows 10+ is detected, don't check the following cases. */
} else
#endif /* defined(_WIN32_WINNT_WIN10) && (_WIN32_WINNT_MAXVER >= _WIN32_WINNT_WIN10) */
if (IsWindows8Point1OrGreater()) {
PPG_si_osType = "Windows 8.1";
Expand Down

0 comments on commit f842ddc

Please sign in to comment.