libc_signal.h 5.4 KB

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