hotspot/src/os/bsd/vm/jsig.c
author serb
Wed, 13 May 2015 19:19:03 +0300
changeset 30931 dad3f622d47a
parent 10565 dc90c239f4ec
child 31618 8b074d70d72c
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) 2001, 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
/* CopyrightVersion 1.2 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    26
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    27
/* This is a special library that should be loaded before libc &
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    28
 * libthread to interpose the signal handler installation functions:
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    29
 * sigaction(), signal(), sigset().
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    30
 * Used for signal-chaining. See RFE 4381843.
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    31
 */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    32
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    33
#include <signal.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    34
#include <dlfcn.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    35
#include <pthread.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    36
#include <stdio.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    37
#include <stdlib.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    38
#include <stdbool.h>
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    39
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    40
#define MAXSIGNUM 32
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    41
#define MASK(sig) ((unsigned int)1 << sig)
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    42
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    43
static struct sigaction sact[MAXSIGNUM]; /* saved signal handlers */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    44
static unsigned int jvmsigs = 0; /* signals used by jvm */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    45
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    46
/* used to synchronize the installation of signal handlers */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    47
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    48
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    49
static pthread_t tid = 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    50
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    51
typedef void (*sa_handler_t)(int);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    52
typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    53
typedef sa_handler_t (*signal_t)(int, sa_handler_t);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    54
typedef int (*sigaction_t)(int, const struct sigaction *, struct sigaction *);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    55
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    56
static signal_t os_signal = 0; /* os's version of signal()/sigset() */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    57
static sigaction_t os_sigaction = 0; /* os's version of sigaction() */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    58
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    59
static bool jvm_signal_installing = false;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    60
static bool jvm_signal_installed = false;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    61
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    62
static void signal_lock() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    63
  pthread_mutex_lock(&mutex);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    64
  /* When the jvm is installing its set of signal handlers, threads
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    65
   * other than the jvm thread should wait */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    66
  if (jvm_signal_installing) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    67
    if (tid != pthread_self()) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    68
      pthread_cond_wait(&cond, &mutex);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    69
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    70
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    71
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    72
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    73
static void signal_unlock() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    74
  pthread_mutex_unlock(&mutex);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    75
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    76
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    77
static sa_handler_t call_os_signal(int sig, sa_handler_t disp,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    78
                                   bool is_sigset) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    79
  if (os_signal == NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    80
    if (!is_sigset) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    81
      os_signal = (signal_t)dlsym(RTLD_NEXT, "signal");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    82
    } else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    83
      os_signal = (signal_t)dlsym(RTLD_NEXT, "sigset");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    84
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    85
    if (os_signal == NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    86
      printf("%s\n", dlerror());
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    87
      exit(0);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    88
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    89
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    90
  return (*os_signal)(sig, disp);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    91
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    92
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    93
static void save_signal_handler(int sig, sa_handler_t disp) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    94
  sigset_t set;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    95
  sact[sig].sa_handler = disp;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    96
  sigemptyset(&set);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    97
  sact[sig].sa_mask = set;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    98
  sact[sig].sa_flags = 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
    99
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   100
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   101
static sa_handler_t set_signal(int sig, sa_handler_t disp, bool is_sigset) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   102
  sa_handler_t oldhandler;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   103
  bool sigused;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   104
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   105
  signal_lock();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   106
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   107
  sigused = (MASK(sig) & jvmsigs) != 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   108
  if (jvm_signal_installed && sigused) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   109
    /* jvm has installed its signal handler for this signal. */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   110
    /* Save the handler. Don't really install it. */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   111
    oldhandler = sact[sig].sa_handler;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   112
    save_signal_handler(sig, disp);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   113
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   114
    signal_unlock();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   115
    return oldhandler;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   116
  } else if (jvm_signal_installing) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   117
    /* jvm is installing its signal handlers. Install the new
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   118
     * handlers and save the old ones. jvm uses sigaction().
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   119
     * Leave the piece here just in case. */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   120
    oldhandler = call_os_signal(sig, disp, is_sigset);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   121
    save_signal_handler(sig, oldhandler);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   122
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   123
    /* Record the signals used by jvm */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   124
    jvmsigs |= MASK(sig);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   125
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   126
    signal_unlock();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   127
    return oldhandler;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   128
  } else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   129
    /* jvm has no relation with this signal (yet). Install the
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   130
     * the handler. */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   131
    oldhandler = call_os_signal(sig, disp, is_sigset);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   132
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   133
    signal_unlock();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   134
    return oldhandler;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   135
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   136
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   137
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   138
sa_handler_t signal(int sig, sa_handler_t disp) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   139
  return set_signal(sig, disp, false);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   140
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   141
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   142
sa_handler_t sigset(int sig, sa_handler_t disp) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   143
  printf("sigset() is not supported by BSD");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   144
  exit(0);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   145
 }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   146
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   147
static int call_os_sigaction(int sig, const struct sigaction  *act,
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   148
                             struct sigaction *oact) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   149
  if (os_sigaction == NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   150
    os_sigaction = (sigaction_t)dlsym(RTLD_NEXT, "sigaction");
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   151
    if (os_sigaction == NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   152
      printf("%s\n", dlerror());
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   153
      exit(0);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   154
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   155
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   156
  return (*os_sigaction)(sig, act, oact);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   157
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   158
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   159
int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   160
  int res;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   161
  bool sigused;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   162
  struct sigaction oldAct;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   163
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   164
  signal_lock();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   165
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   166
  sigused = (MASK(sig) & jvmsigs) != 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   167
  if (jvm_signal_installed && sigused) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   168
    /* jvm has installed its signal handler for this signal. */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   169
    /* Save the handler. Don't really install it. */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   170
    if (oact != NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   171
      *oact = sact[sig];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   172
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   173
    if (act != NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   174
      sact[sig] = *act;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   175
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   176
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   177
    signal_unlock();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   178
    return 0;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   179
  } else if (jvm_signal_installing) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   180
    /* jvm is installing its signal handlers. Install the new
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   181
     * handlers and save the old ones. */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   182
    res = call_os_sigaction(sig, act, &oldAct);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   183
    sact[sig] = oldAct;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   184
    if (oact != NULL) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   185
      *oact = oldAct;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   186
    }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   187
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   188
    /* Record the signals used by jvm */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   189
    jvmsigs |= MASK(sig);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   190
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   191
    signal_unlock();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   192
    return res;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   193
  } else {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   194
    /* jvm has no relation with this signal (yet). Install the
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   195
     * the handler. */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   196
    res = call_os_sigaction(sig, act, oact);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   197
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   198
    signal_unlock();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   199
    return res;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   200
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   201
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   202
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   203
/* The three functions for the jvm to call into */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   204
void JVM_begin_signal_setting() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   205
  signal_lock();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   206
  jvm_signal_installing = true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   207
  tid = pthread_self();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   208
  signal_unlock();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   209
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   210
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   211
void JVM_end_signal_setting() {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   212
  signal_lock();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   213
  jvm_signal_installed = true;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   214
  jvm_signal_installing = false;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   215
  pthread_cond_broadcast(&cond);
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   216
  signal_unlock();
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   217
}
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   218
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   219
struct sigaction *JVM_get_signal_action(int sig) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   220
  /* Does race condition make sense here? */
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   221
  if ((MASK(sig) & jvmsigs) != 0) {
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   222
    return &sact[sig];
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   223
  }
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   224
  return NULL;
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents:
diff changeset
   225
}