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 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 "memory/metaspaceShared.hpp"
27 #include "runtime/arguments.hpp"
28 #include "runtime/os.hpp"
29 #include "runtime/thread.hpp"
30 #include "utilities/vmError.hpp"
31
32 #include <sys/types.h>
33 #include <sys/wait.h>
34 #include <signal.h>
35
36 #ifdef LINUX
37 #include <sys/syscall.h>
38 #include <unistd.h>
39 #endif
40 #ifdef SOLARIS
41 #include <thread.h>
42 #endif
43 #ifdef AIX
44 #include <unistd.h>
45 #endif
46 #ifdef BSD
47 #include <sys/syscall.h>
48 #include <unistd.h>
49 #endif
105 static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {
106 // unmask current signal
107 sigset_t newset;
108 sigemptyset(&newset);
109 sigaddset(&newset, sig);
110 // also unmask other synchronous signals
111 for (int i = 0; i < NUM_SIGNALS; i++) {
112 sigaddset(&newset, SIGNALS[i]);
113 }
114 os::Posix::unblock_thread_signal_mask(&newset);
115
116 // support safefetch faults in error handling
117 ucontext_t* const uc = (ucontext_t*) ucVoid;
118 address pc = (uc != NULL) ? os::Posix::ucontext_get_pc(uc) : NULL;
119
120 // Correct pc for SIGILL, SIGFPE (see JDK-8176872)
121 if (sig == SIGILL || sig == SIGFPE) {
122 pc = (address) info->si_addr;
123 }
124
125 if (uc && pc && StubRoutines::is_safefetch_fault(pc)) {
126 os::Posix::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
127 return;
128 }
129
130 VMError::report_and_die(NULL, sig, pc, info, ucVoid);
131 }
132
133 void VMError::reset_signal_handlers() {
134 // install signal handlers for all synchronous program error signals
135 sigset_t newset;
136 sigemptyset(&newset);
137
138 for (int i = 0; i < NUM_SIGNALS; i++) {
139 save_signal(i, SIGNALS[i]);
140 os::signal(SIGNALS[i], CAST_FROM_FN_PTR(void *, crash_handler));
141 sigaddset(&newset, SIGNALS[i]);
142 }
143 os::Posix::unblock_thread_signal_mask(&newset);
144
145 }
146
147 // Write a hint to the stream in case siginfo relates to a segv/bus error
148 // and the offending address points into CDS archive.
|
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 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 "memory/metaspaceShared.hpp"
27 #include "runtime/arguments.hpp"
28 #include "runtime/os.hpp"
29 #include "runtime/thread.hpp"
30 #include "utilities/debug.hpp"
31 #include "utilities/vmError.hpp"
32
33 #include <sys/types.h>
34 #include <sys/wait.h>
35 #include <signal.h>
36
37 #ifdef LINUX
38 #include <sys/syscall.h>
39 #include <unistd.h>
40 #endif
41 #ifdef SOLARIS
42 #include <thread.h>
43 #endif
44 #ifdef AIX
45 #include <unistd.h>
46 #endif
47 #ifdef BSD
48 #include <sys/syscall.h>
49 #include <unistd.h>
50 #endif
106 static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {
107 // unmask current signal
108 sigset_t newset;
109 sigemptyset(&newset);
110 sigaddset(&newset, sig);
111 // also unmask other synchronous signals
112 for (int i = 0; i < NUM_SIGNALS; i++) {
113 sigaddset(&newset, SIGNALS[i]);
114 }
115 os::Posix::unblock_thread_signal_mask(&newset);
116
117 // support safefetch faults in error handling
118 ucontext_t* const uc = (ucontext_t*) ucVoid;
119 address pc = (uc != NULL) ? os::Posix::ucontext_get_pc(uc) : NULL;
120
121 // Correct pc for SIGILL, SIGFPE (see JDK-8176872)
122 if (sig == SIGILL || sig == SIGFPE) {
123 pc = (address) info->si_addr;
124 }
125
126 // Needed to make it possible to call SafeFetch.. APIs in error handling.
127 if (uc && pc && StubRoutines::is_safefetch_fault(pc)) {
128 os::Posix::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
129 return;
130 }
131
132 // Needed because asserts may happen in error handling too.
133 #ifdef CAN_SHOW_REGISTERS_ON_ASSERT
134 if ( (sig == SIGSEGV || sig == SIGBUS) && info != NULL && info->si_addr == g_assert_poison) {
135 handle_assert_poison_fault(ucVoid, info->si_addr);
136 return;
137 }
138 #endif // CAN_SHOW_REGISTERS_ON_ASSERT
139
140 VMError::report_and_die(NULL, sig, pc, info, ucVoid);
141 }
142
143 void VMError::reset_signal_handlers() {
144 // install signal handlers for all synchronous program error signals
145 sigset_t newset;
146 sigemptyset(&newset);
147
148 for (int i = 0; i < NUM_SIGNALS; i++) {
149 save_signal(i, SIGNALS[i]);
150 os::signal(SIGNALS[i], CAST_FROM_FN_PTR(void *, crash_handler));
151 sigaddset(&newset, SIGNALS[i]);
152 }
153 os::Posix::unblock_thread_signal_mask(&newset);
154
155 }
156
157 // Write a hint to the stream in case siginfo relates to a segv/bus error
158 // and the offending address points into CDS archive.
|