Path: blob/master/src/hotspot/os/posix/vmError_posix.cpp
40930 views
/*1* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2018, 2020 SAP SE. 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "cds/metaspaceShared.hpp"27#include "runtime/os.hpp"28#include "runtime/stubRoutines.hpp"29#include "runtime/thread.hpp"30#include "signals_posix.hpp"31#include "utilities/debug.hpp"32#include "utilities/vmError.hpp"3334#include <sys/types.h>35#include <sys/wait.h>3637#ifdef LINUX38#include <sys/syscall.h>39#include <unistd.h>40#endif41#ifdef AIX42#include <unistd.h>43#endif44#ifdef BSD45#include <sys/syscall.h>46#include <unistd.h>47#endif484950// Needed for cancelable steps.51static volatile pthread_t reporter_thread_id;5253void VMError::reporting_started() {54// record pthread id of reporter thread.55reporter_thread_id = ::pthread_self();56}5758void VMError::interrupt_reporting_thread() {59// We misuse SIGILL here, but it does not really matter. We need60// a signal which is handled by crash_handler and not likely to61// occurr during error reporting itself.62::pthread_kill(reporter_thread_id, SIGILL);63}6465static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {6667PosixSignals::unblock_error_signals();6869// support safefetch faults in error handling70ucontext_t* const uc = (ucontext_t*) ucVoid;71address pc = (uc != NULL) ? os::Posix::ucontext_get_pc(uc) : NULL;7273// Correct pc for SIGILL, SIGFPE (see JDK-8176872)74if (sig == SIGILL || sig == SIGFPE) {75pc = (address) info->si_addr;76}7778// Needed to make it possible to call SafeFetch.. APIs in error handling.79if (uc && pc && StubRoutines::is_safefetch_fault(pc)) {80os::Posix::ucontext_set_pc(uc, StubRoutines::continuation_for_safefetch_fault(pc));81return;82}8384// Needed because asserts may happen in error handling too.85#ifdef CAN_SHOW_REGISTERS_ON_ASSERT86if ((sig == SIGSEGV || sig == SIGBUS) && info != NULL && info->si_addr == g_assert_poison) {87if (handle_assert_poison_fault(ucVoid, info->si_addr)) {88return;89}90}91#endif // CAN_SHOW_REGISTERS_ON_ASSERT9293VMError::report_and_die(NULL, sig, pc, info, ucVoid);94}9596const void* VMError::crash_handler_address = CAST_FROM_FN_PTR(void *, crash_handler);9798void VMError::install_secondary_signal_handler() {99static const int signals_to_handle[] = {100SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGTRAP,1010 // end102};103for (int i = 0; signals_to_handle[i] != 0; i++) {104os::signal(signals_to_handle[i], CAST_FROM_FN_PTR(void *, crash_handler));105}106}107108// Write a hint to the stream in case siginfo relates to a segv/bus error109// and the offending address points into CDS archive.110void VMError::check_failing_cds_access(outputStream* st, const void* siginfo) {111#if INCLUDE_CDS112if (siginfo && UseSharedSpaces) {113const siginfo_t* const si = (siginfo_t*)siginfo;114if (si->si_signo == SIGBUS || si->si_signo == SIGSEGV) {115const void* const fault_addr = si->si_addr;116if (fault_addr != NULL) {117if (MetaspaceShared::is_in_shared_metaspace(fault_addr)) {118st->print("Error accessing class data sharing archive. "119"Mapped file inaccessible during execution, possible disk/network problem.");120}121}122}123}124#endif125}126127128