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