Home | History | Annotate | Download | only in include
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *  * Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  *  * Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in
     12  *    the documentation and/or other materials provided with the
     13  *    distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
     22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 #ifndef _SIGNAL_H_
     29 #define _SIGNAL_H_
     30 
     31 #include <sys/cdefs.h>
     32 #include <limits.h>		/* For LONG_BIT */
     33 #include <string.h>		/* For memset() */
     34 #include <sys/types.h>
     35 #include <asm/signal.h>
     36 
     37 #define __ARCH_SI_UID_T __kernel_uid32_t
     38 #include <asm/siginfo.h>
     39 #undef __ARCH_SI_UID_T
     40 
     41 __BEGIN_DECLS
     42 
     43 typedef int sig_atomic_t;
     44 
     45 /* crepy NIG / _NSIG handling, just to be safe */
     46 #ifndef NSIG
     47 #  define NSIG  _NSIG
     48 #endif
     49 #ifndef _NSIG
     50 #  define _NSIG  NSIG
     51 #endif
     52 
     53 extern const char * const sys_siglist[];
     54 
     55 static __inline__ int sigismember(sigset_t *set, int signum)
     56 {
     57     unsigned long *local_set = (unsigned long *)set;
     58     signum--;
     59     return (int)((local_set[signum/LONG_BIT] >> (signum%LONG_BIT)) & 1);
     60 }
     61 
     62 
     63 static __inline__ int sigaddset(sigset_t *set, int signum)
     64 {
     65     unsigned long *local_set = (unsigned long *)set;
     66     signum--;
     67     local_set[signum/LONG_BIT] |= 1UL << (signum%LONG_BIT);
     68     return 0;
     69 }
     70 
     71 
     72 static __inline__ int sigdelset(sigset_t *set, int signum)
     73 {
     74     unsigned long *local_set = (unsigned long *)set;
     75     signum--;
     76     local_set[signum/LONG_BIT] &= ~(1UL << (signum%LONG_BIT));
     77     return 0;
     78 }
     79 
     80 
     81 static __inline__ int sigemptyset(sigset_t *set)
     82 {
     83     memset(set, 0, sizeof *set);
     84     return 0;
     85 }
     86 
     87 static __inline__ int sigfillset(sigset_t *set)
     88 {
     89     memset(set, ~0, sizeof *set);
     90     return 0;
     91 }
     92 
     93 
     94 /* compatibility types */
     95 typedef void  (*sig_t)(int);
     96 typedef sig_t sighandler_t;
     97 
     98 /* differentiater between sysv and bsd behaviour 8*/
     99 extern __sighandler_t sysv_signal(int, __sighandler_t);
    100 extern __sighandler_t bsd_signal(int, __sighandler_t);
    101 
    102 /* the default is bsd */
    103 static __inline__ __sighandler_t signal(int s, __sighandler_t f)
    104 {
    105     return bsd_signal(s,f);
    106 }
    107 
    108 /* the syscall itself */
    109 extern __sighandler_t __signal(int, __sighandler_t, int);
    110 
    111 extern int sigprocmask(int, const sigset_t *, sigset_t *);
    112 extern int sigaction(int, const struct sigaction *, struct sigaction *);
    113 
    114 extern int sigpending(sigset_t *);
    115 extern int sigsuspend(const sigset_t *);
    116 extern int sigwait(const sigset_t *set, int *sig);
    117 extern int siginterrupt(int  sig, int  flag);
    118 
    119 extern int raise(int);
    120 extern int kill(pid_t, int);
    121 
    122 
    123 __END_DECLS
    124 
    125 #endif /* _SIGNAL_H_ */
    126