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