annotate src/os/linux/launcher/java_md.c @ 1972:f95d63e2154a

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