ksignals.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. ksignals.h
  5. Abstract:
  6. This header contains definitions for signals sent to user mode programs by
  7. the kernel or other user mode programs.
  8. Author:
  9. Evan Green 29-Mar-2013
  10. --*/
  11. #ifndef _KSIGNALS_H
  12. #define _KSIGNALS_H
  13. //
  14. // ------------------------------------------------------------------- Includes
  15. //
  16. //
  17. // --------------------------------------------------------------------- Macros
  18. //
  19. //
  20. // This macro adds the given signal into the signal set.
  21. //
  22. #define ADD_SIGNAL(_SignalSet, _SignalNumber) \
  23. ((_SignalSet) |= (1ULL << ((_SignalNumber) - 1)))
  24. //
  25. // This macro removes the given signal from the signal set.
  26. //
  27. #define REMOVE_SIGNAL(_SignalSet, _SignalNumber) \
  28. ((_SignalSet) &= ~(1ULL << ((_SignalNumber) - 1)))
  29. //
  30. // This macro evaluates to a non-zero condition if the given signal is set in
  31. // the given signal set.
  32. //
  33. #define IS_SIGNAL_SET(_SignalSet, _SignalNumber) \
  34. (((_SignalSet) & (1ULL << ((_SignalNumber) - 1))) != 0)
  35. //
  36. // This macro initializes a signal set to have no signals set in it.
  37. //
  38. #define INITIALIZE_SIGNAL_SET(_SignalSet) ((_SignalSet) = 0)
  39. //
  40. // This macro ORs together two signal masks into a third. The result is where
  41. // the union is written to, and the two sets are the inputs to combine.
  42. //
  43. #define OR_SIGNAL_SETS(_ResultSet, _Set1, _Set2) \
  44. ((_ResultSet) = (_Set1) | (_Set2))
  45. //
  46. // This macro ANDs together two signal masks into a third. The result is where
  47. // the combination is written to, and the two sets are the inputs to combine.
  48. //
  49. #define AND_SIGNAL_SETS(_ResultSet, _Set1, _Set2) \
  50. ((_ResultSet) = (_Set1) & (_Set2))
  51. //
  52. // This macro removes the signals in the second set from the signals in the
  53. // first, and writes the result back to the first set.
  54. //
  55. #define REMOVE_SIGNALS_FROM_SET(_DestinationSet, _SignalsToRemove) \
  56. ((_DestinationSet) &= ~(_SignalsToRemove))
  57. //
  58. // This macro returns non-zero if the set is empty.
  59. //
  60. #define IS_SIGNAL_SET_EMPTY(_SignalSet) ((_SignalSet) == 0)
  61. //
  62. // This macro returns a signal set with every signal set.
  63. //
  64. #define FILL_SIGNAL_SET(_SignalSet) ((_SignalSet) = -1)
  65. //
  66. // This macro returns non-zero if the default action for the given signal is
  67. // to ignore it.
  68. //
  69. #define IS_SIGNAL_DEFAULT_IGNORE(_SignalNumber) \
  70. (((_SignalNumber) == SIGNAL_CHILD_PROCESS_ACTIVITY) || \
  71. ((_SignalNumber) == SIGNAL_URGENT_DATA_AVAILABLE) || \
  72. ((_SignalNumber) == SIGNAL_TERMINAL_WINDOW_CHANGE))
  73. //
  74. // ---------------------------------------------------------------- Definitions
  75. //
  76. //
  77. // Define the number of standard signals (in the bitmask) before the real time
  78. // signals begin.
  79. //
  80. #define STANDARD_SIGNAL_COUNT 32
  81. //
  82. // Define the number of signals supported by the system.
  83. //
  84. #define SIGNAL_COUNT 64
  85. //
  86. // Define user mode signals.
  87. //
  88. //
  89. // This signal is sent when the application's controlling terminal is closed.
  90. //
  91. #define SIGNAL_CONTROLLING_TERMINAL_CLOSED 1
  92. //
  93. // This signal is sent when the keyboard interrupt combination is pressed.
  94. //
  95. #define SIGNAL_KEYBOARD_INTERRUPT 2
  96. //
  97. // This signal is sent asking the application to perform a core dump.
  98. //
  99. #define SIGNAL_REQUEST_CORE_DUMP 3
  100. //
  101. // This signal is sent to a thread that has just executed an illegal
  102. // instruction.
  103. //
  104. #define SIGNAL_ILLEGAL_INSTRUCTION 4
  105. //
  106. // This signal is sent when a hardware breakpoint is reached in the program.
  107. //
  108. #define SIGNAL_TRAP 5
  109. //
  110. // This signal is sent when a fatal condition occurs in the application.
  111. //
  112. #define SIGNAL_ABORT 6
  113. //
  114. // This signal is sent when an application causes a bus error.
  115. //
  116. #define SIGNAL_BUS_ERROR 7
  117. //
  118. // This signal is sent when the application triggers a math error.
  119. //
  120. #define SIGNAL_MATH_ERROR 8
  121. //
  122. // This signal is sent to kill a process. This signal cannot be caught or
  123. // handled by the application.
  124. //
  125. #define SIGNAL_KILL 9
  126. //
  127. // This signal is never sent by the system, and is available for applications
  128. // to use.
  129. //
  130. #define SIGNAL_APPLICATION1 10
  131. //
  132. // This signal is sent to an application when it improperly accesses a region
  133. // of memory.
  134. //
  135. #define SIGNAL_ACCESS_VIOLATION 11
  136. //
  137. // This signal is never sent by the system, and is available for applications
  138. // to use.
  139. //
  140. #define SIGNAL_APPLICATION2 12
  141. //
  142. // This signal is sent to a process when it attempts to write to a pipe with no
  143. // reader connected at the other end.
  144. //
  145. #define SIGNAL_BROKEN_PIPE 13
  146. //
  147. // This signal is sent to a process when a requested time limit has expired.
  148. //
  149. #define SIGNAL_TIMER 14
  150. //
  151. // This signal is sent to an application to politely request its termination.
  152. //
  153. #define SIGNAL_REQUEST_TERMINATION 15
  154. //
  155. // This signal is sent when a child process terminated, stopped, or continued.
  156. //
  157. #define SIGNAL_CHILD_PROCESS_ACTIVITY 16
  158. //
  159. // This signal is sent to resume a process that was previously stopped.
  160. //
  161. #define SIGNAL_CONTINUE 17
  162. //
  163. // When this signal is sent, it causes the destination process to suspend. This
  164. // signal cannot be caught or ignored.
  165. //
  166. #define SIGNAL_STOP 18
  167. //
  168. // This signal is sent to politely request that the destination process
  169. // suspend itself.
  170. //
  171. #define SIGNAL_REQUEST_STOP 19
  172. //
  173. // This signal is sent when a background process attempts to read from the
  174. // terminal.
  175. //
  176. #define SIGNAL_BACKGROUND_TERMINAL_INPUT 20
  177. //
  178. // This signal is sent when a background process attempts to write to the
  179. // terminal.
  180. //
  181. #define SIGNAL_BACKGROUND_TERMINAL_OUTPUT 21
  182. //
  183. // This signal is sent to indicate that high bandwidth data is available at a
  184. // socket.
  185. //
  186. #define SIGNAL_URGENT_DATA_AVAILABLE 22
  187. //
  188. // This signal is sent to indicate that the destination process has neared or
  189. // exceeded its CPU resource allocation limit.
  190. //
  191. #define SIGNAL_CPU_QUOTA_REACHED 23
  192. //
  193. // This signal is sent when a file size grows beyond the maximum allowed limit.
  194. //
  195. #define SIGNAL_FILE_SIZE_TOO_LARGE 24
  196. //
  197. // This signal is sent when a process executes for a specified duration of time.
  198. //
  199. #define SIGNAL_EXECUTION_TIMER_EXPIRED 25
  200. //
  201. // This signal is sent when a profiling timer expires.
  202. //
  203. #define SIGNAL_PROFILE_TIMER 26
  204. //
  205. // This signal is sent when the application's controlling terminal changes
  206. // size.
  207. //
  208. #define SIGNAL_TERMINAL_WINDOW_CHANGE 27
  209. //
  210. // This signal is sent when asynchronous I/O is available.
  211. //
  212. #define SIGNAL_ASYNCHRONOUS_IO_COMPLETE 28
  213. //
  214. // This signal is sent when a bad system call is attempted.
  215. //
  216. #define SIGNAL_BAD_SYSTEM_CALL 29
  217. //
  218. // Define the signal context flags.
  219. //
  220. //
  221. // This flag is set if the system call the signal interrupted should be
  222. // restarted.
  223. //
  224. #define SIGNAL_CONTEXT_FLAG_RESTART 0x00000001
  225. //
  226. // This flag is set if the FPU context in the signal context is valid.
  227. //
  228. #define SIGNAL_CONTEXT_FLAG_FPU_VALID 0x00000002
  229. //
  230. // This flag is set by user mode if the given context has already been swapped
  231. // in.
  232. //
  233. #define SIGNAL_CONTEXT_FLAG_SWAPPED 0x00000004
  234. //
  235. // Define the child process signal reason codes.
  236. //
  237. //
  238. // This code is used if the process exited naturally.
  239. //
  240. #define CHILD_SIGNAL_REASON_EXITED 1
  241. //
  242. // This code is used if the process was killed by a signal.
  243. //
  244. #define CHILD_SIGNAL_REASON_KILLED 2
  245. //
  246. // This code is used if the process aborted abnormally and a dump was created.
  247. //
  248. #define CHILD_SIGNAL_REASON_DUMPED 3
  249. //
  250. // This code is used if the process took a trap.
  251. //
  252. #define CHILD_SIGNAL_REASON_TRAPPED 4
  253. //
  254. // This code is used if the process is stopped.
  255. //
  256. #define CHILD_SIGNAL_REASON_STOPPED 5
  257. //
  258. // This code is used if the process has continued.
  259. //
  260. #define CHILD_SIGNAL_REASON_CONTINUED 6
  261. //
  262. // Define illegal instruction signal codes.
  263. //
  264. #define ILLEGAL_INSTRUCTION_OPCODE 1
  265. #define ILLEGAL_INSTRUCTION_OPERAND 2
  266. #define ILLEGAL_INSTRUCTION_ADDRESS_MODE 3
  267. #define ILLEGAL_INSTRUCTION_TRAP 4
  268. #define ILLEGAL_INSTRUCTION_PRIVILEGED_OPCODE 5
  269. #define ILLEGAL_INSTRUCTION_PRIVILEGED_REGISTER 6
  270. #define ILLEGAL_INSTRUCTION_COPROCESSOR 7
  271. #define ILLEGAL_INSTRUCTION_BAD_STACK 8
  272. //
  273. // Define the math error signal codes.
  274. //
  275. #define MATH_ERROR_INTEGER_DIVIDE_BY_ZERO 1
  276. #define MATH_ERROR_INTEGER_OVERFLOW 2
  277. #define MATH_ERROR_FLOAT_DIVIDE_BY_ZERO 3
  278. #define MATH_ERROR_FLOAT_OVERFLOW 4
  279. #define MATH_ERROR_FLOAT_UNDERFLOW 5
  280. #define MATH_ERROR_FLOAT_INEXACT_RESULT 6
  281. #define MATH_ERROR_FLOAT_INVALID_OPERATION 7
  282. #define MATH_ERROR_FLOAT_SUBSCRIPT_OUT_RANGE 8
  283. //
  284. // Define access violation signal codes.
  285. //
  286. #define ACCESS_VIOLATION_MAPPING_ERROR 1
  287. #define ACCESS_VIOLATION_PERMISSION_ERROR 2
  288. //
  289. // Define the signal codes that may come with bus error signal (SIGBUS). These
  290. // line up with BUS_ERROR_* definitions.
  291. //
  292. #define BUS_ERROR_ADDRESS_ALIGNMENT 1
  293. #define BUS_ERROR_INVALID_ADDRESS 2
  294. #define BUS_ERROR_HARDWARE 3
  295. //
  296. // Define the signal codes that may come with a trap signal. These line up with
  297. // TRAP_CODE_* definitions.
  298. //
  299. #define TRAP_CODE_BREAKPOINT 1
  300. #define TRAP_CODE_TRACE 2
  301. //
  302. // Define poll signal codes.
  303. //
  304. #define POLL_CODE_IN 1
  305. #define POLL_CODE_OUT 2
  306. #define POLL_CODE_MESSAGE 3
  307. #define POLL_CODE_ERROR 4
  308. #define POLL_CODE_PRIORITY 5
  309. #define POLL_CODE_DISCONNECTED 6
  310. //
  311. // Define user signal codes.
  312. //
  313. #define SIGNAL_CODE_KERNEL (128)
  314. #define SIGNAL_CODE_USER (0)
  315. #define SIGNAL_CODE_QUEUE (-1)
  316. #define SIGNAL_CODE_TIMER (-2)
  317. #define SIGNAL_CODE_IO (-3)
  318. #define SIGNAL_CODE_THREAD_KILL (-4)
  319. #define SIGNAL_CODE_ASYNC_IO (-5)
  320. #define SIGNAL_CODE_MESSAGE (-6)
  321. //
  322. // ------------------------------------------------------ Data Type Definitions
  323. //
  324. //
  325. // Define a signal mask type, to be used for all signal bitmaps.
  326. //
  327. typedef ULONGLONG SIGNAL_SET, *PSIGNAL_SET;
  328. /*++
  329. Structure Description:
  330. This structure defines the signal information structure.
  331. Members:
  332. SignalNumber - Stores the number of the signal being generated.
  333. SignalCode - Stores additional information about the signal. The meaning
  334. of this value is different for each signal.
  335. ErrorNumber - Stores an optional error number to send with the signal.
  336. SendingProcess - Stores the process ID of the process that sent this signal.
  337. FaultingAddress - Stores the faulting address that caused the signal, used
  338. for bus and segmentation fault signals.
  339. OverflowCount - Stores the number of overflows that occurred. Used by the
  340. timers.
  341. BandEvent - Stores the data direction that is available. Used by poll
  342. signals.
  343. Descriptor - Stores the descriptor handle for the file that triggered the
  344. poll signal.
  345. SendingUserId - Stores the user ID of the process that generated the signal.
  346. Parameter - Stores the parameter, which is usually either the exit status
  347. or the user-defined parameter sent with the queued signal.
  348. --*/
  349. typedef struct _SIGNAL_PARAMETERS {
  350. USHORT SignalNumber;
  351. SHORT SignalCode;
  352. INT ErrorNumber;
  353. union {
  354. LONG SendingProcess;
  355. PVOID FaultingAddress;
  356. ULONG OverflowCount;
  357. struct {
  358. LONG BandEvent;
  359. HANDLE Descriptor;
  360. } Poll;
  361. } FromU;
  362. ULONG SendingUserId;
  363. UINTN Parameter;
  364. } SIGNAL_PARAMETERS, *PSIGNAL_PARAMETERS;
  365. /*++
  366. Structure Description:
  367. This structure defines signal stack information.
  368. Members:
  369. Base - Stores the base of the stack.
  370. Flags - Stores a bitfield of flags about the stack. See SIGNAL_STACK_*
  371. definitions.
  372. Size - Stores the size of the stack in bytes.
  373. --*/
  374. typedef struct _SIGNAL_STACK {
  375. PVOID Base;
  376. ULONG Flags;
  377. UINTN Size;
  378. } SIGNAL_STACK, *PSIGNAL_STACK;
  379. /*++
  380. Structure Description:
  381. This structure outlines the state saved by the kernel when a user mode
  382. signal is dispatched. This is usually embedded within an architecture
  383. specific version of the signal context. This lines up with the ucontext
  384. structure in the C library.
  385. Members:
  386. Flags - Stores a bitmask of signal context flags. See SIGNAL_CONTEXT_FLAG_*
  387. for definitions.
  388. Next - Stores a pointer to the next signal context.
  389. Stack - Stores the alternate signal stack information.
  390. Mask - Stores the original signal mask when this signal was applied.
  391. --*/
  392. typedef struct _SIGNAL_CONTEXT {
  393. ULONG Flags;
  394. PVOID Next;
  395. SIGNAL_STACK Stack;
  396. SIGNAL_SET Mask;
  397. } SIGNAL_CONTEXT, *PSIGNAL_CONTEXT;
  398. //
  399. // -------------------------------------------------------------------- Globals
  400. //
  401. //
  402. // -------------------------------------------------------- Function Prototypes
  403. //
  404. #endif