src/os/solaris/vm/vmError_solaris.cpp

Tue, 27 Nov 2012 14:20:21 +0100

author
stefank
date
Tue, 27 Nov 2012 14:20:21 +0100
changeset 4299
f34d701e952e
parent 2314
f95d63e2154a
child 6876
710a3c8b516e
permissions
-rw-r--r--

8003935: Simplify the needed includes for using Thread::current()
Reviewed-by: dholmes, rbackman, coleenp

duke@435 1 /*
stefank@2314 2 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "runtime/arguments.hpp"
stefank@2314 27 #include "runtime/os.hpp"
stefank@2314 28 #include "runtime/thread.hpp"
stefank@2314 29 #include "utilities/vmError.hpp"
duke@435 30
duke@435 31 #include <sys/types.h>
duke@435 32 #include <sys/wait.h>
duke@435 33 #include <signal.h>
duke@435 34
duke@435 35 void VMError::show_message_box(char *buf, int buflen) {
duke@435 36 bool yes;
duke@435 37 do {
duke@435 38 error_string(buf, buflen);
duke@435 39 int len = (int)strlen(buf);
duke@435 40 char *p = &buf[len];
duke@435 41
duke@435 42 jio_snprintf(p, buflen - len,
duke@435 43 "\n\n"
duke@435 44 "Do you want to debug the problem?\n\n"
duke@435 45 "To debug, run 'dbx - %d'; then switch to thread " INTX_FORMAT "\n"
duke@435 46 "Enter 'yes' to launch dbx automatically (PATH must include dbx)\n"
duke@435 47 "Otherwise, press RETURN to abort...",
duke@435 48 os::current_process_id(), os::current_thread_id());
duke@435 49
duke@435 50 yes = os::message_box("Unexpected Error", buf);
duke@435 51
duke@435 52 if (yes) {
duke@435 53 // yes, user asked VM to launch debugger
duke@435 54 jio_snprintf(buf, buflen, "dbx - %d", os::current_process_id());
duke@435 55
duke@435 56 os::fork_and_exec(buf);
duke@435 57 yes = false;
duke@435 58 }
duke@435 59 } while (yes);
duke@435 60 }
duke@435 61
duke@435 62 // Space for our "saved" signal flags and handlers
duke@435 63 static int resettedSigflags[2];
duke@435 64 static address resettedSighandler[2];
duke@435 65
duke@435 66 static void save_signal(int idx, int sig)
duke@435 67 {
duke@435 68 struct sigaction sa;
duke@435 69 sigaction(sig, NULL, &sa);
duke@435 70 resettedSigflags[idx] = sa.sa_flags;
duke@435 71 resettedSighandler[idx] = (sa.sa_flags & SA_SIGINFO)
duke@435 72 ? CAST_FROM_FN_PTR(address, sa.sa_sigaction)
duke@435 73 : CAST_FROM_FN_PTR(address, sa.sa_handler);
duke@435 74 }
duke@435 75
duke@435 76 int VMError::get_resetted_sigflags(int sig) {
duke@435 77 if(SIGSEGV == sig) {
duke@435 78 return resettedSigflags[0];
duke@435 79 } else if(SIGBUS == sig) {
duke@435 80 return resettedSigflags[1];
duke@435 81 }
duke@435 82 return -1;
duke@435 83 }
duke@435 84
duke@435 85 address VMError::get_resetted_sighandler(int sig) {
duke@435 86 if(SIGSEGV == sig) {
duke@435 87 return resettedSighandler[0];
duke@435 88 } else if(SIGBUS == sig) {
duke@435 89 return resettedSighandler[1];
duke@435 90 }
duke@435 91 return NULL;
duke@435 92 }
duke@435 93
duke@435 94 static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {
duke@435 95 // unmask current signal
duke@435 96 sigset_t newset;
duke@435 97 sigemptyset(&newset);
duke@435 98 sigaddset(&newset, sig);
duke@435 99 sigprocmask(SIG_UNBLOCK, &newset, NULL);
duke@435 100
duke@435 101 VMError err(NULL, sig, NULL, info, ucVoid);
duke@435 102 err.report_and_die();
duke@435 103 }
duke@435 104
duke@435 105 void VMError::reset_signal_handlers() {
duke@435 106 // Save sigflags for resetted signals
duke@435 107 save_signal(0, SIGSEGV);
duke@435 108 save_signal(1, SIGBUS);
duke@435 109 os::signal(SIGSEGV, CAST_FROM_FN_PTR(void *, crash_handler));
duke@435 110 os::signal(SIGBUS, CAST_FROM_FN_PTR(void *, crash_handler));
duke@435 111 }

mercurial