hotspot/src/os/bsd/vm/vmError_bsd.cpp
author serb
Wed, 13 May 2015 19:19:03 +0300
changeset 30931 dad3f622d47a
parent 29573 2d800e5d575f
child 33105 294e48b4f704
permissions -rw-r--r--
5109918: Wrong documentation for JSpinner.DateEditor constructor Reviewed-by: alexsch, azvegint
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     1
/*
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     2
 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     4
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     8
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    13
 * accompanied this code).
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    14
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    18
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    21
 * questions.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    22
 *
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    23
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    24
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    25
#include "precompiled.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    26
#include "runtime/arguments.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    27
#include "runtime/os.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    28
#include "runtime/thread.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    29
#include "utilities/vmError.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    30
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    31
#include <sys/types.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    32
#include <sys/wait.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    33
#include <sys/syscall.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    34
#include <unistd.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    35
#include <signal.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    36
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    37
void VMError::show_message_box(char *buf, int buflen) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    38
  bool yes;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    39
  do {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    40
    error_string(buf, buflen);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    41
    int len = (int)strlen(buf);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    42
    char *p = &buf[len];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    43
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    44
    jio_snprintf(p, buflen - len,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    45
               "\n\n"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    46
               "Do you want to debug the problem?\n\n"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    47
               "To debug, run 'gdb /proc/%d/exe %d'; then switch to thread " INTX_FORMAT " (" INTPTR_FORMAT ")\n"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    48
               "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    49
               "Otherwise, press RETURN to abort...",
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    50
               os::current_process_id(), os::current_process_id(),
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    51
               os::current_thread_id(), os::current_thread_id());
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    52
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    53
    yes = os::message_box("Unexpected Error", buf);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    54
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    55
    if (yes) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    56
      // yes, user asked VM to launch debugger
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    57
      jio_snprintf(buf, buflen, "gdb /proc/%d/exe %d",
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    58
                   os::current_process_id(), os::current_process_id());
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    59
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    60
      os::fork_and_exec(buf);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    61
      yes = false;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    62
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    63
  } while (yes);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    64
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    65
28943
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    66
// 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: 10565
diff changeset
    67
// reporting. They must be unblocked, caught, handled.
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    68
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    69
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: 10565
diff changeset
    70
static const int NUM_SIGNALS = sizeof(SIGNALS) / sizeof(int);
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    71
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    72
// Space for our "saved" signal flags and handlers
28943
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    73
static int resettedSigflags[NUM_SIGNALS];
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    74
static address resettedSighandler[NUM_SIGNALS];
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    75
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    76
static void save_signal(int idx, int sig)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    77
{
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    78
  struct sigaction sa;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    79
  sigaction(sig, NULL, &sa);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    80
  resettedSigflags[idx]   = sa.sa_flags;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    81
  resettedSighandler[idx] = (sa.sa_flags & SA_SIGINFO)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    82
                              ? CAST_FROM_FN_PTR(address, sa.sa_sigaction)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    83
                              : CAST_FROM_FN_PTR(address, sa.sa_handler);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    84
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    85
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    86
int VMError::get_resetted_sigflags(int sig) {
28943
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    87
  for (int i = 0; i < NUM_SIGNALS; i++) {
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    88
    if (SIGNALS[i] == sig) {
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    89
      return resettedSigflags[i];
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    90
    }
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    91
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    92
  return -1;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    93
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    94
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    95
address VMError::get_resetted_sighandler(int sig) {
28943
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    96
  for (int i = 0; i < NUM_SIGNALS; i++) {
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    97
    if (SIGNALS[i] == sig) {
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    98
      return resettedSighandler[i];
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
    99
    }
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   100
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   101
  return NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   102
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   103
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   104
static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   105
  // unmask current signal
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   106
  sigset_t newset;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   107
  sigemptyset(&newset);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   108
  sigaddset(&newset, sig);
28943
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   109
  // also unmask other synchronous signals
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   110
  for (int i = 0; i < NUM_SIGNALS; i++) {
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   111
    sigaddset(&newset, SIGNALS[i]);
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   112
  }
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   113
  pthread_sigmask(SIG_UNBLOCK, &newset, NULL);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   114
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 28943
diff changeset
   115
  // support safefetch faults in error handling
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 28943
diff changeset
   116
  ucontext_t* const uc = (ucontext_t*) ucVoid;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 28943
diff changeset
   117
  address const pc = uc ? os::Bsd::ucontext_get_pc(uc) : NULL;
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
  if (uc && pc && StubRoutines::is_safefetch_fault(pc)) {
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 28943
diff changeset
   120
    os::Bsd::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
   121
    return;
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 28943
diff changeset
   122
  }
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 28943
diff changeset
   123
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 28943
diff changeset
   124
  VMError err(NULL, sig, pc, info, ucVoid);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   125
  err.report_and_die();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   126
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   127
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   128
void VMError::reset_signal_handlers() {
28943
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   129
  // install signal handlers for all synchronous program error signals
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   130
  sigset_t newset;
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   131
  sigemptyset(&newset);
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   132
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   133
  for (int i = 0; i < NUM_SIGNALS; i++) {
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   134
    save_signal(i, SIGNALS[i]);
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   135
    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: 10565
diff changeset
   136
    sigaddset(&newset, SIGNALS[i]);
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   137
  }
679546f0cc1f 8065895: Synchronous signals during error reporting may terminate or hang VM process
dholmes
parents: 10565
diff changeset
   138
  pthread_sigmask(SIG_UNBLOCK, &newset, NULL);
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   139
}