libc_signal.h 4.7 KB

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