libc_signal.h 5.3 KB

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