libc_signal.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * File : libc_signal.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2017-09-12 Bernard The first version
  23. */
  24. #ifndef LIBC_SIGNAL_H__
  25. #define LIBC_SIGNAL_H__
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #ifdef HAVE_CCONFIG_H
  30. #include <cconfig.h>
  31. #endif
  32. #ifndef HAVE_SIGVAL
  33. /* Signal Generation and Delivery, P1003.1b-1993, p. 63
  34. NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and
  35. sigev_notify_attributes to the sigevent structure. */
  36. union sigval
  37. {
  38. int sival_int; /* Integer signal value */
  39. void *sival_ptr; /* Pointer signal value */
  40. };
  41. #endif
  42. #ifndef HAVE_SIGEVENT
  43. struct sigevent
  44. {
  45. int sigev_notify; /* Notification type */
  46. int sigev_signo; /* Signal number */
  47. union sigval sigev_value; /* Signal value */
  48. void (*sigev_notify_function)( union sigval );
  49. /* Notification function */
  50. void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */
  51. };
  52. #endif
  53. #ifndef HAVE_SIGINFO
  54. struct siginfo
  55. {
  56. rt_uint16_t si_signo;
  57. rt_uint16_t si_code;
  58. union sigval si_value;
  59. };
  60. typedef struct siginfo siginfo_t;
  61. #endif
  62. #define SI_USER 0x01 /* Signal sent by kill(). */
  63. #define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */
  64. #define SI_TIMER 0x03 /* Signal generated by expiration of a
  65. timer set by timer_settime(). */
  66. #define SI_ASYNCIO 0x04 /* Signal generated by completion of an
  67. asynchronous I/O request. */
  68. #define SI_MESGQ 0x05 /* Signal generated by arrival of a
  69. message on an empty message queue. */
  70. #ifdef RT_USING_NEWLIB
  71. #include <sys/signal.h>
  72. #endif
  73. #ifdef __CC_ARM
  74. #include <signal.h>
  75. typedef unsigned long sigset_t;
  76. #define SIGHUP 1
  77. // #define SIGINT 2
  78. #define SIGQUIT 3
  79. // #define SIGILL 4
  80. #define SIGTRAP 5
  81. // #define SIGABRT 6
  82. #define SIGEMT 7
  83. // #define SIGFPE 8
  84. #define SIGKILL 9
  85. #define SIGBUS 10
  86. // #define SIGSEGV 11
  87. #define SIGSYS 12
  88. #define SIGPIPE 13
  89. #define SIGALRM 14
  90. // #define SIGTERM 15
  91. #define SIGURG 16
  92. #define SIGSTOP 17
  93. #define SIGTSTP 18
  94. #define SIGCONT 19
  95. #define SIGCHLD 20
  96. #define SIGTTIN 21
  97. #define SIGTTOU 22
  98. #define SIGPOLL 23
  99. #define SIGWINCH 24
  100. // #define SIGUSR1 25
  101. // #define SIGUSR2 26
  102. #define SIGRTMIN 27
  103. #define SIGRTMAX 31
  104. #define NSIG 32
  105. #define SIG_SETMASK 0 /* set mask with sigprocmask() */
  106. #define SIG_BLOCK 1 /* set of signals to block */
  107. #define SIG_UNBLOCK 2 /* set of signals to, well, unblock */
  108. typedef void (*_sig_func_ptr)(int);
  109. struct sigaction
  110. {
  111. _sig_func_ptr sa_handler;
  112. sigset_t sa_mask;
  113. int sa_flags;
  114. };
  115. #define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
  116. #define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
  117. #define sigemptyset(what) (*(what) = 0, 0)
  118. #define sigfillset(what) (*(what) = ~(0), 0)
  119. #define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
  120. int sigprocmask (int how, const sigset_t *set, sigset_t *oset);
  121. int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
  122. #elif defined(__IAR_SYSTEMS_ICC__)
  123. #include <signal.h>
  124. typedef unsigned long sigset_t;
  125. #define SIGHUP 1
  126. #define SIGINT 2
  127. #define SIGQUIT 3
  128. #define SIGILL 4
  129. #define SIGTRAP 5
  130. // #define SIGABRT 6
  131. #define SIGEMT 7
  132. #define SIGFPE 8
  133. #define SIGKILL 9
  134. #define SIGBUS 10
  135. #define SIGSEGV 11
  136. #define SIGSYS 12
  137. #define SIGPIPE 13
  138. #define SIGALRM 14
  139. #define SIGTERM 15
  140. #define SIGURG 16
  141. #define SIGSTOP 17
  142. #define SIGTSTP 18
  143. #define SIGCONT 19
  144. #define SIGCHLD 20
  145. #define SIGTTIN 21
  146. #define SIGTTOU 22
  147. #define SIGPOLL 23
  148. #define SIGWINCH 24
  149. #define SIGUSR1 25
  150. #define SIGUSR2 26
  151. #define SIGRTMIN 27
  152. #define SIGRTMAX 31
  153. #define NSIG 32
  154. #define SIG_SETMASK 0 /* set mask with sigprocmask() */
  155. #define SIG_BLOCK 1 /* set of signals to block */
  156. #define SIG_UNBLOCK 2 /* set of signals to, well, unblock */
  157. typedef void (*_sig_func_ptr)(int);
  158. struct sigaction
  159. {
  160. _sig_func_ptr sa_handler;
  161. sigset_t sa_mask;
  162. int sa_flags;
  163. };
  164. #define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
  165. #define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
  166. #define sigemptyset(what) (*(what) = 0, 0)
  167. #define sigfillset(what) (*(what) = ~(0), 0)
  168. #define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
  169. int sigprocmask (int how, const sigset_t *set, sigset_t *oset);
  170. int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
  171. #endif
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175. #endif