Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/solaris/vm/vmError_solaris.cpp
32285 views
/*1* Copyright (c) 2003, 2010, 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 "runtime/arguments.hpp"26#include "runtime/os.hpp"27#include "runtime/thread.hpp"28#include "utilities/vmError.hpp"2930#include <sys/types.h>31#include <sys/wait.h>32#include <signal.h>3334void VMError::show_message_box(char *buf, int buflen) {35bool yes;36do {37error_string(buf, buflen);38int len = (int)strlen(buf);39char *p = &buf[len];4041jio_snprintf(p, buflen - len,42"\n\n"43"Do you want to debug the problem?\n\n"44"To debug, run 'dbx - %d'; then switch to thread " INTX_FORMAT "\n"45"Enter 'yes' to launch dbx automatically (PATH must include dbx)\n"46"Otherwise, press RETURN to abort...",47os::current_process_id(), os::current_thread_id());4849yes = os::message_box("Unexpected Error", buf);5051if (yes) {52// yes, user asked VM to launch debugger53jio_snprintf(buf, buflen, "dbx - %d", os::current_process_id());5455os::fork_and_exec(buf);56yes = false;57}58} while (yes);59}6061// Space for our "saved" signal flags and handlers62static int resettedSigflags[2];63static address resettedSighandler[2];6465static void save_signal(int idx, int sig)66{67struct sigaction sa;68sigaction(sig, NULL, &sa);69resettedSigflags[idx] = sa.sa_flags;70resettedSighandler[idx] = (sa.sa_flags & SA_SIGINFO)71? CAST_FROM_FN_PTR(address, sa.sa_sigaction)72: CAST_FROM_FN_PTR(address, sa.sa_handler);73}7475int VMError::get_resetted_sigflags(int sig) {76if(SIGSEGV == sig) {77return resettedSigflags[0];78} else if(SIGBUS == sig) {79return resettedSigflags[1];80}81return -1;82}8384address VMError::get_resetted_sighandler(int sig) {85if(SIGSEGV == sig) {86return resettedSighandler[0];87} else if(SIGBUS == sig) {88return resettedSighandler[1];89}90return NULL;91}9293static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {94// unmask current signal95sigset_t newset;96sigemptyset(&newset);97sigaddset(&newset, sig);98sigprocmask(SIG_UNBLOCK, &newset, NULL);99100VMError err(NULL, sig, NULL, info, ucVoid);101err.report_and_die();102}103104void VMError::reset_signal_handlers() {105// Save sigflags for resetted signals106save_signal(0, SIGSEGV);107save_signal(1, SIGBUS);108os::signal(SIGSEGV, CAST_FROM_FN_PTR(void *, crash_handler));109os::signal(SIGBUS, CAST_FROM_FN_PTR(void *, crash_handler));110}111112113