signal.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * Copyright (c) mlibc & plct lab
  3. *
  4. * SPDX-License-Identifier: MIT
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023/06/16 bernard the first verison
  9. */
  10. #ifndef __SYS_SIGNAL_H__
  11. #ifndef MLIBC_SIGNAL_H__
  12. #define MLIBC_SIGNAL_H__
  13. #include <stdint.h>
  14. #include <time.h>
  15. #ifndef SIGHUP
  16. #define SIGHUP 1
  17. #endif
  18. #ifndef SIGINT
  19. #define SIGINT 2
  20. #endif
  21. #ifndef SIGQUIT
  22. #define SIGQUIT 3
  23. #endif
  24. #ifndef SIGBUS
  25. #define SIGBUS 7
  26. #endif
  27. #ifndef SIGFPE
  28. #define SIGFPE 8
  29. #endif
  30. #ifndef SIGKILL
  31. #define SIGKILL 9
  32. #endif
  33. #ifndef SIGUSR1
  34. #define SIGUSR1 10
  35. #endif
  36. #ifndef SIGSEGV
  37. #define SIGSEGV 11
  38. #endif
  39. #ifndef SIGUSR2
  40. #define SIGUSR2 12
  41. #endif
  42. #ifndef SIGPIPE
  43. #define SIGPIPE 13
  44. #endif
  45. #ifndef SIGALRM
  46. #define SIGALRM 14
  47. #endif
  48. #ifndef SIGTERM
  49. #define SIGTERM 15
  50. #endif
  51. #ifndef SIGSTKFLT
  52. #define SIGSTKFLT 16
  53. #endif
  54. #ifndef SIGCHLD
  55. #define SIGCHLD 17
  56. #endif
  57. #ifndef SIGCONT
  58. #define SIGCONT 18
  59. #endif
  60. #ifndef SIGSTOP
  61. #define SIGSTOP 19
  62. #endif
  63. #ifndef SIGTSTP
  64. #define SIGTSTP 20
  65. #endif
  66. #ifndef SIGTTIN
  67. #define SIGTTIN 21
  68. #endif
  69. #ifndef SIGTTOU
  70. #define SIGTTOU 22
  71. #endif
  72. #ifndef SIGURG
  73. #define SIGURG 23
  74. #endif
  75. #ifndef SIGXCPU
  76. #define SIGXCPU 24
  77. #endif
  78. #ifndef SIGXFSZ
  79. #define SIGXFSZ 25
  80. #endif
  81. #ifndef SIGVTALRM
  82. #define SIGVTALRM 26
  83. #endif
  84. #ifndef SIGPROF
  85. #define SIGPROF 27
  86. #endif
  87. #ifndef SIGWINCH
  88. #define SIGWINCH 28
  89. #endif
  90. #ifndef SIGIO
  91. #define SIGIO 29
  92. #endif
  93. #ifndef SIGPOLL
  94. #define SIGPOLL 29
  95. #endif
  96. #ifndef SIGPWR
  97. #define SIGPWR 30
  98. #endif
  99. #ifndef SIGSYS
  100. #define SIGSYS 31
  101. #endif
  102. #ifndef SIGUNUSED
  103. #define SIGUNUSED SIGSYS
  104. #endif
  105. #ifndef SA_NOCLDSTOP
  106. #define SA_NOCLDSTOP 1
  107. #endif
  108. #ifndef SA_NOCLDWAIT
  109. #define SA_NOCLDWAIT 2
  110. #endif
  111. #ifndef SA_SIGINFO
  112. #define SA_SIGINFO 4
  113. #endif
  114. #ifndef SA_ONSTACK
  115. #define SA_ONSTACK 0x08000000
  116. #endif
  117. #ifndef SA_RESTART
  118. #define SA_RESTART 0x10000000
  119. #endif
  120. #ifndef SA_NODEFER
  121. #define SA_NODEFER 0x40000000
  122. #endif
  123. #ifndef SA_RESETHAND
  124. #define SA_RESETHAND 0x80000000
  125. #endif
  126. #ifndef SA_RESTORER
  127. #define SA_RESTORER 0x04000000
  128. #endif
  129. #ifndef _NSIG
  130. #define _NSIG 65
  131. #endif
  132. #ifndef SI_KERNEL
  133. #define SI_KERNEL 128
  134. #endif
  135. #ifndef SIG_SETMASK
  136. #define SIG_SETMASK 0 /* set mask with sigprocmask() */
  137. #endif
  138. #ifndef SIG_BLOCK
  139. #define SIG_BLOCK 1 /* set of signals to block */
  140. #endif
  141. #ifndef SIG_UNBLOCK
  142. #define SIG_UNBLOCK 2 /* set of signals to, well, unblock */
  143. #endif
  144. #ifndef _SIG_FUNC_PTR_DEFINED
  145. typedef void (*_sig_func_ptr)(int);
  146. #define _SIG_FUNC_PTR_DEFINED
  147. #endif
  148. #ifndef _SIGSET_T_DEFINED
  149. typedef unsigned long sigset_t;
  150. #define _SIGSET_T_DEFINED
  151. #endif
  152. #ifndef SIG_DFL
  153. #define SIG_DFL ((_sig_func_ptr)0) /* Default action */
  154. #endif
  155. #ifndef SIG_IGN
  156. #define SIG_IGN ((_sig_func_ptr)1) /* Ignore action */
  157. #endif
  158. #ifndef SIG_ERR
  159. #define SIG_ERR ((_sig_func_ptr)-1) /* Error return */
  160. #endif
  161. #ifndef SI_USER
  162. #define SI_USER 0x01 /* Signal sent by kill(). */
  163. #endif
  164. #ifndef SI_QUEUE
  165. #define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */
  166. #endif
  167. #ifndef SI_TIMER
  168. #define SI_TIMER 0x03 /* Signal generated by expiration of a
  169. timer set by timer_settime(). */
  170. #endif
  171. #ifndef SI_ASYNCIO
  172. #define SI_ASYNCIO 0x04 /* Signal generated by completion of an
  173. asynchronous I/O request. */
  174. #endif
  175. #ifndef SI_MESGQ
  176. #define SI_MESGQ 0x05 /* Signal generated by arrival of a
  177. message on an empty message queue. */
  178. #endif
  179. #ifndef CLD_EXITED
  180. #define CLD_EXITED 1
  181. #endif
  182. #ifndef CLD_KILLED
  183. #define CLD_KILLED 2
  184. #endif
  185. #ifndef CLD_DUMPED
  186. #define CLD_DUMPED 3
  187. #endif
  188. #ifndef CLD_TRAPPED
  189. #define CLD_TRAPPED 4
  190. #endif
  191. #ifndef CLD_STOPPED
  192. #define CLD_STOPPED 5
  193. #endif
  194. #ifndef CLD_CONTINUED
  195. #define CLD_CONTINUED 6
  196. #endif
  197. #ifndef SIGEV_SIGNAL
  198. #define SIGEV_SIGNAL 0
  199. #endif
  200. #ifndef SIGEV_NONE
  201. #define SIGEV_NONE 1
  202. #endif
  203. #ifndef SIGEV_THREAD
  204. #define SIGEV_THREAD 2
  205. #endif
  206. #ifndef SIGEV_THREAD_ID
  207. #define SIGEV_THREAD_ID 4
  208. #endif
  209. #ifndef _UNION_SIGVAL_DEFINED
  210. union sigval
  211. {
  212. int sival_int; /* Integer signal value */
  213. void *sival_ptr; /* Pointer signal value */
  214. };
  215. #define _UNION_SIGVAL_DEFINED
  216. #endif
  217. #ifndef _STRUCT_SIGACTION_DEFINED
  218. struct sigaction
  219. {
  220. _sig_func_ptr sa_handler;
  221. sigset_t sa_mask;
  222. int sa_flags;
  223. };
  224. #define _STRUCT_SIGACTION_DEFINED
  225. #endif
  226. #ifndef _STRUCT_SIGEVENT_DEFINED
  227. struct sigevent
  228. {
  229. union sigval sigev_value;
  230. int sigev_signo; /* Signal number */
  231. int sigev_notify; /* Notification type */
  232. void (*sigev_notify_function)( union sigval );
  233. /* Notification function */
  234. void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */
  235. };
  236. #define _STRUCT_SIGEVENT_DEFINED
  237. #endif
  238. #ifndef _SIGINFO_T_DEFINED
  239. typedef struct {
  240. int si_signo, si_errno, si_code;
  241. union {
  242. char __pad[128 - 2*sizeof(int) - sizeof(long)];
  243. struct {
  244. union {
  245. struct {
  246. pid_t si_pid;
  247. uid_t si_uid;
  248. } __piduid;
  249. struct {
  250. int si_timerid;
  251. int si_overrun;
  252. } __timer;
  253. } __first;
  254. union {
  255. union sigval si_value;
  256. struct {
  257. int si_status;
  258. clock_t si_utime, si_stime;
  259. } __sigchld;
  260. } __second;
  261. } __si_common;
  262. struct {
  263. void *si_addr;
  264. short si_addr_lsb;
  265. union {
  266. struct {
  267. void *si_lower;
  268. void *si_upper;
  269. } __addr_bnd;
  270. unsigned si_pkey;
  271. } __first;
  272. } __sigfault;
  273. struct {
  274. long si_band;
  275. int si_fd;
  276. } __sigpoll;
  277. struct {
  278. void *si_call_addr;
  279. int si_syscall;
  280. unsigned si_arch;
  281. } __sigsys;
  282. } __si_fields;
  283. } siginfo_t;
  284. #define _SIGINFO_T_DEFINED
  285. #endif
  286. #define si_pid __si_fields.__si_common.__first.__piduid.si_pid
  287. #define si_uid __si_fields.__si_common.__first.__piduid.si_uid
  288. #define si_status __si_fields.__si_common.__second.__sigchld.si_status
  289. #define si_utime __si_fields.__si_common.__second.__sigchld.si_utime
  290. #define si_stime __si_fields.__si_common.__second.__sigchld.si_stime
  291. #define si_value __si_fields.__si_common.__second.si_value
  292. #define si_addr __si_fields.__sigfault.si_addr
  293. #define si_addr_lsb __si_fields.__sigfault.si_addr_lsb
  294. #define si_lower __si_fields.__sigfault.__first.__addr_bnd.si_lower
  295. #define si_upper __si_fields.__sigfault.__first.__addr_bnd.si_upper
  296. #define si_pkey __si_fields.__sigfault.__first.si_pkey
  297. #define si_band __si_fields.__sigpoll.si_band
  298. #define si_fd __si_fields.__sigpoll.si_fd
  299. #define si_timerid __si_fields.__si_common.__first.__timer.si_timerid
  300. #define si_overrun __si_fields.__si_common.__first.__timer.si_overrun
  301. #define si_ptr si_value.sival_ptr
  302. #define si_int si_value.sival_int
  303. #define si_call_addr __si_fields.__sigsys.si_call_addr
  304. #define si_syscall __si_fields.__sigsys.si_syscall
  305. #define si_arch __si_fields.__sigsys.si_arch
  306. #define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
  307. int sigprocmask(int how, const sigset_t *set, sigset_t *oset);
  308. #ifndef sigemptyset
  309. int sigemptyset(sigset_t *set);
  310. #endif
  311. int sigwait(const sigset_t *set, int *sig);
  312. int raise(int sig);
  313. #endif /*MLIBC_SIGNAL_H__*/
  314. #endif /*__SYS_SIGNAL_H__*/