libc_signal.h 4.9 KB
Newer Older
B
bernard 已提交
1
/*
2
 * Copyright (c) 2006-2018, RT-Thread Development Team
B
bernard 已提交
3
 *
4 5 6 7 8
 * SPDX-License-Identifier: Apache-2.0
 */

/*
 * File      : libc_signal.h
B
bernard 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * Change Logs:
 * Date           Author       Notes
 * 2017-09-12     Bernard      The first version
 */

#ifndef LIBC_SIGNAL_H__
#define LIBC_SIGNAL_H__

#ifdef __cplusplus
extern "C" {
#endif

B
Bernard Xiong 已提交
22 23 24 25 26
#ifdef HAVE_CCONFIG_H
#include <cconfig.h>
#endif

#ifndef HAVE_SIGVAL
27 28 29 30
/*  Signal Generation and Delivery, P1003.1b-1993, p. 63
    NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and
          sigev_notify_attributes to the sigevent structure.  */

B
bernard 已提交
31 32 33 34 35
union sigval 
{
    int    sival_int;    /* Integer signal value */
    void  *sival_ptr;    /* Pointer signal value */
};
B
Bernard Xiong 已提交
36
#endif
B
bernard 已提交
37

B
Bernard Xiong 已提交
38
#ifndef HAVE_SIGEVENT
39 40 41 42 43 44 45 46 47
struct sigevent
{
    int          sigev_notify;               /* Notification type */
    int          sigev_signo;                /* Signal number */
    union sigval sigev_value;                /* Signal value */
    void         (*sigev_notify_function)( union sigval );
                                             /* Notification function */
    void         *sigev_notify_attributes;   /* Notification Attributes, really pthread_attr_t */
};
B
Bernard Xiong 已提交
48
#endif
49

B
Bernard Xiong 已提交
50
#ifndef HAVE_SIGINFO
B
bernard 已提交
51 52
struct siginfo
{
B
Bernard Xiong 已提交
53 54
    rt_uint16_t si_signo;
    rt_uint16_t si_code;
B
bernard 已提交
55 56 57 58

    union sigval si_value;
};
typedef struct siginfo siginfo_t;
59
#endif
B
bernard 已提交
60

61 62 63
#define SI_USER     0x01    /* Signal sent by kill(). */
#define SI_QUEUE    0x02    /* Signal sent by sigqueue(). */
#define SI_TIMER    0x03    /* Signal generated by expiration of a 
B
bernard 已提交
64
                               timer set by timer_settime(). */
65 66 67
#define SI_ASYNCIO  0x04    /* Signal generated by completion of an 
                               asynchronous I/O request. */
#define SI_MESGQ    0x05    /* Signal generated by arrival of a 
B
bernard 已提交
68 69 70 71 72 73
                               message on an empty message queue. */

#ifdef RT_USING_NEWLIB
#include <sys/signal.h>
#endif

B
Bernard Xiong 已提交
74
#if defined(__CC_ARM) || defined(__CLANG_ARM)
B
bernard 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
#include <signal.h>
typedef unsigned long sigset_t;

#define SIGHUP       1
// #define SIGINT       2
#define SIGQUIT      3
// #define SIGILL       4
#define SIGTRAP      5
// #define SIGABRT      6
#define SIGEMT       7
// #define SIGFPE       8
#define SIGKILL      9
#define SIGBUS      10
// #define SIGSEGV     11
#define SIGSYS      12
#define SIGPIPE     13
#define SIGALRM     14
// #define SIGTERM     15
#define SIGURG      16
#define SIGSTOP     17
#define SIGTSTP     18
#define SIGCONT     19
#define SIGCHLD     20
#define SIGTTIN     21
#define SIGTTOU     22
#define SIGPOLL     23
#define SIGWINCH    24
// #define SIGUSR1     25
// #define SIGUSR2     26
#define SIGRTMIN    27
#define SIGRTMAX    31
#define NSIG        32

108 109 110
#define SIG_SETMASK 0   /* set mask with sigprocmask() */
#define SIG_BLOCK   1   /* set of signals to block */
#define SIG_UNBLOCK 2   /* set of signals to, well, unblock */
B
bernard 已提交
111 112 113 114 115

typedef void (*_sig_func_ptr)(int);

struct sigaction 
{
116 117 118
    _sig_func_ptr sa_handler;
    sigset_t sa_mask;
    int sa_flags;
B
bernard 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
};

#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
#define sigemptyset(what)   (*(what) = 0, 0)
#define sigfillset(what)    (*(what) = ~(0), 0)
#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)

int sigprocmask (int how, const sigset_t *set, sigset_t *oset);
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);

#elif defined(__IAR_SYSTEMS_ICC__)
#include <signal.h>
typedef unsigned long sigset_t;

#define SIGHUP       1
#define SIGINT       2
#define SIGQUIT      3
#define SIGILL       4
#define SIGTRAP      5
// #define SIGABRT      6
#define SIGEMT       7
#define SIGFPE       8
#define SIGKILL      9
#define SIGBUS      10
#define SIGSEGV     11
#define SIGSYS      12
#define SIGPIPE     13
#define SIGALRM     14
#define SIGTERM     15
#define SIGURG      16
#define SIGSTOP     17
#define SIGTSTP     18
#define SIGCONT     19
#define SIGCHLD     20
#define SIGTTIN     21
#define SIGTTOU     22
#define SIGPOLL     23
#define SIGWINCH    24
#define SIGUSR1     25
#define SIGUSR2     26
#define SIGRTMIN    27
#define SIGRTMAX    31
#define NSIG        32

164 165 166
#define SIG_SETMASK 0   /* set mask with sigprocmask() */
#define SIG_BLOCK   1   /* set of signals to block */
#define SIG_UNBLOCK 2   /* set of signals to, well, unblock */
B
bernard 已提交
167 168 169 170 171

typedef void (*_sig_func_ptr)(int);

struct sigaction 
{
172 173 174
    _sig_func_ptr sa_handler;
    sigset_t sa_mask;
    int sa_flags;
B
bernard 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
};

#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
#define sigemptyset(what)   (*(what) = 0, 0)
#define sigfillset(what)    (*(what) = ~(0), 0)
#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)

int sigprocmask (int how, const sigset_t *set, sigset_t *oset);
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
#endif

#ifdef __cplusplus
}
#endif

#endif