/* This is a special library that should be loaded before libc & *libthreadtointerposethesignalhandlerinstallationfunctions: *sigaction(),signal(),sigset(). *Usedforsignal-chaining.SeeRFE4381843. *Useofsignal()andsigset()isnowdeprecatedastheseoldAPI'sshould *notbeused-sigactionistheonlytrulysupportedAPI.
*/
/* 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;
staticvoid signal_lock() {
pthread_mutex_lock(&mutex); /* When the jvm is installing its set of signal handlers, threads
* other than the jvm thread should wait. */ if (jvm_signal_installing) { /* tid is not initialized until jvm_signal_installing is set to true. */ if (pthread_equal(tid, pthread_self()) == 0) { do {
pthread_cond_wait(&cond, &mutex);
} while (jvm_signal_installing);
}
}
}
if (os_signal == NULL) { // Deprecation warning first time through
printf(HOTSPOT_VM_DISTRO " VM warning: the use of signal() and sigset() " "for signal chaining was deprecated in version 16.0 and will " "be removed in a future release. Use sigaction() instead.\n"); 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
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);
signal_unlock(); return oldhandler;
} elseif (jvm_signal_installing) { /* jvm is installing its signal handlers. Install the new *handlersandsavetheoldones.jvmusessigaction().
* 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(); return oldhandler;
} else { /* jvm has no relation with this signal (yet). Install the
* the handler. */
oldhandler = call_os_signal(sig, disp, is_sigset);
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 (oact != NULL) {
*oact = sact[sig];
} if (act != NULL) {
sact[sig] = *act;
}
signal_unlock(); return0;
} elseif (jvm_signal_installing) { /* jvm is installing its signal handlers. *-ifthisisamodifyingsigactioncall,weinstallanewsignalhandlerandstoretheoldone *aschainedsignalhandler. *-ifthisisanon-modifyingsigactioncall,wedon'tchangeanystate;wejustreturntheexisting *signalhandlerinthesystem(notthestoredone). *Thisworksundertheassumptionthatthereisonlyonemodifyingsigactioncallforaspecificsignal *withintheJVM_begin_signal_setting-JVM_end_signal_setting-window.Therecanbeanynumberofnon-modifying *calls,buttheywillonlyreturntheexpectedpreexistinghandlerifexecutedbeforethemodifyingcall.
*/
res = call_os_sigaction(sig, act, &oldAct); if (res == 0) { if (act != NULL) { /* store pre-existing handler as chained handler */
sact[sig] = oldAct; /* Record the signals used by jvm. */
sigaddset(&jvmsigs, sig);
} if (oact != NULL) {
*oact = oldAct;
}
}
signal_unlock(); return res;
} else { /* jvm has no relation with this signal (yet). Install the
* the handler. */
res = call_os_sigaction(sig, act, oact);
signal_unlock(); return res;
}
}
/* The three functions for the jvm to call into. */
JNIEXPORT void JVM_begin_signal_setting() {
signal_lock();
sigemptyset(&jvmsigs);
jvm_signal_installing = true;
tid = pthread_self();
signal_unlock();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.