siginfo.h 9.5 KB

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