Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/solaris/native/sun/awt/awt_LoadLibrary.c
+++ new/src/solaris/native/sun/awt/awt_LoadLibrary.c
1 1 /*
2 2 * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 #include <stdio.h>
27 27 #include <dlfcn.h>
28 28 #include <string.h>
29 29 #include <stdlib.h>
30 30 #include <jni.h>
31 31 #include <jni_util.h>
32 32 #include <jvm.h>
33 33 #include "gdefs.h"
34 34
35 35 #include <sys/param.h>
36 36 #include <sys/utsname.h>
37 37
38 38 #include "awt_Plugin.h"
39 39
40 40 #ifdef DEBUG
41 41 #define VERBOSE_AWT_DEBUG
42 42 #endif
43 43
44 44 static void *awtHandle = NULL;
45 45
46 46 typedef JNIEXPORT jint JNICALL JNI_OnLoad_type(JavaVM *vm, void *reserved);
47 47
48 48 /* Initialize the Java VM instance variable when the library is
49 49 first loaded */
50 50 JavaVM *jvm;
51 51
52 52 JNIEXPORT jboolean JNICALL AWTIsHeadless() {
53 53 static JNIEnv *env = NULL;
54 54 static jboolean isHeadless;
55 55 jmethodID headlessFn;
56 56 jclass graphicsEnvClass;
57 57
58 58 if (env == NULL) {
59 59 env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
60 60 graphicsEnvClass = (*env)->FindClass(env,
61 61 "java/awt/GraphicsEnvironment");
62 62 if (graphicsEnvClass == NULL) {
63 63 return JNI_TRUE;
64 64 }
65 65 headlessFn = (*env)->GetStaticMethodID(env,
66 66 graphicsEnvClass, "isHeadless", "()Z");
67 67 if (headlessFn == NULL) {
68 68 return JNI_TRUE;
69 69 }
70 70 isHeadless = (*env)->CallStaticBooleanMethod(env, graphicsEnvClass,
71 71 headlessFn);
72 72 }
73 73 return isHeadless;
74 74 }
75 75
76 76 jint
77 77 AWT_OnLoad(JavaVM *vm, void *reserved)
78 78 {
79 79 Dl_info dlinfo;
80 80 char buf[MAXPATHLEN];
81 81 int32_t len;
82 82 char *p;
83 83 JNI_OnLoad_type *JNI_OnLoad_ptr;
84 84 struct utsname name;
85 85 JNIEnv *env = (JNIEnv *)JNU_GetEnv(vm, JNI_VERSION_1_2);
86 86 void *v;
87 87 char *envvar;
88 88 int xt_before_xm = 0;
89 89 int XAWT = 0;
90 90 jstring toolkit = NULL;
91 91 jstring propname = NULL;
92 92
93 93 if (awtHandle != NULL) {
94 94 /* Avoid several loading attempts */
95 95 return JNI_VERSION_1_2;
96 96 }
97 97
↓ open down ↓ |
97 lines elided |
↑ open up ↑ |
98 98 jvm = vm;
99 99
100 100 /* Get address of this library and the directory containing it. */
101 101 dladdr((void *)JNI_OnLoad, &dlinfo);
102 102 realpath((char *)dlinfo.dli_fname, buf);
103 103 len = strlen(buf);
104 104 p = strrchr(buf, '/');
105 105
106 106 /*
107 107 * The code below is responsible for:
108 - * 1. Loading appropriate awt library, i.e. xawt/libmawt or headless/libwawt
108 + * 1. Loading appropriate awt library, i.e. libawt_xawt or libawt_headless
109 109 * 2. Setting "awt.toolkit" system property to use the appropriate Java toolkit class,
110 110 * (if user has specified the toolkit in env varialble)
111 111 */
112 112
113 113 propname = (*env)->NewStringUTF(env, "awt.toolkit");
114 114 /* Check if toolkit is specified in env variable */
115 115 envvar = getenv("AWT_TOOLKIT");
116 116 if (envvar) {
117 117 if (strstr(envvar, "XToolkit")) {
118 118 toolkit = (*env)->NewStringUTF(env, "sun.awt.X11.XToolkit");
119 119 }
120 120 /* If user specified toolkit then set java system property */
121 121 if (toolkit && propname) {
122 122 JNU_CallStaticMethodByName (env,
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
123 123 NULL,
124 124 "java/lang/System",
125 125 "setProperty",
126 126 "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;",
127 127 propname,toolkit);
128 128 }
129 129 }
130 130
131 131 /* Calculate library name to load */
132 132 if (AWTIsHeadless()) {
133 - strncpy(p, "/headless/libmawt.so", MAXPATHLEN-len-1);
133 + strncpy(p, "/libawt_headless.so", MAXPATHLEN-len-1);
134 134 } else {
135 135 /* Default AWT Toolkit on Linux and Solaris is XAWT. */
136 - strncpy(p, "/xawt/libmawt.so", MAXPATHLEN-len-1);
136 + strncpy(p, "/libawt_xawt.so", MAXPATHLEN-len-1);
137 137 }
138 138
139 139 if (toolkit) {
140 140 (*env)->DeleteLocalRef(env, toolkit);
141 141 }
142 142 if (propname) {
143 143 (*env)->DeleteLocalRef(env, propname);
144 144 }
145 145
146 146 JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load",
147 147 "(Ljava/lang/String;)V",
148 148 JNU_NewStringPlatform(env, buf));
149 149
150 150 awtHandle = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL);
151 151
152 152 return JNI_VERSION_1_2;
153 153 }
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
154 154
155 155 JNIEXPORT jint JNICALL
156 156 JNI_OnLoad(JavaVM *vm, void *reserved)
157 157 {
158 158 return AWT_OnLoad(vm, reserved);
159 159 }
160 160
161 161 /*
162 162 * This entry point must remain in libawt.so as part of a contract
163 163 * with the CDE variant of Java Media Framework. (sdtjmplay)
164 - * Reflect this call over to the correct libmawt.so.
164 + * Reflect this call over to the correct libawt_<toolkit>.so.
165 165 */
166 166 JNIEXPORT void JNICALL
167 167 Java_sun_awt_motif_XsessionWMcommand(JNIEnv *env, jobject this,
168 168 jobject frame, jstring jcommand)
169 169 {
170 170 /* type of the old backdoor function */
171 171 typedef JNIEXPORT void JNICALL
172 172 XsessionWMcommand_type(JNIEnv *env, jobject this,
173 173 jobject frame, jstring jcommand);
174 174
175 175 static XsessionWMcommand_type *XsessionWMcommand = NULL;
176 176
177 177 if (XsessionWMcommand == NULL && awtHandle == NULL) {
178 178 return;
179 179 }
180 180
181 181 XsessionWMcommand = (XsessionWMcommand_type *)
182 182 dlsym(awtHandle, "Java_sun_awt_motif_XsessionWMcommand");
183 183
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
184 184 if (XsessionWMcommand == NULL)
185 185 return;
186 186
187 187 (*XsessionWMcommand)(env, this, frame, jcommand);
188 188 }
189 189
190 190
191 191 /*
192 192 * This entry point must remain in libawt.so as part of a contract
193 193 * with the CDE variant of Java Media Framework. (sdtjmplay)
194 - * Reflect this call over to the correct libmawt.so.
194 + * Reflect this call over to the correct libawt_<toolkit>.so.
195 195 */
196 196 JNIEXPORT void JNICALL
197 197 Java_sun_awt_motif_XsessionWMcommand_New(JNIEnv *env, jobjectArray jargv)
198 198 {
199 199 typedef JNIEXPORT void JNICALL
200 200 XsessionWMcommand_New_type(JNIEnv *env, jobjectArray jargv);
201 201
202 202 static XsessionWMcommand_New_type *XsessionWMcommand = NULL;
203 203
204 204 if (XsessionWMcommand == NULL && awtHandle == NULL) {
205 205 return;
206 206 }
207 207
208 208 XsessionWMcommand = (XsessionWMcommand_New_type *)
209 209 dlsym(awtHandle, "Java_sun_awt_motif_XsessionWMcommand_New");
210 210
211 211 if (XsessionWMcommand == NULL)
212 212 return;
213 213
214 214 (*XsessionWMcommand)(env, jargv);
215 215 }
216 216
217 217
218 218 #define REFLECT_VOID_FUNCTION(name, arglist, paramlist) \
219 219 typedef name##_type arglist; \
220 220 void name arglist \
221 221 { \
222 222 static name##_type *name##_ptr = NULL; \
223 223 if (name##_ptr == NULL && awtHandle == NULL) { \
224 224 return; \
225 225 } \
226 226 name##_ptr = (name##_type *) \
227 227 dlsym(awtHandle, #name); \
228 228 if (name##_ptr == NULL) { \
229 229 return; \
230 230 } \
231 231 (*name##_ptr)paramlist; \
232 232 }
233 233
234 234 #define REFLECT_FUNCTION(return_type, name, arglist, paramlist) \
235 235 typedef return_type name##_type arglist; \
236 236 return_type name arglist \
237 237 { \
238 238 static name##_type *name##_ptr = NULL; \
239 239 if (name##_ptr == NULL && awtHandle == NULL) { \
240 240 return NULL; \
241 241 } \
242 242 name##_ptr = (name##_type *) \
↓ open down ↓ |
38 lines elided |
↑ open up ↑ |
243 243 dlsym(awtHandle, #name); \
244 244 if (name##_ptr == NULL) { \
245 245 return NULL; \
246 246 } \
247 247 return (*name##_ptr)paramlist; \
248 248 }
249 249
250 250
251 251 /*
252 252 * These entry point must remain in libawt.so ***for Java Plugin ONLY***
253 - * Reflect this call over to the correct libmawt.so.
253 + * Reflect this call over to the correct libawt_<toolkit>.so.
254 254 */
255 255
256 256 REFLECT_VOID_FUNCTION(getAwtLockFunctions,
257 257 (void (**AwtLock)(JNIEnv *), void (**AwtUnlock)(JNIEnv *),
258 258 void (**AwtNoFlushUnlock)(JNIEnv *), void *reserved),
259 259 (AwtLock, AwtUnlock, AwtNoFlushUnlock, reserved))
260 260
261 261 REFLECT_VOID_FUNCTION(getAwtData,
262 262 (int32_t *awt_depth, Colormap *awt_cmap, Visual **awt_visual,
263 263 int32_t *awt_num_colors, void *pReserved),
264 264 (awt_depth, awt_cmap, awt_visual,
265 265 awt_num_colors, pReserved))
266 266
267 267 REFLECT_FUNCTION(Display *, getAwtDisplay, (void), ())
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX