1 /* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2017-09-12 Bernard The first version 9 */ 10 11 #ifndef LIBC_SIGNAL_H__ 12 #define LIBC_SIGNAL_H__ 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 #ifdef HAVE_CCONFIG_H 19 #include <cconfig.h> 20 #endif 21 22 #ifndef HAVE_SIGVAL 23 /* Signal Generation and Delivery, P1003.1b-1993, p. 63 24 NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and 25 sigev_notify_attributes to the sigevent structure. */ 26 27 union sigval 28 { 29 int sival_int; /* Integer signal value */ 30 void *sival_ptr; /* Pointer signal value */ 31 }; 32 #endif 33 34 #ifndef HAVE_SIGEVENT 35 struct sigevent 36 { 37 int sigev_notify; /* Notification type */ 38 int sigev_signo; /* Signal number */ 39 union sigval sigev_value; /* Signal value */ 40 void (*sigev_notify_function)( union sigval ); 41 /* Notification function */ 42 void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */ 43 }; 44 #endif 45 46 #ifndef HAVE_SIGINFO 47 struct siginfo 48 { 49 rt_uint16_t si_signo; 50 rt_uint16_t si_code; 51 52 union sigval si_value; 53 }; 54 typedef struct siginfo siginfo_t; 55 #endif 56 57 #define SI_USER 0x01 /* Signal sent by kill(). */ 58 #define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */ 59 #define SI_TIMER 0x03 /* Signal generated by expiration of a 60 timer set by timer_settime(). */ 61 #define SI_ASYNCIO 0x04 /* Signal generated by completion of an 62 asynchronous I/O request. */ 63 #define SI_MESGQ 0x05 /* Signal generated by arrival of a 64 message on an empty message queue. */ 65 66 #ifdef RT_USING_NEWLIB 67 #include <sys/signal.h> 68 #endif 69 70 #if defined(__CC_ARM) || defined(__CLANG_ARM) 71 #include <signal.h> 72 typedef unsigned long sigset_t; 73 74 #define SIGHUP 1 75 /* #define SIGINT 2 */ 76 #define SIGQUIT 3 77 /* #define SIGILL 4 */ 78 #define SIGTRAP 5 79 /* #define SIGABRT 6 */ 80 #define SIGEMT 7 81 /* #define SIGFPE 8 */ 82 #define SIGKILL 9 83 #define SIGBUS 10 84 /* #define SIGSEGV 11 */ 85 #define SIGSYS 12 86 #define SIGPIPE 13 87 #define SIGALRM 14 88 /* #define SIGTERM 15 */ 89 #define SIGURG 16 90 #define SIGSTOP 17 91 #define SIGTSTP 18 92 #define SIGCONT 19 93 #define SIGCHLD 20 94 #define SIGTTIN 21 95 #define SIGTTOU 22 96 #define SIGPOLL 23 97 #define SIGWINCH 24 98 /* #define SIGUSR1 25 */ 99 /* #define SIGUSR2 26 */ 100 #define SIGRTMIN 27 101 #define SIGRTMAX 31 102 #define NSIG 32 103 104 #define SIG_SETMASK 0 /* set mask with sigprocmask() */ 105 #define SIG_BLOCK 1 /* set of signals to block */ 106 #define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ 107 108 typedef void (*_sig_func_ptr)(int); 109 110 struct sigaction 111 { 112 _sig_func_ptr sa_handler; 113 sigset_t sa_mask; 114 int sa_flags; 115 }; 116 117 #define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) 118 #define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0) 119 #define sigemptyset(what) (*(what) = 0, 0) 120 #define sigfillset(what) (*(what) = ~(0), 0) 121 #define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) 122 123 int sigprocmask (int how, const sigset_t *set, sigset_t *oset); 124 int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); 125 126 #elif defined(__IAR_SYSTEMS_ICC__) 127 #include <signal.h> 128 typedef unsigned long sigset_t; 129 130 #define SIGHUP 1 131 #define SIGINT 2 132 #define SIGQUIT 3 133 #define SIGILL 4 134 #define SIGTRAP 5 135 /* #define SIGABRT 6 */ 136 #define SIGEMT 7 137 #define SIGFPE 8 138 #define SIGKILL 9 139 #define SIGBUS 10 140 #define SIGSEGV 11 141 #define SIGSYS 12 142 #define SIGPIPE 13 143 #define SIGALRM 14 144 #define SIGTERM 15 145 #define SIGURG 16 146 #define SIGSTOP 17 147 #define SIGTSTP 18 148 #define SIGCONT 19 149 #define SIGCHLD 20 150 #define SIGTTIN 21 151 #define SIGTTOU 22 152 #define SIGPOLL 23 153 #define SIGWINCH 24 154 #define SIGUSR1 25 155 #define SIGUSR2 26 156 #define SIGRTMIN 27 157 #define SIGRTMAX 31 158 #define NSIG 32 159 160 #define SIG_SETMASK 0 /* set mask with sigprocmask() */ 161 #define SIG_BLOCK 1 /* set of signals to block */ 162 #define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ 163 164 typedef void (*_sig_func_ptr)(int); 165 166 struct sigaction 167 { 168 _sig_func_ptr sa_handler; 169 sigset_t sa_mask; 170 int sa_flags; 171 }; 172 173 #define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) 174 #define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0) 175 #define sigemptyset(what) (*(what) = 0, 0) 176 #define sigfillset(what) (*(what) = ~(0), 0) 177 #define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) 178 179 int sigprocmask (int how, const sigset_t *set, sigset_t *oset); 180 int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); 181 #endif 182 183 #ifdef __cplusplus 184 } 185 #endif 186 187 #endif 188 189