signal.h 7.4 KB

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