Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/os/posix/vmError_posix.cpp
40930 views
1
/*
2
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2018, 2020 SAP SE. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
*
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
9
*
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
15
*
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
*
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
22
* questions.
23
*
24
*/
25
26
#include "precompiled.hpp"
27
#include "cds/metaspaceShared.hpp"
28
#include "runtime/os.hpp"
29
#include "runtime/stubRoutines.hpp"
30
#include "runtime/thread.hpp"
31
#include "signals_posix.hpp"
32
#include "utilities/debug.hpp"
33
#include "utilities/vmError.hpp"
34
35
#include <sys/types.h>
36
#include <sys/wait.h>
37
38
#ifdef LINUX
39
#include <sys/syscall.h>
40
#include <unistd.h>
41
#endif
42
#ifdef AIX
43
#include <unistd.h>
44
#endif
45
#ifdef BSD
46
#include <sys/syscall.h>
47
#include <unistd.h>
48
#endif
49
50
51
// Needed for cancelable steps.
52
static volatile pthread_t reporter_thread_id;
53
54
void VMError::reporting_started() {
55
// record pthread id of reporter thread.
56
reporter_thread_id = ::pthread_self();
57
}
58
59
void VMError::interrupt_reporting_thread() {
60
// We misuse SIGILL here, but it does not really matter. We need
61
// a signal which is handled by crash_handler and not likely to
62
// occurr during error reporting itself.
63
::pthread_kill(reporter_thread_id, SIGILL);
64
}
65
66
static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {
67
68
PosixSignals::unblock_error_signals();
69
70
// support safefetch faults in error handling
71
ucontext_t* const uc = (ucontext_t*) ucVoid;
72
address pc = (uc != NULL) ? os::Posix::ucontext_get_pc(uc) : NULL;
73
74
// Correct pc for SIGILL, SIGFPE (see JDK-8176872)
75
if (sig == SIGILL || sig == SIGFPE) {
76
pc = (address) info->si_addr;
77
}
78
79
// Needed to make it possible to call SafeFetch.. APIs in error handling.
80
if (uc && pc && StubRoutines::is_safefetch_fault(pc)) {
81
os::Posix::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));
82
return;
83
}
84
85
// Needed because asserts may happen in error handling too.
86
#ifdef CAN_SHOW_REGISTERS_ON_ASSERT
87
if ((sig == SIGSEGV || sig == SIGBUS) && info != NULL && info->si_addr == g_assert_poison) {
88
if (handle_assert_poison_fault(ucVoid, info->si_addr)) {
89
return;
90
}
91
}
92
#endif // CAN_SHOW_REGISTERS_ON_ASSERT
93
94
VMError::report_and_die(NULL, sig, pc, info, ucVoid);
95
}
96
97
const void* VMError::crash_handler_address = CAST_FROM_FN_PTR(void *, crash_handler);
98
99
void VMError::install_secondary_signal_handler() {
100
static const int signals_to_handle[] = {
101
SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGTRAP,
102
0 // end
103
};
104
for (int i = 0; signals_to_handle[i] != 0; i++) {
105
os::signal(signals_to_handle[i], CAST_FROM_FN_PTR(void *, crash_handler));
106
}
107
}
108
109
// Write a hint to the stream in case siginfo relates to a segv/bus error
110
// and the offending address points into CDS archive.
111
void VMError::check_failing_cds_access(outputStream* st, const void* siginfo) {
112
#if INCLUDE_CDS
113
if (siginfo && UseSharedSpaces) {
114
const siginfo_t* const si = (siginfo_t*)siginfo;
115
if (si->si_signo == SIGBUS || si->si_signo == SIGSEGV) {
116
const void* const fault_addr = si->si_addr;
117
if (fault_addr != NULL) {
118
if (MetaspaceShared::is_in_shared_metaspace(fault_addr)) {
119
st->print("Error accessing class data sharing archive. "
120
"Mapped file inaccessible during execution, possible disk/network problem.");
121
}
122
}
123
}
124
}
125
#endif
126
}
127
128