comparison src/os/solaris/vm/vmError_solaris.cpp @ 0:a61af66fc99e jdk7-b24

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