changeset 713:4f985ba72055

6714428: 'os.name' system property shows wrong value on 64-bit Windows XP Summary: update to detect the correct os.name for 64-bit XP Reviewed-by: darcy
author sherman
date Wed, 19 Nov 2008 14:29:12 -0800
parents 67718d2bd49c
children 098e456e860e
files src/windows/native/java/lang/java_props_md.c
diffstat 1 files changed, 44 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/native/java/lang/java_props_md.c	Fri Nov 14 17:22:10 2008 +0100
+++ b/src/windows/native/java/lang/java_props_md.c	Wed Nov 19 14:29:12 2008 -0800
@@ -38,6 +38,12 @@
 #define VER_PLATFORM_WIN32_WINDOWS 1
 #endif
 
+#ifndef PROCESSOR_ARCHITECTURE_AMD64
+#define PROCESSOR_ARCHITECTURE_AMD64 9
+#endif
+
+typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
+
 #define SHELL_KEY "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"
 
 /* Encodings for Windows language groups. According to
@@ -674,9 +680,22 @@
     {
         char buf[100];
         OSVERSIONINFOEX ver;
+        SYSTEM_INFO si;
+        PGNSI pGNSI;
+
         ver.dwOSVersionInfoSize = sizeof(ver);
         GetVersionEx((OSVERSIONINFO *) &ver);
 
+        ZeroMemory(&si, sizeof(SYSTEM_INFO));
+        // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise.
+        pGNSI = (PGNSI) GetProcAddress(
+                GetModuleHandle(TEXT("kernel32.dll")),
+                "GetNativeSystemInfo");
+        if(NULL != pGNSI)
+            pGNSI(&si);
+        else
+            GetSystemInfo(&si);
+
         /*
          * From msdn page on OSVERSIONINFOEX, current as of this
          * writing, decoding of dwMajorVersion and dwMinorVersion.
@@ -690,9 +709,14 @@
          * Windows 3.51                 3               51
          * Windows NT 4.0               4               0
          * Windows 2000                 5               0
-         * Windows XP                   5               1
+         * Windows XP 32 bit            5               1
          * Windows Server 2003 family   5               2
+         * Windows XP 64 bit            5               2
+         *       where ((&ver.wServicePackMinor) + 2) = 1
+         *       and  si.wProcessorArchitecture = 9
          * Windows Vista family         6               0
+         * Windows 2008                 6               0
+         *       where ((&ver.wServicePackMinor) + 2) = 1
          *
          * This mapping will presumably be augmented as new Windows
          * versions are released.
@@ -720,7 +744,25 @@
                 switch (ver.dwMinorVersion) {
                 case  0: sprops.os_name = "Windows 2000";         break;
                 case  1: sprops.os_name = "Windows XP";           break;
-                case  2: sprops.os_name = "Windows 2003";         break;
+                case  2:
+                   /*
+                    * From MSDN OSVERSIONINFOEX and SYSTEM_INFO documentation:
+                    *
+                    * "Because the version numbers for Windows Server 2003
+                    * and Windows XP 6u4 bit are identical, you must also test
+                    * whether the wProductType member is VER_NT_WORKSTATION.
+                    * and si.wProcessorArchitecture is
+                    * PROCESSOR_ARCHITECTURE_AMD64 (which is 9)
+                    * If it is, the operating system is Windows XP 64 bit;
+                    * otherwise, it is Windows Server 2003."
+                    */
+                    if(ver.wProductType == VER_NT_WORKSTATION &&
+                       si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) {
+                        sprops.os_name = "Windows XP"; /* 64 bit */
+                    } else {
+                        sprops.os_name = "Windows 2003";
+                    }
+                    break;
                 default: sprops.os_name = "Windows NT (unknown)"; break;
                 }
             } else if (ver.dwMajorVersion == 6) {