Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/bsd/vm/vmError_bsd.cpp
32284 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 <sys/syscall.h>33#include <unistd.h>34#include <signal.h>3536void VMError::show_message_box(char *buf, int buflen) {37bool yes;38do {39error_string(buf, buflen);40int len = (int)strlen(buf);41char *p = &buf[len];4243jio_snprintf(p, buflen - len,44"\n\n"45"Do you want to debug the problem?\n\n"46"To debug, run 'gdb /proc/%d/exe %d'; then switch to thread " INTX_FORMAT " (" INTPTR_FORMAT ")\n"47"Enter 'yes' to launch gdb automatically (PATH must include gdb)\n"48"Otherwise, press RETURN to abort...",49os::current_process_id(), os::current_process_id(),50os::current_thread_id(), os::current_thread_id());5152yes = os::message_box("Unexpected Error", buf);5354if (yes) {55// yes, user asked VM to launch debugger56jio_snprintf(buf, buflen, "gdb /proc/%d/exe %d",57os::current_process_id(), os::current_process_id());5859os::fork_and_exec(buf);60yes = false;61}62} while (yes);63}6465// Space for our "saved" signal flags and handlers66static int resettedSigflags[2];67static address resettedSighandler[2];6869static void save_signal(int idx, int sig)70{71struct sigaction sa;72sigaction(sig, NULL, &sa);73resettedSigflags[idx] = sa.sa_flags;74resettedSighandler[idx] = (sa.sa_flags & SA_SIGINFO)75? CAST_FROM_FN_PTR(address, sa.sa_sigaction)76: CAST_FROM_FN_PTR(address, sa.sa_handler);77}7879int VMError::get_resetted_sigflags(int sig) {80if(SIGSEGV == sig) {81return resettedSigflags[0];82} else if(SIGBUS == sig) {83return resettedSigflags[1];84}85return -1;86}8788address VMError::get_resetted_sighandler(int sig) {89if(SIGSEGV == sig) {90return resettedSighandler[0];91} else if(SIGBUS == sig) {92return resettedSighandler[1];93}94return NULL;95}9697static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {98// unmask current signal99sigset_t newset;100sigemptyset(&newset);101sigaddset(&newset, sig);102sigprocmask(SIG_UNBLOCK, &newset, NULL);103104VMError err(NULL, sig, NULL, info, ucVoid);105err.report_and_die();106}107108void VMError::reset_signal_handlers() {109// Save sigflags for resetted signals110save_signal(0, SIGSEGV);111save_signal(1, SIGBUS);112os::signal(SIGSEGV, CAST_FROM_FN_PTR(void *, crash_handler));113os::signal(SIGBUS, CAST_FROM_FN_PTR(void *, crash_handler));114}115116117