hotspot/src/os/solaris/vm/vmError_solaris.cpp
author fparain
Fri, 14 Mar 2014 12:02:54 +0000
changeset 23443 15e8ed68f73a
parent 7397 5b173b4ca846
child 28943 679546f0cc1f
permissions -rw-r--r--
8036128: Remove deprecated VM flag UseVMInterruptibleIO Reviewed-by: acorn, dholmes, dcubed, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "runtime/arguments.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "runtime/os.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "runtime/thread.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "utilities/vmError.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
#include <sys/types.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
#include <sys/wait.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
#include <signal.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
void VMError::show_message_box(char *buf, int buflen) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  bool yes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    error_string(buf, buflen);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    int len = (int)strlen(buf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    char *p = &buf[len];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    jio_snprintf(p, buflen - len,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
               "\n\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
               "Do you want to debug the problem?\n\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
               "To debug, run 'dbx - %d'; then switch to thread " INTX_FORMAT "\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
               "Enter 'yes' to launch dbx automatically (PATH must include dbx)\n"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
               "Otherwise, press RETURN to abort...",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
               os::current_process_id(), os::current_thread_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    yes = os::message_box("Unexpected Error", buf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    if (yes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
      // yes, user asked VM to launch debugger
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      jio_snprintf(buf, buflen, "dbx - %d", os::current_process_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
      os::fork_and_exec(buf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
      yes = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  } while (yes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
// Space for our "saved" signal flags and handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
static int resettedSigflags[2];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
static address resettedSighandler[2];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
static void save_signal(int idx, int sig)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  struct sigaction sa;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  sigaction(sig, NULL, &sa);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  resettedSigflags[idx]   = sa.sa_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  resettedSighandler[idx] = (sa.sa_flags & SA_SIGINFO)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
                              ? CAST_FROM_FN_PTR(address, sa.sa_sigaction)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
                              : CAST_FROM_FN_PTR(address, sa.sa_handler);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
int VMError::get_resetted_sigflags(int sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  if(SIGSEGV == sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    return resettedSigflags[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  } else if(SIGBUS == sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    return resettedSigflags[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
address VMError::get_resetted_sighandler(int sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  if(SIGSEGV == sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    return resettedSighandler[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  } else if(SIGBUS == sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    return resettedSighandler[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // unmask current signal
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  sigset_t newset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  sigemptyset(&newset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  sigaddset(&newset, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  sigprocmask(SIG_UNBLOCK, &newset, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  VMError err(NULL, sig, NULL, info, ucVoid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  err.report_and_die();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
void VMError::reset_signal_handlers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  // Save sigflags for resetted signals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  save_signal(0, SIGSEGV);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  save_signal(1, SIGBUS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  os::signal(SIGSEGV, CAST_FROM_FN_PTR(void *, crash_handler));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  os::signal(SIGBUS, CAST_FROM_FN_PTR(void *, crash_handler));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
}