< prev index next >

src/windows/native/java/lang/java_props_md.c

Print this page
rev 13466 : 8211106: [windows] Update OS detection code to recognize Windows Server 2019
Reviewed-by: alanb, clanger, bobv
   1 /*
   2  * Copyright (c) 1998, 2016, 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


 334     } else if (strcmp(*language, "nn") == 0) {
 335         strcpy(*language, "no");
 336         strcpy(*country , "NO");
 337         strcpy(*variant, "NY");
 338     }
 339 
 340     /* encoding */
 341     *encoding = getEncodingInternal(lcid);
 342     if (*encoding == NULL) {
 343         return FALSE;
 344     }
 345     return TRUE;
 346 }
 347 
 348 java_props_t *
 349 GetJavaProperties(JNIEnv* env)
 350 {
 351     static java_props_t sprops = {0};
 352     int majorVersion;
 353     int minorVersion;

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


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


 423             if (version_size == 0) {
 424                 break;
 425             }
 426 
 427             version_info = (LPTSTR)malloc(version_size);
 428             if (version_info == NULL) {
 429                 break;
 430             }
 431 
 432             if (!GetFileVersionInfoW(kernel32_path, 0, version_size, version_info)) {
 433                 free(version_info);
 434                 break;
 435             }
 436 
 437             if (!VerQueryValueW(version_info, L"\\", (LPVOID*)&file_info, &len)) {
 438                 free(version_info);
 439                 break;
 440             }
 441             majorVersion = HIWORD(file_info->dwProductVersionMS);
 442             minorVersion = LOWORD(file_info->dwProductVersionMS);

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


 473          *
 474          * This mapping will presumably be augmented as new Windows
 475          * versions are released.
 476          */
 477         switch (platformId) {
 478         case VER_PLATFORM_WIN32_WINDOWS:
 479            if (majorVersion == 4) {
 480                 switch (minorVersion) {
 481                 case  0: sprops.os_name = "Windows 95";           break;
 482                 case 10: sprops.os_name = "Windows 98";           break;
 483                 case 90: sprops.os_name = "Windows Me";           break;
 484                 default: sprops.os_name = "Windows 9X (unknown)"; break;
 485                 }
 486             } else {
 487                 sprops.os_name = "Windows 9X (unknown)";
 488             }
 489             break;
 490         case VER_PLATFORM_WIN32_NT:
 491             if (majorVersion <= 4) {
 492                 sprops.os_name = "Windows NT";


 526                     case  3: sprops.os_name = "Windows 8.1";          break;
 527                     default: sprops.os_name = "Windows NT (unknown)";
 528                     }
 529                 } else {
 530                     switch (minorVersion) {
 531                     case  0: sprops.os_name = "Windows Server 2008";    break;
 532                     case  1: sprops.os_name = "Windows Server 2008 R2"; break;
 533                     case  2: sprops.os_name = "Windows Server 2012";    break;
 534                     case  3: sprops.os_name = "Windows Server 2012 R2"; break;
 535                     default: sprops.os_name = "Windows NT (unknown)";
 536                     }
 537                 }
 538             } else if (majorVersion == 10) {
 539                 if (is_workstation) {
 540                     switch (minorVersion) {
 541                     case  0: sprops.os_name = "Windows 10";           break;
 542                     default: sprops.os_name = "Windows NT (unknown)";
 543                     }
 544                 } else {
 545                     switch (minorVersion) {
 546                     case  0: sprops.os_name = "Windows Server 2016";           break;







 547                     default: sprops.os_name = "Windows NT (unknown)";
 548                     }
 549                 }
 550             } else {
 551                 sprops.os_name = "Windows NT (unknown)";
 552             }
 553             break;
 554         default:
 555             sprops.os_name = "Windows (unknown)";
 556             break;
 557         }
 558         sprintf(buf, "%d.%d", majorVersion, minorVersion);
 559         sprops.os_version = _strdup(buf);
 560 #if _M_IA64
 561         sprops.os_arch = "ia64";
 562 #elif _M_AMD64
 563         sprops.os_arch = "amd64";
 564 #elif _X86_
 565         sprops.os_arch = "x86";
 566 #else


   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


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


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


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


< prev index next >