src/java.base/macosx/native/libjsig/jsig.c
branchihse-remove-mapfiles-branch
changeset 56112 39286667d14e
parent 47216 71c04702a3d5
equal deleted inserted replaced
56111:71934e9574d7 56112:39286667d14e
     1 /*
     1 /*
     2  * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    35 #include <pthread.h>
    35 #include <pthread.h>
    36 #include <stdio.h>
    36 #include <stdio.h>
    37 #include <stdlib.h>
    37 #include <stdlib.h>
    38 #include <stdbool.h>
    38 #include <stdbool.h>
    39 #include <stdint.h>
    39 #include <stdint.h>
       
    40 #include "jni.h"
    40 
    41 
    41 #define MASK(sig) ((uint32_t)1 << (sig-1))  // 0 is not a signal.
    42 #define MASK(sig) ((uint32_t)1 << (sig-1))  // 0 is not a signal.
    42 #if (32 < NSIG-1)
    43 #if (32 < NSIG-1)
    43 #error "Not all signals can be encoded in jvmsigs. Adapt its type!"
    44 #error "Not all signals can be encoded in jvmsigs. Adapt its type!"
    44 #endif
    45 #endif
   141     signal_unlock();
   142     signal_unlock();
   142     return oldhandler;
   143     return oldhandler;
   143   }
   144   }
   144 }
   145 }
   145 
   146 
   146 sa_handler_t signal(int sig, sa_handler_t disp) {
   147 JNIEXPORT sa_handler_t signal(int sig, sa_handler_t disp) {
   147   return set_signal(sig, disp, false);
   148   return set_signal(sig, disp, false);
   148 }
   149 }
   149 
   150 
   150 sa_handler_t sigset(int sig, sa_handler_t disp) {
   151 JNIEXPORT sa_handler_t sigset(int sig, sa_handler_t disp) {
   151   printf("sigset() is not supported by BSD");
   152   printf("sigset() is not supported by BSD");
   152   exit(0);
   153   exit(0);
   153  }
   154  }
   154 
   155 
   155 static int call_os_sigaction(int sig, const struct sigaction  *act,
   156 static int call_os_sigaction(int sig, const struct sigaction  *act,
   162     }
   163     }
   163   }
   164   }
   164   return (*os_sigaction)(sig, act, oact);
   165   return (*os_sigaction)(sig, act, oact);
   165 }
   166 }
   166 
   167 
   167 int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) {
   168 JNIEXPORT int sigaction(int sig, const struct sigaction *act, struct sigaction *oact) {
   168   int res;
   169   int res;
   169   bool sigused;
   170   bool sigused;
   170   struct sigaction oldAct;
   171   struct sigaction oldAct;
   171 
   172 
   172   if (reentry) {
   173   if (reentry) {
   211     return res;
   212     return res;
   212   }
   213   }
   213 }
   214 }
   214 
   215 
   215 /* The three functions for the jvm to call into */
   216 /* The three functions for the jvm to call into */
   216 void JVM_begin_signal_setting() {
   217 JNIEXPORT void JVM_begin_signal_setting() {
   217   signal_lock();
   218   signal_lock();
   218   jvm_signal_installing = true;
   219   jvm_signal_installing = true;
   219   tid = pthread_self();
   220   tid = pthread_self();
   220   signal_unlock();
   221   signal_unlock();
   221 }
   222 }
   222 
   223 
   223 void JVM_end_signal_setting() {
   224 JNIEXPORT void JVM_end_signal_setting() {
   224   signal_lock();
   225   signal_lock();
   225   jvm_signal_installed = true;
   226   jvm_signal_installed = true;
   226   jvm_signal_installing = false;
   227   jvm_signal_installing = false;
   227   pthread_cond_broadcast(&cond);
   228   pthread_cond_broadcast(&cond);
   228   signal_unlock();
   229   signal_unlock();
   229 }
   230 }
   230 
   231 
   231 struct sigaction *JVM_get_signal_action(int sig) {
   232 JNIEXPORT struct sigaction *JVM_get_signal_action(int sig) {
   232   /* Does race condition make sense here? */
   233   /* Does race condition make sense here? */
   233   if ((MASK(sig) & jvmsigs) != 0) {
   234   if ((MASK(sig) & jvmsigs) != 0) {
   234     return &sact[sig];
   235     return &sact[sig];
   235   }
   236   }
   236   return NULL;
   237   return NULL;