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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "runtime/arguments.hpp"
27 #include "runtime/os.hpp"
28 #include "runtime/thread.hpp"
29 #include "utilities/vmError.hpp"
30
31 #include <sys/types.h>
32 #include <sys/wait.h>
33 #include <signal.h>
34
35 void VMError::show_message_box(char *buf, int buflen) {
36 bool yes;
37 do {
38 error_string(buf, buflen);
39 int len = (int)strlen(buf);
40 char *p = &buf[len];
41
42 jio_snprintf(p, buflen - len,
43 "\n\n"
44 "Do you want to debug the problem?\n\n"
45 "To debug, run 'dbx - %d'; then switch to thread " INTX_FORMAT "\n"
46 "Enter 'yes' to launch dbx automatically (PATH must include dbx)\n"
47 "Otherwise, press RETURN to abort...",
48 os::current_process_id(), os::current_thread_id());
49
50 yes = os::message_box("Unexpected Error", buf);
51
52 if (yes) {
53 // yes, user asked VM to launch debugger
54 jio_snprintf(buf, buflen, "dbx - %d", os::current_process_id());
55
56 os::fork_and_exec(buf);
57 yes = false;
58 }
59 } while (yes);
60 }
61
62 // Space for our "saved" signal flags and handlers
63 static int resettedSigflags[2];
64 static address resettedSighandler[2];
65
66 static void save_signal(int idx, int sig)
67 {
68 struct sigaction sa;
69 sigaction(sig, NULL, &sa);
70 resettedSigflags[idx] = sa.sa_flags;
71 resettedSighandler[idx] = (sa.sa_flags & SA_SIGINFO)
72 ? CAST_FROM_FN_PTR(address, sa.sa_sigaction)
73 : CAST_FROM_FN_PTR(address, sa.sa_handler);
74 }
75
76 int VMError::get_resetted_sigflags(int sig) {
77 if(SIGSEGV == sig) {
78 return resettedSigflags[0];
79 } else if(SIGBUS == sig) {
80 return resettedSigflags[1];
81 }
82 return -1;
83 }
84
85 address VMError::get_resetted_sighandler(int sig) {
86 if(SIGSEGV == sig) {
87 return resettedSighandler[0];
88 } else if(SIGBUS == sig) {
89 return resettedSighandler[1];
90 }
91 return NULL;
92 }
93
94 static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {
95 // unmask current signal
96 sigset_t newset;
97 sigemptyset(&newset);
98 sigaddset(&newset, sig);
99 sigprocmask(SIG_UNBLOCK, &newset, NULL);
100
101 VMError err(NULL, sig, NULL, info, ucVoid);
102 err.report_and_die();
103 }
104
105 void VMError::reset_signal_handlers() {
106 // Save sigflags for resetted signals
107 save_signal(0, SIGSEGV);
108 save_signal(1, SIGBUS);
109 os::signal(SIGSEGV, CAST_FROM_FN_PTR(void *, crash_handler));
110 os::signal(SIGBUS, CAST_FROM_FN_PTR(void *, crash_handler));
111 }
|
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "runtime/arguments.hpp"
27 #include "runtime/os.hpp"
28 #include "runtime/thread.hpp"
29 #include "utilities/vmError.hpp"
30
31 #include <sys/types.h>
32 #include <sys/wait.h>
33 #include <thread.h>
34 #include <signal.h>
35
36 void VMError::show_message_box(char *buf, int buflen) {
37 bool yes;
38 do {
39 error_string(buf, buflen);
40 int len = (int)strlen(buf);
41 char *p = &buf[len];
42
43 jio_snprintf(p, buflen - len,
44 "\n\n"
45 "Do you want to debug the problem?\n\n"
46 "To debug, run 'dbx - %d'; then switch to thread " INTX_FORMAT "\n"
47 "Enter 'yes' to launch dbx automatically (PATH must include dbx)\n"
48 "Otherwise, press RETURN to abort...",
49 os::current_process_id(), os::current_thread_id());
50
51 yes = os::message_box("Unexpected Error", buf);
52
53 if (yes) {
54 // yes, user asked VM to launch debugger
55 jio_snprintf(buf, buflen, "dbx - %d", os::current_process_id());
56
57 os::fork_and_exec(buf);
58 yes = false;
59 }
60 } while (yes);
61 }
62
63 // handle all synchronous program error signals which may happen during error
64 // reporting. They must be unblocked, caught, handled.
65
66 static const int SIGNALS[] = { SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGTRAP }; // add more if needed
67 static const int NUM_SIGNALS = sizeof(SIGNALS) / sizeof(int);
68
69 // Space for our "saved" signal flags and handlers
70 static int resettedSigflags[NUM_SIGNALS];
71 static address resettedSighandler[NUM_SIGNALS];
72
73 static void save_signal(int idx, int sig)
74 {
75 struct sigaction sa;
76 sigaction(sig, NULL, &sa);
77 resettedSigflags[idx] = sa.sa_flags;
78 resettedSighandler[idx] = (sa.sa_flags & SA_SIGINFO)
79 ? CAST_FROM_FN_PTR(address, sa.sa_sigaction)
80 : CAST_FROM_FN_PTR(address, sa.sa_handler);
81 }
82
83 int VMError::get_resetted_sigflags(int sig) {
84 for (int i = 0; i < NUM_SIGNALS; i++) {
85 if (SIGNALS[i] == sig) {
86 return resettedSigflags[i];
87 }
88 }
89 return -1;
90 }
91
92 address VMError::get_resetted_sighandler(int sig) {
93 for (int i = 0; i < NUM_SIGNALS; i++) {
94 if (SIGNALS[i] == sig) {
95 return resettedSighandler[i];
96 }
97 }
98 return NULL;
99 }
100
101 static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {
102 // unmask current signal
103 sigset_t newset;
104 sigemptyset(&newset);
105 sigaddset(&newset, sig);
106 // also unmask other synchronous signals
107 for (int i = 0; i < NUM_SIGNALS; i++) {
108 sigaddset(&newset, SIGNALS[i]);
109 }
110 thr_sigsetmask(SIG_UNBLOCK, &newset, NULL);
111
112 VMError err(NULL, sig, NULL, info, ucVoid);
113 err.report_and_die();
114 }
115
116 void VMError::reset_signal_handlers() {
117 // install signal handlers for all synchronous program error signals
118 sigset_t newset;
119 sigemptyset(&newset);
120
121 for (int i = 0; i < NUM_SIGNALS; i++) {
122 save_signal(i, SIGNALS[i]);
123 os::signal(SIGNALS[i], CAST_FROM_FN_PTR(void *, crash_handler));
124 sigaddset(&newset, SIGNALS[i]);
125 }
126 thr_sigsetmask(SIG_UNBLOCK, &newset, NULL);
127 }
|