libc_signal.h 4.8 KB

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