signal.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Copyright (c) 2006-2022, 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. * 2021-07-21 Meco Man move to libc/common
  10. */
  11. #ifndef __SYS_SIGNAL_H__
  12. #define __SYS_SIGNAL_H__
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif /* __cplusplus */
  16. #ifdef RT_USING_MUSLLIBC
  17. #include <signal.h>
  18. #else
  19. #include <stdint.h>
  20. #include <sys/types.h>
  21. /* sigev_notify values
  22. NOTE: P1003.1c/D10, p. 34 adds SIGEV_THREAD. */
  23. #define SIGEV_NONE 1 /* No asynchronous notification shall be delivered */
  24. /* when the event of interest occurs. */
  25. #define SIGEV_SIGNAL 0 /* A queued signal, with an application defined */
  26. /* value, shall be delivered when the event of */
  27. /* interest occurs. */
  28. #define SIGEV_THREAD 2 /* A notification function shall be called to */
  29. /* perform notification. */
  30. /* Signal Generation and Delivery, P1003.1b-1993, p. 63
  31. NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and
  32. sigev_notify_attributes to the sigevent structure. */
  33. union sigval
  34. {
  35. int sival_int; /* Integer signal value */
  36. void *sival_ptr; /* Pointer signal value */
  37. };
  38. struct sigevent
  39. {
  40. union sigval sigev_value;
  41. int sigev_signo; /* Signal number */
  42. int sigev_notify; /* Notification type */
  43. void (*sigev_notify_function)( union sigval );
  44. /* Notification function */
  45. void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */
  46. };
  47. struct siginfo
  48. {
  49. uint16_t si_signo;
  50. uint16_t si_code;
  51. union sigval si_value;
  52. };
  53. typedef struct siginfo siginfo_t;
  54. #define SI_USER 0x01 /* Signal sent by kill(). */
  55. #define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */
  56. #define SI_TIMER 0x03 /* Signal generated by expiration of a timer set by timer_settime(). */
  57. #define SI_ASYNCIO 0x04 /* Signal generated by completion of an asynchronous I/O request. */
  58. #define SI_MESGQ 0x05 /* Signal generated by arrival of a message on an empty message queue. */
  59. typedef void (*_sig_func_ptr)(int);
  60. typedef unsigned long sigset_t;
  61. struct sigaction
  62. {
  63. _sig_func_ptr sa_handler;
  64. sigset_t sa_mask;
  65. int sa_flags;
  66. };
  67. /*
  68. * Structure used in sigaltstack call.
  69. */
  70. typedef struct sigaltstack
  71. {
  72. void *ss_sp; /* Stack base or pointer. */
  73. int ss_flags; /* Flags. */
  74. size_t ss_size; /* Stack size. */
  75. } stack_t;
  76. #define SIG_SETMASK 0 /* set mask with sigprocmask() */
  77. #define SIG_BLOCK 1 /* set of signals to block */
  78. #define SIG_UNBLOCK 2 /* set of signals to, well, unblock */
  79. #define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
  80. #define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
  81. #define sigemptyset(what) (*(what) = 0, 0)
  82. #define sigfillset(what) (*(what) = ~(0), 0)
  83. #define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
  84. int sigprocmask (int how, const sigset_t *set, sigset_t *oset);
  85. int sigpending (sigset_t *set);
  86. int sigsuspend (const sigset_t *set);
  87. #include "time.h"
  88. int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *timeout);
  89. int sigwait(const sigset_t *set, int *sig);
  90. int sigwaitinfo(const sigset_t *set, siginfo_t *info);
  91. int raise(int sig);
  92. int sigqueue(pid_t pid, int signo, const union sigval value);
  93. int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
  94. #ifdef __ARMCC_VERSION
  95. #define SIGHUP 1
  96. /* #define SIGINT 2 */
  97. #define SIGQUIT 3
  98. /* #define SIGILL 4 */
  99. #define SIGTRAP 5
  100. /* #define SIGABRT 6 */
  101. #define SIGEMT 7
  102. /* #define SIGFPE 8 */
  103. #define SIGKILL 9
  104. #define SIGBUS 10
  105. /* #define SIGSEGV 11 */
  106. #define SIGSYS 12
  107. #define SIGPIPE 13
  108. #define SIGALRM 14
  109. /* #define SIGTERM 15 */
  110. #define SIGURG 16
  111. #define SIGSTOP 17
  112. #define SIGTSTP 18
  113. #define SIGCONT 19
  114. #define SIGCHLD 20
  115. #define SIGTTIN 21
  116. #define SIGTTOU 22
  117. #define SIGPOLL 23
  118. #define SIGWINCH 24
  119. #define SIGXCPU 24 /* exceeded CPU time limit */
  120. #define SIGXFSZ 25 /* exceeded file size limit */
  121. #define SIGVTALRM 26 /* virtual time alarm */
  122. /* #define SIGUSR1 25 */
  123. /* #define SIGUSR2 26 */
  124. #define SIGRTMIN 27
  125. #define SIGRTMAX 31
  126. #define NSIG 32
  127. #elif defined(__IAR_SYSTEMS_ICC__)
  128. #define SIGHUP 1
  129. #define SIGINT 2
  130. #define SIGQUIT 3
  131. #define SIGILL 4
  132. #define SIGTRAP 5
  133. /* #define SIGABRT 6 */
  134. #define SIGEMT 7
  135. #define SIGFPE 8
  136. #define SIGKILL 9
  137. #define SIGBUS 10
  138. #define SIGSEGV 11
  139. #define SIGSYS 12
  140. #define SIGPIPE 13
  141. #define SIGALRM 14
  142. #define SIGTERM 15
  143. #define SIGURG 16
  144. #define SIGSTOP 17
  145. #define SIGTSTP 18
  146. #define SIGCONT 19
  147. #define SIGCHLD 20
  148. #define SIGTTIN 21
  149. #define SIGTTOU 22
  150. #define SIGPOLL 23
  151. #define SIGWINCH 24
  152. #define SIGXCPU 24 /* exceeded CPU time limit */
  153. #define SIGXFSZ 25 /* exceeded file size limit */
  154. #define SIGVTALRM 26 /* virtual time alarm */
  155. #define SIGUSR1 25
  156. #define SIGUSR2 26
  157. #define SIGRTMIN 27
  158. #define SIGRTMAX 31
  159. #define NSIG 32
  160. #elif defined(__GNUC__)
  161. #define SIGHUP 1 /* hangup */
  162. #define SIGINT 2 /* interrupt */
  163. #define SIGQUIT 3 /* quit */
  164. #define SIGILL 4 /* illegal instruction (not reset when caught) */
  165. #define SIGTRAP 5 /* trace trap (not reset when caught) */
  166. #define SIGIOT 6 /* IOT instruction */
  167. #define SIGABRT 6 /* used by abort, replace SIGIOT in the future */
  168. #define SIGEMT 7 /* EMT instruction */
  169. #define SIGFPE 8 /* floating point exception */
  170. #define SIGKILL 9 /* kill (cannot be caught or ignored) */
  171. #define SIGBUS 10 /* bus error */
  172. #define SIGSEGV 11 /* segmentation violation */
  173. #define SIGSYS 12 /* bad argument to system call */
  174. #define SIGPIPE 13 /* write on a pipe with no one to read it */
  175. #define SIGALRM 14 /* alarm clock */
  176. #define SIGTERM 15 /* software termination signal from kill */
  177. #define SIGURG 16 /* urgent condition on IO channel */
  178. #define SIGSTOP 17 /* sendable stop signal not from tty */
  179. #define SIGTSTP 18 /* stop signal from tty */
  180. #define SIGCONT 19 /* continue a stopped process */
  181. #define SIGCHLD 20 /* to parent on child stop or exit */
  182. #define SIGCLD 20 /* System V name for SIGCHLD */
  183. #define SIGTTIN 21 /* to readers pgrp upon background tty read */
  184. #define SIGTTOU 22 /* like TTIN for output if (tp->t_local&LTOSTOP) */
  185. #define SIGIO 23 /* input/output possible signal */
  186. #define SIGPOLL SIGIO /* System V name for SIGIO */
  187. #define SIGXCPU 24 /* exceeded CPU time limit */
  188. #define SIGXFSZ 25 /* exceeded file size limit */
  189. #define SIGVTALRM 26 /* virtual time alarm */
  190. #define SIGPROF 27 /* profiling time alarm */
  191. #define SIGWINCH 28 /* window changed */
  192. #define SIGLOST 29 /* resource lost (eg, record-lock lost) */
  193. #define SIGUSR1 30 /* user defined signal 1 */
  194. #define SIGUSR2 31 /* user defined signal 2 */
  195. #define NSIG 32 /* signal 0 implied */
  196. #endif /* __ARMCC_VERSION */
  197. #ifndef RT_USING_MUSLLIBC
  198. /* Some applications take advantage of the fact that <sys/signal.h>
  199. * and <signal.h> are equivalent in glibc. Allow for that here. */
  200. #include <signal.h>
  201. #endif /* RT_USING_MUSLLIBC */
  202. #ifndef SIG_ERR
  203. #define SIG_ERR ((void (*)(int))-1)
  204. #endif
  205. #ifndef SIG_DFL
  206. #define SIG_DFL ((void (*)(int)) 0)
  207. #endif
  208. #ifndef SIG_IGN
  209. #define SIG_IGN ((void (*)(int)) 1)
  210. #endif
  211. #endif /* RT_USING_MUSLLIBC */
  212. #ifdef __cplusplus
  213. }
  214. #endif /* __cplusplus */
  215. #endif /* __SYS_SIGNAL_H__ */