Path: blob/master/src/hotspot/os/posix/jvm_posix.cpp
40930 views
/*1* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "jvm.h"26#include "runtime/interfaceSupport.inline.hpp"27#include "runtime/osThread.hpp"28#include "signals_posix.hpp"2930#include <signal.h>313233// jdk.internal.misc.Signal ///////////////////////////////////////////////////////////34// Signal code is mostly copied from classic vm, signals_md.c 1.4 98/08/2335/*36* This function is included primarily as a debugging aid. If Java is37* running in a console window, then pressing <CTRL-\\> will cause38* the current state of all active threads and monitors to be written39* to the console window.40*/4142JVM_ENTRY_NO_ENV(void*, JVM_RegisterSignal(jint sig, void* handler))43// Copied from classic vm44// signals_md.c 1.4 98/08/2345void* newHandler = handler == (void *)246? os::user_handler()47: handler;48switch (sig) {49/* The following are already used by the VM. */50case SIGFPE:51case SIGILL:52case SIGSEGV:5354#if defined(__APPLE__)55/* On Darwin, memory access errors commonly results in SIGBUS instead56* of SIGSEGV. */57case SIGBUS:58#endif5960/* The following signal is used by the VM to dump thread stacks unless61ReduceSignalUsage is set, in which case the user is allowed to set62his own _native_ handler for this signal; thus, in either case,63we do not allow JVM_RegisterSignal to change the handler. */64case BREAK_SIGNAL:65return (void *)-1;6667/* The following signals are used for Shutdown Hooks support. However, if68ReduceSignalUsage (-Xrs) is set, Shutdown Hooks must be invoked via69System.exit(), Java is not allowed to use these signals, and the the70user is allowed to set his own _native_ handler for these signals and71invoke System.exit() as needed. Terminator.setup() is avoiding72registration of these signals when -Xrs is present.73- If the HUP signal is ignored (from the nohup) command, then Java74is not allowed to use this signal.75*/7677case SHUTDOWN1_SIGNAL:78case SHUTDOWN2_SIGNAL:79case SHUTDOWN3_SIGNAL:80if (ReduceSignalUsage) return (void*)-1;81if (PosixSignals::is_sig_ignored(sig)) return (void*)1;82}8384void* oldHandler = os::signal(sig, newHandler);85if (oldHandler == os::user_handler()) {86return (void *)2;87} else {88return oldHandler;89}90JVM_END919293JVM_ENTRY_NO_ENV(jboolean, JVM_RaiseSignal(jint sig))94if (ReduceSignalUsage) {95// do not allow SHUTDOWN1_SIGNAL,SHUTDOWN2_SIGNAL,SHUTDOWN3_SIGNAL,96// BREAK_SIGNAL to be raised when ReduceSignalUsage is set, since97// no handler for them is actually registered in JVM or via98// JVM_RegisterSignal.99if (sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||100sig == SHUTDOWN3_SIGNAL || sig == BREAK_SIGNAL) {101return JNI_FALSE;102}103}104else if ((sig == SHUTDOWN1_SIGNAL || sig == SHUTDOWN2_SIGNAL ||105sig == SHUTDOWN3_SIGNAL) && PosixSignals::is_sig_ignored(sig)) {106// do not allow SHUTDOWN1_SIGNAL to be raised when SHUTDOWN1_SIGNAL107// is ignored, since no handler for them is actually registered in JVM108// or via JVM_RegisterSignal.109// This also applies for SHUTDOWN2_SIGNAL and SHUTDOWN3_SIGNAL110return JNI_FALSE;111}112113os::signal_raise(sig);114return JNI_TRUE;115JVM_END116117118119