libc_signal.h 4.9 KB

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