signal.inc 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Jonas Maebe,
  4. member of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. Const { For sending a signal }
  12. SA_NOCLDSTOP = $01;
  13. SA_NOCLDWAIT = $02;
  14. SA_RESETHAND = $04;
  15. SA_NODEFER = $08;
  16. SA_RESTART = $10;
  17. SA_ONSTACK = $20;
  18. SA_SIGINFO = $40;
  19. SA_NOMASK = SA_NODEFER;
  20. SA_STACK = SA_ONSTACK;
  21. SA_ONESHOT = SA_RESETHAND;
  22. SIG_BLOCK = 1;
  23. SIG_UNBLOCK = 2;
  24. SIG_SETMASK = 3;
  25. { values for ss_flags }
  26. SS_ONSTACK = $1;
  27. SS_DISABLE = $2;
  28. MINSIGSTKSZ = 4096;
  29. SIGSTKSZ = 16384;
  30. {Haiku Checked}
  31. {
  32. The numbering of signals for BeOS attempts to maintain
  33. some consistency with UN*X conventions so that things
  34. like "kill -9" do what you expect.
  35. }
  36. SIG_DFL = 0;
  37. SIG_IGN = 1;
  38. SIG_ERR = -1;
  39. SIG_HOLD = 3;
  40. SIGHUP = 1;
  41. SIGINT = 2;
  42. SIGQUIT = 3;
  43. SIGILL = 4;
  44. SIGCHLD = 5;
  45. SIGABRT = 6;
  46. SIGPIPE = 7;
  47. SIGFPE = 8;
  48. SIGKILL = 9;
  49. SIGSTOP = 10;
  50. SIGSEGV = 11;
  51. SIGCONT = 12;
  52. SIGTSTP = 13;
  53. SIGALRM = 14;
  54. SIGTERM = 15;
  55. SIGTTIN = 16;
  56. SIGTTOU = 17;
  57. SIGUSR1 = 18;
  58. SIGUSR2 = 19;
  59. SIGWINCH = 20;
  60. SIGKILLTHR = 21;
  61. SIGTRAP = 22;
  62. SIGPOLL = 23;
  63. SIGPROF = 24;
  64. SIGSYS = 25;
  65. SIGURG = 26;
  66. SIGVTALRM = 27;
  67. SIGXCPU = 28;
  68. SIGXFSZ = 29;
  69. SIGBUS = 30;
  70. SIGRESERVED1 = 31;
  71. SIGRESERVED2 = 32;
  72. {
  73. Signal numbers 23-32 are currently free but may be used in future
  74. releases. Use them at your own peril (if you do use them, at least
  75. be smart and use them backwards from signal 32).
  76. }
  77. {$packrecords C}
  78. const
  79. SI_PAD_SIZE = ((128/sizeof(longint)) - 3);
  80. {
  81. * The sequence of the fields/registers in struct sigcontext should match
  82. * those in mcontext_t.
  83. }
  84. type
  85. packed_fp_stack = packed record
  86. st0 : array[0..9] of byte;
  87. st1 : array[0..9] of byte;
  88. st2 : array[0..9] of byte;
  89. st3 : array[0..9] of byte;
  90. st4 : array[0..9] of byte;
  91. st5 : array[0..9] of byte;
  92. st6 : array[0..9] of byte;
  93. st7 : array[0..9] of byte;
  94. end;
  95. packed_mmx_regs = packed record
  96. mm0 : array[0..9] of byte;
  97. mm1 : array[0..9] of byte;
  98. mm2 : array[0..9] of byte;
  99. mm3 : array[0..9] of byte;
  100. mm4 : array[0..9] of byte;
  101. mm5 : array[0..9] of byte;
  102. mm6 : array[0..9] of byte;
  103. mm7 : array[0..9] of byte;
  104. end;
  105. old_extended_regs = packed record
  106. fp_control : word;
  107. _reserved1 : word;
  108. fp_status : word;
  109. _reserved2 : word;
  110. fp_tag : word;
  111. _reserved3 : word;
  112. fp_eip : cardinal;
  113. fp_cs : word;
  114. fp_opcode : word;
  115. fp_datap : word;
  116. fp_ds : word;
  117. _reserved4 : word;
  118. fp_mmx : record
  119. case fp_mmx : byte of
  120. 0 : (fp : packed_fp_stack);
  121. 1 : (mmx : packed_mmx_regs);
  122. end;
  123. end;
  124. fp_stack = record
  125. st0 : array[0..9] of byte;
  126. _reserved_42_47 : array[0..5] of byte;
  127. st1 : array[0..9] of byte;
  128. _reserved_58_63 : array[0..5] of byte;
  129. st2 : array[0..9] of byte;
  130. _reserved_74_79 : array[0..5] of byte;
  131. st3 : array[0..9] of byte;
  132. _reserved_90_95 : array[0..5] of byte;
  133. st4 : array[0..9] of byte;
  134. _reserved_106_111 : array[0..5] of byte;
  135. st5 : array[0..9] of byte;
  136. _reserved_122_127 : array[0..5] of byte;
  137. st6 : array[0..9] of byte;
  138. _reserved_138_143 : array[0..5] of byte;
  139. st7 : array[0..9] of byte;
  140. _reserved_154_159 : array[0..5] of byte;
  141. end;
  142. mmx_regs = record
  143. mm0 : array[0..9] of byte;
  144. _reserved_42_47 : array[0..5] of byte;
  145. mm1 : array[0..9] of byte;
  146. _reserved_58_63 : array[0..5] of byte;
  147. mm2 : array[0..9] of byte;
  148. _reserved_74_79 : array[0..5] of byte;
  149. mm3 : array[0..9] of byte;
  150. _reserved_90_95 : array[0..5] of byte;
  151. mm4 : array[0..9] of byte;
  152. _reserved_106_111 : array[0..5] of byte;
  153. mm5 : array[0..9] of byte;
  154. _reserved_122_127 : array[0..5] of byte;
  155. mm6 : array[0..9] of byte;
  156. _reserved_138_143 : array[0..5] of byte;
  157. mm7 : array[0..9] of byte;
  158. _reserved_154_159 : array[0..5] of byte;
  159. end;
  160. xmmx_regs = record
  161. xmm0 : array [0..15] of byte;
  162. xmm1 : array [0..15] of byte;
  163. xmm2 : array [0..15] of byte;
  164. xmm3 : array [0..15] of byte;
  165. xmm4 : array [0..15] of byte;
  166. xmm5 : array [0..15] of byte;
  167. xmm6 : array [0..15] of byte;
  168. xmm7 : array [0..15] of byte;
  169. end;
  170. new_extended_regs = record
  171. fp_control : word;
  172. fp_status : word;
  173. fp_tag : word;
  174. fp_opcode : word;
  175. fp_eip : Cardinal;
  176. fp_cs : word;
  177. res_14_15 : word;
  178. fp_datap : Cardinal;
  179. fp_ds : word;
  180. _reserved_22_23 : word;
  181. mxcsr : Cardinal;
  182. _reserved_28_31 : Cardinal;
  183. fp_mmx : record
  184. case byte of
  185. 0 : (fp : fp_stack);
  186. 1 : (mmx : mmx_regs);
  187. end;
  188. xmmx : xmmx_regs;
  189. _reserved_288_511 : array[0..223] of byte;
  190. end;
  191. extended_regs = record
  192. state : record
  193. case byte of
  194. 0 : (old_format : old_extended_regs);
  195. 1 : (new_format : new_extended_regs);
  196. end;
  197. format : Cardinal;
  198. end;
  199. vregs = record
  200. eip : Cardinal;
  201. eflags : cardinal;
  202. eax : Cardinal;
  203. ecx : Cardinal;
  204. edx : Cardinal;
  205. esp : Cardinal;
  206. ebp : Cardinal;
  207. _reserved_1 : Cardinal;
  208. xregs : extended_regs;
  209. _reserved_2 : array[0..2] of Cardinal;
  210. end;
  211. Pvregs = ^vregs;
  212. sigset_t = array[0..1] of Cardinal;
  213. PSigContext = ^vregs;
  214. PSigContextRec = ^SigContextRec;
  215. SigContextRec = record
  216. sc_mask : sigset_t; { signal mask to restore }
  217. sc_onstack : longint; { sigstack state to restore }
  218. sc_gs : longint; { machine state (struct trapframe): }
  219. sc_fs : longint;
  220. sc_es : longint;
  221. sc_ds : longint;
  222. sc_edi : longint;
  223. sc_esi : longint;
  224. sc_ebp : longint;
  225. sc_isp : longint;
  226. sc_ebx : longint;
  227. sc_edx : longint;
  228. sc_ecx : longint;
  229. sc_eax : longint;
  230. sc_trapno : longint;
  231. sc_err : longint;
  232. sc_eip : longint;
  233. sc_cs : longint;
  234. sc_efl : longint;
  235. sc_esp : longint;
  236. sc_ss : longint;
  237. {
  238. * XXX FPU state is 27 * 4 bytes h/w, 1 * 4 bytes s/w (probably not
  239. * needed here), or that + 16 * 4 bytes for emulators (probably all
  240. * needed here). The "spare" bytes are mostly not spare.
  241. }
  242. en_cw : cardinal; { control word (16bits used) }
  243. en_sw : cardinal; { status word (16bits) }
  244. en_tw : cardinal; { tag word (16bits) }
  245. en_fip : cardinal; { floating point instruction pointer }
  246. en_fcs : word; { floating code segment selector }
  247. en_opcode : word; { opcode last executed (11 bits ) }
  248. en_foo : cardinal; { floating operand offset }
  249. en_fos : cardinal; { floating operand segment selector }
  250. fpr_acc : array[0..79] of char;
  251. fpr_ex_sw : cardinal;
  252. fpr_pad : array[0..63] of char;
  253. end;
  254. Sigval = Record
  255. Case Boolean OF
  256. { Members as suggested by Annex C of POSIX 1003.1b. }
  257. false : (sigval_int : Longint);
  258. True : (sigval_ptr : Pointer);
  259. End;
  260. PSigInfo = ^SigInfo_t;
  261. PSigInfo_t = ^SigInfo_t;
  262. SigInfo_t = packed record
  263. si_signo, { signal number }
  264. si_code, { signal code }
  265. si_errno, { errno association }
  266. si_pid : pid_t; { sending process }
  267. si_uid : uid_t; { sender's ruid }
  268. si_addr : Pointer; { faulting instruction }
  269. si_status : Longint; { exit value }
  270. si_band : Cardinal; { band event for SIGPOLL }
  271. si_value : SigVal; { signal value }
  272. end;
  273. TSigInfo = SigInfo_t;
  274. TSigInfo_t = TSigInfo;
  275. SignalHandler = Procedure(Sig : Longint);cdecl;
  276. PSignalHandler = ^SignalHandler;
  277. SignalRestorer = Procedure;cdecl;
  278. PSignalRestorer = ^SignalRestorer;
  279. sigActionHandler = procedure(Sig: Longint; SigInfo: PSigInfo; uContext : PSigContext);cdecl;
  280. Sigset=sigset_t;
  281. TSigset=sigset_t;
  282. PSigSet = ^SigSet;
  283. psigset_t=psigset;
  284. SigActionRec = packed record
  285. // Handler : record
  286. sa_handler : sigActionHandler;
  287. // case byte of
  288. // 0: (Sh: SignalHandler);
  289. // 1: (Sa: TSigAction);
  290. // end;
  291. sa_Mask : SigSet;
  292. sa_Flags : Longint;
  293. sa_userdata : pointer
  294. end;
  295. PSigActionRec = ^SigActionRec;
  296. {$PACKRECORDS C}
  297. pstack_t = ^stack_t;
  298. stack_t = packed record
  299. ss_sp: pChar; {* signal stack base *}
  300. ss_size: size_t; {* signal stack length *}
  301. ss_flags: cInt; {* SS_DISABLE and/or SS_ONSTACK *}
  302. end;
  303. TStack = stack_t;
  304. PStack = pstack_t;
  305. {
  306. Change action of process upon receipt of a signal.
  307. Signum specifies the signal (all except SigKill and SigStop).
  308. If Act is non-nil, it is used to specify the new action.
  309. If OldAct is non-nil the previous action is saved there.
  310. }