jdk/src/windows/bin/java_md.c
author herrick
Fri, 12 Jun 2009 14:56:32 -0400
changeset 3111 fefdeafb7ab9
parent 1776 33e9405ab91b
child 3834 16342ebd576d
permissions -rw-r--r--
6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7 6845973: Update JDK7 with deployment changes in 6u13, 6u14 4802695: Support 64-bit Java Plug-in and Java webstart on Windows/Linux on AMD64 6825019: DownloadManager should not be loaded and referenced for full JRE 6738770: REGRESSION:JSException throws when use LiveConnect javascript facility 6772884: plugin2 : java.lang.OutOfMemoryError or crash 6707535: Crossing domain hole affecting multiple sites/domains using plug-in 6728071: Non-verification of Update files may allow unintended updates 6704154: Code loaded from local filesystem should not get access to localhost 6727081: Web Start security restrictions bypass using special extension jnlp 6727079: Java Web Start Socket() restriction bypass 6727071: Cache location/user name information disclosure in SingleInstanceImpl. 6716217: AppletClassLoader adds permissions based on codebase regardless of CS 6694892: Java Webstart inclusion via system properties override [CVE-2008-2086] 6704074: localhost socket access due to cache location exposed 6703909: Java webstart arbitrary file creation using nativelib 6665315: browser crashes when deployment.properties has more slashes ( / ) 6660121: Encoding values in JNLP files can cause buffer overflow 6606110: URLConnection.setProxiedHost for resources that are loaded via proxy 6581221: SSV(VISTA): Redirection FAILS to work if user does a downgrade install 6609756: Buffer Overflow in Java ActiveX component 6608712: Bypassing the same origin policy in Java with crafted names 6534630: "gnumake clobber" doesn't 6849953: JDK7 - replacement of bufferoverflowU.lib on amd64 breaks build 6849029: Need some JDK7 merge clean-up after comments on the webrev 6847582: Build problem on JDK7 with isSecureProperty in merge 6827935: JDK 7 deployment merging - problem in Compiler-msvm.gmk 6823215: latest merge fixes from 6u12 -> JDK7 6816153: further mergers for JDK7 deployment integration 6807074: Fix Java Kernel and JQS in initial JDK7 builds Summary: Initial changeset for implementing 6uX Deployment Features into JDK7 Reviewed-by: dgu, billyh
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 39
diff changeset
     2
 * Copyright 1997-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <windows.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <io.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <process.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include <stdarg.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <sys/stat.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <wtypes.h>
39
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
    36
