1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/os/linux/vm/jvm_linux.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,202 @@ 1.4 +/* 1.5 + * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "incls/_precompiled.incl" 1.29 +#include "incls/_jvm_linux.cpp.incl" 1.30 + 1.31 +#include <signal.h> 1.32 + 1.33 +/* 1.34 + * FIXME: This is temporary hack to keep Linux Runtime.exec() 1.35 + * code happy. See $JDK/src/linux/native/java/lang/UnixProcess_md.c 1.36 + */ 1.37 +int _JVM_native_threads = 1; 1.38 + 1.39 +// sun.misc.Signal /////////////////////////////////////////////////////////// 1.40 +// Signal code is mostly copied from classic vm, signals_md.c 1.4 98/08/23 1.41 +/* 1.42 + * This function is included primarily as a debugging aid. If Java is 1.43 + * running in a console window, then pressing <CTRL-\\> will cause 1.44 + * the current state of all active threads and monitors to be written 1.45 + * to the console window. 1.46 + */ 1.47 + 1.48 +JVM_ENTRY_NO_ENV(void*, JVM_RegisterSignal(jint sig, void* handler)) 1.49 + // Copied from classic vm 1.50 + // signals_md.c 1.4 98/08/23 1.51 + void* newHandler = handler == (void *)2 1.52 + ? os::user_handler() 1.53 + : handler; 1.54 + switch (sig) { 1.55 + /* The following are already used by the VM. */ 1.56 + case INTERRUPT_SIGNAL: 1.57 + case SIGFPE: 1.58 + case SIGILL: 1.59 + case SIGSEGV: 1.60 + 1.61 + /* The following signal is used by the VM to dump thread stacks unless 1.62 + ReduceSignalUsage is set, in which case the user is allowed to set 1.63 + his own _native_ handler for this signal; thus, in either case, 1.64 + we do not allow JVM_RegisterSignal to change the handler. */ 1.65 + case BREAK_SIGNAL: 1.66 + return (void *)-1; 1.67 + 1.68 + /* The following signals are used for Shutdown Hooks support. However, if 1.69 + ReduceSignalUsage (-Xrs) is set, Shutdown Hooks must be invoked via 1.70 + System.exit(), Java is not allowed to use these signals, and the the 1.71 + user is allowed to set his own _native_ handler for these signals and 1.72 + invoke System.exit() as needed. Terminator.setup() is avoiding 1.73 + registration of these signals when -Xrs is present. 1.74 + - If the HUP signal is ignored (from the nohup) command, then Java 1.75 + is not allowed to use this signal. 1.76 + */ 1.77 + 1.78 + case SHUTDOWN1_SIGNAL: 1.79 + case SHUTDOWN2_SIGNAL: 1.80 + case SHUTDOWN3_SIGNAL: 1.81 + if (ReduceSignalUsage) return (void*)-1; 1.82 + if (os::Linux::is_sig_ignored(sig)) return (void*)1; 1.83 + } 1.84 + 1.85 + void* oldHandler = os::signal(sig, newHandler); 1.86 + if (oldHandler == os::user_handler()) { 1.87 + return (void *)2; 1.88 + } else { 1.89 + return oldHandler; 1.90 + } 1.91 +JVM_END 1.92 + 1.93 + 1.94 +JVM_ENTRY_NO_ENV(jboolean, JVM_RaiseSignal(jint sig)) 1.95 + if (ReduceSignalUsage) { 1.96 + // do not allow SHUTDOWN1_SIGNAL,SHUTDOWN2_SIGNAL,SHUTDOWN3_SIGNAL, 1.97 + // BREAK_SIGNAL to be raised when ReduceSignalUsage is set, since 1.98 + // no handler for them is actually registered in JVM or via 1.99 + // JVM_RegisterSignal. 1.100 + if (sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL || 1.101 + sig == SHUTDOWN3_SIGNAL || sig == BREAK_SIGNAL) { 1.102 + return JNI_FALSE; 1.103 + } 1.104 + } 1.105 + else if ((sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL || 1.106 + sig == SHUTDOWN3_SIGNAL) && os::Linux::is_sig_ignored(sig)) { 1.107 + // do not allow SHUTDOWN1_SIGNAL to be raised when SHUTDOWN1_SIGNAL 1.108 + // is ignored, since no handler for them is actually registered in JVM 1.109 + // or via JVM_RegisterSignal. 1.110 + // This also applies for SHUTDOWN2_SIGNAL and SHUTDOWN3_SIGNAL 1.111 + return JNI_FALSE; 1.112 + } 1.113 + 1.114 + os::signal_raise(sig); 1.115 + return JNI_TRUE; 1.116 +JVM_END 1.117 + 1.118 +/* 1.119 + All the defined signal names for Linux. 1.120 + 1.121 + NOTE that not all of these names are accepted by our Java implementation 1.122 + 1.123 + Via an existing claim by the VM, sigaction restrictions, or 1.124 + the "rules of Unix" some of these names will be rejected at runtime. 1.125 + For example the VM sets up to handle USR1, sigaction returns EINVAL for 1.126 + STOP, and Linux simply doesn't allow catching of KILL. 1.127 + 1.128 + Here are the names currently accepted by a user of sun.misc.Signal with 1.129 + 1.4.1 (ignoring potential interaction with use of chaining, etc): 1.130 + 1.131 + HUP, INT, TRAP, ABRT, IOT, BUS, USR2, PIPE, ALRM, TERM, STKFLT, 1.132 + CLD, CHLD, CONT, TSTP, TTIN, TTOU, URG, XCPU, XFSZ, VTALRM, PROF, 1.133 + WINCH, POLL, IO, PWR, SYS 1.134 + 1.135 +*/ 1.136 + 1.137 +struct siglabel { 1.138 + char *name; 1.139 + int number; 1.140 +}; 1.141 + 1.142 +struct siglabel siglabels[] = { 1.143 + /* derived from /usr/include/bits/signum.h on RH7.2 */ 1.144 + "HUP", SIGHUP, /* Hangup (POSIX). */ 1.145 + "INT", SIGINT, /* Interrupt (ANSI). */ 1.146 + "QUIT", SIGQUIT, /* Quit (POSIX). */ 1.147 + "ILL", SIGILL, /* Illegal instruction (ANSI). */ 1.148 + "TRAP", SIGTRAP, /* Trace trap (POSIX). */ 1.149 + "ABRT", SIGABRT, /* Abort (ANSI). */ 1.150 + "IOT", SIGIOT, /* IOT trap (4.2 BSD). */ 1.151 + "BUS", SIGBUS, /* BUS error (4.2 BSD). */ 1.152 + "FPE", SIGFPE, /* Floating-point exception (ANSI). */ 1.153 + "KILL", SIGKILL, /* Kill, unblockable (POSIX). */ 1.154 + "USR1", SIGUSR1, /* User-defined signal 1 (POSIX). */ 1.155 + "SEGV", SIGSEGV, /* Segmentation violation (ANSI). */ 1.156 + "USR2", SIGUSR2, /* User-defined signal 2 (POSIX). */ 1.157 + "PIPE", SIGPIPE, /* Broken pipe (POSIX). */ 1.158 + "ALRM", SIGALRM, /* Alarm clock (POSIX). */ 1.159 + "TERM", SIGTERM, /* Termination (ANSI). */ 1.160 +#ifdef SIGSTKFLT 1.161 + "STKFLT", SIGSTKFLT, /* Stack fault. */ 1.162 +#endif 1.163 + "CLD", SIGCLD, /* Same as SIGCHLD (System V). */ 1.164 + "CHLD", SIGCHLD, /* Child status has changed (POSIX). */ 1.165 + "CONT", SIGCONT, /* Continue (POSIX). */ 1.166 + "STOP", SIGSTOP, /* Stop, unblockable (POSIX). */ 1.167 + "TSTP", SIGTSTP, /* Keyboard stop (POSIX). */ 1.168 + "TTIN", SIGTTIN, /* Background read from tty (POSIX). */ 1.169 + "TTOU", SIGTTOU, /* Background write to tty (POSIX). */ 1.170 + "URG", SIGURG, /* Urgent condition on socket (4.2 BSD). */ 1.171 + "XCPU", SIGXCPU, /* CPU limit exceeded (4.2 BSD). */ 1.172 + "XFSZ", SIGXFSZ, /* File size limit exceeded (4.2 BSD). */ 1.173 + "VTALRM", SIGVTALRM, /* Virtual alarm clock (4.2 BSD). */ 1.174 + "PROF", SIGPROF, /* Profiling alarm clock (4.2 BSD). */ 1.175 + "WINCH", SIGWINCH, /* Window size change (4.3 BSD, Sun). */ 1.176 + "POLL", SIGPOLL, /* Pollable event occurred (System V). */ 1.177 + "IO", SIGIO, /* I/O now possible (4.2 BSD). */ 1.178 + "PWR", SIGPWR, /* Power failure restart (System V). */ 1.179 +#ifdef SIGSYS 1.180 + "SYS", SIGSYS /* Bad system call. Only on some Linuxen! */ 1.181 +#endif 1.182 + }; 1.183 + 1.184 +JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name)) 1.185 + 1.186 + /* find and return the named signal's number */ 1.187 + 1.188 + for(uint i=0; i<ARRAY_SIZE(siglabels); i++) 1.189 + if(!strcmp(name, siglabels[i].name)) 1.190 + return siglabels[i].number; 1.191 + 1.192 + return -1; 1.193 + 1.194 +JVM_END 1.195 + 1.196 +// used by os::exception_name() 1.197 +extern bool signal_name(int signo, char* buf, size_t len) { 1.198 + for(uint i = 0; i < ARRAY_SIZE(siglabels); i++) { 1.199 + if (signo == siglabels[i].number) { 1.200 + jio_snprintf(buf, len, "SIG%s", siglabels[i].name); 1.201 + return true; 1.202 + } 1.203 + } 1.204 + return false; 1.205 +}