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