#include <commctrl.h>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "java.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "version_comp.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#define JVM_DLL "jvm.dll"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#define JAVA_DLL "java.dll"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Prototypes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
static jboolean GetPublicJREHome(char *path, jint pathsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                           char *jvmpath, jint jvmpathsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
static jboolean GetJREPath(char *path, jint pathsize);
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
    52
static void EnsureJreInstallation(const char *jrepath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
static jboolean _isjavaw = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
IsJavaw()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    return _isjavaw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Returns the arch path, to get the current arch use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * macro GetArch, nbits here is ignored for now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
GetArchPath(int nbits)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#ifdef _M_AMD64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    return "amd64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
#elif defined(_M_IA64)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    return "ia64";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    return "i386";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
CreateExecutionEnvironment(int *_argc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                           char ***_argv,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                           char jrepath[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                           jint so_jrepath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                           char jvmpath[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                           jint so_jvmpath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                           char **original_argv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    char * jvmtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    char** pargv = *_argv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    int running = CURRENT_DATA_MODEL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    int wanted = running;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    for (i = 0; i < *_argc ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (JLI_StrCmp(pargv[i], "-J-d64") == 0 || JLI_StrCmp(pargv[i], "-d64") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            wanted = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (JLI_StrCmp(pargv[i], "-J-d32") == 0 || JLI_StrCmp(pargv[i], "-d32") == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            wanted = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    if (running != wanted) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   108
        JLI_ReportErrorMessage(JRE_ERROR2, wanted);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   112
    /* Do this before we read jvm.cfg */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   113
    EnsureJreInstallation(jrepath);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   114
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /* Find out where the JRE is that we will be using. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    if (!GetJREPath(jrepath, so_jrepath)) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   117
        JLI_ReportErrorMessage(JRE_ERROR1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        exit(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /* Find the specified JVM type */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    if (ReadKnownVMs(jrepath, (char*)GetArch(), JNI_FALSE) < 1) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   123
        JLI_ReportErrorMessage(CFG_ERROR7);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    jvmtype = CheckJvmType(_argc, _argv, JNI_FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    jvmpath[0] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   130
        JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        exit(4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /* If we got here, jvmpath has been correctly initialized. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   137
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   138
static jboolean
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   139
LoadMSVCRT()
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   140
{
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   141
    // Only do this once
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   142
    static int loaded = 0;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   143
    char crtpath[MAXPATHLEN];
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   144
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   145
    if (!loaded) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   146
        /*
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   147
         * The Microsoft C Runtime Library needs to be loaded first.  A copy is
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   148
         * assumed to be present in the "JRE path" directory.  If it is not found
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   149
         * there (or "JRE path" fails to resolve), skip the explicit load and let
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   150
         * nature take its course, which is likely to be a failure to execute.
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   151
         */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   152
#ifdef _MSC_VER
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   153
#if _MSC_VER < 1400
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   154
#define CRT_DLL "msvcr71.dll"
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   155
#endif
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   156
#ifdef CRT_DLL
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   157
        if (GetJREPath(crtpath, MAXPATHLEN)) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   158
            (void)JLI_StrCat(crtpath, "\\bin\\" CRT_DLL);   /* Add crt dll */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   159
            JLI_TraceLauncher("CRT path is %s\n", crtpath);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   160
            if (_access(crtpath, 0) == 0) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   161
                if (LoadLibrary(crtpath) == 0) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   162
                    JLI_ReportErrorMessage(DLL_ERROR4, crtpath);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   163
                    return JNI_FALSE;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   164
                }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   165
            }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   166
        }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   167
#endif /* CRT_DLL */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   168
#endif /* _MSC_VER */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   169
        loaded = 1;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   170
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   171
    return JNI_TRUE;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   172
}
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   173
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   174
/*
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   175
 * The preJVMStart is a function in the jkernel.dll, which
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   176
 * performs the final step of synthesizing back the decomposed
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   177
 * modules  (partial install) to the full JRE. Any tool which
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   178
 * uses the  JRE must peform this step to ensure the complete synthesis.
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   179
 * The EnsureJreInstallation function calls preJVMStart based on
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   180
 * the conditions outlined below, noting that the operation
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   181
 * will fail silently if any of conditions are not met.
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   182
 * NOTE: this call must be made before jvm.dll is loaded, or jvm.cfg
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   183
 * is read, since jvm.cfg will be modified by the preJVMStart.
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   184
 * 1. Are we on a supported platform.
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   185
 * 2. Find the location of the JRE or the Kernel JRE.
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   186
 * 3. check existence of JREHOME/lib/bundles
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   187
 * 4. check jkernel.dll and invoke the entry-point
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   188
 */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   189
typedef VOID (WINAPI *PREJVMSTART)();
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   190
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   191
static void
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   192
EnsureJreInstallation(const char* jrepath)
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   193
{
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   194
    HINSTANCE handle;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   195
    char tmpbuf[MAXPATHLEN];
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   196
    PREJVMSTART PreJVMStart;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   197
    struct stat s;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   198
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   199
    /* 32 bit windows only please */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   200
    if (strcmp(GetArch(), "i386") != 0 ) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   201
        return;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   202
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   203
    /* Does our bundle directory exist ? */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   204
    strcpy(tmpbuf, jrepath);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   205
    strcat(tmpbuf, "\\lib\\bundles");
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   206
    if (stat(tmpbuf, &s) != 0) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   207
        return;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   208
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   209
    /* Does our jkernel dll exist ? */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   210
    strcpy(tmpbuf, jrepath);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   211
    strcat(tmpbuf, "\\bin\\jkernel.dll");
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   212
    if (stat(tmpbuf, &s) != 0) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   213
        return;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   214
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   215
    /* The Microsoft C Runtime Library needs to be loaded first. */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   216
    if (!LoadMSVCRT()) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   217
        return;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   218
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   219
    /* Load the jkernel.dll */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   220
    if ((handle = LoadLibrary(tmpbuf)) == 0) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   221
        return;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   222
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   223
    /* Get the function address */
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   224
    PreJVMStart = (PREJVMSTART)GetProcAddress(handle, "preJVMStart");
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   225
    if (PreJVMStart == NULL) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   226
        FreeLibrary(handle);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   227
        return;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   228
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   229
    PreJVMStart();
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   230
    FreeLibrary(handle);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   231
    return;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   232
}
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   233
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 * Find path to JRE based on .exe's location or registry settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
GetJREPath(char *path, jint pathsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    char javadll[MAXPATHLEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    struct stat s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    if (GetApplicationHome(path, pathsize)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        /* Is JRE co-located with the application? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        sprintf(javadll, "%s\\bin\\" JAVA_DLL, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        if (stat(javadll, &s) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            goto found;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        /* Does this app ship a private JRE in <apphome>\jre directory? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        sprintf(javadll, "%s\\jre\\bin\\" JAVA_DLL, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (stat(javadll, &s) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            JLI_StrCat(path, "\\jre");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            goto found;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /* Look for a public JRE on this machine. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    if (GetPublicJREHome(path, pathsize)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        goto found;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   263
    JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 found:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    JLI_TraceLauncher("JRE path is %s\n", path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * Given a JRE location and a JVM type, construct what the name the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 * JVM shared library will be.  Return true, if such a library
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 * exists, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
GetJVMPath(const char *jrepath, const char *jvmtype,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
           char *jvmpath, jint jvmpathsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    struct stat s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    if (JLI_StrChr(jvmtype, '/') || JLI_StrChr(jvmtype, '\\')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        sprintf(jvmpath, "%s\\" JVM_DLL, jvmtype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        sprintf(jvmpath, "%s\\bin\\%s\\" JVM_DLL, jrepath, jvmtype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    if (stat(jvmpath, &s) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
 * Load a jvm from "jvmpath" and initialize the invocation functions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    HINSTANCE handle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    JLI_TraceLauncher("JVM path is %s\n", jvmpath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * The Microsoft C Runtime Library needs to be loaded first.  A copy is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * assumed to be present in the "JRE path" directory.  If it is not found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * there (or "JRE path" fails to resolve), skip the explicit load and let
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * nature take its course, which is likely to be a failure to execute.
1776
33e9405ab91b 6754862: jdk/src/windows/bin/java_md.c: hardcoded reference to msvcr71.dll
tbell
parents: 1331
diff changeset
   308
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 1776
diff changeset
   310
    LoadMSVCRT();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /* Load the Java VM DLL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    if ((handle = LoadLibrary(jvmpath)) == 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   314
        JLI_ReportErrorMessage(DLL_ERROR4, (char *)jvmpath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /* Now get the function addresses */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    ifn->CreateJavaVM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        (void *)GetProcAddress(handle, "JNI_CreateJavaVM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    ifn->GetDefaultJavaVMInitArgs =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        (void *)GetProcAddress(handle, "JNI_GetDefaultJavaVMInitArgs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    if (ifn->CreateJavaVM == 0 || ifn->GetDefaultJavaVMInitArgs == 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   324
        JLI_ReportErrorMessage(JNI_ERROR1, (char *)jvmpath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
 * If app is "c:\foo\bin\javac", then put "c:\foo" into buf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
GetApplicationHome(char *buf, jint bufsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    char *cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    GetModuleFileName(0, buf, bufsize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    *JLI_StrRChr(buf, '\\') = '\0'; /* remove .exe file name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    if ((cp = JLI_StrRChr(buf, '\\')) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        /* This happens if the application is in a drive root, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
         * there is no bin directory. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        buf[0] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    *cp = '\0';  /* remove the bin\ part */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
 * Helpers to look in the registry for a public JRE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    /* Same for 1.5.0, 1.5.1, 1.5.2 etc. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
#define JRE_KEY     "Software\\JavaSoft\\Java Runtime Environment"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
GetStringFromRegistry(HKEY key, const char *name, char *buf, jint bufsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    DWORD type, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    if (RegQueryValueEx(key, name, 0, &type, 0, &size) == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        && type == REG_SZ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        && (size < (unsigned int)bufsize)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (RegQueryValueEx(key, name, 0, 0, buf, &size) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
GetPublicJREHome(char *buf, jint bufsize)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    HKEY key, subkey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    char version[MAXPATHLEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Note: There is a very similar implementation of the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * registry reading code in the Windows java control panel (javacp.cpl).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * If there are bugs here, a similar bug probably exists there.  Hence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * changes here require inspection there.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /* Find the current version of the JRE */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, JRE_KEY, 0, KEY_READ, &key) != 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   386
        JLI_ReportErrorMessage(REG_ERROR1, JRE_KEY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    if (!GetStringFromRegistry(key, "CurrentVersion",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                               version, sizeof(version))) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   392
        JLI_ReportErrorMessage(REG_ERROR2, JRE_KEY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    if (JLI_StrCmp(version, GetDotVersion()) != 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   398
        JLI_ReportErrorMessage(REG_ERROR3, JRE_KEY, version, GetDotVersion()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /* Find directory where the current version is installed. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    if (RegOpenKeyEx(key, version, 0, KEY_READ, &subkey) != 0) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   406
        JLI_ReportErrorMessage(REG_ERROR1, JRE_KEY, version);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    if (!GetStringFromRegistry(subkey, "JavaHome", buf, bufsize)) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   412
        JLI_ReportErrorMessage(REG_ERROR4, JRE_KEY, version);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        RegCloseKey(subkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    if (JLI_IsTraceLauncher()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        char micro[MAXPATHLEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (!GetStringFromRegistry(subkey, "MicroVersion", micro,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                                   sizeof(micro))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            printf("Warning: Can't read MicroVersion\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            micro[0] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        printf("Version major.minor.micro = %s.%s\n", version, micro);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    RegCloseKey(subkey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
 * Support for doing cheap, accurate interval timing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
static jboolean counterAvailable = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
static jboolean counterInitialized = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
static LARGE_INTEGER counterFrequency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
jlong CounterGet()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    LARGE_INTEGER count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    if (!counterInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        counterAvailable = QueryPerformanceFrequency(&counterFrequency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        counterInitialized = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    if (!counterAvailable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    QueryPerformanceCounter(&count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    return (jlong)(count.QuadPart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
jlong Counter2Micros(jlong counts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    if (!counterAvailable || !counterInitialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    return (counts * 1000 * 1000)/counterFrequency.QuadPart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
void
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   464
JLI_ReportErrorMessage(const char* fmt, ...) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    va_list vl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    va_start(vl,fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    if (IsJavaw()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        char *message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        /* get the length of the string we need */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        int n = _vscprintf(fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        message = (char *)JLI_MemAlloc(n + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        _vsnprintf(message, n, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        message[n]='\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        MessageBox(NULL, message, "Java Virtual Machine Launcher",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        JLI_MemFree(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        vfprintf(stderr, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        fprintf(stderr, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    va_end(vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
/*
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   488
 * Just like JLI_ReportErrorMessage, except that it concatenates the system
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
 * error message if any, its upto the calling routine to correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
 * format the separation of the messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
void
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   493
JLI_ReportErrorMessageSys(const char *fmt, ...)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    va_list vl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    int save_errno = errno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    DWORD       errval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    jboolean freeit = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    char  *errtext = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    va_start(vl, fmt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    if ((errval = GetLastError()) != 0) {               /* Platform SDK / DOS Error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            NULL, errval, 0, (LPTSTR)&errtext, 0, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (errtext == NULL || n == 0) {                /* Paranoia check */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            errtext = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            n = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            freeit = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            if (n > 2) {                                /* Drop final CR, LF */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                if (errtext[n - 1] == '\n') n--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                if (errtext[n - 1] == '\r') n--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                errtext[n] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    } else {   /* C runtime error that has no corresponding DOS error code */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        errtext = strerror(save_errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    if (IsJavaw()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        char *message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        int mlen;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        /* get the length of the string we need */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        int len = mlen =  _vscprintf(fmt, vl) + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        if (freeit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
           mlen += JLI_StrLen(errtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        message = (char *)JLI_MemAlloc(mlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        _vsnprintf(message, len, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        message[len]='\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        if (freeit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
           JLI_StrCat(message, errtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        MessageBox(NULL, message, "Java Virtual Machine Launcher",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        JLI_MemFree(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        vfprintf(stderr, fmt, vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        if (freeit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
           fprintf(stderr, "%s", errtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    if (freeit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        (void)LocalFree((HLOCAL)errtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    va_end(vl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   556
void  JLI_ReportExceptionDescription(JNIEnv * env) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    if (IsJavaw()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
       /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        * This code should be replaced by code which opens a window with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        * the exception detail message, for now atleast put a dialog up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        MessageBox(NULL, "A Java Exception has occurred.", "Java Virtual Machine Launcher",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
               (MB_OK|MB_ICONSTOP|MB_APPLMODAL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
ServerClassMachine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    return (GetErgoPolicy() == ALWAYS_SERVER_CLASS) ? JNI_TRUE : JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
 * Determine if there is an acceptable JRE in the registry directory top_key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
 * Upon locating the "best" one, return a fully qualified path to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
 * "Best" is defined as the most advanced JRE meeting the constraints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
 * contained in the manifest_info. If no JRE in this directory meets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
 * constraints, return NULL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
 * It doesn't matter if we get an error reading the registry, or we just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
 * don't find anything interesting in the directory.  We just return NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
 * in either case.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
static char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
ProcessDir(manifest_info* info, HKEY top_key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    DWORD   index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    HKEY    ver_key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    char    name[MAXNAMELEN];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    int     len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    char    *best = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * Enumerate "<top_key>/SOFTWARE/JavaSoft/Java Runtime Environment"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * searching for the best available version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    while (RegEnumKey(top_key, index, name, MAXNAMELEN) == ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        if (JLI_AcceptableRelease(name, info->jre_version))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            if ((best == NULL) || (JLI_ExactVersionId(name, best) > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                if (best != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                    JLI_MemFree(best);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                best = JLI_StringDup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * Extract "JavaHome" from the "best" registry directory and return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * that path.  If no appropriate version was located, or there is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * error in extracting the "JavaHome" string, return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    if (best == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        return (NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        if (RegOpenKeyEx(top_key, best, 0, KEY_READ, &ver_key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
          != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            JLI_MemFree(best);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            if (ver_key != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                RegCloseKey(ver_key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            return (NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        JLI_MemFree(best);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        len = MAXNAMELEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (RegQueryValueEx(ver_key, "JavaHome", NULL, NULL, (LPBYTE)name, &len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
          != ERROR_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            if (ver_key != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                RegCloseKey(ver_key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            return (NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        if (ver_key != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            RegCloseKey(ver_key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        return (JLI_StringDup(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
 * This is the global entry point. It examines the host for the optimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
 * JRE to be used by scanning a set of registry entries.  This set of entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
 * is hardwired on Windows as "Software\JavaSoft\Java Runtime Environment"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
 * under the set of roots "{ HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE }".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
 * This routine simply opens each of these registry directories before passing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
 * control onto ProcessDir().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
LocateJRE(manifest_info* info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    HKEY    key = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    char    *path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    int     key_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    HKEY    root_keys[2] = { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    for (key_index = 0; key_index <= 1; key_index++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        if (RegOpenKeyEx(root_keys[key_index], JRE_KEY, 0, KEY_READ, &key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
          == ERROR_SUCCESS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            if ((path = ProcessDir(info, key)) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                if (key != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                    RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                return (path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        if (key != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            RegCloseKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
 * Local helper routine to isolate a single token (option or argument)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
 * from the command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
 * This routine accepts a pointer to a character pointer.  The first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
 * token (as defined by MSDN command-line argument syntax) is isolated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
 * from that string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
 * Upon return, the input character pointer pointed to by the parameter s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
 * is updated to point to the remainding, unscanned, portion of the string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
 * or to a null character if the entire string has been consummed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
 * This function returns a pointer to a null-terminated string which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
 * contains the isolated first token, or to the null character if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
 * token could be isolated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
 * Note the side effect of modifying the input string s by the insertion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
 * of a null character, making it two strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
 * See "Parsing C Command-Line Arguments" in the MSDN Library for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
 * parsing rule details.  The rule summary from that specification is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
 *  * Arguments are delimited by white space, which is either a space or a tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
 *  * A string surrounded by double quotation marks is interpreted as a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
 *    argument, regardless of white space contained within. A quoted string can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
 *    be embedded in an argument. Note that the caret (^) is not recognized as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
 *    an escape character or delimiter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
 *  * A double quotation mark preceded by a backslash, \", is interpreted as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
 *    literal double quotation mark (").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
 *  * Backslashes are interpreted literally, unless they immediately precede a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
 *    double quotation mark.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
 *  * If an even number of backslashes is followed by a double quotation mark,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
 *    then one backslash (\) is placed in the argv array for every pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
 *    backslashes (\\), and the double quotation mark (") is interpreted as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
 *    string delimiter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
 *  * If an odd number of backslashes is followed by a double quotation mark,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
 *    then one backslash (\) is placed in the argv array for every pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
 *    backslashes (\\) and the double quotation mark is interpreted as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
 *    escape sequence by the remaining backslash, causing a literal double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
 *    quotation mark (") to be placed in argv.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
static char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
nextarg(char** s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    char    *p = *s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    char    *head;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    int     slashes = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    int     inquote = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * Strip leading whitespace, which MSDN defines as only space or tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * (Hence, no locale specific "isspace" here.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    while (*p != (char)0 && (*p == ' ' || *p == '\t'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    head = p;                   /* Save the start of the token to return */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * Isolate a token from the command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    while (*p != (char)0 && (inquote || !(*p == ' ' || *p == '\t'))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        if (*p == '\\' && *(p+1) == '"' && slashes % 2 == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        else if (*p == '"')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            inquote = !inquote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        slashes = (*p++ == '\\') ? slashes + 1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * If the token isolated isn't already terminated in a "char zero",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * then replace the whitespace character with one and move to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * next character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    if (*p != (char)0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        *p++ = (char)0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * Update the parameter to point to the head of the remaining string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * reflecting the command line and return a pointer to the leading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * token which was isolated from the command line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    *s = p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    return (head);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
 * Local helper routine to return a string equivalent to the input string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
 * s, but with quotes removed so the result is a string as would be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
 * in argv[].  The returned string should be freed by a call to JLI_MemFree().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
 * The rules for quoting (and escaped quotes) are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
 *  1 A double quotation mark preceded by a backslash, \", is interpreted as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
 *    literal double quotation mark (").
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
 *  2 Backslashes are interpreted literally, unless they immediately precede a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
 *    double quotation mark.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
 *  3 If an even number of backslashes is followed by a double quotation mark,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
 *    then one backslash (\) is placed in the argv array for every pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
 *    backslashes (\\), and the double quotation mark (") is interpreted as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
 *    string delimiter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
 *  4 If an odd number of backslashes is followed by a double quotation mark,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
 *    then one backslash (\) is placed in the argv array for every pair of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
 *    backslashes (\\) and the double quotation mark is interpreted as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
 *    escape sequence by the remaining backslash, causing a literal double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
 *    quotation mark (") to be placed in argv.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
static char*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
unquote(const char *s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    const char *p = s;          /* Pointer to the tail of the original string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    char *un = (char*)JLI_MemAlloc(JLI_StrLen(s) + 1);  /* Ptr to unquoted string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    char *pun = un;             /* Pointer to the tail of the unquoted string */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    while (*p != '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        if (*p == '"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        } else if (*p == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            const char *q = p + JLI_StrSpn(p,"\\");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            if (*q == '"')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                    *pun++ = '\\';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                    p += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                 } while (*p == '\\' && p < q);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                while (p < q)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                    *pun++ = *p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            *pun++ = *p++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    *pun = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    return un;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
 * Given a path to a jre to execute, this routine checks if this process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
 * is indeed that jre.  If not, it exec's that jre.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
 * We want to actually check the paths rather than just the version string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
 * built into the executable, so that given version specification will yield
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
 * the exact same Java environment, regardless of the version of the arbitrary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
 * launcher we start with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
ExecJRE(char *jre, char **argv) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    int     len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    char    path[MAXPATHLEN + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    const char *progname = GetProgramName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * Resolve the real path to the currently running launcher.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    len = GetModuleFileName(NULL, path, MAXPATHLEN + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    if (len == 0 || len > MAXPATHLEN) {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   827
        JLI_ReportErrorMessageSys(JRE_ERROR9, progname);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    JLI_TraceLauncher("ExecJRE: old: %s\n", path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    JLI_TraceLauncher("ExecJRE: new: %s\n", jre);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * If the path to the selected JRE directory is a match to the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * portion of the path to the currently executing JRE, we have a winner!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * If so, just return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
    if (JLI_StrNCaseCmp(jre, path, JLI_StrLen(jre)) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        return;                 /* I am the droid you were looking for */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * If this isn't the selected version, exec the selected version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    (void)JLI_StrCat(JLI_StrCat(JLI_StrCpy(path, jre), "\\bin\\"), progname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    (void)JLI_StrCat(path, ".exe");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * Although Windows has an execv() entrypoint, it doesn't actually
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * overlay a process: it can only create a new process and terminate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * the old process.  Therefore, any processes waiting on the initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * process wake up and they shouldn't.  Hence, a chain of pseudo-zombie
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * processes must be retained to maintain the proper wait semantics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * Fortunately the image size of the launcher isn't too large at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * If it weren't for this semantic flaw, the code below would be ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     *     execv(path, argv);
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   860
     *     JLI_ReportErrorMessage("Error: Exec of %s failed\n", path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     *     exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * The incorrect exec semantics could be addressed by:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     *     exit((int)spawnv(_P_WAIT, path, argv));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * Unfortunately, a bug in Windows spawn/exec impementation prevents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * this from completely working.  All the Windows POSIX process creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * interfaces are implemented as wrappers around the native Windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * function CreateProcess().  CreateProcess() takes a single string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * to specify command line options and arguments, so the POSIX routine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * wrappers build a single string from the argv[] array and in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * process, any quoting information is lost.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * The solution to this to get the original command line, to process it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * to remove the new multiple JRE options (if any) as was done for argv
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * in the common SelectVersion() routine and finally to pass it directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * to the native CreateProcess() Windows process control interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        char    *cmdline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        char    *p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        char    *np;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        char    *ocl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        char    *ccl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        char    *unquoted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        DWORD   exitCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        STARTUPINFO si;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        PROCESS_INFORMATION pi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
         * The following code block gets and processes the original command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
         * line, replacing the argv[0] equivalent in the command line with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
         * the path to the new executable and removing the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
         * Multiple JRE support options. Note that similar logic exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
         * in the platform independent SelectVersion routine, but is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
         * replicated here due to the syntax of CreateProcess().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
         * The magic "+ 4" characters added to the command line length are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
         * 2 possible quotes around the path (argv[0]), a space after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
         * path and a terminating null character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        ocl = GetCommandLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        np = ccl = JLI_StringDup(ocl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        p = nextarg(&np);               /* Discard argv[0] */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        cmdline = (char *)JLI_MemAlloc(JLI_StrLen(path) + JLI_StrLen(np) + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        if (JLI_StrChr(path, (int)' ') == NULL && JLI_StrChr(path, (int)'\t') == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            cmdline = JLI_StrCpy(cmdline, path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            cmdline = JLI_StrCat(JLI_StrCat(JLI_StrCpy(cmdline, "\""), path), "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        while (*np != (char)0) {                /* While more command-line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            p = nextarg(&np);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            if (*p != (char)0) {                /* If a token was isolated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                unquoted = unquote(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                if (*unquoted == '-') {         /* Looks like an option */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                    if (JLI_StrCmp(unquoted, "-classpath") == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                      JLI_StrCmp(unquoted, "-cp") == 0) {       /* Unique cp syntax */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                        cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                        p = nextarg(&np);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                        if (*p != (char)0)      /* If a token was isolated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                            cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                    } else if (JLI_StrNCmp(unquoted, "-version:", 9) != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                      JLI_StrCmp(unquoted, "-jre-restrict-search") != 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                      JLI_StrCmp(unquoted, "-no-jre-restrict-search") != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                        cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                } else {                        /* End of options */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                    cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                    cmdline = JLI_StrCat(JLI_StrCat(cmdline, " "), np);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                    JLI_MemFree((void *)unquoted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                JLI_MemFree((void *)unquoted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        JLI_MemFree((void *)ccl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        if (JLI_IsTraceLauncher()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            np = ccl = JLI_StringDup(cmdline);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            p = nextarg(&np);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            printf("ReExec Command: %s (%s)\n", path, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            printf("ReExec Args: %s\n", np);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            JLI_MemFree((void *)ccl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        (void)fflush(stdout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        (void)fflush(stderr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
         * The following code is modeled after a model presented in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
         * Microsoft Technical Article "Moving Unix Applications to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
         * Windows NT" (March 6, 1994) and "Creating Processes" on MSDN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
         * (Februrary 2005).  It approximates UNIX spawn semantics with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
         * the parent waiting for termination of the child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        memset(&si, 0, sizeof(si));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        si.cb =sizeof(STARTUPINFO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        memset(&pi, 0, sizeof(pi));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        if (!CreateProcess((LPCTSTR)path,       /* executable name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
          (LPTSTR)cmdline,                      /* command line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
          (LPSECURITY_ATTRIBUTES)NULL,          /* process security attr. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
          (LPSECURITY_ATTRIBUTES)NULL,          /* thread security attr. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
          (BOOL)TRUE,                           /* inherits system handles */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
          (DWORD)0,                             /* creation flags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
          (LPVOID)NULL,                         /* environment block */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
          (LPCTSTR)NULL,                        /* current directory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
          (LPSTARTUPINFO)&si,                   /* (in) startup information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
          (LPPROCESS_INFORMATION)&pi)) {        /* (out) process information */
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   970
            JLI_ReportErrorMessageSys(SYS_ERROR1, path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        if (WaitForSingleObject(pi.hProcess, INFINITE) != WAIT_FAILED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            if (GetExitCodeProcess(pi.hProcess, &exitCode) == FALSE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                exitCode = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        } else {
1145
404b11752c57 6685121: (launcher) make ReportErrorMessages accessible by other launcher subsystems
ksrini
parents: 715
diff changeset
   978
            JLI_ReportErrorMessage(SYS_ERROR2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            exitCode = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        CloseHandle(pi.hThread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        CloseHandle(pi.hProcess);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        exit(exitCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
 * Wrapper for platform dependent unsetenv function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
UnsetEnv(char *name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    int ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
    char *buf = JLI_MemAlloc(JLI_StrLen(name) + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    buf = JLI_StrCat(JLI_StrCpy(buf, name), "=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    ret = _putenv(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    JLI_MemFree(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    return (ret);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
/* --- Splash Screen shared library support --- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
static const char* SPLASHSCREEN_SO = "\\bin\\splashscreen.dll";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
static HMODULE hSplashLib = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
void* SplashProcAddress(const char* name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    char libraryPath[MAXPATHLEN]; /* some extra space for JLI_StrCat'ing SPLASHSCREEN_SO */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    if (!GetJREPath(libraryPath, MAXPATHLEN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    if (JLI_StrLen(libraryPath)+JLI_StrLen(SPLASHSCREEN_SO) >= MAXPATHLEN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    JLI_StrCat(libraryPath, SPLASHSCREEN_SO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    if (!hSplashLib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        hSplashLib = LoadLibrary(libraryPath);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    if (hSplashLib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        return GetProcAddress(hSplashLib, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
void SplashFreeLibrary() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    if (hSplashLib) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        FreeLibrary(hSplashLib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        hSplashLib = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
jlong_format_specifier() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    return "%I64d";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
 * Block current thread and continue execution in a new thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    int rslt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
    unsigned thread_id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
#ifndef STACK_SIZE_PARAM_IS_A_RESERVATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
#define STACK_SIZE_PARAM_IS_A_RESERVATION  (0x10000)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * STACK_SIZE_PARAM_IS_A_RESERVATION is what we want, but it's not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * supported on older version of Windows. Try first with the flag; and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * if that fails try again without the flag. See MSDN document or HotSpot
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * source (os_win32.cpp) for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    HANDLE thread_handle =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
      (HANDLE)_beginthreadex(NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                             (unsigned)stack_size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                             continuation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                             args,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                             STACK_SIZE_PARAM_IS_A_RESERVATION,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                             &thread_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    if (thread_handle == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
      thread_handle =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
      (HANDLE)_beginthreadex(NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                             (unsigned)stack_size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                             continuation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                             args,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                             &thread_id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    if (thread_handle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
      WaitForSingleObject(thread_handle, INFINITE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
      GetExitCodeThread(thread_handle, &rslt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
      CloseHandle(thread_handle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
      rslt = continuation(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
    return rslt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1087
/* Unix only, empty on windows. */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
void SetJavaLauncherPlatformProps() {}
39
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1089
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1090
/*
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1091
 * The implementation for finding classes from the bootstrap
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1092
 * class loader, refer to java.h
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1093
 */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1094
static FindClassFromBootLoader_t *findBootClass = NULL;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1095
1331
05e272c957d8 6755847: (launcher) will trigger assertions in debug build
ksrini
parents: 1323
diff changeset
  1096
#ifdef _M_AMD64
05e272c957d8 6755847: (launcher) will trigger assertions in debug build
ksrini
parents: 1323
diff changeset
  1097
#define JVM_BCLOADER "JVM_FindClassFromClassLoader"
05e272c957d8 6755847: (launcher) will trigger assertions in debug build
ksrini
parents: 1323
diff changeset
  1098
#else
05e272c957d8 6755847: (launcher) will trigger assertions in debug build
ksrini
parents: 1323
diff changeset
  1099
#define JVM_BCLOADER "_JVM_FindClassFromClassLoader@20"
05e272c957d8 6755847: (launcher) will trigger assertions in debug build
ksrini
parents: 1323
diff changeset
  1100
#endif /* _M_AMD64 */
05e272c957d8 6755847: (launcher) will trigger assertions in debug build
ksrini
parents: 1323
diff changeset
  1101
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1102
jclass FindBootStrapClass(JNIEnv *env, const char *classname)
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1103
{
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1104
   HMODULE hJvm;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1105
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1106
   if (findBootClass == NULL) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1107
       hJvm = GetModuleHandle(JVM_DLL);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1108
       if (hJvm == NULL) return NULL;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1109
       /* need to use the demangled entry point */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1110
       findBootClass = (FindClassFromBootLoader_t *)GetProcAddress(hJvm,
1331
05e272c957d8 6755847: (launcher) will trigger assertions in debug build
ksrini
parents: 1323
diff changeset
  1111
            JVM_BCLOADER);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1112
       if (findBootClass == NULL) {
1331
05e272c957d8 6755847: (launcher) will trigger assertions in debug build
ksrini
parents: 1323
diff changeset
  1113
          JLI_ReportErrorMessage(DLL_ERROR4, JVM_BCLOADER);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1114
          return NULL;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1115
       }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1116
   }
1331
05e272c957d8 6755847: (launcher) will trigger assertions in debug build
ksrini
parents: 1323
diff changeset
  1117
   return findBootClass(env, classname, JNI_FALSE, (jobject)NULL, JNI_FALSE);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1118
}
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 1145
diff changeset
  1119
39
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1120
void
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1121
InitLauncher(boolean javaw)
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1122
{
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1123
    INITCOMMONCONTROLSEX icx;
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1124
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1125
    /*
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1126
     * Required for javaw mode MessageBox output as well as for
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1127
     * HotSpot -XX:+ShowMessageBoxOnError in java mode, an empty
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1128
     * flag field is sufficient to perform the basic UI initialization.
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1129
     */
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1130
    memset(&icx, 0, sizeof(INITCOMMONCONTROLSEX));
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1131
    icx.dwSize = sizeof(INITCOMMONCONTROLSEX);
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1132
    InitCommonControlsEx(&icx);
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1133
    _isjavaw = javaw;
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1134
    JLI_SetTraceLauncher();
560da37936db 6596475: (launcher) javaw should call InitCommonControls
ksrini
parents: 2
diff changeset
  1135
}