20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 /* CopyrightVersion 1.2 */
26
27 /* This is a special library that should be loaded before libc &
28 * libthread to interpose the signal handler installation functions:
29 * sigaction(), signal(), sigset().
30 * Used for signal-chaining. See RFE 4381843.
31 */
32
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <signal.h>
37 #include <dlfcn.h>
38 #include <thread.h>
39 #include <synch.h>
40 #include "jvm_md.h"
41
42 #define bool int
43 #define true 1
44 #define false 0
45
46 static struct sigaction *sact = (struct sigaction *)NULL; /* saved signal handlers */
47 static sigset_t jvmsigs;
48
49 /* used to synchronize the installation of signal handlers */
50 static mutex_t mutex = DEFAULTMUTEX;
51 static cond_t cond = DEFAULTCV;
52 static thread_t tid = 0;
53
54 typedef void (*sa_handler_t)(int);
55 typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
56 typedef sa_handler_t (*signal_t)(int, sa_handler_t);
57 typedef int (*sigaction_t)(int, const struct sigaction *, struct sigaction *);
58
59 static signal_t os_signal = 0; /* os's version of signal()/sigset() */
159 * handlers and save the old ones. jvm uses sigaction().
160 * Leave the piece here just in case. */
161 oldhandler = call_os_signal(sig, disp, is_sigset);
162 save_signal_handler(sig, oldhandler, is_sigset);
163
164 /* Record the signals used by jvm */
165 sigaddset(&jvmsigs, sig);
166
167 signal_unlock();
168 return oldhandler;
169 } else {
170 /* jvm has no relation with this signal (yet). Install the
171 * the handler. */
172 oldhandler = call_os_signal(sig, disp, is_sigset);
173
174 signal_unlock();
175 return oldhandler;
176 }
177 }
178
179 sa_handler_t signal(int sig, sa_handler_t disp) {
180 return set_signal(sig, disp, false);
181 }
182
183 sa_handler_t sigset(int sig, sa_handler_t disp) {
184 return set_signal(sig, disp, true);
185 }
186
187 static int call_os_sigaction(int sig, const struct sigaction *act,
188 struct sigaction *oact) {
189 if (os_sigaction == NULL) {
190 os_sigaction = (sigaction_t)dlsym(RTLD_NEXT, "sigaction");
191 if (os_sigaction == NULL) {
192 printf("%s\n", dlerror());
193 exit(0);
194 }
195 }
196 return (*os_sigaction)(sig, act, oact);
197 }
198
199 int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) {
200 int res;
201 struct sigaction oldAct;
202
203 signal_lock();
204
205 if (sact == NULL ) {
206 allocate_sact();
207 }
208 if (jvm_signal_installed && sigismember(&jvmsigs, sig)) {
209 /* jvm has installed its signal handler for this signal. */
210 /* Save the handler. Don't really install it. */
211 if (oact != NULL) {
212 *oact = sact[sig];
213 }
214 if (act != NULL) {
215 sact[sig] = *act;
216 }
217
218 signal_unlock();
219 return 0;
225 if (oact != NULL) {
226 *oact = oldAct;
227 }
228
229 /* Record the signals used by jvm */
230 sigaddset(&jvmsigs, sig);
231
232 signal_unlock();
233 return res;
234 } else {
235 /* jvm has no relation with this signal (yet). Install the
236 * the handler. */
237 res = call_os_sigaction(sig, act, oact);
238
239 signal_unlock();
240 return res;
241 }
242 }
243
244 /* The four functions for the jvm to call into */
245 void JVM_begin_signal_setting() {
246 signal_lock();
247 jvm_signal_installing = true;
248 tid = thr_self();
249 signal_unlock();
250 }
251
252 void JVM_end_signal_setting() {
253 signal_lock();
254 jvm_signal_installed = true;
255 jvm_signal_installing = false;
256 cond_broadcast(&cond);
257 signal_unlock();
258 }
259
260 struct sigaction *JVM_get_signal_action(int sig) {
261 if (sact == NULL) {
262 allocate_sact();
263 }
264 /* Does race condition make sense here? */
265 if (sigismember(&jvmsigs, sig)) {
266 return &sact[sig];
267 }
268 return NULL;
269 }
270
271 int JVM_get_libjsig_version() {
272 return JSIG_VERSION_1_4_1;
273 }
|
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 /* CopyrightVersion 1.2 */
26
27 /* This is a special library that should be loaded before libc &
28 * libthread to interpose the signal handler installation functions:
29 * sigaction(), signal(), sigset().
30 * Used for signal-chaining. See RFE 4381843.
31 */
32
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <signal.h>
37 #include <dlfcn.h>
38 #include <thread.h>
39 #include <synch.h>
40 #include "jni.h"
41 #include "jvm_md.h"
42
43 #define bool int
44 #define true 1
45 #define false 0
46
47 static struct sigaction *sact = (struct sigaction *)NULL; /* saved signal handlers */
48 static sigset_t jvmsigs;
49
50 /* used to synchronize the installation of signal handlers */
51 static mutex_t mutex = DEFAULTMUTEX;
52 static cond_t cond = DEFAULTCV;
53 static thread_t tid = 0;
54
55 typedef void (*sa_handler_t)(int);
56 typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
57 typedef sa_handler_t (*signal_t)(int, sa_handler_t);
58 typedef int (*sigaction_t)(int, const struct sigaction *, struct sigaction *);
59
60 static signal_t os_signal = 0; /* os's version of signal()/sigset() */
160 * handlers and save the old ones. jvm uses sigaction().
161 * Leave the piece here just in case. */
162 oldhandler = call_os_signal(sig, disp, is_sigset);
163 save_signal_handler(sig, oldhandler, is_sigset);
164
165 /* Record the signals used by jvm */
166 sigaddset(&jvmsigs, sig);
167
168 signal_unlock();
169 return oldhandler;
170 } else {
171 /* jvm has no relation with this signal (yet). Install the
172 * the handler. */
173 oldhandler = call_os_signal(sig, disp, is_sigset);
174
175 signal_unlock();
176 return oldhandler;
177 }
178 }
179
180 JNIEXPORT sa_handler_t JNICALL
181 signal(int sig, sa_handler_t disp) {
182 return set_signal(sig, disp, false);
183 }
184
185 JNIEXPORT sa_handler_t JNICALL
186 sigset(int sig, sa_handler_t disp) {
187 return set_signal(sig, disp, true);
188 }
189
190 static int call_os_sigaction(int sig, const struct sigaction *act,
191 struct sigaction *oact) {
192 if (os_sigaction == NULL) {
193 os_sigaction = (sigaction_t)dlsym(RTLD_NEXT, "sigaction");
194 if (os_sigaction == NULL) {
195 printf("%s\n", dlerror());
196 exit(0);
197 }
198 }
199 return (*os_sigaction)(sig, act, oact);
200 }
201
202 JNIEXPORT int JNICALL
203 sigaction(int sig, const struct sigaction *act, struct sigaction *oact) {
204 int res;
205 struct sigaction oldAct;
206
207 signal_lock();
208
209 if (sact == NULL ) {
210 allocate_sact();
211 }
212 if (jvm_signal_installed && sigismember(&jvmsigs, sig)) {
213 /* jvm has installed its signal handler for this signal. */
214 /* Save the handler. Don't really install it. */
215 if (oact != NULL) {
216 *oact = sact[sig];
217 }
218 if (act != NULL) {
219 sact[sig] = *act;
220 }
221
222 signal_unlock();
223 return 0;
229 if (oact != NULL) {
230 *oact = oldAct;
231 }
232
233 /* Record the signals used by jvm */
234 sigaddset(&jvmsigs, sig);
235
236 signal_unlock();
237 return res;
238 } else {
239 /* jvm has no relation with this signal (yet). Install the
240 * the handler. */
241 res = call_os_sigaction(sig, act, oact);
242
243 signal_unlock();
244 return res;
245 }
246 }
247
248 /* The four functions for the jvm to call into */
249 JNIEXPORT void JNICALL
250 JVM_begin_signal_setting() {
251 signal_lock();
252 jvm_signal_installing = true;
253 tid = thr_self();
254 signal_unlock();
255 }
256
257 JNIEXPORT void JNICALL
258 JVM_end_signal_setting() {
259 signal_lock();
260 jvm_signal_installed = true;
261 jvm_signal_installing = false;
262 cond_broadcast(&cond);
263 signal_unlock();
264 }
265
266 JNIEXPORT struct sigaction * JNICALL
267 JVM_get_signal_action(int sig) {
268 if (sact == NULL) {
269 allocate_sact();
270 }
271 /* Does race condition make sense here? */
272 if (sigismember(&jvmsigs, sig)) {
273 return &sact[sig];
274 }
275 return NULL;
276 }
277
278 JNIEXPORT int JNICALL
279 JVM_get_libjsig_version() {
280 return JSIG_VERSION_1_4_1;
281 }
|