< prev index next >

src/java.base/windows/native/libjava/java_props_md.c

Print this page
rev 52189 : 8211106: [windows] Update OS detection code to recognize Windows Server 2019
   1 /*
   2  * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 342         strcpy(*country , "NO");
 343         strcpy(*variant, "NY");
 344     }
 345 
 346     /* encoding */
 347     *encoding = getEncodingInternal(lcid);
 348     if (*encoding == NULL) {
 349         return FALSE;
 350     }
 351     return TRUE;
 352 }
 353 
 354 // GetVersionEx is deprecated; disable the warning until a replacement is found
 355 #pragma warning(disable : 4996)
 356 java_props_t *
 357 GetJavaProperties(JNIEnv* env)
 358 {
 359     static java_props_t sprops = {0};
 360     int majorVersion;
 361     int minorVersion;

 362 
 363     if (sprops.line_separator) {
 364         return &sprops;
 365     }
 366 
 367     /* AWT properties */
 368     sprops.awt_toolkit = "sun.awt.windows.WToolkit";
 369 
 370     /* tmp dir */
 371     {
 372         WCHAR tmpdir[MAX_PATH + 1];
 373         /* we might want to check that this succeed */
 374         GetTempPathW(MAX_PATH + 1, tmpdir);
 375         sprops.tmp_dir = _wcsdup(tmpdir);
 376     }
 377 
 378     /* Printing properties */
 379     sprops.printerJob = "sun.awt.windows.WPrinterJob";
 380 
 381     /* Java2D properties */
 382     sprops.graphics_env = "sun.awt.Win32GraphicsEnvironment";
 383 
 384     {    /* This is used only for debugging of font problems. */
 385         WCHAR *path = _wgetenv(L"JAVA2D_FONTPATH");
 386         sprops.font_dir = (path != NULL) ? _wcsdup(path) : NULL;
 387     }
 388 
 389     /* OS properties */
 390     {
 391         char buf[100];
 392         boolean is_workstation;
 393         boolean is_64bit;
 394         DWORD platformId;
 395         {
 396             OSVERSIONINFOEX ver;
 397             ver.dwOSVersionInfoSize = sizeof(ver);
 398             GetVersionEx((OSVERSIONINFO *) &ver);
 399             majorVersion = ver.dwMajorVersion;
 400             minorVersion = ver.dwMinorVersion;


 401             is_workstation = (ver.wProductType == VER_NT_WORKSTATION);
 402             platformId = ver.dwPlatformId;
 403             sprops.patch_level = _strdup(ver.szCSDVersion);
 404         }
 405 
 406         {
 407             SYSTEM_INFO si;
 408             ZeroMemory(&si, sizeof(SYSTEM_INFO));
 409             GetNativeSystemInfo(&si);
 410 
 411             is_64bit = (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64);
 412         }
 413         do {
 414             // Read the major and minor version number from kernel32.dll
 415             VS_FIXEDFILEINFO *file_info;
 416             WCHAR kernel32_path[MAX_PATH];
 417             DWORD version_size;
 418             LPTSTR version_info;
 419             UINT len, ret;
 420 


 431             if (version_size == 0) {
 432                 break;
 433             }
 434 
 435             version_info = (LPTSTR)malloc(version_size);
 436             if (version_info == NULL) {
 437                 break;
 438             }
 439 
 440             if (!GetFileVersionInfoW(kernel32_path, 0, version_size, version_info)) {
 441                 free(version_info);
 442                 break;
 443             }
 444 
 445             if (!VerQueryValueW(version_info, L"\\", (LPVOID*)&file_info, &len)) {
 446                 free(version_info);
 447                 break;
 448             }
 449             majorVersion = HIWORD(file_info->dwProductVersionMS);
 450             minorVersion = LOWORD(file_info->dwProductVersionMS);

 451             free(version_info);
 452         } while (0);
 453 
 454         /*
 455          * From msdn page on OSVERSIONINFOEX, current as of this
 456          * writing, decoding of dwMajorVersion and dwMinorVersion.
 457          *
 458          *  Operating system            dwMajorVersion  dwMinorVersion
 459          * ==================           ==============  ==============
 460          *
 461          * Windows 95                   4               0
 462          * Windows 98                   4               10
 463          * Windows ME                   4               90
 464          * Windows 3.51                 3               51
 465          * Windows NT 4.0               4               0
 466          * Windows 2000                 5               0
 467          * Windows XP 32 bit            5               1
 468          * Windows Server 2003 family   5               2
 469          * Windows XP 64 bit            5               2
 470          *       where ((&ver.wServicePackMinor) + 2) = 1
 471          *       and  si.wProcessorArchitecture = 9
 472          * Windows Vista family         6               0  (VER_NT_WORKSTATION)
 473          * Windows Server 2008          6               0  (!VER_NT_WORKSTATION)
 474          * Windows 7                    6               1  (VER_NT_WORKSTATION)
 475          * Windows Server 2008 R2       6               1  (!VER_NT_WORKSTATION)
 476          * Windows 8                    6               2  (VER_NT_WORKSTATION)
 477          * Windows Server 2012          6               2  (!VER_NT_WORKSTATION)
 478          * Windows Server 2012 R2       6               3  (!VER_NT_WORKSTATION)
 479          * Windows 10                   10              0  (VER_NT_WORKSTATION)
 480          * Windows Server 2016          10              0  (!VER_NT_WORKSTATION)


 481          *
 482          * This mapping will presumably be augmented as new Windows
 483          * versions are released.
 484          */
 485         switch (platformId) {
 486         case VER_PLATFORM_WIN32_WINDOWS:
 487            if (majorVersion == 4) {
 488                 switch (minorVersion) {
 489                 case  0: sprops.os_name = "Windows 95";           break;
 490                 case 10: sprops.os_name = "Windows 98";           break;
 491                 case 90: sprops.os_name = "Windows Me";           break;
 492                 default: sprops.os_name = "Windows 9X (unknown)"; break;
 493                 }
 494             } else {
 495                 sprops.os_name = "Windows 9X (unknown)";
 496             }
 497             break;
 498         case VER_PLATFORM_WIN32_NT:
 499             if (majorVersion <= 4) {
 500                 sprops.os_name = "Windows NT";


 534                     case  3: sprops.os_name = "Windows 8.1";          break;
 535                     default: sprops.os_name = "Windows NT (unknown)";
 536                     }
 537                 } else {
 538                     switch (minorVersion) {
 539                     case  0: sprops.os_name = "Windows Server 2008";    break;
 540                     case  1: sprops.os_name = "Windows Server 2008 R2"; break;
 541                     case  2: sprops.os_name = "Windows Server 2012";    break;
 542                     case  3: sprops.os_name = "Windows Server 2012 R2"; break;
 543                     default: sprops.os_name = "Windows NT (unknown)";
 544                     }
 545                 }
 546             } else if (majorVersion == 10) {
 547                 if (is_workstation) {
 548                     switch (minorVersion) {
 549                     case  0: sprops.os_name = "Windows 10";           break;
 550                     default: sprops.os_name = "Windows NT (unknown)";
 551                     }
 552                 } else {
 553                     switch (minorVersion) {
 554                     case  0: sprops.os_name = "Windows Server 2016";           break;







 555                     default: sprops.os_name = "Windows NT (unknown)";
 556                     }
 557                 }
 558             } else {
 559                 sprops.os_name = "Windows NT (unknown)";
 560             }
 561             break;
 562         default:
 563             sprops.os_name = "Windows (unknown)";
 564             break;
 565         }
 566         sprintf(buf, "%d.%d", majorVersion, minorVersion);
 567         sprops.os_version = _strdup(buf);
 568 #if _M_AMD64
 569         sprops.os_arch = "amd64";
 570 #elif _X86_
 571         sprops.os_arch = "x86";
 572 #else
 573         sprops.os_arch = "unknown";
 574 #endif


   1 /*
   2  * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 342         strcpy(*country , "NO");
 343         strcpy(*variant, "NY");
 344     }
 345 
 346     /* encoding */
 347     *encoding = getEncodingInternal(lcid);
 348     if (*encoding == NULL) {
 349         return FALSE;
 350     }
 351     return TRUE;
 352 }
 353 
 354 // GetVersionEx is deprecated; disable the warning until a replacement is found
 355 #pragma warning(disable : 4996)
 356 java_props_t *
 357 GetJavaProperties(JNIEnv* env)
 358 {
 359     static java_props_t sprops = {0};
 360     int majorVersion;
 361     int minorVersion;
 362     int buildNumber = 0;
 363 
 364     if (sprops.line_separator) {
 365         return &sprops;
 366     }
 367 
 368     /* AWT properties */
 369     sprops.awt_toolkit = "sun.awt.windows.WToolkit";
 370 
 371     /* tmp dir */
 372     {
 373         WCHAR tmpdir[MAX_PATH + 1];
 374         /* we might want to check that this succeed */
 375         GetTempPathW(MAX_PATH + 1, tmpdir);
 376         sprops.tmp_dir = _wcsdup(tmpdir);
 377     }
 378 
 379     /* Printing properties */
 380     sprops.printerJob = "sun.awt.windows.WPrinterJob";
 381 
 382     /* Java2D properties */
 383     sprops.graphics_env = "sun.awt.Win32GraphicsEnvironment";
 384 
 385     {    /* This is used only for debugging of font problems. */
 386         WCHAR *path = _wgetenv(L"JAVA2D_FONTPATH");
 387         sprops.font_dir = (path != NULL) ? _wcsdup(path) : NULL;
 388     }
 389 
 390     /* OS properties */
 391     {
 392         char buf[100];
 393         boolean is_workstation;
 394         boolean is_64bit;
 395         DWORD platformId;
 396         {
 397             OSVERSIONINFOEX ver;
 398             ver.dwOSVersionInfoSize = sizeof(ver);
 399             GetVersionEx((OSVERSIONINFO *) &ver);
 400             majorVersion = ver.dwMajorVersion;
 401             minorVersion = ver.dwMinorVersion;
 402             /* distinguish Windows Server 2016 and 2019 by build number */
 403             buildNumber = ver.dwBuildNumber;
 404             is_workstation = (ver.wProductType == VER_NT_WORKSTATION);
 405             platformId = ver.dwPlatformId;
 406             sprops.patch_level = _strdup(ver.szCSDVersion);
 407         }
 408 
 409         {
 410             SYSTEM_INFO si;
 411             ZeroMemory(&si, sizeof(SYSTEM_INFO));
 412             GetNativeSystemInfo(&si);
 413 
 414             is_64bit = (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64);
 415         }
 416         do {
 417             // Read the major and minor version number from kernel32.dll
 418             VS_FIXEDFILEINFO *file_info;
 419             WCHAR kernel32_path[MAX_PATH];
 420             DWORD version_size;
 421             LPTSTR version_info;
 422             UINT len, ret;
 423 


 434             if (version_size == 0) {
 435                 break;
 436             }
 437 
 438             version_info = (LPTSTR)malloc(version_size);
 439             if (version_info == NULL) {
 440                 break;
 441             }
 442 
 443             if (!GetFileVersionInfoW(kernel32_path, 0, version_size, version_info)) {
 444                 free(version_info);
 445                 break;
 446             }
 447 
 448             if (!VerQueryValueW(version_info, L"\\", (LPVOID*)&file_info, &len)) {
 449                 free(version_info);
 450                 break;
 451             }
 452             majorVersion = HIWORD(file_info->dwProductVersionMS);
 453             minorVersion = LOWORD(file_info->dwProductVersionMS);
 454             buildNumber  = HIWORD(file_info->dwProductVersionLS);
 455             free(version_info);
 456         } while (0);
 457 
 458         /*
 459          * From msdn page on OSVERSIONINFOEX, current as of this
 460          * writing, decoding of dwMajorVersion and dwMinorVersion.
 461          *
 462          *  Operating system            dwMajorVersion  dwMinorVersion
 463          * ==================           ==============  ==============
 464          *
 465          * Windows 95                   4               0
 466          * Windows 98                   4               10
 467          * Windows ME                   4               90
 468          * Windows 3.51                 3               51
 469          * Windows NT 4.0               4               0
 470          * Windows 2000                 5               0
 471          * Windows XP 32 bit            5               1
 472          * Windows Server 2003 family   5               2
 473          * Windows XP 64 bit            5               2
 474          *       where ((&ver.wServicePackMinor) + 2) = 1
 475          *       and  si.wProcessorArchitecture = 9
 476          * Windows Vista family         6               0  (VER_NT_WORKSTATION)
 477          * Windows Server 2008          6               0  (!VER_NT_WORKSTATION)
 478          * Windows 7                    6               1  (VER_NT_WORKSTATION)
 479          * Windows Server 2008 R2       6               1  (!VER_NT_WORKSTATION)
 480          * Windows 8                    6               2  (VER_NT_WORKSTATION)
 481          * Windows Server 2012          6               2  (!VER_NT_WORKSTATION)
 482          * Windows Server 2012 R2       6               3  (!VER_NT_WORKSTATION)
 483          * Windows 10                   10              0  (VER_NT_WORKSTATION)
 484          * Windows Server 2016          10              0  (!VER_NT_WORKSTATION)
 485          * Windows Server 2019          10              0  (!VER_NT_WORKSTATION)
 486          *       where (buildNumber > 17762)
 487          *
 488          * This mapping will presumably be augmented as new Windows
 489          * versions are released.
 490          */
 491         switch (platformId) {
 492         case VER_PLATFORM_WIN32_WINDOWS:
 493            if (majorVersion == 4) {
 494                 switch (minorVersion) {
 495                 case  0: sprops.os_name = "Windows 95";           break;
 496                 case 10: sprops.os_name = "Windows 98";           break;
 497                 case 90: sprops.os_name = "Windows Me";           break;
 498                 default: sprops.os_name = "Windows 9X (unknown)"; break;
 499                 }
 500             } else {
 501                 sprops.os_name = "Windows 9X (unknown)";
 502             }
 503             break;
 504         case VER_PLATFORM_WIN32_NT:
 505             if (majorVersion <= 4) {
 506                 sprops.os_name = "Windows NT";


 540                     case  3: sprops.os_name = "Windows 8.1";          break;
 541                     default: sprops.os_name = "Windows NT (unknown)";
 542                     }
 543                 } else {
 544                     switch (minorVersion) {
 545                     case  0: sprops.os_name = "Windows Server 2008";    break;
 546                     case  1: sprops.os_name = "Windows Server 2008 R2"; break;
 547                     case  2: sprops.os_name = "Windows Server 2012";    break;
 548                     case  3: sprops.os_name = "Windows Server 2012 R2"; break;
 549                     default: sprops.os_name = "Windows NT (unknown)";
 550                     }
 551                 }
 552             } else if (majorVersion == 10) {
 553                 if (is_workstation) {
 554                     switch (minorVersion) {
 555                     case  0: sprops.os_name = "Windows 10";           break;
 556                     default: sprops.os_name = "Windows NT (unknown)";
 557                     }
 558                 } else {
 559                     switch (minorVersion) {
 560                     case  0:
 561                         /* Windows server 2019 GA 10/2018 build number is 17763 */
 562                         if (buildNumber > 17762) {
 563                             sprops.os_name = "Windows Server 2019";
 564                         } else {
 565                             sprops.os_name = "Windows Server 2016";
 566                         }           
 567                         break;
 568                     default: sprops.os_name = "Windows NT (unknown)";
 569                     }
 570                 }
 571             } else {
 572                 sprops.os_name = "Windows NT (unknown)";
 573             }
 574             break;
 575         default:
 576             sprops.os_name = "Windows (unknown)";
 577             break;
 578         }
 579         sprintf(buf, "%d.%d", majorVersion, minorVersion);
 580         sprops.os_version = _strdup(buf);
 581 #if _M_AMD64
 582         sprops.os_arch = "amd64";
 583 #elif _X86_
 584         sprops.os_arch = "x86";
 585 #else
 586         sprops.os_arch = "unknown";
 587 #endif


< prev index next >