author | david |
Tue, 29 Sep 2015 11:02:08 +0200 | |
changeset 33105 | 294e48b4f704 |
parent 29573 | 2d800e5d575f |
permissions | -rw-r--r-- |
1 | 1 |
/* |
7397 | 2 |
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "runtime/arguments.hpp" |
|
27 |
#include "runtime/os.hpp" |
|
28 |
#include "runtime/thread.hpp" |
|
29 |
#include "utilities/vmError.hpp" |
|
1 | 30 |
|
31 |
#include <sys/types.h> |
|
32 |
#include <sys/wait.h> |
|
28943
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
33 |
#include <thread.h> |
1 | 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 |
||
28943
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
63 |
// handle all synchronous program error signals which may happen during error |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
64 |
// reporting. They must be unblocked, caught, handled. |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
65 |
|
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
66 |
static const int SIGNALS[] = { SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGTRAP }; // add more if needed |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
67 |
static const int NUM_SIGNALS = sizeof(SIGNALS) / sizeof(int); |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
68 |
|
1 | 69 |
// Space for our "saved" signal flags and handlers |
28943
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
70 |
static int resettedSigflags[NUM_SIGNALS]; |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
71 |
static address resettedSighandler[NUM_SIGNALS]; |
1 | 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) { |
|
28943
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
84 |
for (int i = 0; i < NUM_SIGNALS; i++) { |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
85 |
if (SIGNALS[i] == sig) { |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
86 |
return resettedSigflags[i]; |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
87 |
} |
1 | 88 |
} |
89 |
return -1; |
|
90 |
} |
|
91 |
||
92 |
address VMError::get_resetted_sighandler(int sig) { |
|
28943
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
93 |
for (int i = 0; i < NUM_SIGNALS; i++) { |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
94 |
if (SIGNALS[i] == sig) { |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
95 |
return resettedSighandler[i]; |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
96 |
} |
1 | 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); |
|
28943
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
106 |
// also unmask other synchronous signals |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
107 |
for (int i = 0; i < NUM_SIGNALS; i++) { |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
108 |
sigaddset(&newset, SIGNALS[i]); |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
109 |
} |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
110 |
thr_sigsetmask(SIG_UNBLOCK, &newset, NULL); |
1 | 111 |
|
29573
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
28943
diff
changeset
|
112 |
// support safefetch faults in error handling |
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
28943
diff
changeset
|
113 |
ucontext_t* const uc = (ucontext_t*) ucVoid; |
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
28943
diff
changeset
|
114 |
address const pc = uc ? os::Solaris::ucontext_get_pc(uc) : NULL; |
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
28943
diff
changeset
|
115 |
if (uc && pc && StubRoutines::is_safefetch_fault(pc)) { |
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
28943
diff
changeset
|
116 |
os::Solaris::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc)); |
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
28943
diff
changeset
|
117 |
return; |
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
28943
diff
changeset
|
118 |
} |
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
28943
diff
changeset
|
119 |
|
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
29573
diff
changeset
|
120 |
VMError::report_and_die(NULL, sig, pc, info, ucVoid); |
1 | 121 |
} |
122 |
||
123 |
void VMError::reset_signal_handlers() { |
|
28943
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
124 |
// install signal handlers for all synchronous program error signals |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
125 |
sigset_t newset; |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
126 |
sigemptyset(&newset); |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
127 |
|
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
128 |
for (int i = 0; i < NUM_SIGNALS; i++) { |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
129 |
save_signal(i, SIGNALS[i]); |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
130 |
os::signal(SIGNALS[i], CAST_FROM_FN_PTR(void *, crash_handler)); |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
131 |
sigaddset(&newset, SIGNALS[i]); |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
132 |
} |
679546f0cc1f
8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents:
7397
diff
changeset
|
133 |
thr_sigsetmask(SIG_UNBLOCK, &newset, NULL); |
1 | 134 |
} |