< prev index next >
src/java.base/aix/native/libjsig/jsig.c
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2015 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
--- 1,7 ----
/*
! * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2015 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
*** 21,64 ****
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
- /* CopyrightVersion 1.2 */
-
/* This is a special library that should be loaded before libc &
* libthread to interpose the signal handler installation functions:
* sigaction(), signal(), sigset().
* Used for signal-chaining. See RFE 4381843.
*/
- #include <signal.h>
#include <dlfcn.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
- #include <stdint.h>
! #define bool int
! #define true 1
! #define false 0
static struct sigaction sact[NSIG]; /* saved signal handlers */
static sigset_t jvmsigs; /* Signals used by jvm. */
/* Used to synchronize the installation of signal handlers. */
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
static pthread_t tid = 0;
typedef void (*sa_handler_t)(int);
typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
! // signal_t is already defined on AIX.
! typedef sa_handler_t (*signal_like_function_t)(int, sa_handler_t);
typedef int (*sigaction_t)(int, const struct sigaction *, struct sigaction *);
! static signal_like_function_t os_signal = 0; /* os's version of signal()/sigset() */
static sigaction_t os_sigaction = 0; /* os's version of sigaction() */
static bool jvm_signal_installing = false;
static bool jvm_signal_installed = false;
--- 21,68 ----
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
/* This is a special library that should be loaded before libc &
* libthread to interpose the signal handler installation functions:
* sigaction(), signal(), sigset().
* Used for signal-chaining. See RFE 4381843.
*/
#include <dlfcn.h>
#include <pthread.h>
+ #include <signal.h>
#include <stdio.h>
#include <stdlib.h>
! #if (__STDC_VERSION__ >= 199901L)
! #include <stdbool.h>
! #else
! #define bool int
! #define true 1
! #define false 0
! #endif
static struct sigaction sact[NSIG]; /* saved signal handlers */
static sigset_t jvmsigs; /* Signals used by jvm. */
+ #ifdef MACOSX
+ static __thread bool reentry = false; /* prevent reentry deadlock (per-thread) */
+ #endif
+
/* Used to synchronize the installation of signal handlers. */
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
static pthread_t tid = 0;
typedef void (*sa_handler_t)(int);
typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
! typedef sa_handler_t (*signal_function_t)(int, sa_handler_t);
typedef int (*sigaction_t)(int, const struct sigaction *, struct sigaction *);
! static signal_function_t os_signal = 0; /* os's version of signal()/sigset() */
static sigaction_t os_sigaction = 0; /* os's version of sigaction() */
static bool jvm_signal_installing = false;
static bool jvm_signal_installed = false;
*** 77,131 ****
pthread_mutex_unlock(&mutex);
}
static sa_handler_t call_os_signal(int sig, sa_handler_t disp,
bool is_sigset) {
if (os_signal == NULL) {
if (!is_sigset) {
! // Aix: call functions directly instead of dlsym'ing them.
! os_signal = signal;
} else {
! // Aix: call functions directly instead of dlsym'ing them.
! os_signal = sigset;
}
if (os_signal == NULL) {
printf("%s\n", dlerror());
exit(0);
}
}
! return (*os_signal)(sig, disp);
}
! static void save_signal_handler(int sig, sa_handler_t disp) {
sigset_t set;
sact[sig].sa_handler = disp;
sigemptyset(&set);
sact[sig].sa_mask = set;
sact[sig].sa_flags = 0;
}
static sa_handler_t set_signal(int sig, sa_handler_t disp, bool is_sigset) {
sa_handler_t oldhandler;
bool sigused;
signal_lock();
sigused = sigismember(&jvmsigs, sig);
if (jvm_signal_installed && sigused) {
/* jvm has installed its signal handler for this signal. */
/* Save the handler. Don't really install it. */
oldhandler = sact[sig].sa_handler;
! save_signal_handler(sig, disp);
signal_unlock();
return oldhandler;
} else if (jvm_signal_installing) {
/* jvm is installing its signal handlers. Install the new
* handlers and save the old ones. jvm uses sigaction().
* Leave the piece here just in case. */
oldhandler = call_os_signal(sig, disp, is_sigset);
! save_signal_handler(sig, oldhandler);
/* Record the signals used by jvm */
sigaddset(&jvmsigs, sig);
signal_unlock();
--- 81,170 ----
pthread_mutex_unlock(&mutex);
}
static sa_handler_t call_os_signal(int sig, sa_handler_t disp,
bool is_sigset) {
+ sa_handler_t res;
+
if (os_signal == NULL) {
if (!is_sigset) {
! os_signal = (signal_function_t)dlsym(RTLD_NEXT, "signal");
} else {
! os_signal = (signal_function_t)dlsym(RTLD_NEXT, "sigset");
}
if (os_signal == NULL) {
printf("%s\n", dlerror());
exit(0);
}
}
!
! #ifdef MACOSX
! /* On macosx, the OS implementation of signal calls sigaction.
! * Make sure we do not deadlock with ourself. (See JDK-8072147). */
! reentry = true;
! #endif
!
! res = (*os_signal)(sig, disp);
!
! #ifdef MACOSX
! reentry = false;
! #endif
!
! return res;
}
! static void save_signal_handler(int sig, sa_handler_t disp, bool is_sigset) {
sigset_t set;
sact[sig].sa_handler = disp;
sigemptyset(&set);
sact[sig].sa_mask = set;
+ if (!is_sigset) {
+ #ifdef SOLARIS
+ sact[sig].sa_flags = SA_NODEFER;
+ if (sig != SIGILL && sig != SIGTRAP && sig != SIGPWR) {
+ sact[sig].sa_flags |= SA_RESETHAND;
+ }
+ #else
+ sact[sig].sa_flags = 0;
+ #endif
+ } else {
sact[sig].sa_flags = 0;
+ }
}
static sa_handler_t set_signal(int sig, sa_handler_t disp, bool is_sigset) {
sa_handler_t oldhandler;
bool sigused;
+ bool sigblocked;
signal_lock();
sigused = sigismember(&jvmsigs, sig);
if (jvm_signal_installed && sigused) {
/* jvm has installed its signal handler for this signal. */
/* Save the handler. Don't really install it. */
+ if (is_sigset) {
+ sigblocked = sigismember(&(sact[sig].sa_mask), sig);
+ }
oldhandler = sact[sig].sa_handler;
! save_signal_handler(sig, disp, is_sigset);
!
! #ifdef SOLARIS
! if (is_sigset && sigblocked) {
! /* We won't honor the SIG_HOLD request to change the signal mask */
! oldhandler = SIG_HOLD;
! }
! #endif
signal_unlock();
return oldhandler;
} else if (jvm_signal_installing) {
/* jvm is installing its signal handlers. Install the new
* handlers and save the old ones. jvm uses sigaction().
* Leave the piece here just in case. */
oldhandler = call_os_signal(sig, disp, is_sigset);
! save_signal_handler(sig, oldhandler, is_sigset);
/* Record the signals used by jvm */
sigaddset(&jvmsigs, sig);
signal_unlock();
*** 143,160 ****
sa_handler_t signal(int sig, sa_handler_t disp) {
return set_signal(sig, disp, false);
}
sa_handler_t sigset(int sig, sa_handler_t disp) {
return set_signal(sig, disp, true);
}
static int call_os_sigaction(int sig, const struct sigaction *act,
struct sigaction *oact) {
if (os_sigaction == NULL) {
! // Aix: call functions directly instead of dlsym'ing them.
! os_sigaction = sigaction;
if (os_sigaction == NULL) {
printf("%s\n", dlerror());
exit(0);
}
}
--- 182,203 ----
sa_handler_t signal(int sig, sa_handler_t disp) {
return set_signal(sig, disp, false);
}
sa_handler_t sigset(int sig, sa_handler_t disp) {
+ #ifdef _ALLBSD_SOURCE
+ printf("sigset() is not supported by BSD");
+ exit(0);
+ #else
return set_signal(sig, disp, true);
+ #endif
}
static int call_os_sigaction(int sig, const struct sigaction *act,
struct sigaction *oact) {
if (os_sigaction == NULL) {
! os_sigaction = (sigaction_t)dlsym(RTLD_NEXT, "sigaction");
if (os_sigaction == NULL) {
printf("%s\n", dlerror());
exit(0);
}
}
*** 164,173 ****
--- 207,222 ----
int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) {
int res;
bool sigused;
struct sigaction oldAct;
+ #ifdef MACOSX
+ if (reentry) {
+ return call_os_sigaction(sig, act, oact);
+ }
+ #endif
+
signal_lock();
sigused = sigismember(&jvmsigs, sig);
if (jvm_signal_installed && sigused) {
/* jvm has installed its signal handler for this signal. */
< prev index next >