aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "prims/jvm.h" aoqi@0: #include "runtime/interfaceSupport.hpp" aoqi@0: #include "runtime/osThread.hpp" aoqi@0: aoqi@0: #include aoqi@0: aoqi@0: aoqi@0: // sun.misc.Signal /////////////////////////////////////////////////////////// aoqi@0: // Signal code is mostly copied from classic vm, signals_md.c 1.4 98/08/23 aoqi@0: /* aoqi@0: * This function is included primarily as a debugging aid. If Java is aoqi@0: * running in a console window, then pressing will cause aoqi@0: * the current state of all active threads and monitors to be written aoqi@0: * to the console window. aoqi@0: */ aoqi@0: aoqi@0: JVM_ENTRY_NO_ENV(void*, JVM_RegisterSignal(jint sig, void* handler)) aoqi@0: // Copied from classic vm aoqi@0: // signals_md.c 1.4 98/08/23 aoqi@0: void* newHandler = handler == (void *)2 aoqi@0: ? os::user_handler() aoqi@0: : handler; aoqi@0: switch (sig) { aoqi@0: /* The following are already used by the VM. */ aoqi@0: case INTERRUPT_SIGNAL: aoqi@0: case SIGFPE: aoqi@0: case SIGILL: aoqi@0: case SIGSEGV: aoqi@0: aoqi@0: /* The following signal is used by the VM to dump thread stacks unless aoqi@0: ReduceSignalUsage is set, in which case the user is allowed to set aoqi@0: his own _native_ handler for this signal; thus, in either case, aoqi@0: we do not allow JVM_RegisterSignal to change the handler. */ aoqi@0: case BREAK_SIGNAL: aoqi@0: return (void *)-1; aoqi@0: aoqi@0: /* The following signals are used for Shutdown Hooks support. However, if aoqi@0: ReduceSignalUsage (-Xrs) is set, Shutdown Hooks must be invoked via aoqi@0: System.exit(), Java is not allowed to use these signals, and the the aoqi@0: user is allowed to set his own _native_ handler for these signals and aoqi@0: invoke System.exit() as needed. Terminator.setup() is avoiding aoqi@0: registration of these signals when -Xrs is present. aoqi@0: - If the HUP signal is ignored (from the nohup) command, then Java aoqi@0: is not allowed to use this signal. aoqi@0: */ aoqi@0: aoqi@0: case SHUTDOWN1_SIGNAL: aoqi@0: case SHUTDOWN2_SIGNAL: aoqi@0: case SHUTDOWN3_SIGNAL: aoqi@0: if (ReduceSignalUsage) return (void*)-1; aoqi@0: if (os::Bsd::is_sig_ignored(sig)) return (void*)1; aoqi@0: } aoqi@0: aoqi@0: void* oldHandler = os::signal(sig, newHandler); aoqi@0: if (oldHandler == os::user_handler()) { aoqi@0: return (void *)2; aoqi@0: } else { aoqi@0: return oldHandler; aoqi@0: } aoqi@0: JVM_END aoqi@0: aoqi@0: aoqi@0: JVM_ENTRY_NO_ENV(jboolean, JVM_RaiseSignal(jint sig)) aoqi@0: if (ReduceSignalUsage) { aoqi@0: // do not allow SHUTDOWN1_SIGNAL,SHUTDOWN2_SIGNAL,SHUTDOWN3_SIGNAL, aoqi@0: // BREAK_SIGNAL to be raised when ReduceSignalUsage is set, since aoqi@0: // no handler for them is actually registered in JVM or via aoqi@0: // JVM_RegisterSignal. aoqi@0: if (sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL || aoqi@0: sig == SHUTDOWN3_SIGNAL || sig == BREAK_SIGNAL) { aoqi@0: return JNI_FALSE; aoqi@0: } aoqi@0: } aoqi@0: else if ((sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL || aoqi@0: sig == SHUTDOWN3_SIGNAL) && os::Bsd::is_sig_ignored(sig)) { aoqi@0: // do not allow SHUTDOWN1_SIGNAL to be raised when SHUTDOWN1_SIGNAL aoqi@0: // is ignored, since no handler for them is actually registered in JVM aoqi@0: // or via JVM_RegisterSignal. aoqi@0: // This also applies for SHUTDOWN2_SIGNAL and SHUTDOWN3_SIGNAL aoqi@0: return JNI_FALSE; aoqi@0: } aoqi@0: aoqi@0: os::signal_raise(sig); aoqi@0: return JNI_TRUE; aoqi@0: JVM_END aoqi@0: aoqi@0: /* aoqi@0: All the defined signal names for Bsd. aoqi@0: aoqi@0: NOTE that not all of these names are accepted by our Java implementation aoqi@0: aoqi@0: Via an existing claim by the VM, sigaction restrictions, or aoqi@0: the "rules of Unix" some of these names will be rejected at runtime. aoqi@0: For example the VM sets up to handle USR1, sigaction returns EINVAL for aoqi@0: STOP, and Bsd simply doesn't allow catching of KILL. aoqi@0: aoqi@0: Here are the names currently accepted by a user of sun.misc.Signal with aoqi@0: 1.4.1 (ignoring potential interaction with use of chaining, etc): aoqi@0: aoqi@0: HUP, INT, TRAP, ABRT, IOT, BUS, USR2, PIPE, ALRM, TERM, STKFLT, aoqi@0: CLD, CHLD, CONT, TSTP, TTIN, TTOU, URG, XCPU, XFSZ, VTALRM, PROF, aoqi@0: WINCH, POLL, IO, PWR, SYS aoqi@0: aoqi@0: */ aoqi@0: aoqi@0: struct siglabel { aoqi@0: const char *name; aoqi@0: int number; aoqi@0: }; aoqi@0: aoqi@0: struct siglabel siglabels[] = { aoqi@0: /* derived from /usr/include/bits/signum.h on RH7.2 */ aoqi@0: "HUP", SIGHUP, /* Hangup (POSIX). */ aoqi@0: "INT", SIGINT, /* Interrupt (ANSI). */ aoqi@0: "QUIT", SIGQUIT, /* Quit (POSIX). */ aoqi@0: "ILL", SIGILL, /* Illegal instruction (ANSI). */ aoqi@0: "TRAP", SIGTRAP, /* Trace trap (POSIX). */ aoqi@0: "ABRT", SIGABRT, /* Abort (ANSI). */ aoqi@0: "EMT", SIGEMT, /* EMT trap */ aoqi@0: "FPE", SIGFPE, /* Floating-point exception (ANSI). */ aoqi@0: "KILL", SIGKILL, /* Kill, unblockable (POSIX). */ aoqi@0: "BUS", SIGBUS, /* BUS error (4.2 BSD). */ aoqi@0: "SEGV", SIGSEGV, /* Segmentation violation (ANSI). */ aoqi@0: "SYS", SIGSYS, /* Bad system call. Only on some Bsden! */ aoqi@0: "PIPE", SIGPIPE, /* Broken pipe (POSIX). */ aoqi@0: "ALRM", SIGALRM, /* Alarm clock (POSIX). */ aoqi@0: "TERM", SIGTERM, /* Termination (ANSI). */ aoqi@0: "URG", SIGURG, /* Urgent condition on socket (4.2 BSD). */ aoqi@0: "STOP", SIGSTOP, /* Stop, unblockable (POSIX). */ aoqi@0: "TSTP", SIGTSTP, /* Keyboard stop (POSIX). */ aoqi@0: "CONT", SIGCONT, /* Continue (POSIX). */ aoqi@0: "CHLD", SIGCHLD, /* Child status has changed (POSIX). */ aoqi@0: "TTIN", SIGTTIN, /* Background read from tty (POSIX). */ aoqi@0: "TTOU", SIGTTOU, /* Background write to tty (POSIX). */ aoqi@0: "IO", SIGIO, /* I/O now possible (4.2 BSD). */ aoqi@0: "XCPU", SIGXCPU, /* CPU limit exceeded (4.2 BSD). */ aoqi@0: "XFSZ", SIGXFSZ, /* File size limit exceeded (4.2 BSD). */ aoqi@0: "VTALRM", SIGVTALRM, /* Virtual alarm clock (4.2 BSD). */ aoqi@0: "PROF", SIGPROF, /* Profiling alarm clock (4.2 BSD). */ aoqi@0: "WINCH", SIGWINCH, /* Window size change (4.3 BSD, Sun). */ aoqi@0: "INFO", SIGINFO, /* Information request. */ aoqi@0: "USR1", SIGUSR1, /* User-defined signal 1 (POSIX). */ aoqi@0: "USR2", SIGUSR2 /* User-defined signal 2 (POSIX). */ aoqi@0: }; aoqi@0: aoqi@0: JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name)) aoqi@0: aoqi@0: /* find and return the named signal's number */ aoqi@0: aoqi@0: for(uint i=0; i