siginfo.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. #ifndef _ASM_GENERIC_SIGINFO_H
  2. #define _ASM_GENERIC_SIGINFO_H
  3. #include <linux/compiler.h>
  4. #include <linux/types.h>
  5. typedef union sigval {
  6. int sival_int;
  7. void __user *sival_ptr;
  8. } sigval_t;
  9. /*
  10. * This is the size (including padding) of the part of the
  11. * struct siginfo that is before the union.
  12. */
  13. #ifndef __ARCH_SI_PREAMBLE_SIZE
  14. #define __ARCH_SI_PREAMBLE_SIZE (3 * sizeof(int))
  15. #endif
  16. #define SI_MAX_SIZE 128
  17. #ifndef SI_PAD_SIZE
  18. #define SI_PAD_SIZE ((SI_MAX_SIZE - __ARCH_SI_PREAMBLE_SIZE) / sizeof(int))
  19. #endif
  20. #ifndef __ARCH_SI_UID_T
  21. #define __ARCH_SI_UID_T __kernel_uid32_t
  22. #endif
  23. /*
  24. * The default "si_band" type is "long", as specified by POSIX.
  25. * However, some architectures want to override this to "int"
  26. * for historical compatibility reasons, so we allow that.
  27. */
  28. #ifndef __ARCH_SI_BAND_T
  29. #define __ARCH_SI_BAND_T long
  30. #endif
  31. #ifndef HAVE_ARCH_SIGINFO_T
  32. typedef struct siginfo {
  33. int si_signo;
  34. int si_errno;
  35. int si_code;
  36. union {
  37. int _pad[SI_PAD_SIZE];
  38. /* kill() */
  39. struct {
  40. __kernel_pid_t _pid; /* sender's pid */
  41. __ARCH_SI_UID_T _uid; /* sender's uid */
  42. } _kill;
  43. /* POSIX.1b timers */
  44. struct {
  45. __kernel_timer_t _tid; /* timer id */
  46. int _overrun; /* overrun count */
  47. char _pad[sizeof( __ARCH_SI_UID_T) - sizeof(int)];
  48. sigval_t _sigval; /* same as below */
  49. int _sys_private; /* not to be passed to user */
  50. } _timer;
  51. /* POSIX.1b signals */
  52. struct {
  53. __kernel_pid_t _pid; /* sender's pid */
  54. __ARCH_SI_UID_T _uid; /* sender's uid */
  55. sigval_t _sigval;
  56. } _rt;
  57. /* SIGCHLD */
  58. struct {
  59. __kernel_pid_t _pid; /* which child */
  60. __ARCH_SI_UID_T _uid; /* sender's uid */
  61. int _status; /* exit code */
  62. __kernel_clock_t _utime;
  63. __kernel_clock_t _stime;
  64. } _sigchld;
  65. /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
  66. struct {
  67. void __user *_addr; /* faulting insn/memory ref. */
  68. #ifdef __ARCH_SI_TRAPNO
  69. int _trapno; /* TRAP # which caused the signal */
  70. #endif
  71. short _addr_lsb; /* LSB of the reported address */
  72. } _sigfault;
  73. /* SIGPOLL */
  74. struct {
  75. __ARCH_SI_BAND_T _band; /* POLL_IN, POLL_OUT, POLL_MSG */
  76. int _fd;
  77. } _sigpoll;
  78. } _sifields;
  79. } siginfo_t;
  80. #endif
  81. /*
  82. * How these fields are to be accessed.
  83. */
  84. #define si_pid _sifields._kill._pid
  85. #define si_uid _sifields._kill._uid
  86. #define si_tid _sifields._timer._tid
  87. #define si_overrun _sifields._timer._overrun
  88. #define si_sys_private _sifields._timer._sys_private
  89. #define si_status _sifields._sigchld._status
  90. #define si_utime _sifields._sigchld._utime
  91. #define si_stime _sifields._sigchld._stime
  92. #define si_value _sifields._rt._sigval
  93. #define si_int _sifields._rt._sigval.sival_int
  94. #define si_ptr _sifields._rt._sigval.sival_ptr
  95. #define si_addr _sifields._sigfault._addr
  96. #ifdef __ARCH_SI_TRAPNO
  97. #define si_trapno _sifields._sigfault._trapno
  98. #endif
  99. #define si_addr_lsb _sifields._sigfault._addr_lsb
  100. #define si_band _sifields._sigpoll._band
  101. #define si_fd _sifields._sigpoll._fd
  102. #ifdef __KERNEL__
  103. #define __SI_MASK 0xffff0000u
  104. #define __SI_KILL (0 << 16)
  105. #define __SI_TIMER (1 << 16)
  106. #define __SI_POLL (2 << 16)
  107. #define __SI_FAULT (3 << 16)
  108. #define __SI_CHLD (4 << 16)
  109. #define __SI_RT (5 << 16)
  110. #define __SI_MESGQ (6 << 16)
  111. #define __SI_CODE(T,N) ((T) | ((N) & 0xffff))
  112. #else
  113. #define __SI_KILL 0
  114. #define __SI_TIMER 0
  115. #define __SI_POLL 0
  116. #define __SI_FAULT 0
  117. #define __SI_CHLD 0
  118. #define __SI_RT 0
  119. #define __SI_MESGQ 0
  120. #define __SI_CODE(T,N) (N)
  121. #endif
  122. /*
  123. * si_code values
  124. * Digital reserves positive values for kernel-generated signals.
  125. */
  126. #define SI_USER 0 /* sent by kill, sigsend, raise */
  127. #define SI_KERNEL 0x80 /* sent by the kernel from somewhere */
  128. #define SI_QUEUE -1 /* sent by sigqueue */
  129. #define SI_TIMER __SI_CODE(__SI_TIMER,-2) /* sent by timer expiration */
  130. #define SI_MESGQ __SI_CODE(__SI_MESGQ,-3) /* sent by real time mesq state change */
  131. #define SI_ASYNCIO -4 /* sent by AIO completion */
  132. #define SI_SIGIO -5 /* sent by queued SIGIO */
  133. #define SI_TKILL -6 /* sent by tkill system call */
  134. #define SI_DETHREAD -7 /* sent by execve() killing subsidiary threads */
  135. #define SI_FROMUSER(siptr) ((siptr)->si_code <= 0)
  136. #define SI_FROMKERNEL(siptr) ((siptr)->si_code > 0)
  137. /*
  138. * SIGILL si_codes
  139. */
  140. #define ILL_ILLOPC (__SI_FAULT|1) /* illegal opcode */
  141. #define ILL_ILLOPN (__SI_FAULT|2) /* illegal operand */
  142. #define ILL_ILLADR (__SI_FAULT|3) /* illegal addressing mode */
  143. #define ILL_ILLTRP (__SI_FAULT|4) /* illegal trap */
  144. #define ILL_PRVOPC (__SI_FAULT|5) /* privileged opcode */
  145. #define ILL_PRVREG (__SI_FAULT|6) /* privileged register */
  146. #define ILL_COPROC (__SI_FAULT|7) /* coprocessor error */
  147. #define ILL_BADSTK (__SI_FAULT|8) /* internal stack error */
  148. #define NSIGILL 8
  149. /*
  150. * SIGFPE si_codes
  151. */
  152. #define FPE_INTDIV (__SI_FAULT|1) /* integer divide by zero */
  153. #define FPE_INTOVF (__SI_FAULT|2) /* integer overflow */
  154. #define FPE_FLTDIV (__SI_FAULT|3) /* floating point divide by zero */
  155. #define FPE_FLTOVF (__SI_FAULT|4) /* floating point overflow */
  156. #define FPE_FLTUND (__SI_FAULT|5) /* floating point underflow */
  157. #define FPE_FLTRES (__SI_FAULT|6) /* floating point inexact result */
  158. #define FPE_FLTINV (__SI_FAULT|7) /* floating point invalid operation */
  159. #define FPE_FLTSUB (__SI_FAULT|8) /* subscript out of range */
  160. #define NSIGFPE 8
  161. /*
  162. * SIGSEGV si_codes
  163. */
  164. #define SEGV_MAPERR (__SI_FAULT|1) /* address not mapped to object */
  165. #define SEGV_ACCERR (__SI_FAULT|2) /* invalid permissions for mapped object */
  166. #define NSIGSEGV 2
  167. /*
  168. * SIGBUS si_codes
  169. */
  170. #define BUS_ADRALN (__SI_FAULT|1) /* invalid address alignment */
  171. #define BUS_ADRERR (__SI_FAULT|2) /* non-existent physical address */
  172. #define BUS_OBJERR (__SI_FAULT|3) /* object specific hardware error */
  173. /* hardware memory error consumed on a machine check: action required */
  174. #define BUS_MCEERR_AR (__SI_FAULT|4)
  175. /* hardware memory error detected in process but not consumed: action optional*/
  176. #define BUS_MCEERR_AO (__SI_FAULT|5)
  177. #define NSIGBUS 5
  178. /*
  179. * SIGTRAP si_codes
  180. */
  181. #define TRAP_BRKPT (__SI_FAULT|1) /* process breakpoint */
  182. #define TRAP_TRACE (__SI_FAULT|2) /* process trace trap */
  183. #define TRAP_BRANCH (__SI_FAULT|3) /* process taken branch trap */
  184. #define TRAP_HWBKPT (__SI_FAULT|4) /* hardware breakpoint/watchpoint */
  185. #define NSIGTRAP 4
  186. /*
  187. * SIGCHLD si_codes
  188. */
  189. #define CLD_EXITED (__SI_CHLD|1) /* child has exited */
  190. #define CLD_KILLED (__SI_CHLD|2) /* child was killed */
  191. #define CLD_DUMPED (__SI_CHLD|3) /* child terminated abnormally */
  192. #define CLD_TRAPPED (__SI_CHLD|4) /* traced child has trapped */
  193. #define CLD_STOPPED (__SI_CHLD|5) /* child has stopped */
  194. #define CLD_CONTINUED (__SI_CHLD|6) /* stopped child has continued */
  195. #define NSIGCHLD 6
  196. /*
  197. * SIGPOLL si_codes
  198. */
  199. #define POLL_IN (__SI_POLL|1) /* data input available */
  200. #define POLL_OUT (__SI_POLL|2) /* output buffers available */
  201. #define POLL_MSG (__SI_POLL|3) /* input message available */
  202. #define POLL_ERR (__SI_POLL|4) /* i/o error */
  203. #define POLL_PRI (__SI_POLL|5) /* high priority input available */
  204. #define POLL_HUP (__SI_POLL|6) /* device disconnected */
  205. #define NSIGPOLL 6
  206. /*
  207. * sigevent definitions
  208. *
  209. * It seems likely that SIGEV_THREAD will have to be handled from
  210. * userspace, libpthread transmuting it to SIGEV_SIGNAL, which the
  211. * thread manager then catches and does the appropriate nonsense.
  212. * However, everything is written out here so as to not get lost.
  213. */
  214. #define SIGEV_SIGNAL 0 /* notify via signal */
  215. #define SIGEV_NONE 1 /* other notification: meaningless */
  216. #define SIGEV_THREAD 2 /* deliver via thread creation */
  217. #define SIGEV_THREAD_ID 4 /* deliver to thread */
  218. /*
  219. * This works because the alignment is ok on all current architectures
  220. * but we leave open this being overridden in the future
  221. */
  222. #ifndef __ARCH_SIGEV_PREAMBLE_SIZE
  223. #define __ARCH_SIGEV_PREAMBLE_SIZE (sizeof(int) * 2 + sizeof(sigval_t))
  224. #endif
  225. #define SIGEV_MAX_SIZE 64
  226. #define SIGEV_PAD_SIZE ((SIGEV_MAX_SIZE - __ARCH_SIGEV_PREAMBLE_SIZE) \
  227. / sizeof(int))
  228. typedef struct sigevent {
  229. sigval_t sigev_value;
  230. int sigev_signo;
  231. int sigev_notify;
  232. union {
  233. int _pad[SIGEV_PAD_SIZE];
  234. int _tid;
  235. struct {
  236. void (*_function)(sigval_t);
  237. void *_attribute; /* really pthread_attr_t */
  238. } _sigev_thread;
  239. } _sigev_un;
  240. } sigevent_t;
  241. #define sigev_notify_function _sigev_un._sigev_thread._function
  242. #define sigev_notify_attributes _sigev_un._sigev_thread._attribute
  243. #define sigev_notify_thread_id _sigev_un._tid
  244. #ifdef __KERNEL__
  245. struct siginfo;
  246. void do_schedule_next_timer(struct siginfo *info);
  247. #ifndef HAVE_ARCH_COPY_SIGINFO
  248. #include <linux/string.h>
  249. static inline void copy_siginfo(struct siginfo *to, struct siginfo *from)
  250. {
  251. if (from->si_code < 0)
  252. memcpy(to, from, sizeof(*to));
  253. else
  254. /* _sigchld is currently the largest know union member */
  255. memcpy(to, from, __ARCH_SI_PREAMBLE_SIZE + sizeof(from->_sifields._sigchld));
  256. }
  257. #endif
  258. extern int copy_siginfo_to_user(struct siginfo __user *to, struct siginfo *from);
  259. #endif /* __KERNEL__ */
  260. #endif