author | itakiguchi |
Wed, 08 May 2019 22:59:20 -0700 | |
changeset 54875 | bcfedddcf4ce |
parent 53319 | db7b41933563 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
54875
bcfedddcf4ce
8211826: StringIndexOutOfBoundsException happens via GetStringUTFRegion()
itakiguchi
parents:
53319
diff
changeset
|
2 |
* Copyright (c) 2004, 2019, 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 <stdlib.h> |
|
27 |
#include <string.h> |
|
28 |
#include <unistd.h> |
|
29 |
#include <dlfcn.h> |
|
30 |
||
31 |
#include <jni.h> |
|
18232 | 32 |
#include <sizecalc.h> |
2 | 33 |
#include "sun_awt_UNIXToolkit.h" |
34 |
||
35 |
#ifndef HEADLESS |
|
36 |
#include "awt.h" |
|
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
37 |
#include "gtk_interface.h" |
2 | 38 |
#endif /* !HEADLESS */ |
39 |
||
40 |
||
41 |
static jclass this_class = NULL; |
|
42 |
static jmethodID icon_upcall_method = NULL; |
|
43 |
||
44 |
||
45 |
/* |
|
46 |
* Class: sun_awt_UNIXToolkit |
|
47 |
* Method: check_gtk |
|
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
48 |
* Signature: (I)Z |
2 | 49 |
*/ |
50 |
JNIEXPORT jboolean JNICALL |
|
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
51 |
Java_sun_awt_UNIXToolkit_check_1gtk(JNIEnv *env, jclass klass, jint version) { |
2 | 52 |
#ifndef HEADLESS |
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
53 |
return (jboolean)gtk_check_version(version); |
2 | 54 |
#else |
55 |
return JNI_FALSE; |
|
56 |
#endif /* !HEADLESS */ |
|
57 |
} |
|
58 |
||
59 |
||
60 |
/* |
|
61 |
* Class: sun_awt_UNIXToolkit |
|
62 |
* Method: load_gtk |
|
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
63 |
* Signature: (I)Z |
2 | 64 |
*/ |
65 |
JNIEXPORT jboolean JNICALL |
|
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
66 |
Java_sun_awt_UNIXToolkit_load_1gtk(JNIEnv *env, jclass klass, jint version, |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
67 |
jboolean verbose) { |
2 | 68 |
#ifndef HEADLESS |
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
69 |
return (jboolean)gtk_load(env, version, verbose); |
2 | 70 |
#else |
71 |
return JNI_FALSE; |
|
72 |
#endif /* !HEADLESS */ |
|
73 |
} |
|
74 |
||
75 |
||
76 |
/* |
|
77 |
* Class: sun_awt_UNIXToolkit |
|
78 |
* Method: unload_gtk |
|
79 |
* Signature: ()Z |
|
80 |
*/ |
|
81 |
JNIEXPORT jboolean JNICALL |
|
82 |
Java_sun_awt_UNIXToolkit_unload_1gtk(JNIEnv *env, jclass klass) |
|
83 |
{ |
|
84 |
#ifndef HEADLESS |
|
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
85 |
return (jboolean)gtk->unload(); |
2 | 86 |
#else |
87 |
return JNI_FALSE; |
|
88 |
#endif /* !HEADLESS */ |
|
89 |
} |
|
90 |
||
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
91 |
jboolean init_method(JNIEnv *env, jobject this) |
2 | 92 |
{ |
93 |
if (this_class == NULL) { |
|
94 |
this_class = (*env)->NewGlobalRef(env, |
|
95 |
(*env)->GetObjectClass(env, this)); |
|
96 |
icon_upcall_method = (*env)->GetMethodID(env, this_class, |
|
97 |
"loadIconCallback", "([BIIIIIZ)V"); |
|
24130
db72fc72f87b
8031001: [Parfait] warnings from b121 for jdk/src/solaris/native/sun/awt: JNI-related warnings
pchelko
parents:
23010
diff
changeset
|
98 |
CHECK_NULL_RETURN(icon_upcall_method, JNI_FALSE); |
2 | 99 |
} |
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
100 |
return JNI_TRUE; |
2 | 101 |
} |
102 |
||
103 |
/* |
|
104 |
* Class: sun_awt_UNIXToolkit |
|
105 |
* Method: load_gtk_icon |
|
106 |
* Signature: (Ljava/lang/String)Z |
|
107 |
* |
|
108 |
* This method assumes that GTK libs are present. |
|
109 |
*/ |
|
110 |
JNIEXPORT jboolean JNICALL |
|
111 |
Java_sun_awt_UNIXToolkit_load_1gtk_1icon(JNIEnv *env, jobject this, |
|
112 |
jstring filename) |
|
113 |
{ |
|
114 |
#ifndef HEADLESS |
|
115 |
int len; |
|
54875
bcfedddcf4ce
8211826: StringIndexOutOfBoundsException happens via GetStringUTFRegion()
itakiguchi
parents:
53319
diff
changeset
|
116 |
jsize jlen; |
2 | 117 |
char *filename_str = NULL; |
118 |
GError **error = NULL; |
|
119 |
||
120 |
if (filename == NULL) |
|
121 |
{ |
|
122 |
return JNI_FALSE; |
|
123 |
} |
|
124 |
||
125 |
len = (*env)->GetStringUTFLength(env, filename); |
|
54875
bcfedddcf4ce
8211826: StringIndexOutOfBoundsException happens via GetStringUTFRegion()
itakiguchi
parents:
53319
diff
changeset
|
126 |
jlen = (*env)->GetStringLength(env, filename); |
18232 | 127 |
filename_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc, |
128 |
sizeof(char), len + 1); |
|
2 | 129 |
if (filename_str == NULL) { |
130 |
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); |
|
131 |
return JNI_FALSE; |
|
132 |
} |
|
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
133 |
if (!init_method(env, this) ) { |
40146
e824dfef29db
8161740: [parfait] Memory leak in Java_sun_awt_UNIXToolkit_load_1gtk_1icon of awt_UNIXToolkit.c:132
vadim
parents:
37711
diff
changeset
|
134 |
free(filename_str); |
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
135 |
return JNI_FALSE; |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
136 |
} |
54875
bcfedddcf4ce
8211826: StringIndexOutOfBoundsException happens via GetStringUTFRegion()
itakiguchi
parents:
53319
diff
changeset
|
137 |
(*env)->GetStringUTFRegion(env, filename, 0, jlen, filename_str); |
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
138 |
jboolean result = gtk->get_file_icon_data(env, filename_str, error, |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
139 |
icon_upcall_method, this); |
2 | 140 |
|
141 |
/* Release the strings we've allocated. */ |
|
142 |
free(filename_str); |
|
143 |
||
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
144 |
return result; |
2 | 145 |
#else /* HEADLESS */ |
146 |
return JNI_FALSE; |
|
147 |
#endif /* !HEADLESS */ |
|
148 |
} |
|
149 |
||
150 |
/* |
|
151 |
* Class: sun_awt_UNIXToolkit |
|
152 |
* Method: load_stock_icon |
|
153 |
* Signature: (ILjava/lang/String;IILjava/lang/String;)Z |
|
154 |
* |
|
155 |
* This method assumes that GTK libs are present. |
|
156 |
*/ |
|
157 |
JNIEXPORT jboolean JNICALL |
|
158 |
Java_sun_awt_UNIXToolkit_load_1stock_1icon(JNIEnv *env, jobject this, |
|
159 |
jint widget_type, jstring stock_id, jint icon_size, |
|
160 |
jint text_direction, jstring detail) |
|
161 |
{ |
|
162 |
#ifndef HEADLESS |
|
163 |
int len; |
|
54875
bcfedddcf4ce
8211826: StringIndexOutOfBoundsException happens via GetStringUTFRegion()
itakiguchi
parents:
53319
diff
changeset
|
164 |
jsize jlen; |
2 | 165 |
char *stock_id_str = NULL; |
166 |
char *detail_str = NULL; |
|
53319 | 167 |
jboolean result = JNI_FALSE; |
2 | 168 |
|
169 |
if (stock_id == NULL) |
|
170 |
{ |
|
171 |
return JNI_FALSE; |
|
172 |
} |
|
173 |
||
174 |
len = (*env)->GetStringUTFLength(env, stock_id); |
|
54875
bcfedddcf4ce
8211826: StringIndexOutOfBoundsException happens via GetStringUTFRegion()
itakiguchi
parents:
53319
diff
changeset
|
175 |
jlen = (*env)->GetStringLength(env, stock_id); |
18232 | 176 |
stock_id_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc, |
177 |
sizeof(char), len + 1); |
|
2 | 178 |
if (stock_id_str == NULL) { |
179 |
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); |
|
180 |
return JNI_FALSE; |
|
181 |
} |
|
54875
bcfedddcf4ce
8211826: StringIndexOutOfBoundsException happens via GetStringUTFRegion()
itakiguchi
parents:
53319
diff
changeset
|
182 |
(*env)->GetStringUTFRegion(env, stock_id, 0, jlen, stock_id_str); |
2 | 183 |
|
184 |
/* Detail isn't required so check for NULL. */ |
|
185 |
if (detail != NULL) |
|
186 |
{ |
|
187 |
len = (*env)->GetStringUTFLength(env, detail); |
|
54875
bcfedddcf4ce
8211826: StringIndexOutOfBoundsException happens via GetStringUTFRegion()
itakiguchi
parents:
53319
diff
changeset
|
188 |
jlen = (*env)->GetStringLength(env, detail); |
18232 | 189 |
detail_str = (char *)SAFE_SIZE_ARRAY_ALLOC(malloc, |
190 |
sizeof(char), len + 1); |
|
2 | 191 |
if (detail_str == NULL) { |
52251
b43c2aa001a5
8211317: avoid memory leak in Java_sun_awt_UNIXToolkit_load_1stock_1icon
mbaesken
parents:
47216
diff
changeset
|
192 |
free(stock_id_str); |
2 | 193 |
JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); |
194 |
return JNI_FALSE; |
|
195 |
} |
|
54875
bcfedddcf4ce
8211826: StringIndexOutOfBoundsException happens via GetStringUTFRegion()
itakiguchi
parents:
53319
diff
changeset
|
196 |
(*env)->GetStringUTFRegion(env, detail, 0, jlen, detail_str); |
2 | 197 |
} |
198 |
||
53319 | 199 |
if (init_method(env, this)) { |
200 |
result = gtk->get_icon_data(env, widget_type, stock_id_str, |
|
201 |
icon_size, text_direction, detail_str, |
|
202 |
icon_upcall_method, this); |
|
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
203 |
} |
2 | 204 |
/* Release the strings we've allocated. */ |
205 |
free(stock_id_str); |
|
53319 | 206 |
free(detail_str); |
207 |
||
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
208 |
return result; |
2 | 209 |
#else /* HEADLESS */ |
210 |
return JNI_FALSE; |
|
211 |
#endif /* !HEADLESS */ |
|
212 |
} |
|
213 |
||
214 |
/* |
|
215 |
* Class: sun_awt_UNIXToolkit |
|
216 |
* Method: nativeSync |
|
217 |
* Signature: ()V |
|
218 |
*/ |
|
219 |
JNIEXPORT void JNICALL |
|
220 |
Java_sun_awt_UNIXToolkit_nativeSync(JNIEnv *env, jobject this) |
|
221 |
{ |
|
222 |
#ifndef HEADLESS |
|
223 |
AWT_LOCK(); |
|
224 |
XSync(awt_display, False); |
|
225 |
AWT_UNLOCK(); |
|
226 |
#endif /* !HEADLESS */ |
|
227 |
} |
|
228 |
||
229 |
/* |
|
230 |
* Class: sun_awt_SunToolkit |
|
231 |
* Method: closeSplashScreen |
|
232 |
* Signature: ()V |
|
233 |
*/ |
|
234 |
JNIEXPORT void JNICALL |
|
235 |
Java_sun_awt_SunToolkit_closeSplashScreen(JNIEnv *env, jclass cls) |
|
236 |
{ |
|
237 |
typedef void (*SplashClose_t)(); |
|
238 |
SplashClose_t splashClose; |
|
239 |
void* hSplashLib = dlopen(0, RTLD_LAZY); |
|
240 |
if (!hSplashLib) { |
|
241 |
return; |
|
242 |
} |
|
243 |
splashClose = (SplashClose_t)dlsym(hSplashLib, |
|
244 |
"SplashClose"); |
|
245 |
if (splashClose) { |
|
246 |
splashClose(); |
|
247 |
} |
|
248 |
dlclose(hSplashLib); |
|
249 |
} |
|
5444
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
250 |
|
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
251 |
/* |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
252 |
* Class: sun_awt_UNIXToolkit |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
253 |
* Method: gtkCheckVersionImpl |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
254 |
* Signature: (III)Ljava/lang/String; |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
255 |
*/ |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
256 |
JNIEXPORT jboolean JNICALL |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
257 |
Java_sun_awt_UNIXToolkit_gtkCheckVersionImpl(JNIEnv *env, jobject this, |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
258 |
jint major, jint minor, jint micro) |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
259 |
{ |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
260 |
char *ret; |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
261 |
|
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
262 |
ret = gtk->gtk_check_version(major, minor, micro); |
5444
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
263 |
if (ret == NULL) { |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
264 |
return TRUE; |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
265 |
} |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
266 |
|
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
267 |
return FALSE; |
f7c5aeb82a14
6913179: The java.awt.FileDialog should use native GTK file chooser on linux distros
anthony
parents:
2
diff
changeset
|
268 |
} |
37711
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
269 |
|
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
270 |
/* |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
271 |
* Class: sun_awt_UNIXToolkit |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
272 |
* Method: get_gtk_version |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
273 |
* Signature: ()I |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
274 |
*/ |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
275 |
JNIEXPORT jint JNICALL |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
276 |
Java_sun_awt_UNIXToolkit_get_1gtk_1version(JNIEnv *env, jclass klass) |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
277 |
{ |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
278 |
#ifndef HEADLESS |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
279 |
return gtk ? gtk->version : GTK_ANY; |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
280 |
#else |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
281 |
return GTK_ANY; |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
282 |
#endif /* !HEADLESS */ |
972001566d66
8145547: [AWT/Swing] Conditional support for GTK 3 on Linux
ssadetsky
parents:
26751
diff
changeset
|
283 |
} |