src/os/bsd/vm/jvm_bsd.cpp

Wed, 05 Jun 2013 14:12:49 -0400

author
hseigel
date
Wed, 05 Jun 2013 14:12:49 -0400
changeset 5218
6bf8b8bb7c19
parent 0
f90c822e73f8
permissions
-rw-r--r--

8009302: Mac OS X: JVM crash on infinite recursion on Appkit Thread
Summary: Use SA_ONSTACK flag to ensure signal gets delivered properly.
Reviewed-by: dholmes, coleenp
Contributed-by: gerard.ziemski@oracle.com

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "prims/jvm.h"
aoqi@0 27 #include "runtime/interfaceSupport.hpp"
aoqi@0 28 #include "runtime/osThread.hpp"
aoqi@0 29
aoqi@0 30 #include <signal.h>
aoqi@0 31
aoqi@0 32
aoqi@0 33 // sun.misc.Signal ///////////////////////////////////////////////////////////
aoqi@0 34 // Signal code is mostly copied from classic vm, signals_md.c 1.4 98/08/23
aoqi@0 35 /*
aoqi@0 36 * This function is included primarily as a debugging aid. If Java is
aoqi@0 37 * running in a console window, then pressing <CTRL-\\> will cause
aoqi@0 38 * the current state of all active threads and monitors to be written
aoqi@0 39 * to the console window.
aoqi@0 40 */
aoqi@0 41
aoqi@0 42 JVM_ENTRY_NO_ENV(void*, JVM_RegisterSignal(jint sig, void* handler))
aoqi@0 43 // Copied from classic vm
aoqi@0 44 // signals_md.c 1.4 98/08/23
aoqi@0 45 void* newHandler = handler == (void *)2
aoqi@0 46 ? os::user_handler()
aoqi@0 47 : handler;
aoqi@0 48 switch (sig) {
aoqi@0 49 /* The following are already used by the VM. */
aoqi@0 50 case INTERRUPT_SIGNAL:
aoqi@0 51 case SIGFPE:
aoqi@0 52 case SIGILL:
aoqi@0 53 case SIGSEGV:
aoqi@0 54
aoqi@0 55 /* The following signal is used by the VM to dump thread stacks unless
aoqi@0 56 ReduceSignalUsage is set, in which case the user is allowed to set
aoqi@0 57 his own _native_ handler for this signal; thus, in either case,
aoqi@0 58 we do not allow JVM_RegisterSignal to change the handler. */
aoqi@0 59 case BREAK_SIGNAL:
aoqi@0 60 return (void *)-1;
aoqi@0 61
aoqi@0 62 /* The following signals are used for Shutdown Hooks support. However, if
aoqi@0 63 ReduceSignalUsage (-Xrs) is set, Shutdown Hooks must be invoked via
aoqi@0 64 System.exit(), Java is not allowed to use these signals, and the the
aoqi@0 65 user is allowed to set his own _native_ handler for these signals and
aoqi@0 66 invoke System.exit() as needed. Terminator.setup() is avoiding
aoqi@0 67 registration of these signals when -Xrs is present.
aoqi@0 68 - If the HUP signal is ignored (from the nohup) command, then Java
aoqi@0 69 is not allowed to use this signal.
aoqi@0 70 */
aoqi@0 71
aoqi@0 72 case SHUTDOWN1_SIGNAL:
aoqi@0 73 case SHUTDOWN2_SIGNAL:
aoqi@0 74 case SHUTDOWN3_SIGNAL:
aoqi@0 75 if (ReduceSignalUsage) return (void*)-1;
aoqi@0 76 if (os::Bsd::is_sig_ignored(sig)) return (void*)1;
aoqi@0 77 }
aoqi@0 78
aoqi@0 79 void* oldHandler = os::signal(sig, newHandler);
aoqi@0 80 if (oldHandler == os::user_handler()) {
aoqi@0 81 return (void *)2;
aoqi@0 82 } else {
aoqi@0 83 return oldHandler;
aoqi@0 84 }
aoqi@0 85 JVM_END
aoqi@0 86
aoqi@0 87
aoqi@0 88 JVM_ENTRY_NO_ENV(jboolean, JVM_RaiseSignal(jint sig))
aoqi@0 89 if (ReduceSignalUsage) {
aoqi@0 90 // do not allow SHUTDOWN1_SIGNAL,SHUTDOWN2_SIGNAL,SHUTDOWN3_SIGNAL,
aoqi@0 91 // BREAK_SIGNAL to be raised when ReduceSignalUsage is set, since
aoqi@0 92 // no handler for them is actually registered in JVM or via
aoqi@0 93 // JVM_RegisterSignal.
aoqi@0 94 if (sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
aoqi@0 95 sig == SHUTDOWN3_SIGNAL || sig == BREAK_SIGNAL) {
aoqi@0 96 return JNI_FALSE;
aoqi@0 97 }
aoqi@0 98 }
aoqi@0 99 else if ((sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
aoqi@0 100 sig == SHUTDOWN3_SIGNAL) && os::Bsd::is_sig_ignored(sig)) {
aoqi@0 101 // do not allow SHUTDOWN1_SIGNAL to be raised when SHUTDOWN1_SIGNAL
aoqi@0 102 // is ignored, since no handler for them is actually registered in JVM
aoqi@0 103 // or via JVM_RegisterSignal.
aoqi@0 104 // This also applies for SHUTDOWN2_SIGNAL and SHUTDOWN3_SIGNAL
aoqi@0 105 return JNI_FALSE;
aoqi@0 106 }
aoqi@0 107
aoqi@0 108 os::signal_raise(sig);
aoqi@0 109 return JNI_TRUE;
aoqi@0 110 JVM_END
aoqi@0 111
aoqi@0 112 /*
aoqi@0 113 All the defined signal names for Bsd.
aoqi@0 114
aoqi@0 115 NOTE that not all of these names are accepted by our Java implementation
aoqi@0 116
aoqi@0 117 Via an existing claim by the VM, sigaction restrictions, or
aoqi@0 118 the "rules of Unix" some of these names will be rejected at runtime.
aoqi@0 119 For example the VM sets up to handle USR1, sigaction returns EINVAL for
aoqi@0 120 STOP, and Bsd simply doesn't allow catching of KILL.
aoqi@0 121
aoqi@0 122 Here are the names currently accepted by a user of sun.misc.Signal with
aoqi@0 123 1.4.1 (ignoring potential interaction with use of chaining, etc):
aoqi@0 124
aoqi@0 125 HUP, INT, TRAP, ABRT, IOT, BUS, USR2, PIPE, ALRM, TERM, STKFLT,
aoqi@0 126 CLD, CHLD, CONT, TSTP, TTIN, TTOU, URG, XCPU, XFSZ, VTALRM, PROF,
aoqi@0 127 WINCH, POLL, IO, PWR, SYS
aoqi@0 128
aoqi@0 129 */
aoqi@0 130
aoqi@0 131 struct siglabel {
aoqi@0 132 const char *name;
aoqi@0 133 int number;
aoqi@0 134 };
aoqi@0 135
aoqi@0 136 struct siglabel siglabels[] = {
aoqi@0 137 /* derived from /usr/include/bits/signum.h on RH7.2 */
aoqi@0 138 "HUP", SIGHUP, /* Hangup (POSIX). */
aoqi@0 139 "INT", SIGINT, /* Interrupt (ANSI). */
aoqi@0 140 "QUIT", SIGQUIT, /* Quit (POSIX). */
aoqi@0 141 "ILL", SIGILL, /* Illegal instruction (ANSI). */
aoqi@0 142 "TRAP", SIGTRAP, /* Trace trap (POSIX). */
aoqi@0 143 "ABRT", SIGABRT, /* Abort (ANSI). */
aoqi@0 144 "EMT", SIGEMT, /* EMT trap */
aoqi@0 145 "FPE", SIGFPE, /* Floating-point exception (ANSI). */
aoqi@0 146 "KILL", SIGKILL, /* Kill, unblockable (POSIX). */
aoqi@0 147 "BUS", SIGBUS, /* BUS error (4.2 BSD). */
aoqi@0 148 "SEGV", SIGSEGV, /* Segmentation violation (ANSI). */
aoqi@0 149 "SYS", SIGSYS, /* Bad system call. Only on some Bsden! */
aoqi@0 150 "PIPE", SIGPIPE, /* Broken pipe (POSIX). */
aoqi@0 151 "ALRM", SIGALRM, /* Alarm clock (POSIX). */
aoqi@0 152 "TERM", SIGTERM, /* Termination (ANSI). */
aoqi@0 153 "URG", SIGURG, /* Urgent condition on socket (4.2 BSD). */
aoqi@0 154 "STOP", SIGSTOP, /* Stop, unblockable (POSIX). */
aoqi@0 155 "TSTP", SIGTSTP, /* Keyboard stop (POSIX). */
aoqi@0 156 "CONT", SIGCONT, /* Continue (POSIX). */
aoqi@0 157 "CHLD", SIGCHLD, /* Child status has changed (POSIX). */
aoqi@0 158 "TTIN", SIGTTIN, /* Background read from tty (POSIX). */
aoqi@0 159 "TTOU", SIGTTOU, /* Background write to tty (POSIX). */
aoqi@0 160 "IO", SIGIO, /* I/O now possible (4.2 BSD). */
aoqi@0 161 "XCPU", SIGXCPU, /* CPU limit exceeded (4.2 BSD). */
aoqi@0 162 "XFSZ", SIGXFSZ, /* File size limit exceeded (4.2 BSD). */
aoqi@0 163 "VTALRM", SIGVTALRM, /* Virtual alarm clock (4.2 BSD). */
aoqi@0 164 "PROF", SIGPROF, /* Profiling alarm clock (4.2 BSD). */
aoqi@0 165 "WINCH", SIGWINCH, /* Window size change (4.3 BSD, Sun). */
aoqi@0 166 "INFO", SIGINFO, /* Information request. */
aoqi@0 167 "USR1", SIGUSR1, /* User-defined signal 1 (POSIX). */
aoqi@0 168 "USR2", SIGUSR2 /* User-defined signal 2 (POSIX). */
aoqi@0 169 };
aoqi@0 170
aoqi@0 171 JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
aoqi@0 172
aoqi@0 173 /* find and return the named signal's number */
aoqi@0 174
aoqi@0 175 for(uint i=0; i<ARRAY_SIZE(siglabels); i++)
aoqi@0 176 if(!strcmp(name, siglabels[i].name))
aoqi@0 177 return siglabels[i].number;
aoqi@0 178
aoqi@0 179 return -1;
aoqi@0 180
aoqi@0 181 JVM_END
aoqi@0 182
aoqi@0 183 // used by os::exception_name()
aoqi@0 184 extern bool signal_name(int signo, char* buf, size_t len) {
aoqi@0 185 for(uint i = 0; i < ARRAY_SIZE(siglabels); i++) {
aoqi@0 186 if (signo == siglabels[i].number) {
aoqi@0 187 jio_snprintf(buf, len, "SIG%s", siglabels[i].name);
aoqi@0 188 return true;
aoqi@0 189 }
aoqi@0 190 }
aoqi@0 191 return false;
aoqi@0 192 }

mercurial