hotspot/src/os/solaris/vm/jsig.c
author xdono
Thu, 02 Oct 2008 19:58:19 -0700
changeset 1217 5eb97f366a6a
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6754988: Update copyright year Summary: Update for files that have been modified starting July 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2001-2003 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
/* CopyrightVersion 1.2 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
/* This is a special library that should be loaded before libc &
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
 * libthread to interpose the signal handler installation functions:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
 * sigaction(), signal(), sigset().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
 * Used for signal-chaining. See RFE 4381843.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
#include <stdlib.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
#include <stdio.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
#include <string.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
#include <signal.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
#include <dlfcn.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
#include <thread.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
#include <synch.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
#include "jvm_solaris.h"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
#define bool int
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
#define true 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
#define false 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
static struct sigaction *sact = (struct sigaction *)NULL; /* saved signal handlers */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
static sigset_t jvmsigs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
/* used to synchronize the installation of signal handlers */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
static mutex_t mutex = DEFAULTMUTEX;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
static cond_t cond = DEFAULTCV;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
static thread_t tid = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
typedef void (*sa_handler_t)(int);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
typedef sa_handler_t (*signal_t)(int, sa_handler_t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
typedef int (*sigaction_t)(int, const struct sigaction *, struct sigaction *);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
static signal_t os_signal = 0; /* os's version of signal()/sigset() */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
static sigaction_t os_sigaction = 0; /* os's version of sigaction() */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
static bool jvm_signal_installing = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
static bool jvm_signal_installed = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
/* assume called within signal_lock */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
static void allocate_sact() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  size_t maxsignum;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  maxsignum = SIGRTMAX;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  if (sact == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    sact = (struct sigaction *)malloc((maxsignum+1) * (size_t)sizeof(struct sigaction));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    memset(sact, 0, (maxsignum+1) * (size_t)sizeof(struct sigaction));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  if (sact == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    printf("%s\n", "libjsig.so unable to allocate memory");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    exit(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  sigemptyset(&jvmsigs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
static void signal_lock() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  mutex_lock(&mutex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  /* When the jvm is installing its set of signal handlers, threads
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
   * other than the jvm thread should wait */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  if (jvm_signal_installing) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    if (tid != thr_self()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      cond_wait(&cond, &mutex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  }
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 signal_unlock() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  mutex_unlock(&mutex);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
static sa_handler_t call_os_signal(int sig, sa_handler_t disp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
                                   bool is_sigset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  if (os_signal == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    if (!is_sigset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      os_signal = (signal_t)dlsym(RTLD_NEXT, "signal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      os_signal = (signal_t)dlsym(RTLD_NEXT, "sigset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    if (os_signal == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      printf("%s\n", dlerror());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      exit(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  return (*os_signal)(sig, disp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
static void save_signal_handler(int sig, sa_handler_t disp, bool is_sigset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  sigset_t set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  if (sact == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    allocate_sact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  sact[sig].sa_handler = disp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  sigemptyset(&set);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  sact[sig].sa_mask = set;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  if (!is_sigset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    sact[sig].sa_flags = SA_NODEFER;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    if (sig != SIGILL && sig != SIGTRAP && sig != SIGPWR) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      sact[sig].sa_flags |= SA_RESETHAND;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    sact[sig].sa_flags = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
static sa_handler_t set_signal(int sig, sa_handler_t disp, bool is_sigset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  sa_handler_t oldhandler;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  bool sigblocked;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  signal_lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  if (sact == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    allocate_sact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  if (jvm_signal_installed && sigismember(&jvmsigs, sig)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    /* jvm has installed its signal handler for this signal. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    /* Save the handler. Don't really install it. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    if (is_sigset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      /* We won't honor the SIG_HOLD request to change the signal mask */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      sigblocked = sigismember(&(sact[sig].sa_mask), sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    oldhandler = sact[sig].sa_handler;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    save_signal_handler(sig, disp, is_sigset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    if (is_sigset && sigblocked) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      oldhandler = SIG_HOLD;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    signal_unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    return oldhandler;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  } else if (jvm_signal_installing) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    /* jvm is installing its signal handlers. Install the new
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
     * handlers and save the old ones. jvm uses sigaction().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
     * Leave the piece here just in case. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    oldhandler = call_os_signal(sig, disp, is_sigset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    save_signal_handler(sig, oldhandler, is_sigset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    /* Record the signals used by jvm */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    sigaddset(&jvmsigs, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    signal_unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    return oldhandler;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    /* jvm has no relation with this signal (yet). Install the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
     * the handler. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    oldhandler = call_os_signal(sig, disp, is_sigset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    signal_unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    return oldhandler;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
sa_handler_t signal(int sig, sa_handler_t disp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  return set_signal(sig, disp, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
sa_handler_t sigset(int sig, sa_handler_t disp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  return set_signal(sig, disp, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
static int call_os_sigaction(int sig, const struct sigaction  *act,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
                             struct sigaction *oact) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  if (os_sigaction == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    os_sigaction = (sigaction_t)dlsym(RTLD_NEXT, "sigaction");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    if (os_sigaction == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      printf("%s\n", dlerror());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      exit(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  return (*os_sigaction)(sig, act, oact);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  int res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  struct sigaction oldAct;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  signal_lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  if (sact == NULL ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    allocate_sact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  if (jvm_signal_installed && sigismember(&jvmsigs, sig)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    /* jvm has installed its signal handler for this signal. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    /* Save the handler. Don't really install it. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    if (oact != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      *oact = sact[sig];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    if (act != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      sact[sig] = *act;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    signal_unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  } else if (jvm_signal_installing) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    /* jvm is installing its signal handlers. Install the new
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
     * handlers and save the old ones. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    res = call_os_sigaction(sig, act, &oldAct);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    sact[sig] = oldAct;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    if (oact != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
      *oact = oldAct;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    /* Record the signals used by jvm */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    sigaddset(&jvmsigs, sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    signal_unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    /* jvm has no relation with this signal (yet). Install the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
     * the handler. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    res = call_os_sigaction(sig, act, oact);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    signal_unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
/* The four functions for the jvm to call into */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
void JVM_begin_signal_setting() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  signal_lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  jvm_signal_installing = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  tid = thr_self();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  signal_unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
void JVM_end_signal_setting() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  signal_lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  jvm_signal_installed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  jvm_signal_installing = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  cond_broadcast(&cond);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  signal_unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
struct sigaction *JVM_get_signal_action(int sig) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  if (sact == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    allocate_sact();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  /* Does race condition make sense here? */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  if (sigismember(&jvmsigs, sig)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    return &sact[sig];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
int JVM_get_libjsig_version() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  return JSIG_VERSION_1_4_1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
}