src/os/solaris/vm/jvm_solaris.cpp

changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/os/solaris/vm/jvm_solaris.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,148 @@
     1.4 +/*
     1.5 + * Copyright 1998-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_solaris.cpp.incl"
    1.30 +
    1.31 +#include <signal.h>
    1.32 +
    1.33 +// sun.misc.Signal ///////////////////////////////////////////////////////////
    1.34 +// Signal code is mostly copied from classic vm, signals_md.c   1.4 98/08/23
    1.35 +/*
    1.36 + * This function is included primarily as a debugging aid. If Java is
    1.37 + * running in a console window, then pressing <CTRL-\\> will cause
    1.38 + * the current state of all active threads and monitors to be written
    1.39 + * to the console window.
    1.40 + */
    1.41 +
    1.42 +JVM_ENTRY_NO_ENV(void*, JVM_RegisterSignal(jint sig, void* handler))
    1.43 +  // Copied from classic vm
    1.44 +  // signals_md.c       1.4 98/08/23
    1.45 +  void* newHandler = handler == (void *)2
    1.46 +                   ? os::user_handler()
    1.47 +                   : handler;
    1.48 +  switch (sig) {
    1.49 +    /* The following are already used by the VM. */
    1.50 +    case SIGFPE:
    1.51 +    case SIGILL:
    1.52 +    case SIGSEGV:
    1.53 +
    1.54 +    /* The following signal is used by the VM to dump thread stacks unless
    1.55 +       ReduceSignalUsage is set, in which case the user is allowed to set
    1.56 +       his own _native_ handler for this signal; thus, in either case,
    1.57 +       we do not allow JVM_RegisterSignal to change the handler. */
    1.58 +    case BREAK_SIGNAL:
    1.59 +      return (void *)-1;
    1.60 +
    1.61 +    /* The following signals are used for Shutdown Hooks support. However, if
    1.62 +       ReduceSignalUsage (-Xrs) is set, Shutdown Hooks must be invoked via
    1.63 +       System.exit(), Java is not allowed to use these signals, and the the
    1.64 +       user is allowed to set his own _native_ handler for these signals and
    1.65 +       invoke System.exit() as needed. Terminator.setup() is avoiding
    1.66 +       registration of these signals when -Xrs is present.
    1.67 +       - If the HUP signal is ignored (from the nohup) command, then Java
    1.68 +         is not allowed to use this signal.
    1.69 +     */
    1.70 +    case SHUTDOWN1_SIGNAL:
    1.71 +    case SHUTDOWN2_SIGNAL:
    1.72 +    case SHUTDOWN3_SIGNAL:
    1.73 +      if (ReduceSignalUsage) return (void*)-1;
    1.74 +      if (os::Solaris::is_sig_ignored(sig)) return (void*)1;
    1.75 +  }
    1.76 +
    1.77 +  /* Check parameterized signals. Don't allow sharing of our interrupt signal */
    1.78 +  if (sig == os::Solaris::SIGinterrupt()) {
    1.79 +      return (void *)-1;
    1.80 +  }
    1.81 +
    1.82 +  void* oldHandler = os::signal(sig, newHandler);
    1.83 +  if (oldHandler == os::user_handler()) {
    1.84 +      return (void *)2;
    1.85 +  } else {
    1.86 +      return oldHandler;
    1.87 +  }
    1.88 +JVM_END
    1.89 +
    1.90 +
    1.91 +JVM_ENTRY_NO_ENV(jboolean, JVM_RaiseSignal(jint sig))
    1.92 +  if (ReduceSignalUsage) {
    1.93 +    // do not allow SHUTDOWN1_SIGNAL,SHUTDOWN2_SIGNAL,SHUTDOWN3_SIGNAL,
    1.94 +    // BREAK_SIGNAL to be raised when ReduceSignalUsage is set, since
    1.95 +    // no handler for them is actually registered in JVM or via
    1.96 +    // JVM_RegisterSignal.
    1.97 +    if (sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
    1.98 +        sig == SHUTDOWN3_SIGNAL || sig == BREAK_SIGNAL) {
    1.99 +      return JNI_FALSE;
   1.100 +    }
   1.101 +  }
   1.102 +  else if ((sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
   1.103 +            sig == SHUTDOWN3_SIGNAL) && os::Solaris::is_sig_ignored(sig)) {
   1.104 +    // do not allow SHUTDOWN1_SIGNAL to be raised when SHUTDOWN1_SIGNAL
   1.105 +    // is ignored, since no handler for them is actually registered in JVM
   1.106 +    // or via JVM_RegisterSignal.
   1.107 +    // This also applies for SHUTDOWN2_SIGNAL and SHUTDOWN3_SIGNAL
   1.108 +    return JNI_FALSE;
   1.109 +  }
   1.110 +
   1.111 +  os::signal_raise(sig);
   1.112 +  return JNI_TRUE;
   1.113 +JVM_END
   1.114 +
   1.115 +
   1.116 +/*
   1.117 +  All the defined signal names for Solaris are defined by str2sig().
   1.118 +
   1.119 +  NOTE that not all of these names are accepted by our Java implementation
   1.120 +
   1.121 +  Via an existing claim by the VM, sigaction restrictions, or
   1.122 +  the "rules of Unix" some of these names will be rejected at runtime.
   1.123 +  For example the VM sets up to handle USR1, sigaction returns EINVAL for
   1.124 +  CANCEL, and Solaris simply doesn't allow catching of KILL.
   1.125 +
   1.126 +  Here are the names currently accepted by a user of sun.misc.Signal with
   1.127 +  1.4.1 (ignoring potential interaction with use of chaining, etc):
   1.128 +
   1.129 +      HUP, INT, TRAP, IOT, ABRT, EMT, BUS, SYS, PIPE, ALRM, TERM, USR2,
   1.130 +      CLD, CHLD, PWR, WINCH, URG, POLL, IO, TSTP, CONT, TTIN, TTOU, VTALRM,
   1.131 +      PROF, XCPU, XFSZ, FREEZE, THAW, LOST
   1.132 +*/
   1.133 +
   1.134 +JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
   1.135 +
   1.136 +  int sig;
   1.137 +
   1.138 +  /* return the named signal's number */
   1.139 +
   1.140 +  if(str2sig(name, &sig))
   1.141 +    return -1;
   1.142 +  else
   1.143 +    return sig;
   1.144 +
   1.145 +JVM_END
   1.146 +
   1.147 +
   1.148 +//Reconciliation History
   1.149 +// 1.4 98/10/07 13:39:41 jvm_win32.cpp
   1.150 +// 1.6 99/06/22 16:39:00 jvm_win32.cpp
   1.151 +//End

mercurial