annotate src/os/solaris/launcher/java_md.c @ 470:ad8c8ca4ab0f jdk7-b42

6785258: Update copyright year Summary: Update copyright for files that have been modified starting July 2008 to Dec 2008 Reviewed-by: katleman, ohair, tbell
author xdono
date Mon, 15 Dec 2008 16:55:11 -0800
parents f008d3631bd1
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
470
ad8c8ca4ab0f 6785258: Update copyright year
xdono
parents: 388
diff changeset
2 * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
26 * Gamma (Hotspot internal engineering test) launcher based on 1.6.0-b28 JDK,
a61af66fc99e Initial load
duke
parents:
diff changeset
27 * search "GAMMA" for gamma specific changes.
a61af66fc99e Initial load
duke
parents:
diff changeset
28 */
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 #include "java.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
31 #include <dirent.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
32 #include <dlfcn.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
33 #include <fcntl.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
34 #include <inttypes.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
35 #include <stdio.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
36 #include <string.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
37 #include <stdlib.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
38 #include <limits.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
39 #include <sys/stat.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
40 #include <unistd.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
41 #include <sys/types.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 #ifndef GAMMA
a61af66fc99e Initial load
duke
parents:
diff changeset
44 #include "manifest_info.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
45 #include "version_comp.h"
a61af66fc99e Initial load
duke
parents:
diff changeset
46 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 #define JVM_DLL "libjvm.so"
a61af66fc99e Initial load
duke
parents:
diff changeset
49 #define JAVA_DLL "libjava.so"
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 #ifndef GAMMA /* launcher.make defines ARCH */
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
54 * If a processor / os combination has the ability to run binaries of
a61af66fc99e Initial load
duke
parents:
diff changeset
55 * two data models and cohabitation of jre/jdk bits with both data
a61af66fc99e Initial load
duke
parents:
diff changeset
56 * models is supported, then DUAL_MODE is defined. When DUAL_MODE is
a61af66fc99e Initial load
duke
parents:
diff changeset
57 * defined, the architecture names for the narrow and wide version of
a61af66fc99e Initial load
duke
parents:
diff changeset
58 * the architecture are defined in BIG_ARCH and SMALL_ARCH. Currently
a61af66fc99e Initial load
duke
parents:
diff changeset
59 * only Solaris on sparc/sparcv9 and i586/amd64 is DUAL_MODE; linux
a61af66fc99e Initial load
duke
parents:
diff changeset
60 * i586/amd64 could be defined as DUAL_MODE but that is not the
a61af66fc99e Initial load
duke
parents:
diff changeset
61 * current policy.
a61af66fc99e Initial load
duke
parents:
diff changeset
62 */
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 #ifdef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 # ifdef ia64
a61af66fc99e Initial load
duke
parents:
diff changeset
67 # define ARCH "ia64"
a61af66fc99e Initial load
duke
parents:
diff changeset
68 # elif defined(amd64)
a61af66fc99e Initial load
duke
parents:
diff changeset
69 # define ARCH "amd64"
a61af66fc99e Initial load
duke
parents:
diff changeset
70 # elif defined(__sparc)
a61af66fc99e Initial load
duke
parents:
diff changeset
71 # define ARCH "sparcv9"
a61af66fc99e Initial load
duke
parents:
diff changeset
72 # else
a61af66fc99e Initial load
duke
parents:
diff changeset
73 # define ARCH "unknown" /* unknown 64-bit architecture */
a61af66fc99e Initial load
duke
parents:
diff changeset
74 # endif
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 #else /* 32-bit data model */
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 # ifdef i586
a61af66fc99e Initial load
duke
parents:
diff changeset
79 # define ARCH "i386"
a61af66fc99e Initial load
duke
parents:
diff changeset
80 # elif defined(__sparc)
a61af66fc99e Initial load
duke
parents:
diff changeset
81 # define ARCH "sparc"
a61af66fc99e Initial load
duke
parents:
diff changeset
82 # endif
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 #endif /* _LP64 */
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 #ifdef __sun
a61af66fc99e Initial load
duke
parents:
diff changeset
87 # define DUAL_MODE
a61af66fc99e Initial load
duke
parents:
diff changeset
88 # ifdef __sparc
a61af66fc99e Initial load
duke
parents:
diff changeset
89 # define BIG_ARCH "sparcv9"
a61af66fc99e Initial load
duke
parents:
diff changeset
90 # define SMALL_ARCH "sparc"
a61af66fc99e Initial load
duke
parents:
diff changeset
91 # else
a61af66fc99e Initial load
duke
parents:
diff changeset
92 # define BIG_ARCH "amd64"
a61af66fc99e Initial load
duke
parents:
diff changeset
93 # define SMALL_ARCH "i386"
a61af66fc99e Initial load
duke
parents:
diff changeset
94 # endif
a61af66fc99e Initial load
duke
parents:
diff changeset
95 # include <sys/systeminfo.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
96 # include <sys/elf.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
97 # include <stdio.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
98 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
99 # ifndef ARCH
a61af66fc99e Initial load
duke
parents:
diff changeset
100 # include <sys/systeminfo.h>
a61af66fc99e Initial load
duke
parents:
diff changeset
101 # endif
a61af66fc99e Initial load
duke
parents:
diff changeset
102 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 #endif /* ifndef GAMMA */
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 /* pointer to environment */
a61af66fc99e Initial load
duke
parents:
diff changeset
107 extern char **environ;
a61af66fc99e Initial load
duke
parents:
diff changeset
108
a61af66fc99e Initial load
duke
parents:
diff changeset
109 #ifndef GAMMA
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
112 * A collection of useful strings. One should think of these as #define
a61af66fc99e Initial load
duke
parents:
diff changeset
113 * entries, but actual strings can be more efficient (with many compilers).
a61af66fc99e Initial load
duke
parents:
diff changeset
114 */
a61af66fc99e Initial load
duke
parents:
diff changeset
115 #ifdef __linux__
a61af66fc99e Initial load
duke
parents:
diff changeset
116 static const char *system_dir = "/usr/java";
a61af66fc99e Initial load
duke
parents:
diff changeset
117 static const char *user_dir = "/java";
a61af66fc99e Initial load
duke
parents:
diff changeset
118 #else /* Solaris */
a61af66fc99e Initial load
duke
parents:
diff changeset
119 static const char *system_dir = "/usr/jdk";
a61af66fc99e Initial load
duke
parents:
diff changeset
120 static const char *user_dir = "/jdk";
a61af66fc99e Initial load
duke
parents:
diff changeset
121 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 #endif /* ifndef GAMMA */
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
126 * Flowchart of launcher execs and options processing on unix
a61af66fc99e Initial load
duke
parents:
diff changeset
127 *
a61af66fc99e Initial load
duke
parents:
diff changeset
128 * The selection of the proper vm shared library to open depends on
a61af66fc99e Initial load
duke
parents:
diff changeset
129 * several classes of command line options, including vm "flavor"
a61af66fc99e Initial load
duke
parents:
diff changeset
130 * options (-client, -server) and the data model options, -d32 and
a61af66fc99e Initial load
duke
parents:
diff changeset
131 * -d64, as well as a version specification which may have come from
a61af66fc99e Initial load
duke
parents:
diff changeset
132 * the command line or from the manifest of an executable jar file.
a61af66fc99e Initial load
duke
parents:
diff changeset
133 * The vm selection options are not passed to the running
a61af66fc99e Initial load
duke
parents:
diff changeset
134 * virtual machine; they must be screened out by the launcher.
a61af66fc99e Initial load
duke
parents:
diff changeset
135 *
a61af66fc99e Initial load
duke
parents:
diff changeset
136 * The version specification (if any) is processed first by the
a61af66fc99e Initial load
duke
parents:
diff changeset
137 * platform independent routine SelectVersion. This may result in
a61af66fc99e Initial load
duke
parents:
diff changeset
138 * the exec of the specified launcher version.
a61af66fc99e Initial load
duke
parents:
diff changeset
139 *
a61af66fc99e Initial load
duke
parents:
diff changeset
140 * Typically, the launcher execs at least once to ensure a suitable
a61af66fc99e Initial load
duke
parents:
diff changeset
141 * LD_LIBRARY_PATH is in effect for the process. The first exec
a61af66fc99e Initial load
duke
parents:
diff changeset
142 * screens out all the data model options; leaving the choice of data
a61af66fc99e Initial load
duke
parents:
diff changeset
143 * model implicit in the binary selected to run. However, in case no
a61af66fc99e Initial load
duke
parents:
diff changeset
144 * exec is done, the data model options are screened out before the vm
a61af66fc99e Initial load
duke
parents:
diff changeset
145 * is invoked.
a61af66fc99e Initial load
duke
parents:
diff changeset
146 *
a61af66fc99e Initial load
duke
parents:
diff changeset
147 * incoming argv ------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
148 * | |
a61af66fc99e Initial load
duke
parents:
diff changeset
149 * \|/ |
a61af66fc99e Initial load
duke
parents:
diff changeset
150 * CheckJVMType |
a61af66fc99e Initial load
duke
parents:
diff changeset
151 * (removes -client, -server, etc.) |
a61af66fc99e Initial load
duke
parents:
diff changeset
152 * \|/
a61af66fc99e Initial load
duke
parents:
diff changeset
153 * CreateExecutionEnvironment
a61af66fc99e Initial load
duke
parents:
diff changeset
154 * (removes -d32 and -d64,
a61af66fc99e Initial load
duke
parents:
diff changeset
155 * determines desired data model,
a61af66fc99e Initial load
duke
parents:
diff changeset
156 * sets up LD_LIBRARY_PATH,
a61af66fc99e Initial load
duke
parents:
diff changeset
157 * and exec's)
a61af66fc99e Initial load
duke
parents:
diff changeset
158 * |
a61af66fc99e Initial load
duke
parents:
diff changeset
159 * --------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
160 * |
a61af66fc99e Initial load
duke
parents:
diff changeset
161 * \|/
a61af66fc99e Initial load
duke
parents:
diff changeset
162 * exec child 1 incoming argv -----------------
a61af66fc99e Initial load
duke
parents:
diff changeset
163 * | |
a61af66fc99e Initial load
duke
parents:
diff changeset
164 * \|/ |
a61af66fc99e Initial load
duke
parents:
diff changeset
165 * CheckJVMType |
a61af66fc99e Initial load
duke
parents:
diff changeset
166 * (removes -client, -server, etc.) |
a61af66fc99e Initial load
duke
parents:
diff changeset
167 * | \|/
a61af66fc99e Initial load
duke
parents:
diff changeset
168 * | CreateExecutionEnvironment
a61af66fc99e Initial load
duke
parents:
diff changeset
169 * | (verifies desired data model
a61af66fc99e Initial load
duke
parents:
diff changeset
170 * | is running and acceptable
a61af66fc99e Initial load
duke
parents:
diff changeset
171 * | LD_LIBRARY_PATH;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 * | no-op in child)
a61af66fc99e Initial load
duke
parents:
diff changeset
173 * |
a61af66fc99e Initial load
duke
parents:
diff changeset
174 * \|/
a61af66fc99e Initial load
duke
parents:
diff changeset
175 * TranslateDashJArgs...
a61af66fc99e Initial load
duke
parents:
diff changeset
176 * (Prepare to pass args to vm)
a61af66fc99e Initial load
duke
parents:
diff changeset
177 * |
a61af66fc99e Initial load
duke
parents:
diff changeset
178 * |
a61af66fc99e Initial load
duke
parents:
diff changeset
179 * |
a61af66fc99e Initial load
duke
parents:
diff changeset
180 * \|/
a61af66fc99e Initial load
duke
parents:
diff changeset
181 * ParseArguments
a61af66fc99e Initial load
duke
parents:
diff changeset
182 * (ignores -d32 and -d64,
a61af66fc99e Initial load
duke
parents:
diff changeset
183 * processes version options,
a61af66fc99e Initial load
duke
parents:
diff changeset
184 * creates argument list for vm,
a61af66fc99e Initial load
duke
parents:
diff changeset
185 * etc.)
a61af66fc99e Initial load
duke
parents:
diff changeset
186 *
a61af66fc99e Initial load
duke
parents:
diff changeset
187 */
a61af66fc99e Initial load
duke
parents:
diff changeset
188
a61af66fc99e Initial load
duke
parents:
diff changeset
189 static char *SetExecname(char **argv);
a61af66fc99e Initial load
duke
parents:
diff changeset
190 static char * GetExecname();
a61af66fc99e Initial load
duke
parents:
diff changeset
191 static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
a61af66fc99e Initial load
duke
parents:
diff changeset
192 char *jvmpath, jint jvmpathsize, char * arch);
a61af66fc99e Initial load
duke
parents:
diff changeset
193 static jboolean GetJREPath(char *path, jint pathsize, char * arch, jboolean speculative);
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 const char *
a61af66fc99e Initial load
duke
parents:
diff changeset
196 GetArch()
a61af66fc99e Initial load
duke
parents:
diff changeset
197 {
a61af66fc99e Initial load
duke
parents:
diff changeset
198 static char *arch = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 static char buf[12];
a61af66fc99e Initial load
duke
parents:
diff changeset
200 if (arch) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 return arch;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 #ifdef ARCH
a61af66fc99e Initial load
duke
parents:
diff changeset
205 strcpy(buf, ARCH);
a61af66fc99e Initial load
duke
parents:
diff changeset
206 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
207 sysinfo(SI_ARCHITECTURE, buf, sizeof(buf));
a61af66fc99e Initial load
duke
parents:
diff changeset
208 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
209 arch = buf;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 return arch;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 void
a61af66fc99e Initial load
duke
parents:
diff changeset
214 CreateExecutionEnvironment(int *_argcp,
a61af66fc99e Initial load
duke
parents:
diff changeset
215 char ***_argvp,
a61af66fc99e Initial load
duke
parents:
diff changeset
216 char jrepath[],
a61af66fc99e Initial load
duke
parents:
diff changeset
217 jint so_jrepath,
a61af66fc99e Initial load
duke
parents:
diff changeset
218 char jvmpath[],
a61af66fc99e Initial load
duke
parents:
diff changeset
219 jint so_jvmpath,
a61af66fc99e Initial load
duke
parents:
diff changeset
220 char **original_argv) {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
222 * First, determine if we are running the desired data model. If we
a61af66fc99e Initial load
duke
parents:
diff changeset
223 * are running the desired data model, all the error messages
a61af66fc99e Initial load
duke
parents:
diff changeset
224 * associated with calling GetJREPath, ReadKnownVMs, etc. should be
a61af66fc99e Initial load
duke
parents:
diff changeset
225 * output. However, if we are not running the desired data model,
a61af66fc99e Initial load
duke
parents:
diff changeset
226 * some of the errors should be suppressed since it is more
a61af66fc99e Initial load
duke
parents:
diff changeset
227 * informative to issue an error message based on whether or not the
a61af66fc99e Initial load
duke
parents:
diff changeset
228 * os/processor combination has dual mode capabilities.
a61af66fc99e Initial load
duke
parents:
diff changeset
229 */
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 char *execname = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 int original_argc = *_argcp;
a61af66fc99e Initial load
duke
parents:
diff changeset
233 jboolean jvmpathExists;
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 /* Compute the name of the executable */
a61af66fc99e Initial load
duke
parents:
diff changeset
236 execname = SetExecname(*_argvp);
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 #ifndef GAMMA
a61af66fc99e Initial load
duke
parents:
diff changeset
239 /* Set the LD_LIBRARY_PATH environment variable, check data model
a61af66fc99e Initial load
duke
parents:
diff changeset
240 flags, and exec process, if needed */
a61af66fc99e Initial load
duke
parents:
diff changeset
241 {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 char *arch = (char *)GetArch(); /* like sparc or sparcv9 */
a61af66fc99e Initial load
duke
parents:
diff changeset
243 char * jvmtype = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
244 int argc = *_argcp;
a61af66fc99e Initial load
duke
parents:
diff changeset
245 char **argv = original_argv;
a61af66fc99e Initial load
duke
parents:
diff changeset
246
a61af66fc99e Initial load
duke
parents:
diff changeset
247 char *runpath = NULL; /* existing effective LD_LIBRARY_PATH
a61af66fc99e Initial load
duke
parents:
diff changeset
248 setting */
a61af66fc99e Initial load
duke
parents:
diff changeset
249
a61af66fc99e Initial load
duke
parents:
diff changeset
250 int running = /* What data model is being ILP32 =>
a61af66fc99e Initial load
duke
parents:
diff changeset
251 32 bit vm; LP64 => 64 bit vm */
a61af66fc99e Initial load
duke
parents:
diff changeset
252 #ifdef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
253 64;
a61af66fc99e Initial load
duke
parents:
diff changeset
254 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
255 32;
a61af66fc99e Initial load
duke
parents:
diff changeset
256 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
257
a61af66fc99e Initial load
duke
parents:
diff changeset
258 int wanted = running; /* What data mode is being
a61af66fc99e Initial load
duke
parents:
diff changeset
259 asked for? Current model is
a61af66fc99e Initial load
duke
parents:
diff changeset
260 fine unless another model
a61af66fc99e Initial load
duke
parents:
diff changeset
261 is asked for */
a61af66fc99e Initial load
duke
parents:
diff changeset
262
a61af66fc99e Initial load
duke
parents:
diff changeset
263 char* new_runpath = NULL; /* desired new LD_LIBRARY_PATH string */
a61af66fc99e Initial load
duke
parents:
diff changeset
264 char* newpath = NULL; /* path on new LD_LIBRARY_PATH */
a61af66fc99e Initial load
duke
parents:
diff changeset
265 char* lastslash = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 char** newenvp = NULL; /* current environment */
a61af66fc99e Initial load
duke
parents:
diff changeset
268
a61af66fc99e Initial load
duke
parents:
diff changeset
269 char** newargv = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
270 int newargc = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
271 #ifdef __sun
a61af66fc99e Initial load
duke
parents:
diff changeset
272 char* dmpath = NULL; /* data model specific LD_LIBRARY_PATH,
a61af66fc99e Initial load
duke
parents:
diff changeset
273 Solaris only */
a61af66fc99e Initial load
duke
parents:
diff changeset
274 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
275
a61af66fc99e Initial load
duke
parents:
diff changeset
276 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
277 * Starting in 1.5, all unix platforms accept the -d32 and -d64
a61af66fc99e Initial load
duke
parents:
diff changeset
278 * options. On platforms where only one data-model is supported
a61af66fc99e Initial load
duke
parents:
diff changeset
279 * (e.g. ia-64 Linux), using the flag for the other data model is
a61af66fc99e Initial load
duke
parents:
diff changeset
280 * an error and will terminate the program.
a61af66fc99e Initial load
duke
parents:
diff changeset
281 */
a61af66fc99e Initial load
duke
parents:
diff changeset
282
a61af66fc99e Initial load
duke
parents:
diff changeset
283 { /* open new scope to declare local variables */
a61af66fc99e Initial load
duke
parents:
diff changeset
284 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 newargv = (char **)MemAlloc((argc+1) * sizeof(*newargv));
a61af66fc99e Initial load
duke
parents:
diff changeset
287 newargv[newargc++] = argv[0];
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 /* scan for data model arguments and remove from argument list;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 last occurrence determines desired data model */
a61af66fc99e Initial load
duke
parents:
diff changeset
291 for (i=1; i < argc; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292
a61af66fc99e Initial load
duke
parents:
diff changeset
293 if (strcmp(argv[i], "-J-d64") == 0 || strcmp(argv[i], "-d64") == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
294 wanted = 64;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297 if (strcmp(argv[i], "-J-d32") == 0 || strcmp(argv[i], "-d32") == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
298 wanted = 32;
a61af66fc99e Initial load
duke
parents:
diff changeset
299 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301 newargv[newargc++] = argv[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 #ifdef JAVA_ARGS
a61af66fc99e Initial load
duke
parents:
diff changeset
304 if (argv[i][0] != '-')
a61af66fc99e Initial load
duke
parents:
diff changeset
305 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
307 if (strcmp(argv[i], "-classpath") == 0 || strcmp(argv[i], "-cp") == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 i++;
a61af66fc99e Initial load
duke
parents:
diff changeset
309 if (i >= argc) break;
a61af66fc99e Initial load
duke
parents:
diff changeset
310 newargv[newargc++] = argv[i];
a61af66fc99e Initial load
duke
parents:
diff changeset
311 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
313 if (argv[i][0] != '-') { i++; break; }
a61af66fc99e Initial load
duke
parents:
diff changeset
314 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
315 }
a61af66fc99e Initial load
duke
parents:
diff changeset
316
a61af66fc99e Initial load
duke
parents:
diff changeset
317 /* copy rest of args [i .. argc) */
a61af66fc99e Initial load
duke
parents:
diff changeset
318 while (i < argc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
319 newargv[newargc++] = argv[i++];
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321 newargv[newargc] = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
322
a61af66fc99e Initial load
duke
parents:
diff changeset
323 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
324 * newargv has all proper arguments here
a61af66fc99e Initial load
duke
parents:
diff changeset
325 */
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 argc = newargc;
a61af66fc99e Initial load
duke
parents:
diff changeset
328 argv = newargv;
a61af66fc99e Initial load
duke
parents:
diff changeset
329 }
a61af66fc99e Initial load
duke
parents:
diff changeset
330
a61af66fc99e Initial load
duke
parents:
diff changeset
331 /* If the data model is not changing, it is an error if the
a61af66fc99e Initial load
duke
parents:
diff changeset
332 jvmpath does not exist */
a61af66fc99e Initial load
duke
parents:
diff changeset
333 if (wanted == running) {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 /* Find out where the JRE is that we will be using. */
a61af66fc99e Initial load
duke
parents:
diff changeset
335 if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
336 fprintf(stderr, "Error: could not find Java 2 Runtime Environment.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
337 exit(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
338 }
a61af66fc99e Initial load
duke
parents:
diff changeset
339
a61af66fc99e Initial load
duke
parents:
diff changeset
340 /* Find the specified JVM type */
a61af66fc99e Initial load
duke
parents:
diff changeset
341 if (ReadKnownVMs(jrepath, arch, JNI_FALSE) < 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
342 fprintf(stderr, "Error: no known VMs. (check for corrupt jvm.cfg file)\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
343 exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
344 }
a61af66fc99e Initial load
duke
parents:
diff changeset
345
a61af66fc99e Initial load
duke
parents:
diff changeset
346 jvmpath[0] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
347 jvmtype = CheckJvmType(_argcp, _argvp, JNI_FALSE);
a61af66fc99e Initial load
duke
parents:
diff changeset
348
a61af66fc99e Initial load
duke
parents:
diff changeset
349 if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath, arch )) {
a61af66fc99e Initial load
duke
parents:
diff changeset
350 fprintf(stderr, "Error: no `%s' JVM at `%s'.\n", jvmtype, jvmpath);
a61af66fc99e Initial load
duke
parents:
diff changeset
351 exit(4);
a61af66fc99e Initial load
duke
parents:
diff changeset
352 }
a61af66fc99e Initial load
duke
parents:
diff changeset
353 } else { /* do the same speculatively or exit */
a61af66fc99e Initial load
duke
parents:
diff changeset
354 #ifdef DUAL_MODE
a61af66fc99e Initial load
duke
parents:
diff changeset
355 if (running != wanted) {
a61af66fc99e Initial load
duke
parents:
diff changeset
356 /* Find out where the JRE is that we will be using. */
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if (!GetJREPath(jrepath, so_jrepath, ((wanted==64)?BIG_ARCH:SMALL_ARCH), JNI_TRUE)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 goto EndDataModelSpeculate;
a61af66fc99e Initial load
duke
parents:
diff changeset
359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
360
a61af66fc99e Initial load
duke
parents:
diff changeset
361 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
362 * Read in jvm.cfg for target data model and process vm
a61af66fc99e Initial load
duke
parents:
diff changeset
363 * selection options.
a61af66fc99e Initial load
duke
parents:
diff changeset
364 */
a61af66fc99e Initial load
duke
parents:
diff changeset
365 if (ReadKnownVMs(jrepath, ((wanted==64)?BIG_ARCH:SMALL_ARCH), JNI_TRUE) < 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
366 goto EndDataModelSpeculate;
a61af66fc99e Initial load
duke
parents:
diff changeset
367 }
a61af66fc99e Initial load
duke
parents:
diff changeset
368 jvmpath[0] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
369 jvmtype = CheckJvmType(_argcp, _argvp, JNI_TRUE);
a61af66fc99e Initial load
duke
parents:
diff changeset
370 /* exec child can do error checking on the existence of the path */
a61af66fc99e Initial load
duke
parents:
diff changeset
371 jvmpathExists = GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath,
a61af66fc99e Initial load
duke
parents:
diff changeset
372 ((wanted==64)?BIG_ARCH:SMALL_ARCH));
a61af66fc99e Initial load
duke
parents:
diff changeset
373
a61af66fc99e Initial load
duke
parents:
diff changeset
374 }
a61af66fc99e Initial load
duke
parents:
diff changeset
375 EndDataModelSpeculate: /* give up and let other code report error message */
a61af66fc99e Initial load
duke
parents:
diff changeset
376 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
377 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
378 fprintf(stderr, "Running a %d-bit JVM is not supported on this platform.\n", wanted);
a61af66fc99e Initial load
duke
parents:
diff changeset
379 exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
380 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
381 }
a61af66fc99e Initial load
duke
parents:
diff changeset
382
a61af66fc99e Initial load
duke
parents:
diff changeset
383 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
384 * We will set the LD_LIBRARY_PATH as follows:
a61af66fc99e Initial load
duke
parents:
diff changeset
385 *
a61af66fc99e Initial load
duke
parents:
diff changeset
386 * o $JVMPATH (directory portion only)
a61af66fc99e Initial load
duke
parents:
diff changeset
387 * o $JRE/lib/$ARCH
a61af66fc99e Initial load
duke
parents:
diff changeset
388 * o $JRE/../lib/$ARCH
a61af66fc99e Initial load
duke
parents:
diff changeset
389 *
a61af66fc99e Initial load
duke
parents:
diff changeset
390 * followed by the user's previous effective LD_LIBRARY_PATH, if
a61af66fc99e Initial load
duke
parents:
diff changeset
391 * any.
a61af66fc99e Initial load
duke
parents:
diff changeset
392 */
a61af66fc99e Initial load
duke
parents:
diff changeset
393
a61af66fc99e Initial load
duke
parents:
diff changeset
394 #ifdef __sun
a61af66fc99e Initial load
duke
parents:
diff changeset
395 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
396 * Starting in Solaris 7, ld.so.1 supports three LD_LIBRARY_PATH
a61af66fc99e Initial load
duke
parents:
diff changeset
397 * variables:
a61af66fc99e Initial load
duke
parents:
diff changeset
398 *
a61af66fc99e Initial load
duke
parents:
diff changeset
399 * 1. LD_LIBRARY_PATH -- used for 32 and 64 bit searches if
a61af66fc99e Initial load
duke
parents:
diff changeset
400 * data-model specific variables are not set.
a61af66fc99e Initial load
duke
parents:
diff changeset
401 *
a61af66fc99e Initial load
duke
parents:
diff changeset
402 * 2. LD_LIBRARY_PATH_64 -- overrides and replaces LD_LIBRARY_PATH
a61af66fc99e Initial load
duke
parents:
diff changeset
403 * for 64-bit binaries.
a61af66fc99e Initial load
duke
parents:
diff changeset
404 *
a61af66fc99e Initial load
duke
parents:
diff changeset
405 * 3. LD_LIBRARY_PATH_32 -- overrides and replaces LD_LIBRARY_PATH
a61af66fc99e Initial load
duke
parents:
diff changeset
406 * for 32-bit binaries.
a61af66fc99e Initial load
duke
parents:
diff changeset
407 *
a61af66fc99e Initial load
duke
parents:
diff changeset
408 * The vm uses LD_LIBRARY_PATH to set the java.library.path system
a61af66fc99e Initial load
duke
parents:
diff changeset
409 * property. To shield the vm from the complication of multiple
a61af66fc99e Initial load
duke
parents:
diff changeset
410 * LD_LIBRARY_PATH variables, if the appropriate data model
a61af66fc99e Initial load
duke
parents:
diff changeset
411 * specific variable is set, we will act as if LD_LIBRARY_PATH had
a61af66fc99e Initial load
duke
parents:
diff changeset
412 * the value of the data model specific variant and the data model
a61af66fc99e Initial load
duke
parents:
diff changeset
413 * specific variant will be unset. Note that the variable for the
a61af66fc99e Initial load
duke
parents:
diff changeset
414 * *wanted* data model must be used (if it is set), not simply the
a61af66fc99e Initial load
duke
parents:
diff changeset
415 * current running data model.
a61af66fc99e Initial load
duke
parents:
diff changeset
416 */
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418 switch(wanted) {
a61af66fc99e Initial load
duke
parents:
diff changeset
419 case 0:
a61af66fc99e Initial load
duke
parents:
diff changeset
420 if(running == 32) {
a61af66fc99e Initial load
duke
parents:
diff changeset
421 dmpath = getenv("LD_LIBRARY_PATH_32");
a61af66fc99e Initial load
duke
parents:
diff changeset
422 wanted = 32;
a61af66fc99e Initial load
duke
parents:
diff changeset
423 }
a61af66fc99e Initial load
duke
parents:
diff changeset
424 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
425 dmpath = getenv("LD_LIBRARY_PATH_64");
a61af66fc99e Initial load
duke
parents:
diff changeset
426 wanted = 64;
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
429
a61af66fc99e Initial load
duke
parents:
diff changeset
430 case 32:
a61af66fc99e Initial load
duke
parents:
diff changeset
431 dmpath = getenv("LD_LIBRARY_PATH_32");
a61af66fc99e Initial load
duke
parents:
diff changeset
432 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
433
a61af66fc99e Initial load
duke
parents:
diff changeset
434 case 64:
a61af66fc99e Initial load
duke
parents:
diff changeset
435 dmpath = getenv("LD_LIBRARY_PATH_64");
a61af66fc99e Initial load
duke
parents:
diff changeset
436 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
437
a61af66fc99e Initial load
duke
parents:
diff changeset
438 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
439 fprintf(stderr, "Improper value at line %d.", __LINE__);
a61af66fc99e Initial load
duke
parents:
diff changeset
440 exit(1); /* unknown value in wanted */
a61af66fc99e Initial load
duke
parents:
diff changeset
441 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
442 }
a61af66fc99e Initial load
duke
parents:
diff changeset
443
a61af66fc99e Initial load
duke
parents:
diff changeset
444 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
445 * If dmpath is NULL, the relevant data model specific variable is
a61af66fc99e Initial load
duke
parents:
diff changeset
446 * not set and normal LD_LIBRARY_PATH should be used.
a61af66fc99e Initial load
duke
parents:
diff changeset
447 */
a61af66fc99e Initial load
duke
parents:
diff changeset
448 if( dmpath == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
449 runpath = getenv("LD_LIBRARY_PATH");
a61af66fc99e Initial load
duke
parents:
diff changeset
450 }
a61af66fc99e Initial load
duke
parents:
diff changeset
451 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
452 runpath = dmpath;
a61af66fc99e Initial load
duke
parents:
diff changeset
453 }
a61af66fc99e Initial load
duke
parents:
diff changeset
454 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
455 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
456 * If not on Solaris, assume only a single LD_LIBRARY_PATH
a61af66fc99e Initial load
duke
parents:
diff changeset
457 * variable.
a61af66fc99e Initial load
duke
parents:
diff changeset
458 */
a61af66fc99e Initial load
duke
parents:
diff changeset
459 runpath = getenv("LD_LIBRARY_PATH");
a61af66fc99e Initial load
duke
parents:
diff changeset
460 #endif /* __sun */
a61af66fc99e Initial load
duke
parents:
diff changeset
461
a61af66fc99e Initial load
duke
parents:
diff changeset
462 #ifdef __linux
a61af66fc99e Initial load
duke
parents:
diff changeset
463 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
464 * On linux, if a binary is running as sgid or suid, glibc sets
a61af66fc99e Initial load
duke
parents:
diff changeset
465 * LD_LIBRARY_PATH to the empty string for security purposes. (In
a61af66fc99e Initial load
duke
parents:
diff changeset
466 * contrast, on Solaris the LD_LIBRARY_PATH variable for a
a61af66fc99e Initial load
duke
parents:
diff changeset
467 * privileged binary does not lose its settings; but the dynamic
a61af66fc99e Initial load
duke
parents:
diff changeset
468 * linker does apply more scrutiny to the path.) The launcher uses
a61af66fc99e Initial load
duke
parents:
diff changeset
469 * the value of LD_LIBRARY_PATH to prevent an exec loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
470 * Therefore, if we are running sgid or suid, this function's
a61af66fc99e Initial load
duke
parents:
diff changeset
471 * setting of LD_LIBRARY_PATH will be ineffective and we should
a61af66fc99e Initial load
duke
parents:
diff changeset
472 * return from the function now. Getting the right libraries to
a61af66fc99e Initial load
duke
parents:
diff changeset
473 * be found must be handled through other mechanisms.
a61af66fc99e Initial load
duke
parents:
diff changeset
474 */
a61af66fc99e Initial load
duke
parents:
diff changeset
475 if((getgid() != getegid()) || (getuid() != geteuid()) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
476 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
477 }
a61af66fc99e Initial load
duke
parents:
diff changeset
478 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
479
a61af66fc99e Initial load
duke
parents:
diff changeset
480 /* runpath contains current effective LD_LIBRARY_PATH setting */
a61af66fc99e Initial load
duke
parents:
diff changeset
481
a61af66fc99e Initial load
duke
parents:
diff changeset
482 jvmpath = strdup(jvmpath);
a61af66fc99e Initial load
duke
parents:
diff changeset
483 new_runpath = MemAlloc( ((runpath!=NULL)?strlen(runpath):0) +
a61af66fc99e Initial load
duke
parents:
diff changeset
484 2*strlen(jrepath) + 2*strlen(arch) +
a61af66fc99e Initial load
duke
parents:
diff changeset
485 strlen(jvmpath) + 52);
a61af66fc99e Initial load
duke
parents:
diff changeset
486 newpath = new_runpath + strlen("LD_LIBRARY_PATH=");
a61af66fc99e Initial load
duke
parents:
diff changeset
487
a61af66fc99e Initial load
duke
parents:
diff changeset
488
a61af66fc99e Initial load
duke
parents:
diff changeset
489 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
490 * Create desired LD_LIBRARY_PATH value for target data model.
a61af66fc99e Initial load
duke
parents:
diff changeset
491 */
a61af66fc99e Initial load
duke
parents:
diff changeset
492 {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 /* remove the name of the .so from the JVM path */
a61af66fc99e Initial load
duke
parents:
diff changeset
494 lastslash = strrchr(jvmpath, '/');
a61af66fc99e Initial load
duke
parents:
diff changeset
495 if (lastslash)
a61af66fc99e Initial load
duke
parents:
diff changeset
496 *lastslash = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
497
a61af66fc99e Initial load
duke
parents:
diff changeset
498
a61af66fc99e Initial load
duke
parents:
diff changeset
499 /* jvmpath, ((running != wanted)?((wanted==64)?"/"BIG_ARCH:"/.."):""), */
a61af66fc99e Initial load
duke
parents:
diff changeset
500
a61af66fc99e Initial load
duke
parents:
diff changeset
501 sprintf(new_runpath, "LD_LIBRARY_PATH="
a61af66fc99e Initial load
duke
parents:
diff changeset
502 "%s:"
a61af66fc99e Initial load
duke
parents:
diff changeset
503 "%s/lib/%s:"
a61af66fc99e Initial load
duke
parents:
diff changeset
504 "%s/../lib/%s",
a61af66fc99e Initial load
duke
parents:
diff changeset
505 jvmpath,
a61af66fc99e Initial load
duke
parents:
diff changeset
506 #ifdef DUAL_MODE
a61af66fc99e Initial load
duke
parents:
diff changeset
507 jrepath, ((wanted==64)?BIG_ARCH:SMALL_ARCH),
a61af66fc99e Initial load
duke
parents:
diff changeset
508 jrepath, ((wanted==64)?BIG_ARCH:SMALL_ARCH)
a61af66fc99e Initial load
duke
parents:
diff changeset
509 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
510 jrepath, arch,
a61af66fc99e Initial load
duke
parents:
diff changeset
511 jrepath, arch
a61af66fc99e Initial load
duke
parents:
diff changeset
512 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
513 );
a61af66fc99e Initial load
duke
parents:
diff changeset
514
a61af66fc99e Initial load
duke
parents:
diff changeset
515
a61af66fc99e Initial load
duke
parents:
diff changeset
516 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
517 * Check to make sure that the prefix of the current path is the
a61af66fc99e Initial load
duke
parents:
diff changeset
518 * desired environment variable setting.
a61af66fc99e Initial load
duke
parents:
diff changeset
519 */
a61af66fc99e Initial load
duke
parents:
diff changeset
520 if (runpath != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
521 strncmp(newpath, runpath, strlen(newpath))==0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
522 (runpath[strlen(newpath)] == 0 || runpath[strlen(newpath)] == ':') &&
a61af66fc99e Initial load
duke
parents:
diff changeset
523 (running == wanted) /* data model does not have to be changed */
a61af66fc99e Initial load
duke
parents:
diff changeset
524 #ifdef __sun
a61af66fc99e Initial load
duke
parents:
diff changeset
525 && (dmpath == NULL) /* data model specific variables not set */
a61af66fc99e Initial load
duke
parents:
diff changeset
526 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
527 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
528
a61af66fc99e Initial load
duke
parents:
diff changeset
529 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
530
a61af66fc99e Initial load
duke
parents:
diff changeset
531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
532 }
a61af66fc99e Initial load
duke
parents:
diff changeset
533
a61af66fc99e Initial load
duke
parents:
diff changeset
534 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
535 * Place the desired environment setting onto the prefix of
a61af66fc99e Initial load
duke
parents:
diff changeset
536 * LD_LIBRARY_PATH. Note that this prevents any possible infinite
a61af66fc99e Initial load
duke
parents:
diff changeset
537 * loop of execv() because we test for the prefix, above.
a61af66fc99e Initial load
duke
parents:
diff changeset
538 */
a61af66fc99e Initial load
duke
parents:
diff changeset
539 if (runpath != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
540 strcat(new_runpath, ":");
a61af66fc99e Initial load
duke
parents:
diff changeset
541 strcat(new_runpath, runpath);
a61af66fc99e Initial load
duke
parents:
diff changeset
542 }
a61af66fc99e Initial load
duke
parents:
diff changeset
543
a61af66fc99e Initial load
duke
parents:
diff changeset
544 if( putenv(new_runpath) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
545 exit(1); /* problem allocating memory; LD_LIBRARY_PATH not set
a61af66fc99e Initial load
duke
parents:
diff changeset
546 properly */
a61af66fc99e Initial load
duke
parents:
diff changeset
547 }
a61af66fc99e Initial load
duke
parents:
diff changeset
548
a61af66fc99e Initial load
duke
parents:
diff changeset
549 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
550 * Unix systems document that they look at LD_LIBRARY_PATH only
a61af66fc99e Initial load
duke
parents:
diff changeset
551 * once at startup, so we have to re-exec the current executable
a61af66fc99e Initial load
duke
parents:
diff changeset
552 * to get the changed environment variable to have an effect.
a61af66fc99e Initial load
duke
parents:
diff changeset
553 */
a61af66fc99e Initial load
duke
parents:
diff changeset
554
a61af66fc99e Initial load
duke
parents:
diff changeset
555 #ifdef __sun
a61af66fc99e Initial load
duke
parents:
diff changeset
556 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
557 * If dmpath is not NULL, remove the data model specific string
a61af66fc99e Initial load
duke
parents:
diff changeset
558 * in the environment for the exec'ed child.
a61af66fc99e Initial load
duke
parents:
diff changeset
559 */
a61af66fc99e Initial load
duke
parents:
diff changeset
560
a61af66fc99e Initial load
duke
parents:
diff changeset
561 if( dmpath != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
562 (void)UnsetEnv((wanted==32)?"LD_LIBRARY_PATH_32":"LD_LIBRARY_PATH_64");
a61af66fc99e Initial load
duke
parents:
diff changeset
563 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
564
a61af66fc99e Initial load
duke
parents:
diff changeset
565 newenvp = environ;
a61af66fc99e Initial load
duke
parents:
diff changeset
566
a61af66fc99e Initial load
duke
parents:
diff changeset
567 {
a61af66fc99e Initial load
duke
parents:
diff changeset
568 char *newexec = execname;
a61af66fc99e Initial load
duke
parents:
diff changeset
569 #ifdef DUAL_MODE
a61af66fc99e Initial load
duke
parents:
diff changeset
570 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
571 * If the data model is being changed, the path to the
a61af66fc99e Initial load
duke
parents:
diff changeset
572 * executable must be updated accordingly; the executable name
a61af66fc99e Initial load
duke
parents:
diff changeset
573 * and directory the executable resides in are separate. In the
a61af66fc99e Initial load
duke
parents:
diff changeset
574 * case of 32 => 64, the new bits are assumed to reside in, e.g.
a61af66fc99e Initial load
duke
parents:
diff changeset
575 * "olddir/BIGARCH/execname"; in the case of 64 => 32,
a61af66fc99e Initial load
duke
parents:
diff changeset
576 * the bits are assumed to be in "olddir/../execname". For example,
a61af66fc99e Initial load
duke
parents:
diff changeset
577 *
a61af66fc99e Initial load
duke
parents:
diff changeset
578 * olddir/sparcv9/execname
a61af66fc99e Initial load
duke
parents:
diff changeset
579 * olddir/amd64/execname
a61af66fc99e Initial load
duke
parents:
diff changeset
580 *
a61af66fc99e Initial load
duke
parents:
diff changeset
581 * for Solaris SPARC and Linux amd64, respectively.
a61af66fc99e Initial load
duke
parents:
diff changeset
582 */
a61af66fc99e Initial load
duke
parents:
diff changeset
583
a61af66fc99e Initial load
duke
parents:
diff changeset
584 if (running != wanted) {
a61af66fc99e Initial load
duke
parents:
diff changeset
585 char *oldexec = strcpy(MemAlloc(strlen(execname) + 1), execname);
a61af66fc99e Initial load
duke
parents:
diff changeset
586 char *olddir = oldexec;
a61af66fc99e Initial load
duke
parents:
diff changeset
587 char *oldbase = strrchr(oldexec, '/');
a61af66fc99e Initial load
duke
parents:
diff changeset
588
a61af66fc99e Initial load
duke
parents:
diff changeset
589
a61af66fc99e Initial load
duke
parents:
diff changeset
590 newexec = MemAlloc(strlen(execname) + 20);
a61af66fc99e Initial load
duke
parents:
diff changeset
591 *oldbase++ = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
592 sprintf(newexec, "%s/%s/%s", olddir,
a61af66fc99e Initial load
duke
parents:
diff changeset
593 ((wanted==64) ? BIG_ARCH : ".."), oldbase);
a61af66fc99e Initial load
duke
parents:
diff changeset
594 argv[0] = newexec;
a61af66fc99e Initial load
duke
parents:
diff changeset
595 }
a61af66fc99e Initial load
duke
parents:
diff changeset
596 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
597
a61af66fc99e Initial load
duke
parents:
diff changeset
598 execve(newexec, argv, newenvp);
a61af66fc99e Initial load
duke
parents:
diff changeset
599 perror("execve()");
a61af66fc99e Initial load
duke
parents:
diff changeset
600
a61af66fc99e Initial load
duke
parents:
diff changeset
601 fprintf(stderr, "Error trying to exec %s.\n", newexec);
a61af66fc99e Initial load
duke
parents:
diff changeset
602 fprintf(stderr, "Check if file exists and permissions are set correctly.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
603
a61af66fc99e Initial load
duke
parents:
diff changeset
604 #ifdef DUAL_MODE
a61af66fc99e Initial load
duke
parents:
diff changeset
605 if (running != wanted) {
a61af66fc99e Initial load
duke
parents:
diff changeset
606 fprintf(stderr, "Failed to start a %d-bit JVM process from a %d-bit JVM.\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
607 wanted, running);
a61af66fc99e Initial load
duke
parents:
diff changeset
608 # ifdef __sun
a61af66fc99e Initial load
duke
parents:
diff changeset
609
a61af66fc99e Initial load
duke
parents:
diff changeset
610 # ifdef __sparc
a61af66fc99e Initial load
duke
parents:
diff changeset
611 fprintf(stderr, "Verify all necessary J2SE components have been installed.\n" );
a61af66fc99e Initial load
duke
parents:
diff changeset
612 fprintf(stderr,
a61af66fc99e Initial load
duke
parents:
diff changeset
613 "(Solaris SPARC 64-bit components must be installed after 32-bit components.)\n" );
a61af66fc99e Initial load
duke
parents:
diff changeset
614 # else
a61af66fc99e Initial load
duke
parents:
diff changeset
615 fprintf(stderr, "Either 64-bit processes are not supported by this platform\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
616 fprintf(stderr, "or the 64-bit components have not been installed.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
617 # endif
a61af66fc99e Initial load
duke
parents:
diff changeset
618 }
a61af66fc99e Initial load
duke
parents:
diff changeset
619 # endif
a61af66fc99e Initial load
duke
parents:
diff changeset
620 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
621
a61af66fc99e Initial load
duke
parents:
diff changeset
622 }
a61af66fc99e Initial load
duke
parents:
diff changeset
623
a61af66fc99e Initial load
duke
parents:
diff changeset
624 exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
625 }
a61af66fc99e Initial load
duke
parents:
diff changeset
626
a61af66fc99e Initial load
duke
parents:
diff changeset
627 #else /* ifndef GAMMA */
a61af66fc99e Initial load
duke
parents:
diff changeset
628
a61af66fc99e Initial load
duke
parents:
diff changeset
629 /* gamma launcher is simpler in that it doesn't handle VM flavors, data */
a61af66fc99e Initial load
duke
parents:
diff changeset
630 /* model, LD_LIBRARY_PATH, etc. Assuming everything is set-up correctly */
a61af66fc99e Initial load
duke
parents:
diff changeset
631 /* all we need to do here is to return correct path names. See also */
a61af66fc99e Initial load
duke
parents:
diff changeset
632 /* GetJVMPath() and GetApplicationHome(). */
a61af66fc99e Initial load
duke
parents:
diff changeset
633
a61af66fc99e Initial load
duke
parents:
diff changeset
634 { char *arch = (char *)GetArch(); /* like sparc or sparcv9 */
a61af66fc99e Initial load
duke
parents:
diff changeset
635 char *p;
a61af66fc99e Initial load
duke
parents:
diff changeset
636
a61af66fc99e Initial load
duke
parents:
diff changeset
637 if (!GetJREPath(jrepath, so_jrepath, arch, JNI_FALSE) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
638 fprintf(stderr, "Error: could not find Java 2 Runtime Environment.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
639 exit(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
640 }
a61af66fc99e Initial load
duke
parents:
diff changeset
641
a61af66fc99e Initial load
duke
parents:
diff changeset
642 if (!GetJVMPath(jrepath, NULL, jvmpath, so_jvmpath, arch )) {
a61af66fc99e Initial load
duke
parents:
diff changeset
643 fprintf(stderr, "Error: no JVM at `%s'.\n", jvmpath);
a61af66fc99e Initial load
duke
parents:
diff changeset
644 exit(4);
a61af66fc99e Initial load
duke
parents:
diff changeset
645 }
a61af66fc99e Initial load
duke
parents:
diff changeset
646 }
a61af66fc99e Initial load
duke
parents:
diff changeset
647
a61af66fc99e Initial load
duke
parents:
diff changeset
648 #endif /* ifndef GAMMA */
a61af66fc99e Initial load
duke
parents:
diff changeset
649 }
a61af66fc99e Initial load
duke
parents:
diff changeset
650
a61af66fc99e Initial load
duke
parents:
diff changeset
651
a61af66fc99e Initial load
duke
parents:
diff changeset
652 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
653 * On Solaris VM choosing is done by the launcher (java.c).
a61af66fc99e Initial load
duke
parents:
diff changeset
654 */
a61af66fc99e Initial load
duke
parents:
diff changeset
655 static jboolean
a61af66fc99e Initial load
duke
parents:
diff changeset
656 GetJVMPath(const char *jrepath, const char *jvmtype,
a61af66fc99e Initial load
duke
parents:
diff changeset
657 char *jvmpath, jint jvmpathsize, char * arch)
a61af66fc99e Initial load
duke
parents:
diff changeset
658 {
a61af66fc99e Initial load
duke
parents:
diff changeset
659 struct stat s;
a61af66fc99e Initial load
duke
parents:
diff changeset
660
a61af66fc99e Initial load
duke
parents:
diff changeset
661 #ifndef GAMMA
a61af66fc99e Initial load
duke
parents:
diff changeset
662 if (strchr(jvmtype, '/')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
663 sprintf(jvmpath, "%s/" JVM_DLL, jvmtype);
a61af66fc99e Initial load
duke
parents:
diff changeset
664 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
665 sprintf(jvmpath, "%s/lib/%s/%s/" JVM_DLL, jrepath, arch, jvmtype);
a61af66fc99e Initial load
duke
parents:
diff changeset
666 }
a61af66fc99e Initial load
duke
parents:
diff changeset
667 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
668 /* For gamma launcher, JVM is either built-in or in the same directory. */
a61af66fc99e Initial load
duke
parents:
diff changeset
669 /* Either way we return "<exe_path>/libjvm.so" where <exe_path> is the */
a61af66fc99e Initial load
duke
parents:
diff changeset
670 /* directory where gamma launcher is located. */
a61af66fc99e Initial load
duke
parents:
diff changeset
671
a61af66fc99e Initial load
duke
parents:
diff changeset
672 char *p;
a61af66fc99e Initial load
duke
parents:
diff changeset
673
a61af66fc99e Initial load
duke
parents:
diff changeset
674 snprintf(jvmpath, jvmpathsize, "%s", GetExecname());
a61af66fc99e Initial load
duke
parents:
diff changeset
675 p = strrchr(jvmpath, '/');
a61af66fc99e Initial load
duke
parents:
diff changeset
676 if (p) {
a61af66fc99e Initial load
duke
parents:
diff changeset
677 /* replace executable name with libjvm.so */
a61af66fc99e Initial load
duke
parents:
diff changeset
678 snprintf(p + 1, jvmpathsize - (p + 1 - jvmpath), "%s", JVM_DLL);
a61af66fc99e Initial load
duke
parents:
diff changeset
679 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
680 /* this case shouldn't happen */
a61af66fc99e Initial load
duke
parents:
diff changeset
681 snprintf(jvmpath, jvmpathsize, "%s", JVM_DLL);
a61af66fc99e Initial load
duke
parents:
diff changeset
682 }
a61af66fc99e Initial load
duke
parents:
diff changeset
683 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
684
a61af66fc99e Initial load
duke
parents:
diff changeset
685 if (_launcher_debug)
a61af66fc99e Initial load
duke
parents:
diff changeset
686 printf("Does `%s' exist ... ", jvmpath);
a61af66fc99e Initial load
duke
parents:
diff changeset
687
a61af66fc99e Initial load
duke
parents:
diff changeset
688 if (stat(jvmpath, &s) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
689 if (_launcher_debug)
a61af66fc99e Initial load
duke
parents:
diff changeset
690 printf("yes.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
691 return JNI_TRUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
692 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
693 if (_launcher_debug)
a61af66fc99e Initial load
duke
parents:
diff changeset
694 printf("no.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
695 return JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
696 }
a61af66fc99e Initial load
duke
parents:
diff changeset
697 }
a61af66fc99e Initial load
duke
parents:
diff changeset
698
a61af66fc99e Initial load
duke
parents:
diff changeset
699 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
700 * Find path to JRE based on .exe's location or registry settings.
a61af66fc99e Initial load
duke
parents:
diff changeset
701 */
a61af66fc99e Initial load
duke
parents:
diff changeset
702 static jboolean
a61af66fc99e Initial load
duke
parents:
diff changeset
703 GetJREPath(char *path, jint pathsize, char * arch, jboolean speculative)
a61af66fc99e Initial load
duke
parents:
diff changeset
704 {
a61af66fc99e Initial load
duke
parents:
diff changeset
705 char libjava[MAXPATHLEN];
a61af66fc99e Initial load
duke
parents:
diff changeset
706
a61af66fc99e Initial load
duke
parents:
diff changeset
707 if (GetApplicationHome(path, pathsize)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
708 /* Is JRE co-located with the application? */
a61af66fc99e Initial load
duke
parents:
diff changeset
709 sprintf(libjava, "%s/lib/%s/" JAVA_DLL, path, arch);
a61af66fc99e Initial load
duke
parents:
diff changeset
710 if (access(libjava, F_OK) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
711 goto found;
a61af66fc99e Initial load
duke
parents:
diff changeset
712 }
a61af66fc99e Initial load
duke
parents:
diff changeset
713
a61af66fc99e Initial load
duke
parents:
diff changeset
714 /* Does the app ship a private JRE in <apphome>/jre directory? */
a61af66fc99e Initial load
duke
parents:
diff changeset
715 sprintf(libjava, "%s/jre/lib/%s/" JAVA_DLL, path, arch);
a61af66fc99e Initial load
duke
parents:
diff changeset
716 if (access(libjava, F_OK) == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
717 strcat(path, "/jre");
a61af66fc99e Initial load
duke
parents:
diff changeset
718 goto found;
a61af66fc99e Initial load
duke
parents:
diff changeset
719 }
a61af66fc99e Initial load
duke
parents:
diff changeset
720 }
a61af66fc99e Initial load
duke
parents:
diff changeset
721
a61af66fc99e Initial load
duke
parents:
diff changeset
722 if (!speculative)
a61af66fc99e Initial load
duke
parents:
diff changeset
723 fprintf(stderr, "Error: could not find " JAVA_DLL "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
724 return JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
725
a61af66fc99e Initial load
duke
parents:
diff changeset
726 found:
a61af66fc99e Initial load
duke
parents:
diff changeset
727 if (_launcher_debug)
a61af66fc99e Initial load
duke
parents:
diff changeset
728 printf("JRE path is %s\n", path);
a61af66fc99e Initial load
duke
parents:
diff changeset
729 return JNI_TRUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
730 }
a61af66fc99e Initial load
duke
parents:
diff changeset
731
a61af66fc99e Initial load
duke
parents:
diff changeset
732 jboolean
a61af66fc99e Initial load
duke
parents:
diff changeset
733 LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
a61af66fc99e Initial load
duke
parents:
diff changeset
734 {
a61af66fc99e Initial load
duke
parents:
diff changeset
735 #ifdef GAMMA
a61af66fc99e Initial load
duke
parents:
diff changeset
736 /* JVM is directly linked with gamma launcher; no dlopen() */
a61af66fc99e Initial load
duke
parents:
diff changeset
737 ifn->CreateJavaVM = JNI_CreateJavaVM;
a61af66fc99e Initial load
duke
parents:
diff changeset
738 ifn->GetDefaultJavaVMInitArgs = JNI_GetDefaultJavaVMInitArgs;
a61af66fc99e Initial load
duke
parents:
diff changeset
739 return JNI_TRUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
740 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
741 Dl_info dlinfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
742 void *libjvm;
a61af66fc99e Initial load
duke
parents:
diff changeset
743
a61af66fc99e Initial load
duke
parents:
diff changeset
744 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
745 printf("JVM path is %s\n", jvmpath);
a61af66fc99e Initial load
duke
parents:
diff changeset
746 }
a61af66fc99e Initial load
duke
parents:
diff changeset
747
a61af66fc99e Initial load
duke
parents:
diff changeset
748 libjvm = dlopen(jvmpath, RTLD_NOW + RTLD_GLOBAL);
a61af66fc99e Initial load
duke
parents:
diff changeset
749 if (libjvm == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
750 #if defined(__sparc) && !defined(_LP64) /* i.e. 32-bit sparc */
a61af66fc99e Initial load
duke
parents:
diff changeset
751 FILE * fp;
a61af66fc99e Initial load
duke
parents:
diff changeset
752 Elf32_Ehdr elf_head;
a61af66fc99e Initial load
duke
parents:
diff changeset
753 int count;
a61af66fc99e Initial load
duke
parents:
diff changeset
754 int location;
a61af66fc99e Initial load
duke
parents:
diff changeset
755
a61af66fc99e Initial load
duke
parents:
diff changeset
756 fp = fopen(jvmpath, "r");
a61af66fc99e Initial load
duke
parents:
diff changeset
757 if(fp == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
758 goto error;
a61af66fc99e Initial load
duke
parents:
diff changeset
759
a61af66fc99e Initial load
duke
parents:
diff changeset
760 /* read in elf header */
a61af66fc99e Initial load
duke
parents:
diff changeset
761 count = fread((void*)(&elf_head), sizeof(Elf32_Ehdr), 1, fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
762 fclose(fp);
a61af66fc99e Initial load
duke
parents:
diff changeset
763 if(count < 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
764 goto error;
a61af66fc99e Initial load
duke
parents:
diff changeset
765
a61af66fc99e Initial load
duke
parents:
diff changeset
766 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
767 * Check for running a server vm (compiled with -xarch=v8plus)
a61af66fc99e Initial load
duke
parents:
diff changeset
768 * on a stock v8 processor. In this case, the machine type in
a61af66fc99e Initial load
duke
parents:
diff changeset
769 * the elf header would not be included the architecture list
a61af66fc99e Initial load
duke
parents:
diff changeset
770 * provided by the isalist command, which is turn is gotten from
a61af66fc99e Initial load
duke
parents:
diff changeset
771 * sysinfo. This case cannot occur on 64-bit hardware and thus
a61af66fc99e Initial load
duke
parents:
diff changeset
772 * does not have to be checked for in binaries with an LP64 data
a61af66fc99e Initial load
duke
parents:
diff changeset
773 * model.
a61af66fc99e Initial load
duke
parents:
diff changeset
774 */
a61af66fc99e Initial load
duke
parents:
diff changeset
775 if(elf_head.e_machine == EM_SPARC32PLUS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
776 char buf[257]; /* recommended buffer size from sysinfo man
a61af66fc99e Initial load
duke
parents:
diff changeset
777 page */
a61af66fc99e Initial load
duke
parents:
diff changeset
778 long length;
a61af66fc99e Initial load
duke
parents:
diff changeset
779 char* location;
a61af66fc99e Initial load
duke
parents:
diff changeset
780
a61af66fc99e Initial load
duke
parents:
diff changeset
781 length = sysinfo(SI_ISALIST, buf, 257);
a61af66fc99e Initial load
duke
parents:
diff changeset
782 if(length > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
783 location = strstr(buf, "sparcv8plus ");
a61af66fc99e Initial load
duke
parents:
diff changeset
784 if(location == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
785 fprintf(stderr, "SPARC V8 processor detected; Server compiler requires V9 or better.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
786 fprintf(stderr, "Use Client compiler on V8 processors.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
787 fprintf(stderr, "Could not create the Java virtual machine.\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
788 return JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
789 }
a61af66fc99e Initial load
duke
parents:
diff changeset
790 }
a61af66fc99e Initial load
duke
parents:
diff changeset
791 }
a61af66fc99e Initial load
duke
parents:
diff changeset
792 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
793 fprintf(stderr, "dl failure on line %d", __LINE__);
a61af66fc99e Initial load
duke
parents:
diff changeset
794 goto error;
a61af66fc99e Initial load
duke
parents:
diff changeset
795 }
a61af66fc99e Initial load
duke
parents:
diff changeset
796
a61af66fc99e Initial load
duke
parents:
diff changeset
797 ifn->CreateJavaVM = (CreateJavaVM_t)
a61af66fc99e Initial load
duke
parents:
diff changeset
798 dlsym(libjvm, "JNI_CreateJavaVM");
a61af66fc99e Initial load
duke
parents:
diff changeset
799 if (ifn->CreateJavaVM == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
800 goto error;
a61af66fc99e Initial load
duke
parents:
diff changeset
801
a61af66fc99e Initial load
duke
parents:
diff changeset
802 ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t)
a61af66fc99e Initial load
duke
parents:
diff changeset
803 dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs");
a61af66fc99e Initial load
duke
parents:
diff changeset
804 if (ifn->GetDefaultJavaVMInitArgs == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
805 goto error;
a61af66fc99e Initial load
duke
parents:
diff changeset
806
a61af66fc99e Initial load
duke
parents:
diff changeset
807 return JNI_TRUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
808
a61af66fc99e Initial load
duke
parents:
diff changeset
809 error:
a61af66fc99e Initial load
duke
parents:
diff changeset
810 fprintf(stderr, "Error: failed %s, because %s\n", jvmpath, dlerror());
a61af66fc99e Initial load
duke
parents:
diff changeset
811 return JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
812 #endif /* GAMMA */
a61af66fc99e Initial load
duke
parents:
diff changeset
813 }
a61af66fc99e Initial load
duke
parents:
diff changeset
814
a61af66fc99e Initial load
duke
parents:
diff changeset
815 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
816 * Get the path to the file that has the usage message for -X options.
a61af66fc99e Initial load
duke
parents:
diff changeset
817 */
a61af66fc99e Initial load
duke
parents:
diff changeset
818 void
a61af66fc99e Initial load
duke
parents:
diff changeset
819 GetXUsagePath(char *buf, jint bufsize)
a61af66fc99e Initial load
duke
parents:
diff changeset
820 {
a61af66fc99e Initial load
duke
parents:
diff changeset
821 static const char Xusage_txt[] = "/Xusage.txt";
a61af66fc99e Initial load
duke
parents:
diff changeset
822 Dl_info dlinfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
823
a61af66fc99e Initial load
duke
parents:
diff changeset
824 /* we use RTLD_NOW because of problems with ld.so.1 and green threads */
a61af66fc99e Initial load
duke
parents:
diff changeset
825 dladdr(dlsym(dlopen(JVM_DLL, RTLD_NOW), "JNI_CreateJavaVM"), &dlinfo);
a61af66fc99e Initial load
duke
parents:
diff changeset
826 strncpy(buf, (char *)dlinfo.dli_fname, bufsize - sizeof(Xusage_txt));
a61af66fc99e Initial load
duke
parents:
diff changeset
827
a61af66fc99e Initial load
duke
parents:
diff changeset
828 buf[bufsize-1] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
829 strcpy(strrchr(buf, '/'), Xusage_txt);
a61af66fc99e Initial load
duke
parents:
diff changeset
830 }
a61af66fc99e Initial load
duke
parents:
diff changeset
831
a61af66fc99e Initial load
duke
parents:
diff changeset
832 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
833 * If app is "/foo/bin/javac", or "/foo/bin/sparcv9/javac" then put
a61af66fc99e Initial load
duke
parents:
diff changeset
834 * "/foo" into buf.
a61af66fc99e Initial load
duke
parents:
diff changeset
835 */
a61af66fc99e Initial load
duke
parents:
diff changeset
836 jboolean
a61af66fc99e Initial load
duke
parents:
diff changeset
837 GetApplicationHome(char *buf, jint bufsize)
a61af66fc99e Initial load
duke
parents:
diff changeset
838 {
a61af66fc99e Initial load
duke
parents:
diff changeset
839 #ifdef __linux__
a61af66fc99e Initial load
duke
parents:
diff changeset
840 char *execname = GetExecname();
a61af66fc99e Initial load
duke
parents:
diff changeset
841 if (execname) {
a61af66fc99e Initial load
duke
parents:
diff changeset
842 strncpy(buf, execname, bufsize-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
843 buf[bufsize-1] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
844 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
845 return JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
846 }
a61af66fc99e Initial load
duke
parents:
diff changeset
847 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
848 Dl_info dlinfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
849
a61af66fc99e Initial load
duke
parents:
diff changeset
850 dladdr((void *)GetApplicationHome, &dlinfo);
a61af66fc99e Initial load
duke
parents:
diff changeset
851 if (realpath(dlinfo.dli_fname, buf) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
852 fprintf(stderr, "Error: realpath(`%s') failed.\n", dlinfo.dli_fname);
a61af66fc99e Initial load
duke
parents:
diff changeset
853 return JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
854 }
a61af66fc99e Initial load
duke
parents:
diff changeset
855 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
856
a61af66fc99e Initial load
duke
parents:
diff changeset
857 #ifdef GAMMA
a61af66fc99e Initial load
duke
parents:
diff changeset
858 {
a61af66fc99e Initial load
duke
parents:
diff changeset
859 /* gamma launcher uses JAVA_HOME environment variable to find JDK/JRE */
a61af66fc99e Initial load
duke
parents:
diff changeset
860 char* java_home_var = getenv("JAVA_HOME");
a61af66fc99e Initial load
duke
parents:
diff changeset
861 if (java_home_var == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
862 printf("JAVA_HOME must point to a valid JDK/JRE to run gamma\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
863 return JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
864 }
a61af66fc99e Initial load
duke
parents:
diff changeset
865 snprintf(buf, bufsize, "%s", java_home_var);
a61af66fc99e Initial load
duke
parents:
diff changeset
866 }
a61af66fc99e Initial load
duke
parents:
diff changeset
867 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
868 if (strrchr(buf, '/') == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
869 buf[0] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
870 return JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
871 }
a61af66fc99e Initial load
duke
parents:
diff changeset
872 *(strrchr(buf, '/')) = '\0'; /* executable file */
a61af66fc99e Initial load
duke
parents:
diff changeset
873 if (strlen(buf) < 4 || strrchr(buf, '/') == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
874 buf[0] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
875 return JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
876 }
a61af66fc99e Initial load
duke
parents:
diff changeset
877 if (strcmp("/bin", buf + strlen(buf) - 4) != 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
878 *(strrchr(buf, '/')) = '\0'; /* sparcv9 or amd64 */
a61af66fc99e Initial load
duke
parents:
diff changeset
879 if (strlen(buf) < 4 || strcmp("/bin", buf + strlen(buf) - 4) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
880 buf[0] = '\0';
a61af66fc99e Initial load
duke
parents:
diff changeset
881 return JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
882 }
a61af66fc99e Initial load
duke
parents:
diff changeset
883 *(strrchr(buf, '/')) = '\0'; /* bin */
a61af66fc99e Initial load
duke
parents:
diff changeset
884 #endif /* GAMMA */
a61af66fc99e Initial load
duke
parents:
diff changeset
885
a61af66fc99e Initial load
duke
parents:
diff changeset
886 return JNI_TRUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
887 }
a61af66fc99e Initial load
duke
parents:
diff changeset
888
a61af66fc99e Initial load
duke
parents:
diff changeset
889
a61af66fc99e Initial load
duke
parents:
diff changeset
890 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
891 * Return true if the named program exists
a61af66fc99e Initial load
duke
parents:
diff changeset
892 */
a61af66fc99e Initial load
duke
parents:
diff changeset
893 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
894 ProgramExists(char *name)
a61af66fc99e Initial load
duke
parents:
diff changeset
895 {
a61af66fc99e Initial load
duke
parents:
diff changeset
896 struct stat sb;
a61af66fc99e Initial load
duke
parents:
diff changeset
897 if (stat(name, &sb) != 0) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
898 if (S_ISDIR(sb.st_mode)) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
899 return (sb.st_mode & S_IEXEC) != 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
900 }
a61af66fc99e Initial load
duke
parents:
diff changeset
901
a61af66fc99e Initial load
duke
parents:
diff changeset
902
a61af66fc99e Initial load
duke
parents:
diff changeset
903 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
904 * Find a command in a directory, returning the path.
a61af66fc99e Initial load
duke
parents:
diff changeset
905 */
a61af66fc99e Initial load
duke
parents:
diff changeset
906 static char *
a61af66fc99e Initial load
duke
parents:
diff changeset
907 Resolve(char *indir, char *cmd)
a61af66fc99e Initial load
duke
parents:
diff changeset
908 {
a61af66fc99e Initial load
duke
parents:
diff changeset
909 char name[PATH_MAX + 2], *real;
a61af66fc99e Initial load
duke
parents:
diff changeset
910
a61af66fc99e Initial load
duke
parents:
diff changeset
911 if ((strlen(indir) + strlen(cmd) + 1) > PATH_MAX) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
912 sprintf(name, "%s%c%s", indir, FILE_SEPARATOR, cmd);
a61af66fc99e Initial load
duke
parents:
diff changeset
913 if (!ProgramExists(name)) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
914 real = MemAlloc(PATH_MAX + 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
915 if (!realpath(name, real))
a61af66fc99e Initial load
duke
parents:
diff changeset
916 strcpy(real, name);
a61af66fc99e Initial load
duke
parents:
diff changeset
917 return real;
a61af66fc99e Initial load
duke
parents:
diff changeset
918 }
a61af66fc99e Initial load
duke
parents:
diff changeset
919
a61af66fc99e Initial load
duke
parents:
diff changeset
920
a61af66fc99e Initial load
duke
parents:
diff changeset
921 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
922 * Find a path for the executable
a61af66fc99e Initial load
duke
parents:
diff changeset
923 */
a61af66fc99e Initial load
duke
parents:
diff changeset
924 static char *
a61af66fc99e Initial load
duke
parents:
diff changeset
925 FindExecName(char *program)
a61af66fc99e Initial load
duke
parents:
diff changeset
926 {
a61af66fc99e Initial load
duke
parents:
diff changeset
927 char cwdbuf[PATH_MAX+2];
a61af66fc99e Initial load
duke
parents:
diff changeset
928 char *path;
a61af66fc99e Initial load
duke
parents:
diff changeset
929 char *tmp_path;
a61af66fc99e Initial load
duke
parents:
diff changeset
930 char *f;
a61af66fc99e Initial load
duke
parents:
diff changeset
931 char *result = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
932
a61af66fc99e Initial load
duke
parents:
diff changeset
933 /* absolute path? */
a61af66fc99e Initial load
duke
parents:
diff changeset
934 if (*program == FILE_SEPARATOR ||
a61af66fc99e Initial load
duke
parents:
diff changeset
935 (FILE_SEPARATOR=='\\' && strrchr(program, ':')))
a61af66fc99e Initial load
duke
parents:
diff changeset
936 return Resolve("", program+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
937
a61af66fc99e Initial load
duke
parents:
diff changeset
938 /* relative path? */
a61af66fc99e Initial load
duke
parents:
diff changeset
939 if (strrchr(program, FILE_SEPARATOR) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
940 char buf[PATH_MAX+2];
a61af66fc99e Initial load
duke
parents:
diff changeset
941 return Resolve(getcwd(cwdbuf, sizeof(cwdbuf)), program);
a61af66fc99e Initial load
duke
parents:
diff changeset
942 }
a61af66fc99e Initial load
duke
parents:
diff changeset
943
a61af66fc99e Initial load
duke
parents:
diff changeset
944 /* from search path? */
a61af66fc99e Initial load
duke
parents:
diff changeset
945 path = getenv("PATH");
a61af66fc99e Initial load
duke
parents:
diff changeset
946 if (!path || !*path) path = ".";
a61af66fc99e Initial load
duke
parents:
diff changeset
947 tmp_path = MemAlloc(strlen(path) + 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
948 strcpy(tmp_path, path);
a61af66fc99e Initial load
duke
parents:
diff changeset
949
a61af66fc99e Initial load
duke
parents:
diff changeset
950 for (f=tmp_path; *f && result==0; ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
951 char *s = f;
a61af66fc99e Initial load
duke
parents:
diff changeset
952 while (*f && (*f != PATH_SEPARATOR)) ++f;
a61af66fc99e Initial load
duke
parents:
diff changeset
953 if (*f) *f++ = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
954 if (*s == FILE_SEPARATOR)
a61af66fc99e Initial load
duke
parents:
diff changeset
955 result = Resolve(s, program);
a61af66fc99e Initial load
duke
parents:
diff changeset
956 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
957 /* relative path element */
a61af66fc99e Initial load
duke
parents:
diff changeset
958 char dir[2*PATH_MAX];
a61af66fc99e Initial load
duke
parents:
diff changeset
959 sprintf(dir, "%s%c%s", getcwd(cwdbuf, sizeof(cwdbuf)),
a61af66fc99e Initial load
duke
parents:
diff changeset
960 FILE_SEPARATOR, s);
a61af66fc99e Initial load
duke
parents:
diff changeset
961 result = Resolve(dir, program);
a61af66fc99e Initial load
duke
parents:
diff changeset
962 }
a61af66fc99e Initial load
duke
parents:
diff changeset
963 if (result != 0) break;
a61af66fc99e Initial load
duke
parents:
diff changeset
964 }
a61af66fc99e Initial load
duke
parents:
diff changeset
965
a61af66fc99e Initial load
duke
parents:
diff changeset
966 free(tmp_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
967 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
968 }
a61af66fc99e Initial load
duke
parents:
diff changeset
969
a61af66fc99e Initial load
duke
parents:
diff changeset
970
a61af66fc99e Initial load
duke
parents:
diff changeset
971 /* Store the name of the executable once computed */
a61af66fc99e Initial load
duke
parents:
diff changeset
972 static char *execname = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
973
a61af66fc99e Initial load
duke
parents:
diff changeset
974 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
975 * Compute the name of the executable
a61af66fc99e Initial load
duke
parents:
diff changeset
976 *
a61af66fc99e Initial load
duke
parents:
diff changeset
977 * In order to re-exec securely we need the absolute path of the
a61af66fc99e Initial load
duke
parents:
diff changeset
978 * executable. On Solaris getexecname(3c) may not return an absolute
a61af66fc99e Initial load
duke
parents:
diff changeset
979 * path so we use dladdr to get the filename of the executable and
a61af66fc99e Initial load
duke
parents:
diff changeset
980 * then use realpath to derive an absolute path. From Solaris 9
a61af66fc99e Initial load
duke
parents:
diff changeset
981 * onwards the filename returned in DL_info structure from dladdr is
a61af66fc99e Initial load
duke
parents:
diff changeset
982 * an absolute pathname so technically realpath isn't required.
a61af66fc99e Initial load
duke
parents:
diff changeset
983 * On Linux we read the executable name from /proc/self/exe.
a61af66fc99e Initial load
duke
parents:
diff changeset
984 * As a fallback, and for platforms other than Solaris and Linux,
a61af66fc99e Initial load
duke
parents:
diff changeset
985 * we use FindExecName to compute the executable name.
a61af66fc99e Initial load
duke
parents:
diff changeset
986 */
a61af66fc99e Initial load
duke
parents:
diff changeset
987 static char *
a61af66fc99e Initial load
duke
parents:
diff changeset
988 SetExecname(char **argv)
a61af66fc99e Initial load
duke
parents:
diff changeset
989 {
a61af66fc99e Initial load
duke
parents:
diff changeset
990 char* exec_path = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
991
a61af66fc99e Initial load
duke
parents:
diff changeset
992 if (execname != NULL) /* Already determined */
a61af66fc99e Initial load
duke
parents:
diff changeset
993 return (execname);
a61af66fc99e Initial load
duke
parents:
diff changeset
994
a61af66fc99e Initial load
duke
parents:
diff changeset
995 #if defined(__sun)
a61af66fc99e Initial load
duke
parents:
diff changeset
996 {
a61af66fc99e Initial load
duke
parents:
diff changeset
997 Dl_info dlinfo;
a61af66fc99e Initial load
duke
parents:
diff changeset
998 if (dladdr((void*)&SetExecname, &dlinfo)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
999 char *resolved = (char*)MemAlloc(PATH_MAX+1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 if (resolved != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 exec_path = realpath(dlinfo.dli_fname, resolved);
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 if (exec_path == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 free(resolved);
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 #elif defined(__linux__)
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1010 const char* self = "/proc/self/exe";
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 char buf[PATH_MAX+1];
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 int len = readlink(self, buf, PATH_MAX);
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 if (len >= 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 buf[len] = '\0'; /* readlink doesn't nul terminate */
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 exec_path = strdup(buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 #else /* !__sun && !__linux */
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 /* Not implemented */
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1023
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 if (exec_path == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 exec_path = FindExecName(argv[0]);
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 execname = exec_path;
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 return exec_path;
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1030
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 * Return the name of the executable. Used in java_md.c to find the JRE area.
a61af66fc99e Initial load
duke
parents:
diff changeset
1033 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 static char *
a61af66fc99e Initial load
duke
parents:
diff changeset
1035 GetExecname() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 return execname;
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1038
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 void ReportErrorMessage(char * message, jboolean always) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 if (always) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 fprintf(stderr, "%s\n", message);
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1044
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 void ReportErrorMessage2(char * format, char * string, jboolean always) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 if (always) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 fprintf(stderr, format, string);
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 fprintf(stderr, "\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1049 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1051
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 void ReportExceptionDescription(JNIEnv * env) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 (*env)->ExceptionDescribe(env);
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1055
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 * Return JNI_TRUE for an option string that has no effect but should
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 * _not_ be passed on to the vm; return JNI_FALSE otherwise. On
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 * Solaris SPARC, this screening needs to be done if:
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 * 1) LD_LIBRARY_PATH does _not_ need to be reset and
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 * 2) -d32 or -d64 is passed to a binary with a matching data model
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 * (the exec in SetLibraryPath removes -d<n> options and points the
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 * exec to the proper binary). When this exec is not done, these options
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 * would end up getting passed onto the vm.
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 jboolean RemovableMachineDependentOption(char * option) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 * Unconditionally remove both -d32 and -d64 options since only
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 * the last such options has an effect; e.g.
a61af66fc99e Initial load
duke
parents:
diff changeset
1070 * java -d32 -d64 -d32 -version
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 * is equivalent to
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 * java -d32 -version
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1074
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 if( (strcmp(option, "-d32") == 0 ) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 (strcmp(option, "-d64") == 0 ))
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 return JNI_TRUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 else
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 return JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1081
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 void PrintMachineDependentOptions() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 fprintf(stdout,
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 " -d32 use a 32-bit data model if available\n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 "\n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 " -d64 use a 64-bit data model if available\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1089
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 #ifndef GAMMA /* gamma launcher does not have ergonomics */
a61af66fc99e Initial load
duke
parents:
diff changeset
1091
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 * The following methods (down to ServerClassMachine()) answer
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 * the question about whether a machine is a "server-class"
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 * machine. A server-class machine is loosely defined as one
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 * with 2 or more processors and 2 gigabytes or more physical
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 * memory. The definition of a processor is a physical package,
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 * not a hyperthreaded chip masquerading as a multi-processor.
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 * The definition of memory is also somewhat fuzzy, since x86
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 * machines seem not to report all the memory in their DIMMs, we
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 * think because of memory mapping of graphics cards, etc.
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 *
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 * This code is somewhat more confused with #ifdef's than we'd
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 * like because this file is used by both Solaris and Linux
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 * platforms, and so needs to be parameterized for SPARC and
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 * i586 hardware. The other Linux platforms (amd64 and ia64)
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 * don't even ask this question, because they only come with
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 * server JVMs. */
a61af66fc99e Initial load
duke
parents:
diff changeset
1109
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 # define KB (1024UL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 # define MB (1024UL * KB)
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 # define GB (1024UL * MB)
a61af66fc99e Initial load
duke
parents:
diff changeset
1113
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 /* Compute physical memory by asking the OS */
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 uint64_t
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 physical_memory(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 const uint64_t pages = (uint64_t) sysconf(_SC_PHYS_PAGES);
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 const uint64_t page_size = (uint64_t) sysconf(_SC_PAGESIZE);
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 const uint64_t result = pages * page_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 # define UINT64_FORMAT "%" PRIu64
a61af66fc99e Initial load
duke
parents:
diff changeset
1121
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 printf("pages: " UINT64_FORMAT
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 " page_size: " UINT64_FORMAT
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 " physical memory: " UINT64_FORMAT " (%.3fGB)\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 pages, page_size, result, result / (double) GB);
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1130
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 #if defined(__sun) && defined(__sparc)
a61af66fc99e Initial load
duke
parents:
diff changeset
1132
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 /* Methods for solaris-sparc: these are easy. */
a61af66fc99e Initial load
duke
parents:
diff changeset
1134
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 /* Ask the OS how many processors there are. */
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 unsigned long
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 physical_processors(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 const unsigned long sys_processors = sysconf(_SC_NPROCESSORS_CONF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1139
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 printf("sysconf(_SC_NPROCESSORS_CONF): %lu\n", sys_processors);
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 return sys_processors;
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1145
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 /* The solaris-sparc version of the "server-class" predicate. */
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 jboolean
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 solaris_sparc_ServerClassMachine(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 jboolean result = JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 /* How big is a server class machine? */
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 const unsigned long server_processors = 2UL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 const uint64_t server_memory = 2UL * GB;
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 const uint64_t actual_memory = physical_memory();
a61af66fc99e Initial load
duke
parents:
diff changeset
1154
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 /* Is this a server class machine? */
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 if (actual_memory >= server_memory) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 const unsigned long actual_processors = physical_processors();
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 if (actual_processors >= server_processors) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 result = JNI_TRUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 printf("solaris_" ARCH "_ServerClassMachine: %s\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 (result == JNI_TRUE ? "JNI_TRUE" : "JNI_FALSE"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1168
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 #endif /* __sun && __sparc */
a61af66fc99e Initial load
duke
parents:
diff changeset
1170
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 #if defined(__sun) && defined(i586)
a61af66fc99e Initial load
duke
parents:
diff changeset
1172
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 * A utility method for asking the CPU about itself.
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 * There's a corresponding version of linux-i586
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 * because the compilers are different.
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 void
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 get_cpuid(uint32_t arg,
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 uint32_t* eaxp,
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 uint32_t* ebxp,
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 uint32_t* ecxp,
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 uint32_t* edxp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1184 #ifdef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 asm(
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 /* rbx is a callee-saved register */
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 " movq %rbx, %r11 \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 /* rdx and rcx are 3rd and 4th argument registers */
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 " movq %rdx, %r10 \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 " movq %rcx, %r9 \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 " movl %edi, %eax \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 " cpuid \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 " movl %eax, (%rsi)\n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 " movl %ebx, (%r10)\n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 " movl %ecx, (%r9) \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 " movl %edx, (%r8) \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 /* Restore rbx */
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 " movq %r11, %rbx");
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 /* EBX is a callee-saved register */
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 asm(" pushl %ebx");
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 /* Need ESI for storing through arguments */
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 asm(" pushl %esi");
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 asm(" movl 8(%ebp), %eax \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 " cpuid \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 " movl 12(%ebp), %esi \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 " movl %eax, (%esi) \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 " movl 16(%ebp), %esi \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 " movl %ebx, (%esi) \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 " movl 20(%ebp), %esi \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 " movl %ecx, (%esi) \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 " movl 24(%ebp), %esi \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 " movl %edx, (%esi) ");
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 /* Restore ESI and EBX */
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 asm(" popl %esi");
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 /* Restore EBX */
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 asm(" popl %ebx");
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1220
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 #endif /* __sun && i586 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1222
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 #if defined(__linux__) && defined(i586)
a61af66fc99e Initial load
duke
parents:
diff changeset
1224
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 * A utility method for asking the CPU about itself.
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 * There's a corresponding version of solaris-i586
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 * because the compilers are different.
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 void
a61af66fc99e Initial load
duke
parents:
diff changeset
1231 get_cpuid(uint32_t arg,
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 uint32_t* eaxp,
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 uint32_t* ebxp,
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 uint32_t* ecxp,
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 uint32_t* edxp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 #ifdef _LP64
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 __asm__ volatile (/* Instructions */
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 " movl %4, %%eax \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 " cpuid \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 " movl %%eax, (%0)\n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 " movl %%ebx, (%1)\n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 " movl %%ecx, (%2)\n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 " movl %%edx, (%3)\n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 : /* Outputs */
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 : /* Inputs */
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 "r" (eaxp),
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 "r" (ebxp),
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 "r" (ecxp),
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 "r" (edxp),
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 "r" (arg)
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 : /* Clobbers */
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 "%rax", "%rbx", "%rcx", "%rdx", "memory"
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 );
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 uint32_t value_of_eax = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 uint32_t value_of_ebx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 uint32_t value_of_ecx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 uint32_t value_of_edx = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 __asm__ volatile (/* Instructions */
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 /* ebx is callee-save, so push it */
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 /* even though it's in the clobbers section */
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 " pushl %%ebx \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 " movl %4, %%eax \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 " cpuid \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 " movl %%eax, %0 \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 " movl %%ebx, %1 \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 " movl %%ecx, %2 \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 " movl %%edx, %3 \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1269 /* restore ebx */
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 " popl %%ebx \n"
a61af66fc99e Initial load
duke
parents:
diff changeset
1271
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 : /* Outputs */
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 "=m" (value_of_eax),
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 "=m" (value_of_ebx),
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 "=m" (value_of_ecx),
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 "=m" (value_of_edx)
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 : /* Inputs */
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 "m" (arg)
a61af66fc99e Initial load
duke
parents:
diff changeset
1279 : /* Clobbers */
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 "%eax", "%ebx", "%ecx", "%edx"
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 );
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 *eaxp = value_of_eax;
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 *ebxp = value_of_ebx;
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 *ecxp = value_of_ecx;
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 *edxp = value_of_edx;
a61af66fc99e Initial load
duke
parents:
diff changeset
1286 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1288
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 #endif /* __linux__ && i586 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1290
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 #ifdef i586
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 * Routines shared by solaris-i586 and linux-i586.
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1295
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 enum HyperThreadingSupport_enum {
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 hts_supported = 1,
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 hts_too_soon_to_tell = 0,
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 hts_not_supported = -1,
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 hts_not_pentium4 = -2,
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 hts_not_intel = -3
a61af66fc99e Initial load
duke
parents:
diff changeset
1302 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 typedef enum HyperThreadingSupport_enum HyperThreadingSupport;
a61af66fc99e Initial load
duke
parents:
diff changeset
1304
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 /* Determine if hyperthreading is supported */
a61af66fc99e Initial load
duke
parents:
diff changeset
1306 HyperThreadingSupport
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 hyperthreading_support(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 HyperThreadingSupport result = hts_too_soon_to_tell;
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 /* Bits 11 through 8 is family processor id */
a61af66fc99e Initial load
duke
parents:
diff changeset
1310 # define FAMILY_ID_SHIFT 8
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 # define FAMILY_ID_MASK 0xf
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 /* Bits 23 through 20 is extended family processor id */
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 # define EXT_FAMILY_ID_SHIFT 20
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 # define EXT_FAMILY_ID_MASK 0xf
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 /* Pentium 4 family processor id */
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 # define PENTIUM4_FAMILY_ID 0xf
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 /* Bit 28 indicates Hyper-Threading Technology support */
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 # define HT_BIT_SHIFT 28
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 # define HT_BIT_MASK 1
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 uint32_t vendor_id[3] = { 0U, 0U, 0U };
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 uint32_t value_of_eax = 0U;
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 uint32_t value_of_edx = 0U;
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 uint32_t dummy = 0U;
a61af66fc99e Initial load
duke
parents:
diff changeset
1324
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 /* Yes, this is supposed to be [0], [2], [1] */
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 get_cpuid(0, &dummy, &vendor_id[0], &vendor_id[2], &vendor_id[1]);
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 printf("vendor: %c %c %c %c %c %c %c %c %c %c %c %c \n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 ((vendor_id[0] >> 0) & 0xff),
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 ((vendor_id[0] >> 8) & 0xff),
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 ((vendor_id[0] >> 16) & 0xff),
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 ((vendor_id[0] >> 24) & 0xff),
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 ((vendor_id[1] >> 0) & 0xff),
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 ((vendor_id[1] >> 8) & 0xff),
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 ((vendor_id[1] >> 16) & 0xff),
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 ((vendor_id[1] >> 24) & 0xff),
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 ((vendor_id[2] >> 0) & 0xff),
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 ((vendor_id[2] >> 8) & 0xff),
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 ((vendor_id[2] >> 16) & 0xff),
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 ((vendor_id[2] >> 24) & 0xff));
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 get_cpuid(1, &value_of_eax, &dummy, &dummy, &value_of_edx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 printf("value_of_eax: 0x%x value_of_edx: 0x%x\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 value_of_eax, value_of_edx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 if ((((value_of_eax >> FAMILY_ID_SHIFT) & FAMILY_ID_MASK) == PENTIUM4_FAMILY_ID) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 (((value_of_eax >> EXT_FAMILY_ID_SHIFT) & EXT_FAMILY_ID_MASK) != 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 if ((((vendor_id[0] >> 0) & 0xff) == 'G') &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 (((vendor_id[0] >> 8) & 0xff) == 'e') &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 (((vendor_id[0] >> 16) & 0xff) == 'n') &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 (((vendor_id[0] >> 24) & 0xff) == 'u') &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 (((vendor_id[1] >> 0) & 0xff) == 'i') &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 (((vendor_id[1] >> 8) & 0xff) == 'n') &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 (((vendor_id[1] >> 16) & 0xff) == 'e') &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 (((vendor_id[1] >> 24) & 0xff) == 'I') &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 (((vendor_id[2] >> 0) & 0xff) == 'n') &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 (((vendor_id[2] >> 8) & 0xff) == 't') &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 (((vendor_id[2] >> 16) & 0xff) == 'e') &&
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 (((vendor_id[2] >> 24) & 0xff) == 'l')) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 if (((value_of_edx >> HT_BIT_SHIFT) & HT_BIT_MASK) == HT_BIT_MASK) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 printf("Hyperthreading supported\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 result = hts_supported;
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 printf("Hyperthreading not supported\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 result = hts_not_supported;
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 printf("Not GenuineIntel\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 result = hts_not_intel;
a61af66fc99e Initial load
duke
parents:
diff changeset
1377 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 printf("not Pentium 4 or extended\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 result = hts_not_pentium4;
a61af66fc99e Initial load
duke
parents:
diff changeset
1383 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1384 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1386
a61af66fc99e Initial load
duke
parents:
diff changeset
1387 /* Determine how many logical processors there are per CPU */
a61af66fc99e Initial load
duke
parents:
diff changeset
1388 unsigned int
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 logical_processors_per_package(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 * After CPUID with EAX==1, register EBX bits 23 through 16
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 * indicate the number of logical processors per package
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 # define NUM_LOGICAL_SHIFT 16
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 # define NUM_LOGICAL_MASK 0xff
a61af66fc99e Initial load
duke
parents:
diff changeset
1396 unsigned int result = 1U;
a61af66fc99e Initial load
duke
parents:
diff changeset
1397 const HyperThreadingSupport hyperthreading = hyperthreading_support();
a61af66fc99e Initial load
duke
parents:
diff changeset
1398
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 if (hyperthreading == hts_supported) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1400 uint32_t value_of_ebx = 0U;
a61af66fc99e Initial load
duke
parents:
diff changeset
1401 uint32_t dummy = 0U;
a61af66fc99e Initial load
duke
parents:
diff changeset
1402
a61af66fc99e Initial load
duke
parents:
diff changeset
1403 get_cpuid(1, &dummy, &value_of_ebx, &dummy, &dummy);
a61af66fc99e Initial load
duke
parents:
diff changeset
1404 result = (value_of_ebx >> NUM_LOGICAL_SHIFT) & NUM_LOGICAL_MASK;
a61af66fc99e Initial load
duke
parents:
diff changeset
1405 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1406 printf("logical processors per package: %u\n", result);
a61af66fc99e Initial load
duke
parents:
diff changeset
1407 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1408 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1409 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
1410 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1411
a61af66fc99e Initial load
duke
parents:
diff changeset
1412 /* Compute the number of physical processors, not logical processors */
a61af66fc99e Initial load
duke
parents:
diff changeset
1413 unsigned long
a61af66fc99e Initial load
duke
parents:
diff changeset
1414 physical_processors(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1415 const long sys_processors = sysconf(_SC_NPROCESSORS_CONF);
a61af66fc99e Initial load
duke
parents:
diff changeset
1416 unsigned long result = sys_processors;
a61af66fc99e Initial load
duke
parents:
diff changeset
1417
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 printf("sysconf(_SC_NPROCESSORS_CONF): %lu\n", sys_processors);
a61af66fc99e Initial load
duke
parents:
diff changeset
1420 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1421 if (sys_processors > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1422 unsigned int logical_processors = logical_processors_per_package();
a61af66fc99e Initial load
duke
parents:
diff changeset
1423 if (logical_processors > 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1424 result = (unsigned long) sys_processors / logical_processors;
a61af66fc99e Initial load
duke
parents:
diff changeset
1425 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1426 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1427 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1428 printf("physical processors: %lu\n", result);
a61af66fc99e Initial load
duke
parents:
diff changeset
1429 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1430 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
1431 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1432
a61af66fc99e Initial load
duke
parents:
diff changeset
1433 #endif /* i586 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1434
a61af66fc99e Initial load
duke
parents:
diff changeset
1435 #if defined(__sun) && defined(i586)
a61af66fc99e Initial load
duke
parents:
diff changeset
1436
a61af66fc99e Initial load
duke
parents:
diff changeset
1437 /* The definition of a server-class machine for solaris-i586/amd64 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1438 jboolean
a61af66fc99e Initial load
duke
parents:
diff changeset
1439 solaris_i586_ServerClassMachine(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1440 jboolean result = JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1441 /* How big is a server class machine? */
a61af66fc99e Initial load
duke
parents:
diff changeset
1442 const unsigned long server_processors = 2UL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1443 const uint64_t server_memory = 2UL * GB;
a61af66fc99e Initial load
duke
parents:
diff changeset
1444 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1445 * We seem not to get our full complement of memory.
a61af66fc99e Initial load
duke
parents:
diff changeset
1446 * We allow some part (1/8?) of the memory to be "missing",
a61af66fc99e Initial load
duke
parents:
diff changeset
1447 * based on the sizes of DIMMs, and maybe graphics cards.
a61af66fc99e Initial load
duke
parents:
diff changeset
1448 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1449 const uint64_t missing_memory = 256UL * MB;
a61af66fc99e Initial load
duke
parents:
diff changeset
1450 const uint64_t actual_memory = physical_memory();
a61af66fc99e Initial load
duke
parents:
diff changeset
1451
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 /* Is this a server class machine? */
a61af66fc99e Initial load
duke
parents:
diff changeset
1453 if (actual_memory >= (server_memory - missing_memory)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1454 const unsigned long actual_processors = physical_processors();
a61af66fc99e Initial load
duke
parents:
diff changeset
1455 if (actual_processors >= server_processors) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1456 result = JNI_TRUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1457 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1459 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1460 printf("solaris_" ARCH "_ServerClassMachine: %s\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1461 (result == JNI_TRUE ? "true" : "false"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1462 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1463 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
1464 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1465
a61af66fc99e Initial load
duke
parents:
diff changeset
1466 #endif /* __sun && i586 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1467
a61af66fc99e Initial load
duke
parents:
diff changeset
1468 #if defined(__linux__) && defined(i586)
a61af66fc99e Initial load
duke
parents:
diff changeset
1469
a61af66fc99e Initial load
duke
parents:
diff changeset
1470 /* The definition of a server-class machine for linux-i586 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1471 jboolean
a61af66fc99e Initial load
duke
parents:
diff changeset
1472 linux_i586_ServerClassMachine(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1473 jboolean result = JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1474 /* How big is a server class machine? */
a61af66fc99e Initial load
duke
parents:
diff changeset
1475 const unsigned long server_processors = 2UL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1476 const uint64_t server_memory = 2UL * GB;
a61af66fc99e Initial load
duke
parents:
diff changeset
1477 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1478 * We seem not to get our full complement of memory.
a61af66fc99e Initial load
duke
parents:
diff changeset
1479 * We allow some part (1/8?) of the memory to be "missing",
a61af66fc99e Initial load
duke
parents:
diff changeset
1480 * based on the sizes of DIMMs, and maybe graphics cards.
a61af66fc99e Initial load
duke
parents:
diff changeset
1481 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1482 const uint64_t missing_memory = 256UL * MB;
a61af66fc99e Initial load
duke
parents:
diff changeset
1483 const uint64_t actual_memory = physical_memory();
a61af66fc99e Initial load
duke
parents:
diff changeset
1484
a61af66fc99e Initial load
duke
parents:
diff changeset
1485 /* Is this a server class machine? */
a61af66fc99e Initial load
duke
parents:
diff changeset
1486 if (actual_memory >= (server_memory - missing_memory)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1487 const unsigned long actual_processors = physical_processors();
a61af66fc99e Initial load
duke
parents:
diff changeset
1488 if (actual_processors >= server_processors) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1489 result = JNI_TRUE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1490 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1491 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1492 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1493 printf("linux_" ARCH "_ServerClassMachine: %s\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1494 (result == JNI_TRUE ? "true" : "false"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1495 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1496 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
1497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1498
a61af66fc99e Initial load
duke
parents:
diff changeset
1499 #endif /* __linux__ && i586 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1500
a61af66fc99e Initial load
duke
parents:
diff changeset
1501 /* Dispatch to the platform-specific definition of "server-class" */
a61af66fc99e Initial load
duke
parents:
diff changeset
1502 jboolean
a61af66fc99e Initial load
duke
parents:
diff changeset
1503 ServerClassMachine(void) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1504 jboolean result = JNI_FALSE;
a61af66fc99e Initial load
duke
parents:
diff changeset
1505 #if defined(__sun) && defined(__sparc)
a61af66fc99e Initial load
duke
parents:
diff changeset
1506 result = solaris_sparc_ServerClassMachine();
a61af66fc99e Initial load
duke
parents:
diff changeset
1507 #elif defined(__sun) && defined(i586)
a61af66fc99e Initial load
duke
parents:
diff changeset
1508 result = solaris_i586_ServerClassMachine();
a61af66fc99e Initial load
duke
parents:
diff changeset
1509 #elif defined(__linux__) && defined(i586)
a61af66fc99e Initial load
duke
parents:
diff changeset
1510 result = linux_i586_ServerClassMachine();
a61af66fc99e Initial load
duke
parents:
diff changeset
1511 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
1512 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1513 printf("ServerClassMachine: returns default value of %s\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
1514 (result == JNI_TRUE ? "true" : "false"));
a61af66fc99e Initial load
duke
parents:
diff changeset
1515 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1516 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1517 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
1518 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1519
a61af66fc99e Initial load
duke
parents:
diff changeset
1520 #endif /* ifndef GAMMA */
a61af66fc99e Initial load
duke
parents:
diff changeset
1521
a61af66fc99e Initial load
duke
parents:
diff changeset
1522 #ifndef GAMMA /* gamma launcher does not choose JDK/JRE/JVM */
a61af66fc99e Initial load
duke
parents:
diff changeset
1523
a61af66fc99e Initial load
duke
parents:
diff changeset
1524 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1525 * Since using the file system as a registry is a bit risky, perform
a61af66fc99e Initial load
duke
parents:
diff changeset
1526 * additional sanity checks on the identified directory to validate
a61af66fc99e Initial load
duke
parents:
diff changeset
1527 * it as a valid jre/sdk.
a61af66fc99e Initial load
duke
parents:
diff changeset
1528 *
a61af66fc99e Initial load
duke
parents:
diff changeset
1529 * Return 0 if the tests fail; otherwise return non-zero (true).
a61af66fc99e Initial load
duke
parents:
diff changeset
1530 *
a61af66fc99e Initial load
duke
parents:
diff changeset
1531 * Note that checking for anything more than the existence of an
a61af66fc99e Initial load
duke
parents:
diff changeset
1532 * executable object at bin/java relative to the path being checked
a61af66fc99e Initial load
duke
parents:
diff changeset
1533 * will break the regression tests.
a61af66fc99e Initial load
duke
parents:
diff changeset
1534 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1535 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
1536 CheckSanity(char *path, char *dir)
a61af66fc99e Initial load
duke
parents:
diff changeset
1537 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1538 char buffer[PATH_MAX];
a61af66fc99e Initial load
duke
parents:
diff changeset
1539
a61af66fc99e Initial load
duke
parents:
diff changeset
1540 if (strlen(path) + strlen(dir) + 11 > PATH_MAX)
a61af66fc99e Initial load
duke
parents:
diff changeset
1541 return (0); /* Silently reject "impossibly" long paths */
a61af66fc99e Initial load
duke
parents:
diff changeset
1542
a61af66fc99e Initial load
duke
parents:
diff changeset
1543 (void)strcat(strcat(strcat(strcpy(buffer, path), "/"), dir), "/bin/java");
a61af66fc99e Initial load
duke
parents:
diff changeset
1544 return ((access(buffer, X_OK) == 0) ? 1 : 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1545 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1546
a61af66fc99e Initial load
duke
parents:
diff changeset
1547 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1548 * Determine if there is an acceptable JRE in the directory dirname.
a61af66fc99e Initial load
duke
parents:
diff changeset
1549 * Upon locating the "best" one, return a fully qualified path to
a61af66fc99e Initial load
duke
parents:
diff changeset
1550 * it. "Best" is defined as the most advanced JRE meeting the
a61af66fc99e Initial load
duke
parents:
diff changeset
1551 * constraints contained in the manifest_info. If no JRE in this
a61af66fc99e Initial load
duke
parents:
diff changeset
1552 * directory meets the constraints, return NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
1553 *
a61af66fc99e Initial load
duke
parents:
diff changeset
1554 * Note that we don't check for errors in reading the directory
a61af66fc99e Initial load
duke
parents:
diff changeset
1555 * (which would be done by checking errno). This is because it
a61af66fc99e Initial load
duke
parents:
diff changeset
1556 * doesn't matter if we get an error reading the directory, or
a61af66fc99e Initial load
duke
parents:
diff changeset
1557 * we just don't find anything interesting in the directory. We
a61af66fc99e Initial load
duke
parents:
diff changeset
1558 * just return NULL in either case.
a61af66fc99e Initial load
duke
parents:
diff changeset
1559 *
a61af66fc99e Initial load
duke
parents:
diff changeset
1560 * The historical names of j2sdk and j2re were changed to jdk and
a61af66fc99e Initial load
duke
parents:
diff changeset
1561 * jre respecively as part of the 1.5 rebranding effort. Since the
a61af66fc99e Initial load
duke
parents:
diff changeset
1562 * former names are legacy on Linux, they must be recognized for
a61af66fc99e Initial load
duke
parents:
diff changeset
1563 * all time. Fortunately, this is a minor cost.
a61af66fc99e Initial load
duke
parents:
diff changeset
1564 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1565 static char
a61af66fc99e Initial load
duke
parents:
diff changeset
1566 *ProcessDir(manifest_info *info, char *dirname)
a61af66fc99e Initial load
duke
parents:
diff changeset
1567 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1568 DIR *dirp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1569 struct dirent *dp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1570 char *best = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1571 int offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
1572 int best_offset = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1573 char *ret_str = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1574 char buffer[PATH_MAX];
a61af66fc99e Initial load
duke
parents:
diff changeset
1575
a61af66fc99e Initial load
duke
parents:
diff changeset
1576 if ((dirp = opendir(dirname)) == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1577 return (NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1578
a61af66fc99e Initial load
duke
parents:
diff changeset
1579 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
1580 if ((dp = readdir(dirp)) != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1581 offset = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1582 if ((strncmp(dp->d_name, "jre", 3) == 0) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1583 (strncmp(dp->d_name, "jdk", 3) == 0))
a61af66fc99e Initial load
duke
parents:
diff changeset
1584 offset = 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
1585 else if (strncmp(dp->d_name, "j2re", 4) == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
1586 offset = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
1587 else if (strncmp(dp->d_name, "j2sdk", 5) == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
1588 offset = 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
1589 if (offset > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1590 if ((acceptable_release(dp->d_name + offset,
a61af66fc99e Initial load
duke
parents:
diff changeset
1591 info->jre_version)) && CheckSanity(dirname, dp->d_name))
a61af66fc99e Initial load
duke
parents:
diff changeset
1592 if ((best == NULL) || (exact_version_id(
a61af66fc99e Initial load
duke
parents:
diff changeset
1593 dp->d_name + offset, best + best_offset) > 0)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1594 if (best != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1595 free(best);
a61af66fc99e Initial load
duke
parents:
diff changeset
1596 best = strdup(dp->d_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
1597 best_offset = offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
1598 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1599 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1600 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1601 } while (dp != NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1602 (void) closedir(dirp);
a61af66fc99e Initial load
duke
parents:
diff changeset
1603 if (best == NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1604 return (NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1605 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1606 ret_str = MemAlloc(strlen(dirname) + strlen(best) + 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1607 ret_str = strcat(strcat(strcpy(ret_str, dirname), "/"), best);
a61af66fc99e Initial load
duke
parents:
diff changeset
1608 free(best);
a61af66fc99e Initial load
duke
parents:
diff changeset
1609 return (ret_str);
a61af66fc99e Initial load
duke
parents:
diff changeset
1610 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1611 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1612
a61af66fc99e Initial load
duke
parents:
diff changeset
1613 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1614 * This is the global entry point. It examines the host for the optimal
a61af66fc99e Initial load
duke
parents:
diff changeset
1615 * JRE to be used by scanning a set of directories. The set of directories
a61af66fc99e Initial load
duke
parents:
diff changeset
1616 * is platform dependent and can be overridden by the environment
a61af66fc99e Initial load
duke
parents:
diff changeset
1617 * variable JAVA_VERSION_PATH.
a61af66fc99e Initial load
duke
parents:
diff changeset
1618 *
a61af66fc99e Initial load
duke
parents:
diff changeset
1619 * This routine itself simply determines the set of appropriate
a61af66fc99e Initial load
duke
parents:
diff changeset
1620 * directories before passing control onto ProcessDir().
a61af66fc99e Initial load
duke
parents:
diff changeset
1621 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1622 char*
a61af66fc99e Initial load
duke
parents:
diff changeset
1623 LocateJRE(manifest_info* info)
a61af66fc99e Initial load
duke
parents:
diff changeset
1624 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1625 char *path;
a61af66fc99e Initial load
duke
parents:
diff changeset
1626 char *home;
a61af66fc99e Initial load
duke
parents:
diff changeset
1627 char *target = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1628 char *dp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1629 char *cp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1630
a61af66fc99e Initial load
duke
parents:
diff changeset
1631 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1632 * Start by getting JAVA_VERSION_PATH
a61af66fc99e Initial load
duke
parents:
diff changeset
1633 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1634 if (info->jre_restrict_search)
a61af66fc99e Initial load
duke
parents:
diff changeset
1635 path = strdup(system_dir);
a61af66fc99e Initial load
duke
parents:
diff changeset
1636 else if ((path = getenv("JAVA_VERSION_PATH")) != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1637 path = strdup(path);
a61af66fc99e Initial load
duke
parents:
diff changeset
1638 else
a61af66fc99e Initial load
duke
parents:
diff changeset
1639 if ((home = getenv("HOME")) != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1640 path = (char *)MemAlloc(strlen(home) + 13);
a61af66fc99e Initial load
duke
parents:
diff changeset
1641 path = strcat(strcat(strcat(strcpy(path, home),
a61af66fc99e Initial load
duke
parents:
diff changeset
1642 user_dir), ":"), system_dir);
a61af66fc99e Initial load
duke
parents:
diff changeset
1643 } else
a61af66fc99e Initial load
duke
parents:
diff changeset
1644 path = strdup(system_dir);
a61af66fc99e Initial load
duke
parents:
diff changeset
1645
a61af66fc99e Initial load
duke
parents:
diff changeset
1646 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1647 * Step through each directory on the path. Terminate the scan with
a61af66fc99e Initial load
duke
parents:
diff changeset
1648 * the first directory with an acceptable JRE.
a61af66fc99e Initial load
duke
parents:
diff changeset
1649 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1650 cp = dp = path;
a61af66fc99e Initial load
duke
parents:
diff changeset
1651 while (dp != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1652 cp = strchr(dp, (int)':');
a61af66fc99e Initial load
duke
parents:
diff changeset
1653 if (cp != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1654 *cp = (char)NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1655 if ((target = ProcessDir(info, dp)) != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1656 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1657 dp = cp;
a61af66fc99e Initial load
duke
parents:
diff changeset
1658 if (dp != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
1659 dp++;
a61af66fc99e Initial load
duke
parents:
diff changeset
1660 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1661 free(path);
a61af66fc99e Initial load
duke
parents:
diff changeset
1662 return (target);
a61af66fc99e Initial load
duke
parents:
diff changeset
1663 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1664
a61af66fc99e Initial load
duke
parents:
diff changeset
1665 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1666 * Given a path to a jre to execute, this routine checks if this process
a61af66fc99e Initial load
duke
parents:
diff changeset
1667 * is indeed that jre. If not, it exec's that jre.
a61af66fc99e Initial load
duke
parents:
diff changeset
1668 *
a61af66fc99e Initial load
duke
parents:
diff changeset
1669 * We want to actually check the paths rather than just the version string
a61af66fc99e Initial load
duke
parents:
diff changeset
1670 * built into the executable, so that given version specification (and
a61af66fc99e Initial load
duke
parents:
diff changeset
1671 * JAVA_VERSION_PATH) will yield the exact same Java environment, regardless
a61af66fc99e Initial load
duke
parents:
diff changeset
1672 * of the version of the arbitrary launcher we start with.
a61af66fc99e Initial load
duke
parents:
diff changeset
1673 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1674 void
a61af66fc99e Initial load
duke
parents:
diff changeset
1675 ExecJRE(char *jre, char **argv)
a61af66fc99e Initial load
duke
parents:
diff changeset
1676 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1677 char wanted[PATH_MAX];
a61af66fc99e Initial load
duke
parents:
diff changeset
1678 char *execname;
a61af66fc99e Initial load
duke
parents:
diff changeset
1679 char *progname;
a61af66fc99e Initial load
duke
parents:
diff changeset
1680
a61af66fc99e Initial load
duke
parents:
diff changeset
1681 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1682 * Resolve the real path to the directory containing the selected JRE.
a61af66fc99e Initial load
duke
parents:
diff changeset
1683 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1684 if (realpath(jre, wanted) == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1685 fprintf(stderr, "Unable to resolve %s\n", jre);
a61af66fc99e Initial load
duke
parents:
diff changeset
1686 exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1687 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1688
a61af66fc99e Initial load
duke
parents:
diff changeset
1689 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1690 * Resolve the real path to the currently running launcher.
a61af66fc99e Initial load
duke
parents:
diff changeset
1691 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1692 execname = SetExecname(argv);
a61af66fc99e Initial load
duke
parents:
diff changeset
1693 if (execname == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1694 fprintf(stderr, "Unable to resolve current executable\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1695 exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1696 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1697
a61af66fc99e Initial load
duke
parents:
diff changeset
1698 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1699 * If the path to the selected JRE directory is a match to the initial
a61af66fc99e Initial load
duke
parents:
diff changeset
1700 * portion of the path to the currently executing JRE, we have a winner!
a61af66fc99e Initial load
duke
parents:
diff changeset
1701 * If so, just return.
a61af66fc99e Initial load
duke
parents:
diff changeset
1702 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1703 if (strncmp(wanted, execname, strlen(wanted)) == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
1704 return; /* I am the droid you were looking for */
a61af66fc99e Initial load
duke
parents:
diff changeset
1705
a61af66fc99e Initial load
duke
parents:
diff changeset
1706 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1707 * If this isn't the selected version, exec the selected version.
a61af66fc99e Initial load
duke
parents:
diff changeset
1708 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1709 #ifdef JAVA_ARGS /* javac, jar and friends. */
a61af66fc99e Initial load
duke
parents:
diff changeset
1710 progname = "java";
a61af66fc99e Initial load
duke
parents:
diff changeset
1711 #else /* java, oldjava, javaw and friends */
a61af66fc99e Initial load
duke
parents:
diff changeset
1712 #ifdef PROGNAME
a61af66fc99e Initial load
duke
parents:
diff changeset
1713 progname = PROGNAME;
a61af66fc99e Initial load
duke
parents:
diff changeset
1714 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
1715 progname = *argv;
a61af66fc99e Initial load
duke
parents:
diff changeset
1716 if ((s = strrchr(progname, FILE_SEPARATOR)) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1717 progname = s + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1718 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1719 #endif /* PROGNAME */
a61af66fc99e Initial load
duke
parents:
diff changeset
1720 #endif /* JAVA_ARGS */
a61af66fc99e Initial load
duke
parents:
diff changeset
1721
a61af66fc99e Initial load
duke
parents:
diff changeset
1722 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1723 * This should never happen (because of the selection code in SelectJRE),
a61af66fc99e Initial load
duke
parents:
diff changeset
1724 * but check for "impossibly" long path names just because buffer overruns
a61af66fc99e Initial load
duke
parents:
diff changeset
1725 * can be so deadly.
a61af66fc99e Initial load
duke
parents:
diff changeset
1726 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1727 if (strlen(wanted) + strlen(progname) + 6 > PATH_MAX) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1728 fprintf(stderr, "Path length exceeds maximum length (PATH_MAX)\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1729 exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1730 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1731
a61af66fc99e Initial load
duke
parents:
diff changeset
1732 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1733 * Construct the path and exec it.
a61af66fc99e Initial load
duke
parents:
diff changeset
1734 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1735 (void)strcat(strcat(wanted, "/bin/"), progname);
a61af66fc99e Initial load
duke
parents:
diff changeset
1736 argv[0] = progname;
a61af66fc99e Initial load
duke
parents:
diff changeset
1737 if (_launcher_debug) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1738 int i;
a61af66fc99e Initial load
duke
parents:
diff changeset
1739 printf("execv(\"%s\"", wanted);
a61af66fc99e Initial load
duke
parents:
diff changeset
1740 for (i = 0; argv[i] != NULL; i++)
a61af66fc99e Initial load
duke
parents:
diff changeset
1741 printf(", \"%s\"", argv[i]);
a61af66fc99e Initial load
duke
parents:
diff changeset
1742 printf(")\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1743 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1744 execv(wanted, argv);
a61af66fc99e Initial load
duke
parents:
diff changeset
1745 fprintf(stderr, "Exec of %s failed\n", wanted);
a61af66fc99e Initial load
duke
parents:
diff changeset
1746 exit(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1747 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1748
a61af66fc99e Initial load
duke
parents:
diff changeset
1749 #endif /* ifndef GAMMA */
a61af66fc99e Initial load
duke
parents:
diff changeset
1750
a61af66fc99e Initial load
duke
parents:
diff changeset
1751 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1752 * "Borrowed" from Solaris 10 where the unsetenv() function is being added
a61af66fc99e Initial load
duke
parents:
diff changeset
1753 * to libc thanks to SUSv3 (Standard Unix Specification, version 3). As
a61af66fc99e Initial load
duke
parents:
diff changeset
1754 * such, in the fullness of time this will appear in libc on all relevant
a61af66fc99e Initial load
duke
parents:
diff changeset
1755 * Solaris/Linux platforms and maybe even the Windows platform. At that
a61af66fc99e Initial load
duke
parents:
diff changeset
1756 * time, this stub can be removed.
a61af66fc99e Initial load
duke
parents:
diff changeset
1757 *
a61af66fc99e Initial load
duke
parents:
diff changeset
1758 * This implementation removes the environment locking for multithreaded
a61af66fc99e Initial load
duke
parents:
diff changeset
1759 * applications. (We don't have access to these mutexes within libc and
a61af66fc99e Initial load
duke
parents:
diff changeset
1760 * the launcher isn't multithreaded.) Note that what remains is platform
a61af66fc99e Initial load
duke
parents:
diff changeset
1761 * independent, because it only relies on attributes that a POSIX environment
a61af66fc99e Initial load
duke
parents:
diff changeset
1762 * defines.
a61af66fc99e Initial load
duke
parents:
diff changeset
1763 *
a61af66fc99e Initial load
duke
parents:
diff changeset
1764 * Returns 0 on success, -1 on failure.
a61af66fc99e Initial load
duke
parents:
diff changeset
1765 *
a61af66fc99e Initial load
duke
parents:
diff changeset
1766 * Also removed was the setting of errno. The only value of errno set
a61af66fc99e Initial load
duke
parents:
diff changeset
1767 * was EINVAL ("Invalid Argument").
a61af66fc99e Initial load
duke
parents:
diff changeset
1768 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1769
a61af66fc99e Initial load
duke
parents:
diff changeset
1770 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1771 * s1(environ) is name=value
a61af66fc99e Initial load
duke
parents:
diff changeset
1772 * s2(name) is name(not the form of name=value).
a61af66fc99e Initial load
duke
parents:
diff changeset
1773 * if names match, return value of 1, else return 0
a61af66fc99e Initial load
duke
parents:
diff changeset
1774 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1775 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
1776 match_noeq(const char *s1, const char *s2)
a61af66fc99e Initial load
duke
parents:
diff changeset
1777 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1778 while (*s1 == *s2++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1779 if (*s1++ == '=')
a61af66fc99e Initial load
duke
parents:
diff changeset
1780 return (1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1781 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1782 if (*s1 == '=' && s2[-1] == '\0')
a61af66fc99e Initial load
duke
parents:
diff changeset
1783 return (1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1784 return (0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1785 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1786
a61af66fc99e Initial load
duke
parents:
diff changeset
1787 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1788 * added for SUSv3 standard
a61af66fc99e Initial load
duke
parents:
diff changeset
1789 *
a61af66fc99e Initial load
duke
parents:
diff changeset
1790 * Delete entry from environ.
a61af66fc99e Initial load
duke
parents:
diff changeset
1791 * Do not free() memory! Other threads may be using it.
a61af66fc99e Initial load
duke
parents:
diff changeset
1792 * Keep it around forever.
a61af66fc99e Initial load
duke
parents:
diff changeset
1793 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1794 static int
a61af66fc99e Initial load
duke
parents:
diff changeset
1795 borrowed_unsetenv(const char *name)
a61af66fc99e Initial load
duke
parents:
diff changeset
1796 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1797 long idx; /* index into environ */
a61af66fc99e Initial load
duke
parents:
diff changeset
1798
a61af66fc99e Initial load
duke
parents:
diff changeset
1799 if (name == NULL || *name == '\0' ||
a61af66fc99e Initial load
duke
parents:
diff changeset
1800 strchr(name, '=') != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1801 return (-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1802 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1803
a61af66fc99e Initial load
duke
parents:
diff changeset
1804 for (idx = 0; environ[idx] != NULL; idx++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1805 if (match_noeq(environ[idx], name))
a61af66fc99e Initial load
duke
parents:
diff changeset
1806 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1807 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1808 if (environ[idx] == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1809 /* name not found but still a success */
a61af66fc99e Initial load
duke
parents:
diff changeset
1810 return (0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1811 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1812 /* squeeze up one entry */
a61af66fc99e Initial load
duke
parents:
diff changeset
1813 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
1814 environ[idx] = environ[idx+1];
a61af66fc99e Initial load
duke
parents:
diff changeset
1815 } while (environ[++idx] != NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
1816
a61af66fc99e Initial load
duke
parents:
diff changeset
1817 return (0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1818 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1819 /* --- End of "borrowed" code --- */
a61af66fc99e Initial load
duke
parents:
diff changeset
1820
a61af66fc99e Initial load
duke
parents:
diff changeset
1821 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
1822 * Wrapper for unsetenv() function.
a61af66fc99e Initial load
duke
parents:
diff changeset
1823 */
a61af66fc99e Initial load
duke
parents:
diff changeset
1824 int
a61af66fc99e Initial load
duke
parents:
diff changeset
1825 UnsetEnv(char *name)
a61af66fc99e Initial load
duke
parents:
diff changeset
1826 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1827 return(borrowed_unsetenv(name));
a61af66fc99e Initial load
duke
parents:
diff changeset
1828 }
388
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1829
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1830 /*
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1831 * The implementation for finding classes from the bootstrap
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1832 * class loader, refer to java.h
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1833 */
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1834 static FindClassFromBootLoader_t *findBootClass = NULL;
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1835
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1836 jclass
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1837 FindBootStrapClass(JNIEnv *env, const char* classname)
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1838 {
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1839 if (findBootClass == NULL) {
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1840 findBootClass = (FindClassFromBootLoader_t *)dlsym(RTLD_DEFAULT,
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1841 "JVM_FindClassFromBootLoader");
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1842 if (findBootClass == NULL) {
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1843 fprintf(stderr, "Error: could not load method JVM_FindClassFromBootLoader");
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1844 return NULL;
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1845 }
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1846 }
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1847 return findBootClass(env, classname, JNI_FALSE);
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1848 }
f008d3631bd1 6755845: JVM_FindClassFromBoot triggers assertions
ksrini
parents: 0
diff changeset
1849