Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/aix/vm/vmError_aix.cpp
32284 views
/*1* Copyright (c) 2003, 2013, 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 <unistd.h>33#include <signal.h>3435void VMError::show_message_box(char *buf, int buflen) {36bool yes;37do {38error_string(buf, buflen);39int len = (int)strlen(buf);40char *p = &buf[len];4142jio_snprintf(p, buflen - len,43"\n\n"44"Do you want to debug the problem?\n\n"45"To debug, run 'dbx -a %d'; then switch to thread tid " INTX_FORMAT ", k-tid " INTX_FORMAT "\n"46"Enter 'yes' to launch dbx automatically (PATH must include dbx)\n"47"Otherwise, press RETURN to abort...",48os::current_process_id(),49os::current_thread_id(), thread_self());5051yes = os::message_box("Unexpected Error", buf);5253if (yes) {54// yes, user asked VM to launch debugger55jio_snprintf(buf, buflen, "dbx -a %d", os::current_process_id());5657os::fork_and_exec(buf);58yes = false;59}60} while (yes);61}6263// Handle all synchronous signals which may happen during signal handling,64// not just SIGSEGV and SIGBUS.65static const int SIGNALS[] = { SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGTRAP }; // add more if needed66static const int NUM_SIGNALS = sizeof(SIGNALS) / sizeof(int);6768// Space for our "saved" signal flags and handlers69static int resettedSigflags[NUM_SIGNALS];70static address resettedSighandler[NUM_SIGNALS];7172static void save_signal(int idx, int sig) {73struct sigaction sa;74sigaction(sig, NULL, &sa);75resettedSigflags[idx] = sa.sa_flags;76resettedSighandler[idx] = (sa.sa_flags & SA_SIGINFO)77? CAST_FROM_FN_PTR(address, sa.sa_sigaction)78: CAST_FROM_FN_PTR(address, sa.sa_handler);79}8081int VMError::get_resetted_sigflags(int sig) {82// Handle all program errors.83for (int i = 0; i < NUM_SIGNALS; i++) {84if (SIGNALS[i] == sig) {85return resettedSigflags[i];86}87}88return -1;89}9091address VMError::get_resetted_sighandler(int sig) {92// Handle all program errors.93for (int i = 0; i < NUM_SIGNALS; i++) {94if (SIGNALS[i] == sig) {95return resettedSighandler[i];96}97}98return NULL;99}100101static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {102// Unmask current signal.103sigset_t newset;104sigemptyset(&newset);105sigaddset(&newset, sig);106107Unimplemented();108}109110void VMError::reset_signal_handlers() {111sigset_t newset;112sigemptyset(&newset);113114for (int i = 0; i < NUM_SIGNALS; i++) {115save_signal(i, SIGNALS[i]);116os::signal(SIGNALS[i], CAST_FROM_FN_PTR(void *, crash_handler));117sigaddset(&newset, SIGNALS[i]);118}119120sigthreadmask(SIG_UNBLOCK, &newset, NULL);121}122123124