src/hotspot/os/posix/jvm_posix.cpp
author naoto
Tue, 09 Jul 2019 08:05:38 -0700
changeset 55627 9c1885fb2a42
parent 50177 9806f23d5e5e
permissions -rw-r--r--
8227127: Era designator not displayed correctly using the COMPAT provider Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     1
/*
48875
c1e7612f6b11 8193308: Disallow installing user signal handlers for SIGBUS on OSX
rwestberg
parents: 47765
diff changeset
     2
 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     4
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     8
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    13
 * accompanied this code).
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    14
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    18
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    21
 * questions.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    22
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    23
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    24
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    25
#include "precompiled.hpp"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    26
#include "jvm.h"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 48875
diff changeset
    27
#include "runtime/interfaceSupport.inline.hpp"
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    28
#include "runtime/osThread.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    29
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    30
#include <signal.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    31
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    32
50177
9806f23d5e5e 8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents: 49449
diff changeset
    33
// jdk.internal.misc.Signal ///////////////////////////////////////////////////////////
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    34
// Signal code is mostly copied from classic vm, signals_md.c   1.4 98/08/23
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    35
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    36
 * This function is included primarily as a debugging aid. If Java is
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    37
 * running in a console window, then pressing <CTRL-\\> will cause
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    38
 * the current state of all active threads and monitors to be written
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    39
 * to the console window.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    40
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    41
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    42
JVM_ENTRY_NO_ENV(void*, JVM_RegisterSignal(jint sig, void* handler))
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    43
  // Copied from classic vm
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    44
  // signals_md.c       1.4 98/08/23
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    45
  void* newHandler = handler == (void *)2
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    46
                   ? os::user_handler()
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    47
                   : handler;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    48
  switch (sig) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    49
    /* The following are already used by the VM. */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    50
    case SIGFPE:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    51
    case SIGILL:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    52
    case SIGSEGV:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    53
48875
c1e7612f6b11 8193308: Disallow installing user signal handlers for SIGBUS on OSX
rwestberg
parents: 47765
diff changeset
    54
#if defined(__APPLE__)
c1e7612f6b11 8193308: Disallow installing user signal handlers for SIGBUS on OSX
rwestberg
parents: 47765
diff changeset
    55
    /* On Darwin, memory access errors commonly results in SIGBUS instead
c1e7612f6b11 8193308: Disallow installing user signal handlers for SIGBUS on OSX
rwestberg
parents: 47765
diff changeset
    56
     * of SIGSEGV. */
c1e7612f6b11 8193308: Disallow installing user signal handlers for SIGBUS on OSX
rwestberg
parents: 47765
diff changeset
    57
    case SIGBUS:
c1e7612f6b11 8193308: Disallow installing user signal handlers for SIGBUS on OSX
rwestberg
parents: 47765
diff changeset
    58
#endif
c1e7612f6b11 8193308: Disallow installing user signal handlers for SIGBUS on OSX
rwestberg
parents: 47765
diff changeset
    59
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    60
    /* The following signal is used by the VM to dump thread stacks unless
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    61
       ReduceSignalUsage is set, in which case the user is allowed to set
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    62
       his own _native_ handler for this signal; thus, in either case,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    63
       we do not allow JVM_RegisterSignal to change the handler. */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    64
    case BREAK_SIGNAL:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    65
      return (void *)-1;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    66
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    67
    /* The following signals are used for Shutdown Hooks support. However, if
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    68
       ReduceSignalUsage (-Xrs) is set, Shutdown Hooks must be invoked via
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    69
       System.exit(), Java is not allowed to use these signals, and the the
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    70
       user is allowed to set his own _native_ handler for these signals and
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    71
       invoke System.exit() as needed. Terminator.setup() is avoiding
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    72
       registration of these signals when -Xrs is present.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    73
       - If the HUP signal is ignored (from the nohup) command, then Java
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    74
         is not allowed to use this signal.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    75
     */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    76
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    77
    case SHUTDOWN1_SIGNAL:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    78
    case SHUTDOWN2_SIGNAL:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    79
    case SHUTDOWN3_SIGNAL:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    80
      if (ReduceSignalUsage) return (void*)-1;
50177
9806f23d5e5e 8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents: 49449
diff changeset
    81
      if (os::Posix::is_sig_ignored(sig)) return (void*)1;
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    82
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    83
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    84
  void* oldHandler = os::signal(sig, newHandler);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    85
  if (oldHandler == os::user_handler()) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    86
      return (void *)2;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    87
  } else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    88
      return oldHandler;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    89
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    90
JVM_END
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    91
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    92
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    93
JVM_ENTRY_NO_ENV(jboolean, JVM_RaiseSignal(jint sig))
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    94
  if (ReduceSignalUsage) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    95
    // do not allow SHUTDOWN1_SIGNAL,SHUTDOWN2_SIGNAL,SHUTDOWN3_SIGNAL,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    96
    // BREAK_SIGNAL to be raised when ReduceSignalUsage is set, since
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    97
    // no handler for them is actually registered in JVM or via
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    98
    // JVM_RegisterSignal.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    99
    if (sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   100
        sig == SHUTDOWN3_SIGNAL || sig == BREAK_SIGNAL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   101
      return JNI_FALSE;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   102
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   103
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   104
  else if ((sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||
50177
9806f23d5e5e 8134537: Much nearly duplicated code for sun.misc.Signal support
coleenp
parents: 49449
diff changeset
   105
            sig == SHUTDOWN3_SIGNAL) && os::Posix::is_sig_ignored(sig)) {
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   106
    // do not allow SHUTDOWN1_SIGNAL to be raised when SHUTDOWN1_SIGNAL
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   107
    // is ignored, since no handler for them is actually registered in JVM
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   108
    // or via JVM_RegisterSignal.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   109
    // This also applies for SHUTDOWN2_SIGNAL and SHUTDOWN3_SIGNAL
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   110
    return JNI_FALSE;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   111
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   112
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   113
  os::signal_raise(sig);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   114
  return JNI_TRUE;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   115
JVM_END
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   116