signal.inc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 = 8;
  13. SA_ONSTACK = $001; { take signal on signal stack }
  14. SA_RESTART = $002; { restart system call on signal return }
  15. SA_RESETHAND = $004; { reset to SIG_DFL when taking signal }
  16. SA_NODEFER = $010; { don't mask the signal we're delivering }
  17. SA_NOCLDWAIT = $020; { don't keep zombies around }
  18. SA_SIGINFO = $040; { signal handler with SA_SIGINFO args }
  19. SA_USERTRAMP = $100; { SUNOS compat: Do not bounce off kernel's sigtramp }
  20. SIG_BLOCK = 1;
  21. SIG_UNBLOCK = 2;
  22. SIG_SETMASK = 3;
  23. {BSD Checked}
  24. SIG_DFL = 0 ;
  25. SIG_IGN = 1 ;
  26. SIG_ERR = -1 ;
  27. SIGHUP = 1;
  28. SIGINT = 2;
  29. SIGQUIT = 3;
  30. SIGILL = 4;
  31. SIGTRAP = 5;
  32. SIGABRT = 6;
  33. SIGIOT = 6;
  34. SIGEMT = 7;
  35. SIGFPE = 8;
  36. SIGKILL = 9;
  37. SIGBUS = 10;
  38. SIGSEGV = 11;
  39. SIGSYS = 12;
  40. SIGPIPE = 13;
  41. SIGALRM = 14;
  42. SIGTERM = 15;
  43. SIGURG = 16;
  44. SIGSTOP = 17;
  45. SIGTSTP = 18;
  46. SIGCONT = 19;
  47. SIGCHLD = 20;
  48. SIGTTIN = 21;
  49. SIGTTOU = 22;
  50. SIGIO = 23;
  51. SIGXCPU = 24;
  52. SIGXFSZ = 25;
  53. SIGVTALRM = 26;
  54. SIGPROF = 27;
  55. SIGWINCH = 28;
  56. SIGINFO = 29;
  57. SIGUSR1 = 30;
  58. SIGUSR2 = 31;
  59. {$packrecords C}
  60. const
  61. SI_PAD_SIZE = ((128/sizeof(longint)) - 3);
  62. {
  63. * The sequence of the fields/registers in struct sigcontext should match
  64. * those in mcontext_t.
  65. }
  66. type sigset_t = array[0..3] of Longint;
  67. psigcontext = ^sigcontextrec;
  68. PSigContextRec = ^SigContextRec;
  69. {$if (defined(CPUi386) or defined(CPUX86_64))}
  70. SigContextRec = record
  71. sc_mask : sigset_t; { signal mask to restore }
  72. sc_onstack : longint; { sigstack state to restore }
  73. sc_gs : longint; { machine state (struct trapframe): }
  74. sc_fs : longint;
  75. sc_es : longint;
  76. sc_ds : longint;
  77. sc_edi : longint;
  78. sc_esi : longint;
  79. sc_ebp : longint;
  80. sc_isp : longint;
  81. sc_ebx : longint;
  82. sc_edx : longint;
  83. sc_ecx : longint;
  84. sc_eax : longint;
  85. sc_trapno : longint;
  86. sc_err : longint;
  87. sc_eip : longint;
  88. sc_cs : longint;
  89. sc_efl : longint;
  90. sc_esp : longint;
  91. sc_ss : longint;
  92. {
  93. * XXX FPU state is 27 * 4 bytes h/w, 1 * 4 bytes s/w (probably not
  94. * needed here), or that + 16 * 4 bytes for emulators (probably all
  95. * needed here). The "spare" bytes are mostly not spare.
  96. }
  97. en_cw : cardinal; { control word (16bits used) }
  98. en_sw : cardinal; { status word (16bits) }
  99. en_tw : cardinal; { tag word (16bits) }
  100. en_fip : cardinal; { floating point instruction pointer }
  101. en_fcs : word; { floating code segment selector }
  102. en_opcode : word; { opcode last executed (11 bits ) }
  103. en_foo : cardinal; { floating operand offset }
  104. en_fos : cardinal; { floating operand segment selector }
  105. fpr_acc : array[0..79] of AnsiChar;
  106. fpr_ex_sw : cardinal;
  107. fpr_pad : array[0..63] of AnsiChar;
  108. end;
  109. {$endif def x86}
  110. {$ifdef CPUAARCH64}
  111. SigContextRec = record
  112. _dummy : cint;
  113. end;
  114. {$endif cpuaarch64}
  115. Sigval = Record
  116. Case Boolean OF
  117. { Members as suggested by Annex C of POSIX 1003.1b. }
  118. false : (sigval_int : Longint);
  119. True : (sigval_ptr : Pointer);
  120. End;
  121. PSigInfo = ^SigInfo_t;
  122. PSigInfo_t = ^SigInfo_t;
  123. SigInfo_t = record
  124. si_signo, { signal number }
  125. si_errno, { errno association }
  126. {
  127. * Cause of signal, one of the SI_ macros or signal-specific
  128. * values, i.e. one of the FPE_... values for SIGFPE. This
  129. * value is equivalent to the second argument to an old-style
  130. * FreeBSD signal handler.
  131. }
  132. si_code, { signal code }
  133. si_pid : Longint; { sending process }
  134. si_uid : Cardinal; { sender's ruid }
  135. si_status : Longint; { exit value }
  136. si_addr : Pointer; { faulting instruction }
  137. si_value : SigVal; { signal value }
  138. si_band : Cardinal; { band event for SIGPOLL }
  139. __spare : array[0..6] of Longint; { gimme some slack }
  140. end;
  141. TSigInfo = SigInfo_t;
  142. TSigInfo_t = TSigInfo;
  143. SignalHandler = Procedure(Sig : Longint);cdecl;
  144. TSignalHandler = Procedure(Sig : Longint);cdecl;
  145. PSignalHandler = ^SignalHandler;
  146. SignalRestorer = Procedure;cdecl;
  147. PSignalRestorer = ^SignalRestorer;
  148. sigActionHandler = procedure(Sig: Longint; sininfo:psiginfo; SigContext: PSigContext);cdecl;
  149. TSigset=sigset_t;
  150. sigset=tsigset;
  151. PSigSet = ^TSigSet;
  152. SigActionRec = packed record
  153. { Handler : record
  154. case byte of
  155. 0: (Sh: SignalHandler);
  156. 1: (Sa: TSigAction);
  157. end;}
  158. sa_handler : sigActionHandler;
  159. Sa_Flags : Longint;
  160. Sa_Mask : TSigSet;
  161. end;
  162. PSigActionRec = ^SigActionRec;
  163. pstack_t = ^stack_t;
  164. stack_t = record
  165. ss_sp: PAnsiChar; {* signal stack base *}
  166. ss_size: size_t; {* signal stack length *}
  167. ss_flags: cInt; {* SS_DISABLE and/or SS_ONSTACK *}
  168. end;
  169. TStack = stack_t;
  170. PStack = pstack_t;
  171. {
  172. Change action of process upon receipt of a signal.
  173. Signum specifies the signal (all except SigKill and SigStop).
  174. If Act is non-nil, it is used to specify the new action.
  175. If OldAct is non-nil the previous action is saved there.
  176. }
  177. const
  178. FPE_INTOVF =1; { integer overflow }
  179. FPE_INTDIV =2; { integer divide by zero }
  180. FPE_FLTDIV =3; { floating point divide by zero }
  181. FPE_FLTOVF =4; { floating point overflow }
  182. FPE_FLTUND =5; { floating point underflow }
  183. FPE_FLTRES =6; { floating point inexact result }
  184. FPE_FLTINV =7; { invalid floating point operation }
  185. FPE_FLTSUB =8; { subscript out of range }