8066504: GetVersionEx in java.base/windows/native/libjava/java_props_md.c might not get correct Windows version 0
System property os.name and os.version should report the version of kernel32.dll Reviewed-by: alanb, igerasim
This commit is contained in:
parent
9966dd8518
commit
c1108923f4
@ -161,7 +161,7 @@ $(eval $(call SetupNativeCompilation,BUILD_LIBJAVA, \
|
|||||||
-export:getLastErrorString \
|
-export:getLastErrorString \
|
||||||
jvm.lib $(BUILD_LIBFDLIBM) $(WIN_VERIFY_LIB) \
|
jvm.lib $(BUILD_LIBFDLIBM) $(WIN_VERIFY_LIB) \
|
||||||
shell32.lib delayimp.lib -DELAYLOAD:shell32.dll \
|
shell32.lib delayimp.lib -DELAYLOAD:shell32.dll \
|
||||||
advapi32.lib, \
|
advapi32.lib version.lib, \
|
||||||
VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \
|
VERSIONINFO_RESOURCE := $(GLOBAL_VERSION_INFO_RESOURCE), \
|
||||||
RC_FLAGS := $(RC_FLAGS) \
|
RC_FLAGS := $(RC_FLAGS) \
|
||||||
-D "JDK_FNAME=java.dll" \
|
-D "JDK_FNAME=java.dll" \
|
||||||
|
@ -52,6 +52,8 @@
|
|||||||
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
|
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
|
||||||
<!-- Windows 8.1 -->
|
<!-- Windows 8.1 -->
|
||||||
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
|
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
|
||||||
|
<!-- Windows 10 -->
|
||||||
|
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
|
||||||
</application>
|
</application>
|
||||||
</compatibility>
|
</compatibility>
|
||||||
|
|
||||||
|
@ -351,8 +351,8 @@ java_props_t *
|
|||||||
GetJavaProperties(JNIEnv* env)
|
GetJavaProperties(JNIEnv* env)
|
||||||
{
|
{
|
||||||
static java_props_t sprops = {0};
|
static java_props_t sprops = {0};
|
||||||
|
int majorVersion;
|
||||||
OSVERSIONINFOEX ver;
|
int minorVersion;
|
||||||
|
|
||||||
if (sprops.line_separator) {
|
if (sprops.line_separator) {
|
||||||
return &sprops;
|
return &sprops;
|
||||||
@ -383,21 +383,65 @@ GetJavaProperties(JNIEnv* env)
|
|||||||
/* OS properties */
|
/* OS properties */
|
||||||
{
|
{
|
||||||
char buf[100];
|
char buf[100];
|
||||||
SYSTEM_INFO si;
|
boolean is_workstation;
|
||||||
PGNSI pGNSI;
|
boolean is_64bit;
|
||||||
|
DWORD platformId;
|
||||||
|
{
|
||||||
|
OSVERSIONINFOEX ver;
|
||||||
ver.dwOSVersionInfoSize = sizeof(ver);
|
ver.dwOSVersionInfoSize = sizeof(ver);
|
||||||
GetVersionEx((OSVERSIONINFO *) &ver);
|
GetVersionEx((OSVERSIONINFO *) &ver);
|
||||||
|
majorVersion = ver.dwMajorVersion;
|
||||||
|
minorVersion = ver.dwMinorVersion;
|
||||||
|
is_workstation = (ver.wProductType == VER_NT_WORKSTATION);
|
||||||
|
platformId = ver.dwPlatformId;
|
||||||
|
sprops.patch_level = _strdup(ver.szCSDVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
SYSTEM_INFO si;
|
||||||
ZeroMemory(&si, sizeof(SYSTEM_INFO));
|
ZeroMemory(&si, sizeof(SYSTEM_INFO));
|
||||||
// Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.
|
GetNativeSystemInfo(&si);
|
||||||
pGNSI = (PGNSI) GetProcAddress(
|
|
||||||
GetModuleHandle(TEXT("kernel32.dll")),
|
is_64bit = (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64);
|
||||||
"GetNativeSystemInfo");
|
}
|
||||||
if(NULL != pGNSI)
|
do {
|
||||||
pGNSI(&si);
|
// Read the major and minor version number from kernel32.dll
|
||||||
else
|
VS_FIXEDFILEINFO *file_info;
|
||||||
GetSystemInfo(&si);
|
WCHAR kernel32_path[MAX_PATH];
|
||||||
|
UINT len, ret;
|
||||||
|
|
||||||
|
// Get the full path to \Windows\System32\kernel32.dll and use that for
|
||||||
|
// determining what version of Windows we're running on.
|
||||||
|
len = MAX_PATH - (UINT)strlen("\\kernel32.dll") - 1;
|
||||||
|
ret = GetSystemDirectoryW(kernel32_path, len);
|
||||||
|
if (ret == 0 || ret > len) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
wcsncat(kernel32_path, L"\\kernel32.dll", MAX_PATH - ret);
|
||||||
|
|
||||||
|
DWORD version_size = GetFileVersionInfoSizeW(kernel32_path, NULL);
|
||||||
|
if (version_size == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
LPTSTR version_info = (LPTSTR)malloc(version_size);
|
||||||
|
if (version_info == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!GetFileVersionInfoW(kernel32_path, 0, version_size, version_info)) {
|
||||||
|
free(version_info);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!VerQueryValueW(version_info, L"\\", (LPVOID*)&file_info, &len)) {
|
||||||
|
free(version_info);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
majorVersion = HIWORD(file_info->dwProductVersionMS);
|
||||||
|
minorVersion = LOWORD(file_info->dwProductVersionMS);
|
||||||
|
free(version_info);
|
||||||
|
} while (0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* From msdn page on OSVERSIONINFOEX, current as of this
|
* From msdn page on OSVERSIONINFOEX, current as of this
|
||||||
@ -423,17 +467,15 @@ GetJavaProperties(JNIEnv* env)
|
|||||||
* Windows Server 2008 R2 6 1 (!VER_NT_WORKSTATION)
|
* Windows Server 2008 R2 6 1 (!VER_NT_WORKSTATION)
|
||||||
* Windows 8 6 2 (VER_NT_WORKSTATION)
|
* Windows 8 6 2 (VER_NT_WORKSTATION)
|
||||||
* Windows Server 2012 6 2 (!VER_NT_WORKSTATION)
|
* Windows Server 2012 6 2 (!VER_NT_WORKSTATION)
|
||||||
|
* Windows 10 10 0 (VER_NT_WORKSTATION)
|
||||||
*
|
*
|
||||||
* This mapping will presumably be augmented as new Windows
|
* This mapping will presumably be augmented as new Windows
|
||||||
* versions are released.
|
* versions are released.
|
||||||
*/
|
*/
|
||||||
switch (ver.dwPlatformId) {
|
switch (platformId) {
|
||||||
case VER_PLATFORM_WIN32s:
|
|
||||||
sprops.os_name = "Windows 3.1";
|
|
||||||
break;
|
|
||||||
case VER_PLATFORM_WIN32_WINDOWS:
|
case VER_PLATFORM_WIN32_WINDOWS:
|
||||||
if (ver.dwMajorVersion == 4) {
|
if (majorVersion == 4) {
|
||||||
switch (ver.dwMinorVersion) {
|
switch (minorVersion) {
|
||||||
case 0: sprops.os_name = "Windows 95"; break;
|
case 0: sprops.os_name = "Windows 95"; break;
|
||||||
case 10: sprops.os_name = "Windows 98"; break;
|
case 10: sprops.os_name = "Windows 98"; break;
|
||||||
case 90: sprops.os_name = "Windows Me"; break;
|
case 90: sprops.os_name = "Windows Me"; break;
|
||||||
@ -444,10 +486,10 @@ GetJavaProperties(JNIEnv* env)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case VER_PLATFORM_WIN32_NT:
|
case VER_PLATFORM_WIN32_NT:
|
||||||
if (ver.dwMajorVersion <= 4) {
|
if (majorVersion <= 4) {
|
||||||
sprops.os_name = "Windows NT";
|
sprops.os_name = "Windows NT";
|
||||||
} else if (ver.dwMajorVersion == 5) {
|
} else if (majorVersion == 5) {
|
||||||
switch (ver.dwMinorVersion) {
|
switch (minorVersion) {
|
||||||
case 0: sprops.os_name = "Windows 2000"; break;
|
case 0: sprops.os_name = "Windows 2000"; break;
|
||||||
case 1: sprops.os_name = "Windows XP"; break;
|
case 1: sprops.os_name = "Windows XP"; break;
|
||||||
case 2:
|
case 2:
|
||||||
@ -462,8 +504,7 @@ GetJavaProperties(JNIEnv* env)
|
|||||||
* If it is, the operating system is Windows XP 64 bit;
|
* If it is, the operating system is Windows XP 64 bit;
|
||||||
* otherwise, it is Windows Server 2003."
|
* otherwise, it is Windows Server 2003."
|
||||||
*/
|
*/
|
||||||
if(ver.wProductType == VER_NT_WORKSTATION &&
|
if (is_workstation && is_64bit) {
|
||||||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
|
|
||||||
sprops.os_name = "Windows XP"; /* 64 bit */
|
sprops.os_name = "Windows XP"; /* 64 bit */
|
||||||
} else {
|
} else {
|
||||||
sprops.os_name = "Windows 2003";
|
sprops.os_name = "Windows 2003";
|
||||||
@ -471,12 +512,12 @@ GetJavaProperties(JNIEnv* env)
|
|||||||
break;
|
break;
|
||||||
default: sprops.os_name = "Windows NT (unknown)"; break;
|
default: sprops.os_name = "Windows NT (unknown)"; break;
|
||||||
}
|
}
|
||||||
} else if (ver.dwMajorVersion == 6) {
|
} else if (majorVersion == 6) {
|
||||||
/*
|
/*
|
||||||
* See table in MSDN OSVERSIONINFOEX documentation.
|
* See table in MSDN OSVERSIONINFOEX documentation.
|
||||||
*/
|
*/
|
||||||
if (ver.wProductType == VER_NT_WORKSTATION) {
|
if (is_workstation) {
|
||||||
switch (ver.dwMinorVersion) {
|
switch (minorVersion) {
|
||||||
case 0: sprops.os_name = "Windows Vista"; break;
|
case 0: sprops.os_name = "Windows Vista"; break;
|
||||||
case 1: sprops.os_name = "Windows 7"; break;
|
case 1: sprops.os_name = "Windows 7"; break;
|
||||||
case 2: sprops.os_name = "Windows 8"; break;
|
case 2: sprops.os_name = "Windows 8"; break;
|
||||||
@ -484,7 +525,7 @@ GetJavaProperties(JNIEnv* env)
|
|||||||
default: sprops.os_name = "Windows NT (unknown)";
|
default: sprops.os_name = "Windows NT (unknown)";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (ver.dwMinorVersion) {
|
switch (minorVersion) {
|
||||||
case 0: sprops.os_name = "Windows Server 2008"; break;
|
case 0: sprops.os_name = "Windows Server 2008"; break;
|
||||||
case 1: sprops.os_name = "Windows Server 2008 R2"; break;
|
case 1: sprops.os_name = "Windows Server 2008 R2"; break;
|
||||||
case 2: sprops.os_name = "Windows Server 2012"; break;
|
case 2: sprops.os_name = "Windows Server 2012"; break;
|
||||||
@ -492,6 +533,17 @@ GetJavaProperties(JNIEnv* env)
|
|||||||
default: sprops.os_name = "Windows NT (unknown)";
|
default: sprops.os_name = "Windows NT (unknown)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (majorVersion == 10) {
|
||||||
|
if (is_workstation) {
|
||||||
|
switch (minorVersion) {
|
||||||
|
case 0: sprops.os_name = "Windows 10"; break;
|
||||||
|
default: sprops.os_name = "Windows NT (unknown)";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (minorVersion) {
|
||||||
|
default: sprops.os_name = "Windows NT (unknown)";
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sprops.os_name = "Windows NT (unknown)";
|
sprops.os_name = "Windows NT (unknown)";
|
||||||
}
|
}
|
||||||
@ -500,7 +552,7 @@ GetJavaProperties(JNIEnv* env)
|
|||||||
sprops.os_name = "Windows (unknown)";
|
sprops.os_name = "Windows (unknown)";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sprintf(buf, "%d.%d", ver.dwMajorVersion, ver.dwMinorVersion);
|
sprintf(buf, "%d.%d", majorVersion, minorVersion);
|
||||||
sprops.os_version = _strdup(buf);
|
sprops.os_version = _strdup(buf);
|
||||||
#if _M_IA64
|
#if _M_IA64
|
||||||
sprops.os_arch = "ia64";
|
sprops.os_arch = "ia64";
|
||||||
@ -511,9 +563,6 @@ GetJavaProperties(JNIEnv* env)
|
|||||||
#else
|
#else
|
||||||
sprops.os_arch = "unknown";
|
sprops.os_arch = "unknown";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sprops.patch_level = _strdup(ver.szCSDVersion);
|
|
||||||
|
|
||||||
sprops.desktop = "windows";
|
sprops.desktop = "windows";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -624,7 +673,7 @@ GetJavaProperties(JNIEnv* env)
|
|||||||
&display_encoding);
|
&display_encoding);
|
||||||
|
|
||||||
sprops.sun_jnu_encoding = getEncodingInternal(systemDefaultLCID);
|
sprops.sun_jnu_encoding = getEncodingInternal(systemDefaultLCID);
|
||||||
if (LANGIDFROMLCID(userDefaultLCID) == 0x0c04 && ver.dwMajorVersion == 6) {
|
if (LANGIDFROMLCID(userDefaultLCID) == 0x0c04 && majorVersion == 6) {
|
||||||
// MS claims "Vista has built-in support for HKSCS-2004.
|
// MS claims "Vista has built-in support for HKSCS-2004.
|
||||||
// All of the HKSCS-2004 characters have Unicode 4.1.
|
// All of the HKSCS-2004 characters have Unicode 4.1.
|
||||||
// PUA code point assignments". But what it really means
|
// PUA code point assignments". But what it really means
|
||||||
|
Loading…
x
Reference in New Issue
Block a user