author | ksrini |
Wed, 18 Dec 2013 10:19:05 -0800 | |
changeset 22065 | 0b2684d4f49f |
parent 20851 | 9f284cf7836b |
child 22606 | 9c09d5a52807 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
20201
50cc2d25a60b
8020552: [launcher] changes to support removal of Solaris 32-bit distribution
ksrini
parents:
17911
diff
changeset
|
2 |
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
#include "java.h" |
|
27 |
#include "jvm_md.h" |
|
28 |
#include <dirent.h> |
|
29 |
#include <dlfcn.h> |
|
30 |
#include <fcntl.h> |
|
31 |
#include <inttypes.h> |
|
32 |
#include <stdio.h> |
|
33 |
#include <string.h> |
|
34 |
#include <stdlib.h> |
|
35 |
#include <sys/stat.h> |
|
36 |
#include <unistd.h> |
|
37 |
#include <sys/types.h> |
|
38 |
#include "manifest_info.h" |
|
39 |
#include "version_comp.h" |
|
40 |
||
41 |
||
42 |
#define JVM_DLL "libjvm.so" |
|
43 |
#define JAVA_DLL "libjava.so" |
|
44 |
#define LD_LIBRARY_PATH "LD_LIBRARY_PATH" |
|
45 |
||
46 |
/* help jettison the LD_LIBRARY_PATH settings in the future */ |
|
47 |
#ifndef SETENV_REQUIRED |
|
48 |
#define SETENV_REQUIRED |
|
49 |
#endif |
|
50 |
||
51 |
#ifdef __solaris__ |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
52 |
# ifndef LIBARCHNAME |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
53 |
# error "The macro LIBARCHNAME was not defined on the compile line" |
12047 | 54 |
# endif |
55 |
# include <sys/systeminfo.h> |
|
56 |
# include <sys/elf.h> |
|
57 |
# include <stdio.h> |
|
58 |
#endif |
|
59 |
||
60 |
/* |
|
61 |
* Flowchart of launcher execs and options processing on unix |
|
62 |
* |
|
63 |
* The selection of the proper vm shared library to open depends on |
|
64 |
* several classes of command line options, including vm "flavor" |
|
65 |
* options (-client, -server) and the data model options, -d32 and |
|
66 |
* -d64, as well as a version specification which may have come from |
|
67 |
* the command line or from the manifest of an executable jar file. |
|
68 |
* The vm selection options are not passed to the running |
|
69 |
* virtual machine; they must be screened out by the launcher. |
|
70 |
* |
|
71 |
* The version specification (if any) is processed first by the |
|
72 |
* platform independent routine SelectVersion. This may result in |
|
73 |
* the exec of the specified launcher version. |
|
74 |
* |
|
75 |
* Previously the launcher modified the LD_LIBRARY_PATH appropriately for the |
|
76 |
* desired data model path, regardless if data models matched or not. The |
|
77 |
* launcher subsequently exec'ed the desired executable, in order to make the |
|
78 |
* LD_LIBRARY_PATH path available, for the runtime linker. |
|
79 |
* |
|
80 |
* Now, in most cases,the launcher will dlopen the target libjvm.so. All |
|
81 |
* required libraries are loaded by the runtime linker, using the |
|
82 |
* $RPATH/$ORIGIN baked into the shared libraries at compile time. Therefore, |
|
83 |
* in most cases, the launcher will only exec, if the data models are |
|
84 |
* mismatched, and will not set any environment variables, regardless of the |
|
85 |
* data models. |
|
86 |
* |
|
87 |
* However, if the environment contains a LD_LIBRARY_PATH, this will cause the |
|
88 |
* launcher to inspect the LD_LIBRARY_PATH. The launcher will check |
|
89 |
* a. if the LD_LIBRARY_PATH's first component is the the path to the desired |
|
90 |
* libjvm.so |
|
91 |
* b. if any other libjvm.so is found in any of the paths. |
|
92 |
* If case b is true, then the launcher will set the LD_LIBRARY_PATH to the |
|
93 |
* desired JRE and reexec, in order to propagate the environment. |
|
94 |
* |
|
95 |
* Main |
|
96 |
* (incoming argv) |
|
97 |
* | |
|
98 |
* \|/ |
|
99 |
* SelectVersion |
|
100 |
* (selects the JRE version, note: not data model) |
|
101 |
* | |
|
102 |
* \|/ |
|
103 |
* CreateExecutionEnvironment |
|
104 |
* (determines desired data model) |
|
105 |
* | |
|
106 |
* | |
|
107 |
* \|/ |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
108 |
* Have Desired Model ? --> NO --> Exit(with error) |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
109 |
* | |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
110 |
* | |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
111 |
* \|/ |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
112 |
* YES |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
113 |
* | |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
114 |
* | |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
115 |
* \|/ |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
116 |
* CheckJvmType |
12047 | 117 |
* (removes -client, -server, etc.) |
118 |
* | |
|
119 |
* | |
|
120 |
* \|/ |
|
121 |
* TranslateDashJArgs... |
|
122 |
* (Prepare to pass args to vm) |
|
123 |
* | |
|
124 |
* | |
|
125 |
* \|/ |
|
126 |
* ParseArguments |
|
127 |
* (removes -d32 and -d64 if any, |
|
128 |
* processes version options, |
|
129 |
* creates argument list for vm, |
|
130 |
* etc.) |
|
131 |
* | |
|
132 |
* | |
|
133 |
* \|/ |
|
134 |
* RequiresSetenv |
|
135 |
* Is LD_LIBRARY_PATH |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
136 |
* and friends set ? --> NO --> Have Desired Model ? NO --> Error/Exit |
12047 | 137 |
* YES YES --> Continue |
138 |
* | |
|
139 |
* | |
|
140 |
* \|/ |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
141 |
* Path is desired JRE ? YES --> Have Desired Model ? NO --> Error/Exit |
12047 | 142 |
* NO YES --> Continue |
143 |
* | |
|
144 |
* | |
|
145 |
* \|/ |
|
146 |
* Paths have well known |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
147 |
* jvm paths ? --> NO --> Have Desired Model ? NO --> Error/Exit |
12047 | 148 |
* YES YES --> Continue |
149 |
* | |
|
150 |
* | |
|
151 |
* \|/ |
|
152 |
* Does libjvm.so exit |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
153 |
* in any of them ? --> NO --> Have Desired Model ? NO --> Error/Exit |
12047 | 154 |
* YES YES --> Continue |
155 |
* | |
|
156 |
* | |
|
157 |
* \|/ |
|
158 |
* Set the LD_LIBRARY_PATH |
|
159 |
* | |
|
160 |
* | |
|
161 |
* \|/ |
|
162 |
* Re-exec |
|
163 |
* | |
|
164 |
* | |
|
165 |
* \|/ |
|
166 |
* Main |
|
167 |
*/ |
|
168 |
||
169 |
/* Store the name of the executable once computed */ |
|
170 |
static char *execname = NULL; |
|
171 |
||
172 |
/* |
|
173 |
* execname accessor from other parts of platform dependent logic |
|
174 |
*/ |
|
175 |
const char * |
|
176 |
GetExecName() { |
|
177 |
return execname; |
|
178 |
} |
|
179 |
||
180 |
#ifdef SETENV_REQUIRED |
|
181 |
static jboolean |
|
182 |
JvmExists(const char *path) { |
|
183 |
char tmp[PATH_MAX + 1]; |
|
184 |
struct stat statbuf; |
|
185 |
JLI_Snprintf(tmp, PATH_MAX, "%s/%s", path, JVM_DLL); |
|
186 |
if (stat(tmp, &statbuf) == 0) { |
|
187 |
return JNI_TRUE; |
|
188 |
} |
|
189 |
return JNI_FALSE; |
|
190 |
} |
|
191 |
/* |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
192 |
* contains a lib/$LIBARCHNAME/{server,client}/libjvm.so ? |
12047 | 193 |
*/ |
194 |
static jboolean |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
195 |
ContainsLibJVM(const char *env) { |
12047 | 196 |
char clientPattern[PATH_MAX + 1]; |
197 |
char serverPattern[PATH_MAX + 1]; |
|
198 |
char *envpath; |
|
199 |
char *path; |
|
200 |
jboolean clientPatternFound; |
|
201 |
jboolean serverPatternFound; |
|
202 |
||
203 |
/* fastest path */ |
|
204 |
if (env == NULL) { |
|
205 |
return JNI_FALSE; |
|
206 |
} |
|
207 |
||
208 |
/* the usual suspects */ |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
209 |
JLI_Snprintf(clientPattern, PATH_MAX, "lib/%s/client", LIBARCHNAME); |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
210 |
JLI_Snprintf(serverPattern, PATH_MAX, "lib/%s/server", LIBARCHNAME); |
12047 | 211 |
|
212 |
/* to optimize for time, test if any of our usual suspects are present. */ |
|
213 |
clientPatternFound = JLI_StrStr(env, clientPattern) != NULL; |
|
214 |
serverPatternFound = JLI_StrStr(env, serverPattern) != NULL; |
|
215 |
if (clientPatternFound == JNI_FALSE && serverPatternFound == JNI_FALSE) { |
|
216 |
return JNI_FALSE; |
|
217 |
} |
|
218 |
||
219 |
/* |
|
220 |
* we have a suspicious path component, check if it contains a libjvm.so |
|
221 |
*/ |
|
222 |
envpath = JLI_StringDup(env); |
|
223 |
for (path = JLI_StrTok(envpath, ":"); path != NULL; path = JLI_StrTok(NULL, ":")) { |
|
224 |
if (clientPatternFound && JLI_StrStr(path, clientPattern) != NULL) { |
|
225 |
if (JvmExists(path)) { |
|
226 |
JLI_MemFree(envpath); |
|
227 |
return JNI_TRUE; |
|
228 |
} |
|
229 |
} |
|
230 |
if (serverPatternFound && JLI_StrStr(path, serverPattern) != NULL) { |
|
231 |
if (JvmExists(path)) { |
|
232 |
JLI_MemFree(envpath); |
|
233 |
return JNI_TRUE; |
|
234 |
} |
|
235 |
} |
|
236 |
} |
|
237 |
JLI_MemFree(envpath); |
|
238 |
return JNI_FALSE; |
|
239 |
} |
|
240 |
||
241 |
/* |
|
242 |
* Test whether the environment variable needs to be set, see flowchart. |
|
243 |
*/ |
|
244 |
static jboolean |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
245 |
RequiresSetenv(const char *jvmpath) { |
12047 | 246 |
char jpath[PATH_MAX + 1]; |
247 |
char *llp; |
|
248 |
char *dmllp = NULL; |
|
249 |
char *p; /* a utility pointer */ |
|
250 |
||
251 |
llp = getenv("LD_LIBRARY_PATH"); |
|
252 |
#ifdef __solaris__ |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
253 |
dmllp = getenv("LD_LIBRARY_PATH_64"); |
12047 | 254 |
#endif /* __solaris__ */ |
255 |
/* no environment variable is a good environment variable */ |
|
256 |
if (llp == NULL && dmllp == NULL) { |
|
257 |
return JNI_FALSE; |
|
258 |
} |
|
259 |
#ifdef __linux |
|
260 |
/* |
|
261 |
* On linux, if a binary is running as sgid or suid, glibc sets |
|
262 |
* LD_LIBRARY_PATH to the empty string for security purposes. (In contrast, |
|
263 |
* on Solaris the LD_LIBRARY_PATH variable for a privileged binary does not |
|
264 |
* lose its settings; but the dynamic linker does apply more scrutiny to the |
|
265 |
* path.) The launcher uses the value of LD_LIBRARY_PATH to prevent an exec |
|
266 |
* loop, here and further downstream. Therefore, if we are running sgid or |
|
267 |
* suid, this function's setting of LD_LIBRARY_PATH will be ineffective and |
|
268 |
* we should case a return from the calling function. Getting the right |
|
269 |
* libraries will be handled by the RPATH. In reality, this check is |
|
270 |
* redundant, as the previous check for a non-null LD_LIBRARY_PATH will |
|
271 |
* return back to the calling function forthwith, it is left here to safe |
|
272 |
* guard against any changes, in the glibc's existing security policy. |
|
273 |
*/ |
|
274 |
if ((getgid() != getegid()) || (getuid() != geteuid())) { |
|
275 |
return JNI_FALSE; |
|
276 |
} |
|
277 |
#endif /* __linux */ |
|
278 |
||
279 |
/* |
|
280 |
* Prevent recursions. Since LD_LIBRARY_PATH is the one which will be set by |
|
281 |
* previous versions of the JRE, thus it is the only path that matters here. |
|
282 |
* So we check to see if the desired JRE is set. |
|
283 |
*/ |
|
284 |
JLI_StrNCpy(jpath, jvmpath, PATH_MAX); |
|
285 |
p = JLI_StrRChr(jpath, '/'); |
|
286 |
*p = '\0'; |
|
287 |
if (llp != NULL && JLI_StrNCmp(llp, jpath, JLI_StrLen(jpath)) == 0) { |
|
288 |
return JNI_FALSE; |
|
289 |
} |
|
290 |
||
291 |
/* scrutinize all the paths further */ |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
292 |
if (llp != NULL && ContainsLibJVM(llp)) { |
12047 | 293 |
return JNI_TRUE; |
294 |
} |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
295 |
if (dmllp != NULL && ContainsLibJVM(dmllp)) { |
12047 | 296 |
return JNI_TRUE; |
297 |
} |
|
298 |
return JNI_FALSE; |
|
299 |
} |
|
300 |
#endif /* SETENV_REQUIRED */ |
|
301 |
||
302 |
void |
|
303 |
CreateExecutionEnvironment(int *pargc, char ***pargv, |
|
304 |
char jrepath[], jint so_jrepath, |
|
305 |
char jvmpath[], jint so_jvmpath, |
|
306 |
char jvmcfg[], jint so_jvmcfg) { |
|
307 |
/* |
|
308 |
* First, determine if we are running the desired data model. If we |
|
309 |
* are running the desired data model, all the error messages |
|
310 |
* associated with calling GetJREPath, ReadKnownVMs, etc. should be |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
311 |
* output, otherwise we simply exit with an error, as we no longer |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
312 |
* support dual data models. |
12047 | 313 |
*/ |
314 |
jboolean jvmpathExists; |
|
315 |
||
316 |
/* Compute/set the name of the executable */ |
|
317 |
SetExecname(*pargv); |
|
318 |
||
319 |
/* Check data model flags, and exec process, if needed */ |
|
320 |
{ |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
321 |
char *arch = LIBARCHNAME; /* like sparc or sparcv9 */ |
12047 | 322 |
char * jvmtype = NULL; |
323 |
int argc = *pargc; |
|
324 |
char **argv = *pargv; |
|
325 |
int running = CURRENT_DATA_MODEL; |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
326 |
/* |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
327 |
* As of jdk9, there is no support for dual mode operations, however |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
328 |
* for legacy error reporting purposes and until -d options are supported |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
329 |
* we need this. |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
330 |
*/ |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
331 |
int wanted = running; |
12047 | 332 |
#ifdef SETENV_REQUIRED |
333 |
jboolean mustsetenv = JNI_FALSE; |
|
334 |
char *runpath = NULL; /* existing effective LD_LIBRARY_PATH setting */ |
|
335 |
char* new_runpath = NULL; /* desired new LD_LIBRARY_PATH string */ |
|
336 |
char* newpath = NULL; /* path on new LD_LIBRARY_PATH */ |
|
337 |
char* lastslash = NULL; |
|
338 |
char** newenvp = NULL; /* current environment */ |
|
339 |
#ifdef __solaris__ |
|
340 |
char* dmpath = NULL; /* data model specific LD_LIBRARY_PATH, |
|
341 |
Solaris only */ |
|
342 |
#endif /* __solaris__ */ |
|
343 |
#endif /* SETENV_REQUIRED */ |
|
344 |
||
345 |
char** newargv = NULL; |
|
346 |
int newargc = 0; |
|
347 |
||
348 |
/* |
|
349 |
* Starting in 1.5, all unix platforms accept the -d32 and -d64 |
|
350 |
* options. On platforms where only one data-model is supported |
|
351 |
* (e.g. ia-64 Linux), using the flag for the other data model is |
|
352 |
* an error and will terminate the program. |
|
353 |
*/ |
|
354 |
||
355 |
{ /* open new scope to declare local variables */ |
|
356 |
int i; |
|
357 |
||
358 |
newargv = (char **)JLI_MemAlloc((argc+1) * sizeof(char*)); |
|
359 |
newargv[newargc++] = argv[0]; |
|
360 |
||
361 |
/* scan for data model arguments and remove from argument list; |
|
362 |
last occurrence determines desired data model */ |
|
363 |
for (i=1; i < argc; i++) { |
|
364 |
||
365 |
if (JLI_StrCmp(argv[i], "-J-d64") == 0 || JLI_StrCmp(argv[i], "-d64") == 0) { |
|
366 |
wanted = 64; |
|
367 |
continue; |
|
368 |
} |
|
369 |
if (JLI_StrCmp(argv[i], "-J-d32") == 0 || JLI_StrCmp(argv[i], "-d32") == 0) { |
|
370 |
wanted = 32; |
|
371 |
continue; |
|
372 |
} |
|
373 |
newargv[newargc++] = argv[i]; |
|
374 |
||
375 |
if (IsJavaArgs()) { |
|
376 |
if (argv[i][0] != '-') continue; |
|
377 |
} else { |
|
378 |
if (JLI_StrCmp(argv[i], "-classpath") == 0 || JLI_StrCmp(argv[i], "-cp") == 0) { |
|
379 |
i++; |
|
380 |
if (i >= argc) break; |
|
381 |
newargv[newargc++] = argv[i]; |
|
382 |
continue; |
|
383 |
} |
|
384 |
if (argv[i][0] != '-') { i++; break; } |
|
385 |
} |
|
386 |
} |
|
387 |
||
388 |
/* copy rest of args [i .. argc) */ |
|
389 |
while (i < argc) { |
|
390 |
newargv[newargc++] = argv[i++]; |
|
391 |
} |
|
392 |
newargv[newargc] = NULL; |
|
393 |
||
394 |
/* |
|
395 |
* newargv has all proper arguments here |
|
396 |
*/ |
|
397 |
||
398 |
argc = newargc; |
|
399 |
argv = newargv; |
|
400 |
} |
|
401 |
||
402 |
/* If the data model is not changing, it is an error if the |
|
403 |
jvmpath does not exist */ |
|
404 |
if (wanted == running) { |
|
405 |
/* Find out where the JRE is that we will be using. */ |
|
406 |
if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) { |
|
407 |
JLI_ReportErrorMessage(JRE_ERROR1); |
|
408 |
exit(2); |
|
409 |
} |
|
410 |
JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%s%s%sjvm.cfg", |
|
411 |
jrepath, FILESEP, FILESEP, arch, FILESEP); |
|
412 |
/* Find the specified JVM type */ |
|
413 |
if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) { |
|
414 |
JLI_ReportErrorMessage(CFG_ERROR7); |
|
415 |
exit(1); |
|
416 |
} |
|
417 |
||
418 |
jvmpath[0] = '\0'; |
|
419 |
jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE); |
|
420 |
if (JLI_StrCmp(jvmtype, "ERROR") == 0) { |
|
421 |
JLI_ReportErrorMessage(CFG_ERROR9); |
|
422 |
exit(4); |
|
423 |
} |
|
424 |
||
425 |
if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch, 0 )) { |
|
426 |
JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath); |
|
427 |
exit(4); |
|
428 |
} |
|
429 |
/* |
|
430 |
* we seem to have everything we need, so without further ado |
|
431 |
* we return back, otherwise proceed to set the environment. |
|
432 |
*/ |
|
433 |
#ifdef SETENV_REQUIRED |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
434 |
mustsetenv = RequiresSetenv(jvmpath); |
12047 | 435 |
JLI_TraceLauncher("mustsetenv: %s\n", mustsetenv ? "TRUE" : "FALSE"); |
436 |
||
437 |
if (mustsetenv == JNI_FALSE) { |
|
14517
e50acb436a8d
8000476: Memory Leaks and uninitialized memory access in PKCS11 and other native code
jzavgren
parents:
12047
diff
changeset
|
438 |
JLI_MemFree(newargv); |
12047 | 439 |
return; |
440 |
} |
|
441 |
#else |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
442 |
JLI_MemFree(newargv); |
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
443 |
return; |
12047 | 444 |
#endif /* SETENV_REQUIRED */ |
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
445 |
} else { /* do the same speculatively or exit */ |
12047 | 446 |
JLI_ReportErrorMessage(JRE_ERROR2, wanted); |
447 |
exit(1); |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
448 |
} |
12047 | 449 |
#ifdef SETENV_REQUIRED |
450 |
if (mustsetenv) { |
|
451 |
/* |
|
452 |
* We will set the LD_LIBRARY_PATH as follows: |
|
453 |
* |
|
454 |
* o $JVMPATH (directory portion only) |
|
455 |
* o $JRE/lib/$LIBARCHNAME |
|
456 |
* o $JRE/../lib/$LIBARCHNAME |
|
457 |
* |
|
458 |
* followed by the user's previous effective LD_LIBRARY_PATH, if |
|
459 |
* any. |
|
460 |
*/ |
|
461 |
||
462 |
#ifdef __solaris__ |
|
463 |
/* |
|
464 |
* Starting in Solaris 7, ld.so.1 supports three LD_LIBRARY_PATH |
|
465 |
* variables: |
|
466 |
* |
|
467 |
* 1. LD_LIBRARY_PATH -- used for 32 and 64 bit searches if |
|
468 |
* data-model specific variables are not set. |
|
469 |
* |
|
470 |
* 2. LD_LIBRARY_PATH_64 -- overrides and replaces LD_LIBRARY_PATH |
|
471 |
* for 64-bit binaries. |
|
472 |
* The vm uses LD_LIBRARY_PATH to set the java.library.path system |
|
473 |
* property. To shield the vm from the complication of multiple |
|
474 |
* LD_LIBRARY_PATH variables, if the appropriate data model |
|
475 |
* specific variable is set, we will act as if LD_LIBRARY_PATH had |
|
476 |
* the value of the data model specific variant and the data model |
|
477 |
* specific variant will be unset. Note that the variable for the |
|
478 |
* *wanted* data model must be used (if it is set), not simply the |
|
479 |
* current running data model. |
|
480 |
*/ |
|
481 |
||
482 |
switch (wanted) { |
|
483 |
case 0: |
|
484 |
case 64: |
|
485 |
dmpath = getenv("LD_LIBRARY_PATH_64"); |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
486 |
wanted = 64; |
12047 | 487 |
break; |
488 |
||
489 |
default: |
|
490 |
JLI_ReportErrorMessage(JRE_ERROR3, __LINE__); |
|
491 |
exit(1); /* unknown value in wanted */ |
|
492 |
break; |
|
493 |
} |
|
494 |
||
495 |
/* |
|
496 |
* If dmpath is NULL, the relevant data model specific variable is |
|
497 |
* not set and normal LD_LIBRARY_PATH should be used. |
|
498 |
*/ |
|
499 |
if (dmpath == NULL) { |
|
500 |
runpath = getenv("LD_LIBRARY_PATH"); |
|
501 |
} else { |
|
502 |
runpath = dmpath; |
|
503 |
} |
|
504 |
#else /* ! __solaris__ */ |
|
505 |
/* |
|
506 |
* If not on Solaris, assume only a single LD_LIBRARY_PATH |
|
507 |
* variable. |
|
508 |
*/ |
|
509 |
runpath = getenv("LD_LIBRARY_PATH"); |
|
510 |
#endif /* __solaris__ */ |
|
511 |
||
512 |
/* runpath contains current effective LD_LIBRARY_PATH setting */ |
|
513 |
||
514 |
jvmpath = JLI_StringDup(jvmpath); |
|
515 |
new_runpath = JLI_MemAlloc(((runpath != NULL) ? JLI_StrLen(runpath) : 0) + |
|
516 |
2 * JLI_StrLen(jrepath) + 2 * JLI_StrLen(arch) + |
|
517 |
JLI_StrLen(jvmpath) + 52); |
|
518 |
newpath = new_runpath + JLI_StrLen("LD_LIBRARY_PATH="); |
|
519 |
||
520 |
||
521 |
/* |
|
522 |
* Create desired LD_LIBRARY_PATH value for target data model. |
|
523 |
*/ |
|
524 |
{ |
|
525 |
/* remove the name of the .so from the JVM path */ |
|
526 |
lastslash = JLI_StrRChr(jvmpath, '/'); |
|
527 |
if (lastslash) |
|
528 |
*lastslash = '\0'; |
|
529 |
||
530 |
sprintf(new_runpath, "LD_LIBRARY_PATH=" |
|
531 |
"%s:" |
|
532 |
"%s/lib/%s:" |
|
533 |
"%s/../lib/%s", |
|
534 |
jvmpath, |
|
535 |
jrepath, arch, |
|
536 |
jrepath, arch |
|
537 |
); |
|
538 |
||
539 |
||
540 |
/* |
|
541 |
* Check to make sure that the prefix of the current path is the |
|
542 |
* desired environment variable setting, though the RequiresSetenv |
|
543 |
* checks if the desired runpath exists, this logic does a more |
|
544 |
* comprehensive check. |
|
545 |
*/ |
|
546 |
if (runpath != NULL && |
|
547 |
JLI_StrNCmp(newpath, runpath, JLI_StrLen(newpath)) == 0 && |
|
548 |
(runpath[JLI_StrLen(newpath)] == 0 || runpath[JLI_StrLen(newpath)] == ':') && |
|
549 |
(running == wanted) /* data model does not have to be changed */ |
|
550 |
#ifdef __solaris__ |
|
551 |
&& (dmpath == NULL) /* data model specific variables not set */ |
|
552 |
#endif /* __solaris__ */ |
|
553 |
) { |
|
17911
04141bd79ced
8015299: Memory leak in jdk/src/solaris/bin/java_md_solinux.c
jzavgren
parents:
14690
diff
changeset
|
554 |
JLI_MemFree(newargv); |
04141bd79ced
8015299: Memory leak in jdk/src/solaris/bin/java_md_solinux.c
jzavgren
parents:
14690
diff
changeset
|
555 |
JLI_MemFree(new_runpath); |
12047 | 556 |
return; |
557 |
} |
|
558 |
} |
|
559 |
||
560 |
/* |
|
561 |
* Place the desired environment setting onto the prefix of |
|
562 |
* LD_LIBRARY_PATH. Note that this prevents any possible infinite |
|
563 |
* loop of execv() because we test for the prefix, above. |
|
564 |
*/ |
|
565 |
if (runpath != 0) { |
|
566 |
JLI_StrCat(new_runpath, ":"); |
|
567 |
JLI_StrCat(new_runpath, runpath); |
|
568 |
} |
|
569 |
||
570 |
if (putenv(new_runpath) != 0) { |
|
571 |
exit(1); /* problem allocating memory; LD_LIBRARY_PATH not set |
|
572 |
properly */ |
|
573 |
} |
|
574 |
||
575 |
/* |
|
576 |
* Unix systems document that they look at LD_LIBRARY_PATH only |
|
577 |
* once at startup, so we have to re-exec the current executable |
|
578 |
* to get the changed environment variable to have an effect. |
|
579 |
*/ |
|
580 |
||
581 |
#ifdef __solaris__ |
|
582 |
/* |
|
583 |
* If dmpath is not NULL, remove the data model specific string |
|
584 |
* in the environment for the exec'ed child. |
|
585 |
*/ |
|
586 |
if (dmpath != NULL) |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
587 |
(void)UnsetEnv("LD_LIBRARY_PATH_64"); |
12047 | 588 |
#endif /* __solaris */ |
589 |
||
590 |
newenvp = environ; |
|
591 |
} |
|
592 |
#endif /* SETENV_REQUIRED */ |
|
593 |
{ |
|
594 |
char *newexec = execname; |
|
595 |
JLI_TraceLauncher("TRACER_MARKER:About to EXEC\n"); |
|
596 |
(void) fflush(stdout); |
|
597 |
(void) fflush(stderr); |
|
598 |
#ifdef SETENV_REQUIRED |
|
599 |
if (mustsetenv) { |
|
600 |
execve(newexec, argv, newenvp); |
|
601 |
} else { |
|
602 |
execv(newexec, argv); |
|
603 |
} |
|
604 |
#else /* !SETENV_REQUIRED */ |
|
605 |
execv(newexec, argv); |
|
606 |
#endif /* SETENV_REQUIRED */ |
|
607 |
JLI_ReportErrorMessageSys(JRE_ERROR4, newexec); |
|
608 |
} |
|
609 |
exit(1); |
|
610 |
} |
|
611 |
} |
|
612 |
||
613 |
/* |
|
614 |
* On Solaris VM choosing is done by the launcher (java.c), |
|
615 |
* bitsWanted is used by MacOSX, on Solaris and Linux this. |
|
616 |
* parameter is unused. |
|
617 |
*/ |
|
618 |
static jboolean |
|
619 |
GetJVMPath(const char *jrepath, const char *jvmtype, |
|
620 |
char *jvmpath, jint jvmpathsize, const char * arch, int bitsWanted) |
|
621 |
{ |
|
622 |
struct stat s; |
|
623 |
||
624 |
if (JLI_StrChr(jvmtype, '/')) { |
|
625 |
JLI_Snprintf(jvmpath, jvmpathsize, "%s/" JVM_DLL, jvmtype); |
|
626 |
} else { |
|
627 |
JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/%s/" JVM_DLL, jrepath, arch, jvmtype); |
|
628 |
} |
|
629 |
||
630 |
JLI_TraceLauncher("Does `%s' exist ... ", jvmpath); |
|
631 |
||
632 |
if (stat(jvmpath, &s) == 0) { |
|
633 |
JLI_TraceLauncher("yes.\n"); |
|
634 |
return JNI_TRUE; |
|
635 |
} else { |
|
636 |
JLI_TraceLauncher("no.\n"); |
|
637 |
return JNI_FALSE; |
|
638 |
} |
|
639 |
} |
|
640 |
||
641 |
/* |
|
642 |
* Find path to JRE based on .exe's location or registry settings. |
|
643 |
*/ |
|
644 |
static jboolean |
|
645 |
GetJREPath(char *path, jint pathsize, const char * arch, jboolean speculative) |
|
646 |
{ |
|
647 |
char libjava[MAXPATHLEN]; |
|
648 |
||
649 |
if (GetApplicationHome(path, pathsize)) { |
|
650 |
/* Is JRE co-located with the application? */ |
|
651 |
JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/%s/" JAVA_DLL, path, arch); |
|
652 |
if (access(libjava, F_OK) == 0) { |
|
653 |
JLI_TraceLauncher("JRE path is %s\n", path); |
|
654 |
return JNI_TRUE; |
|
655 |
} |
|
656 |
||
657 |
/* Does the app ship a private JRE in <apphome>/jre directory? */ |
|
658 |
JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/%s/" JAVA_DLL, path, arch); |
|
659 |
if (access(libjava, F_OK) == 0) { |
|
660 |
JLI_StrCat(path, "/jre"); |
|
661 |
JLI_TraceLauncher("JRE path is %s\n", path); |
|
662 |
return JNI_TRUE; |
|
663 |
} |
|
664 |
} |
|
665 |
||
666 |
if (!speculative) |
|
667 |
JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL); |
|
668 |
return JNI_FALSE; |
|
669 |
} |
|
670 |
||
671 |
jboolean |
|
672 |
LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn) |
|
673 |
{ |
|
674 |
void *libjvm; |
|
675 |
||
676 |
JLI_TraceLauncher("JVM path is %s\n", jvmpath); |
|
677 |
||
678 |
libjvm = dlopen(jvmpath, RTLD_NOW + RTLD_GLOBAL); |
|
679 |
if (libjvm == NULL) { |
|
680 |
#if defined(__solaris__) && defined(__sparc) && !defined(_LP64) /* i.e. 32-bit sparc */ |
|
681 |
FILE * fp; |
|
682 |
Elf32_Ehdr elf_head; |
|
683 |
int count; |
|
684 |
int location; |
|
685 |
||
686 |
fp = fopen(jvmpath, "r"); |
|
687 |
if (fp == NULL) { |
|
688 |
JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror()); |
|
689 |
return JNI_FALSE; |
|
690 |
} |
|
691 |
||
692 |
/* read in elf header */ |
|
693 |
count = fread((void*)(&elf_head), sizeof(Elf32_Ehdr), 1, fp); |
|
694 |
fclose(fp); |
|
695 |
if (count < 1) { |
|
696 |
JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror()); |
|
697 |
return JNI_FALSE; |
|
698 |
} |
|
699 |
||
700 |
/* |
|
701 |
* Check for running a server vm (compiled with -xarch=v8plus) |
|
702 |
* on a stock v8 processor. In this case, the machine type in |
|
703 |
* the elf header would not be included the architecture list |
|
704 |
* provided by the isalist command, which is turn is gotten from |
|
705 |
* sysinfo. This case cannot occur on 64-bit hardware and thus |
|
706 |
* does not have to be checked for in binaries with an LP64 data |
|
707 |
* model. |
|
708 |
*/ |
|
709 |
if (elf_head.e_machine == EM_SPARC32PLUS) { |
|
710 |
char buf[257]; /* recommended buffer size from sysinfo man |
|
711 |
page */ |
|
712 |
long length; |
|
713 |
char* location; |
|
714 |
||
715 |
length = sysinfo(SI_ISALIST, buf, 257); |
|
716 |
if (length > 0) { |
|
717 |
location = JLI_StrStr(buf, "sparcv8plus "); |
|
718 |
if (location == NULL) { |
|
719 |
JLI_ReportErrorMessage(JVM_ERROR3); |
|
720 |
return JNI_FALSE; |
|
721 |
} |
|
722 |
} |
|
723 |
} |
|
724 |
#endif |
|
725 |
JLI_ReportErrorMessage(DLL_ERROR1, __LINE__); |
|
726 |
JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror()); |
|
727 |
return JNI_FALSE; |
|
728 |
} |
|
729 |
||
730 |
ifn->CreateJavaVM = (CreateJavaVM_t) |
|
731 |
dlsym(libjvm, "JNI_CreateJavaVM"); |
|
732 |
if (ifn->CreateJavaVM == NULL) { |
|
733 |
JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror()); |
|
734 |
return JNI_FALSE; |
|
735 |
} |
|
736 |
||
737 |
ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t) |
|
738 |
dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs"); |
|
739 |
if (ifn->GetDefaultJavaVMInitArgs == NULL) { |
|
740 |
JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror()); |
|
741 |
return JNI_FALSE; |
|
742 |
} |
|
743 |
||
744 |
ifn->GetCreatedJavaVMs = (GetCreatedJavaVMs_t) |
|
745 |
dlsym(libjvm, "JNI_GetCreatedJavaVMs"); |
|
746 |
if (ifn->GetCreatedJavaVMs == NULL) { |
|
747 |
JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror()); |
|
748 |
return JNI_FALSE; |
|
749 |
} |
|
750 |
||
751 |
return JNI_TRUE; |
|
752 |
} |
|
753 |
||
754 |
/* |
|
755 |
* Compute the name of the executable |
|
756 |
* |
|
757 |
* In order to re-exec securely we need the absolute path of the |
|
758 |
* executable. On Solaris getexecname(3c) may not return an absolute |
|
759 |
* path so we use dladdr to get the filename of the executable and |
|
760 |
* then use realpath to derive an absolute path. From Solaris 9 |
|
761 |
* onwards the filename returned in DL_info structure from dladdr is |
|
762 |
* an absolute pathname so technically realpath isn't required. |
|
763 |
* On Linux we read the executable name from /proc/self/exe. |
|
764 |
* As a fallback, and for platforms other than Solaris and Linux, |
|
765 |
* we use FindExecName to compute the executable name. |
|
766 |
*/ |
|
767 |
const char* |
|
768 |
SetExecname(char **argv) |
|
769 |
{ |
|
770 |
char* exec_path = NULL; |
|
771 |
#if defined(__solaris__) |
|
772 |
{ |
|
773 |
Dl_info dlinfo; |
|
774 |
int (*fptr)(); |
|
775 |
||
776 |
fptr = (int (*)())dlsym(RTLD_DEFAULT, "main"); |
|
777 |
if (fptr == NULL) { |
|
778 |
JLI_ReportErrorMessage(DLL_ERROR3, dlerror()); |
|
779 |
return JNI_FALSE; |
|
780 |
} |
|
781 |
||
782 |
if (dladdr((void*)fptr, &dlinfo)) { |
|
783 |
char *resolved = (char*)JLI_MemAlloc(PATH_MAX+1); |
|
784 |
if (resolved != NULL) { |
|
785 |
exec_path = realpath(dlinfo.dli_fname, resolved); |
|
786 |
if (exec_path == NULL) { |
|
787 |
JLI_MemFree(resolved); |
|
788 |
} |
|
789 |
} |
|
790 |
} |
|
791 |
} |
|
792 |
#elif defined(__linux__) |
|
793 |
{ |
|
794 |
const char* self = "/proc/self/exe"; |
|
795 |
char buf[PATH_MAX+1]; |
|
796 |
int len = readlink(self, buf, PATH_MAX); |
|
797 |
if (len >= 0) { |
|
17911
04141bd79ced
8015299: Memory leak in jdk/src/solaris/bin/java_md_solinux.c
jzavgren
parents:
14690
diff
changeset
|
798 |
buf[len] = '\0'; /* readlink(2) doesn't NUL terminate */ |
12047 | 799 |
exec_path = JLI_StringDup(buf); |
800 |
} |
|
801 |
} |
|
802 |
#else /* !__solaris__ && !__linux__ */ |
|
803 |
{ |
|
804 |
/* Not implemented */ |
|
805 |
} |
|
806 |
#endif |
|
807 |
||
808 |
if (exec_path == NULL) { |
|
809 |
exec_path = FindExecName(argv[0]); |
|
810 |
} |
|
811 |
execname = exec_path; |
|
812 |
return exec_path; |
|
813 |
} |
|
814 |
||
815 |
/* --- Splash Screen shared library support --- */ |
|
816 |
static const char* SPLASHSCREEN_SO = JNI_LIB_NAME("splashscreen"); |
|
817 |
static void* hSplashLib = NULL; |
|
818 |
||
819 |
void* SplashProcAddress(const char* name) { |
|
820 |
if (!hSplashLib) { |
|
20842
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
821 |
int ret; |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
822 |
char jrePath[MAXPATHLEN]; |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
823 |
char splashPath[MAXPATHLEN]; |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
824 |
|
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
825 |
if (!GetJREPath(jrePath, sizeof(jrePath), LIBARCHNAME, JNI_FALSE)) { |
20842
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
826 |
JLI_ReportErrorMessage(JRE_ERROR1); |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
827 |
return NULL; |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
828 |
} |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
829 |
ret = JLI_Snprintf(splashPath, sizeof(splashPath), "%s/lib/%s/%s", |
22065
0b2684d4f49f
8024033: [launcher] remove solaris dual mode support
ksrini
parents:
20851
diff
changeset
|
830 |
jrePath, LIBARCHNAME, SPLASHSCREEN_SO); |
20842
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
831 |
|
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
832 |
if (ret >= (int) sizeof(splashPath)) { |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
833 |
JLI_ReportErrorMessage(JRE_ERROR11); |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
834 |
return NULL; |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
835 |
} |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
836 |
if (ret < 0) { |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
837 |
JLI_ReportErrorMessage(JRE_ERROR13); |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
838 |
return NULL; |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
839 |
} |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
840 |
hSplashLib = dlopen(splashPath, RTLD_LAZY | RTLD_GLOBAL); |
276a62b19d45
8021355: REGRESSION: Five closed/java/awt/SplashScreen tests fail since 7u45 b01 on Linux, Solaris
ksrini
parents:
17911
diff
changeset
|
841 |
JLI_TraceLauncher("Info: loaded %s\n", splashPath); |
12047 | 842 |
} |
843 |
if (hSplashLib) { |
|
844 |
void* sym = dlsym(hSplashLib, name); |
|
845 |
return sym; |
|
846 |
} else { |
|
847 |
return NULL; |
|
848 |
} |
|
849 |
} |
|
850 |
||
851 |
void SplashFreeLibrary() { |
|
852 |
if (hSplashLib) { |
|
853 |
dlclose(hSplashLib); |
|
854 |
hSplashLib = NULL; |
|
855 |
} |
|
856 |
} |
|
857 |
||
858 |
/* |
|
859 |
* Block current thread and continue execution in a new thread |
|
860 |
*/ |
|
861 |
int |
|
862 |
ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) { |
|
863 |
int rslt; |
|
864 |
#ifdef __linux__ |
|
865 |
pthread_t tid; |
|
866 |
pthread_attr_t attr; |
|
867 |
pthread_attr_init(&attr); |
|
868 |
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); |
|
869 |
||
870 |
if (stack_size > 0) { |
|
871 |
pthread_attr_setstacksize(&attr, stack_size); |
|
872 |
} |
|
873 |
||
874 |
if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) { |
|
875 |
void * tmp; |
|
876 |
pthread_join(tid, &tmp); |
|
877 |
rslt = (int)tmp; |
|
878 |
} else { |
|
879 |
/* |
|
880 |
* Continue execution in current thread if for some reason (e.g. out of |
|
881 |
* memory/LWP) a new thread can't be created. This will likely fail |
|
882 |
* later in continuation as JNI_CreateJavaVM needs to create quite a |
|
883 |
* few new threads, anyway, just give it a try.. |
|
884 |
*/ |
|
885 |
rslt = continuation(args); |
|
886 |
} |
|
887 |
||
888 |
pthread_attr_destroy(&attr); |
|
889 |
#else /* ! __linux__ */ |
|
890 |
thread_t tid; |
|
891 |
long flags = 0; |
|
892 |
if (thr_create(NULL, stack_size, (void *(*)(void *))continuation, args, flags, &tid) == 0) { |
|
893 |
void * tmp; |
|
894 |
thr_join(tid, NULL, &tmp); |
|
895 |
rslt = (int)tmp; |
|
896 |
} else { |
|
897 |
/* See above. Continue in current thread if thr_create() failed */ |
|
898 |
rslt = continuation(args); |
|
899 |
} |
|
900 |
#endif /* __linux__ */ |
|
901 |
return rslt; |
|
902 |
} |
|
903 |
||
904 |
/* Coarse estimation of number of digits assuming the worst case is a 64-bit pid. */ |
|
905 |
#define MAX_PID_STR_SZ 20 |
|
906 |
||
907 |
void SetJavaLauncherPlatformProps() { |
|
908 |
/* Linux only */ |
|
909 |
#ifdef __linux__ |
|
910 |
const char *substr = "-Dsun.java.launcher.pid="; |
|
911 |
char *pid_prop_str = (char *)JLI_MemAlloc(JLI_StrLen(substr) + MAX_PID_STR_SZ + 1); |
|
912 |
sprintf(pid_prop_str, "%s%d", substr, getpid()); |
|
913 |
AddOption(pid_prop_str, NULL); |
|
914 |
#endif /* __linux__ */ |
|
915 |
} |
|
916 |
||
917 |
int |
|
918 |
JVMInit(InvocationFunctions* ifn, jlong threadStackSize, |
|
919 |
int argc, char **argv, |
|
920 |
int mode, char *what, int ret) |
|
921 |
{ |
|
922 |
ShowSplashScreen(); |
|
923 |
return ContinueInNewThread(ifn, threadStackSize, argc, argv, mode, what, ret); |
|
924 |
} |
|
925 |
||
926 |
void |
|
927 |
PostJVMInit(JNIEnv *env, jstring mainClass, JavaVM *vm) |
|
928 |
{ |
|
929 |
// stubbed out for windows and *nixes. |
|
930 |
} |
|
931 |
||
932 |
void |
|
933 |
RegisterThread() |
|
934 |
{ |
|
935 |
// stubbed out for windows and *nixes. |
|
936 |
} |
|
937 |
||
938 |
/* |
|
939 |
* on unix, we return a false to indicate this option is not applicable |
|
940 |
*/ |
|
941 |
jboolean |
|
942 |
ProcessPlatformOption(const char *arg) |
|
943 |
{ |
|
944 |
return JNI_FALSE; |
|
945 |
} |