signal.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Jonas Maebe,
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$packrecords C}
  13. {********************
  14. Signal
  15. ********************}
  16. Const
  17. { For sending a signal }
  18. SA_NOCLDSTOP = 1;
  19. SA_SHIRQ = $04000000;
  20. SA_STACK = $08000000;
  21. SA_RESTART = $10000000;
  22. SA_INTERRUPT = $20000000;
  23. SA_NOMASK = $40000000;
  24. SA_ONESHOT = $80000000;
  25. SIG_BLOCK = 0;
  26. SIG_UNBLOCK = 1;
  27. SIG_SETMASK = 2;
  28. SIG_DFL = 0 ;
  29. SIG_IGN = 1 ;
  30. SIG_ERR = -1 ;
  31. SIGHUP = 1;
  32. SIGINT = 2;
  33. SIGQUIT = 3;
  34. SIGILL = 4;
  35. SIGTRAP = 5;
  36. SIGABRT = 6;
  37. SIGIOT = 6;
  38. SIGBUS = 7;
  39. SIGFPE = 8;
  40. SIGKILL = 9;
  41. SIGUSR1 = 10;
  42. SIGSEGV = 11;
  43. SIGUSR2 = 12;
  44. SIGPIPE = 13;
  45. SIGALRM = 14;
  46. SIGTerm = 15;
  47. SIGSTKFLT = 16;
  48. SIGCHLD = 17;
  49. SIGCONT = 18;
  50. SIGSTOP = 19;
  51. SIGTSTP = 20;
  52. SIGTTIN = 21;
  53. SIGTTOU = 22;
  54. SIGURG = 23;
  55. SIGXCPU = 24;
  56. SIGXFSZ = 25;
  57. SIGVTALRM = 26;
  58. SIGPROF = 27;
  59. SIGWINCH = 28;
  60. SIGIO = 29;
  61. SIGPOLL = SIGIO;
  62. SIGPWR = 30;
  63. SIGUNUSED = 31;
  64. const
  65. SI_PAD_SIZE = ((128 div sizeof(longint)) - 3);
  66. type
  67. tfpreg = record
  68. significand: array[0..3] of word;
  69. exponent: word;
  70. end;
  71. pfpstate = ^tfpstate;
  72. tfpstate = record
  73. cw, sw, tag, ipoff, cssel, dataoff, datasel: cardinal;
  74. st: array[0..7] of tfpreg;
  75. status: cardinal;
  76. end;
  77. SigSet = array[0..wordsinsigset-1] of cint;
  78. sigset_t= SigSet;
  79. PSigSet = ^SigSet;
  80. psigset_t=psigset;
  81. TSigSet = SigSet;
  82. {$ifdef cpui386}
  83. PSigContextRec = ^SigContextRec;
  84. SigContextRec = record
  85. gs, __gsh: word;
  86. fs, __fsh: word;
  87. es, __esh: word;
  88. ds, __dsh: word;
  89. edi: cardinal;
  90. esi: cardinal;
  91. ebp: cardinal;
  92. esp: cardinal;
  93. ebx: cardinal;
  94. edx: cardinal;
  95. ecx: cardinal;
  96. eax: cardinal;
  97. trapno: cardinal;
  98. err: cardinal;
  99. eip: cardinal;
  100. cs, __csh: word;
  101. eflags: cardinal;
  102. esp_at_signal: cardinal;
  103. ss, __ssh: word;
  104. fpstate: pfpstate;
  105. oldmask: cardinal;
  106. cr2: cardinal;
  107. end;
  108. {$endif cpui386}
  109. {$Ifdef cpum68k}
  110. PSigContextRec = ^SigContextRec;
  111. SigContextRec = record
  112. { dummy for now PM }
  113. end;
  114. {$endif cpum68k}
  115. {$ifdef cpupowerpc}
  116. { from include/ppc/ptrace.h }
  117. pptregs = ^tptregs;
  118. tptregs = record
  119. gpr: array[0..31] of cardinal;
  120. nip: cardinal;
  121. msr: cardinal;
  122. orig_gpr3: cardinal; { Used for restarting system calls }
  123. ctr: cardinal;
  124. link: cardinal;
  125. xer: cardinal;
  126. ccr: cardinal;
  127. mq: cardinal; { 601 only (not used at present) }
  128. { Used on APUS to hold IPL value. }
  129. trap: cardinal; { Reason for being here }
  130. dar: cardinal; { Fault registers }
  131. dsisr: cardinal;
  132. result: cardinal; { Result of a system call }
  133. end;
  134. { from include/asm/ppc/siginfo.h }
  135. psiginfo = ^tsiginfo;
  136. tsiginfo = record
  137. si_signo : longint;
  138. si_errno : longint;
  139. si_code : longint;
  140. _sifields : record
  141. case longint of
  142. 0 : ( _pad : array[0..(SI_PAD_SIZE)-1] of longint );
  143. 1 : ( _kill : record
  144. _pid : pid_t;
  145. _uid : uid_t;
  146. end );
  147. 2 : ( _timer : record
  148. _timer1 : dword;
  149. _timer2 : dword;
  150. end );
  151. 3 : ( _rt : record
  152. _pid : pid_t;
  153. _uid : uid_t;
  154. _sigval : pointer;
  155. end );
  156. 4 : ( _sigchld : record
  157. _pid : pid_t;
  158. _uid : uid_t;
  159. _status : longint;
  160. _utime : clock_t;
  161. _stime : clock_t;
  162. end );
  163. 5 : ( _sigfault : record
  164. _addr : pointer;
  165. end );
  166. 6 : ( _sigpoll : record
  167. _band : longint;
  168. _fd : longint;
  169. end );
  170. end;
  171. end;
  172. { from include/asm-ppc/signal.h }
  173. stack_t = record
  174. ss_sp: pointer;
  175. ss_flags: longint;
  176. ss_size: size_t;
  177. end;
  178. { from include/asm-ppc/sigcontext.h }
  179. tsigcontext_struct = record
  180. _unused: array[0..3] of dword;
  181. signal: longint;
  182. handler: dword;
  183. oldmask: dword;
  184. pt_regs: pptregs;
  185. end;
  186. { from include/asm-ppc/ucontext.h }
  187. pucontext = ^tucontext;
  188. tucontext = record
  189. uc_flags : dword;
  190. uc_link : pucontext;
  191. uc_stack : stack_t;
  192. uc_mcontext : tsigcontext_struct;
  193. uc_sigmask : sigset_t;
  194. end;
  195. { from arch/ppc/kernel/signal.c, the type of the actual parameter passed }
  196. { to the sigaction handler }
  197. t_rt_sigframe = record
  198. _unused: array[0..1] of cardinal;
  199. pinfo: psiginfo;
  200. puc: pointer;
  201. siginfo: tsiginfo;
  202. uc: tucontext;
  203. end;
  204. PSigContextRec = ^SigContextRec;
  205. SigContextRec = tsigcontext_struct;
  206. {$endif cpupowerpc}
  207. {$ifdef cpusparc}
  208. PSigContextRec = ^SigContextRec;
  209. SigContextRec = record
  210. { dummy for now PM }
  211. end;
  212. {$endif cpusparc}
  213. {$ifdef cpux86_64}
  214. p_fpstate = ^_fpstate;
  215. _fpstate = packed record
  216. cwd,
  217. swd,
  218. twd, // Note this is not the same as the 32bit/x87/FSAVE twd
  219. fop : word;
  220. rip,
  221. rdp : qword;
  222. mxcsr,
  223. mxcsr_mask : dword;
  224. st_space : array[0..31] of dword; // 8*16 bytes for each FP-reg
  225. xmm_space : array[0..63] of dword; // 16*16 bytes for each XMM-reg
  226. reserved2 : array[0..23] of dword;
  227. end;
  228. PSigContextRec = ^SigContextRec;
  229. SigContextRec = packed record
  230. __pad00 : array[0..4] of qword;
  231. r8,
  232. r9,
  233. r10,
  234. r11,
  235. r12,
  236. r13,
  237. r14,
  238. r15,
  239. rdi,
  240. rsi,
  241. rbp,
  242. rbx,
  243. rdx,
  244. rax,
  245. rcx,
  246. rsp,
  247. rip,
  248. eflags : qword;
  249. cs,
  250. gs,
  251. fs,
  252. __pad0 : word;
  253. err,
  254. trapno,
  255. oldmask,
  256. cr2 : qword;
  257. fpstate : p_fpstate; // zero when no FPU context */
  258. reserved1 : array[0..7] of qword;
  259. end;
  260. {$endif cpux86_64}
  261. {$ifdef cpuarm}
  262. PSigContextRec = ^SigContextRec;
  263. SigContextRec = record
  264. trap_no : dword;
  265. error_code : dword;
  266. oldmask : dword;
  267. arm_r0 : dword;
  268. arm_r1 : dword;
  269. arm_r2 : dword;
  270. arm_r3 : dword;
  271. arm_r4 : dword;
  272. arm_r5 : dword;
  273. arm_r6 : dword;
  274. arm_r7 : dword;
  275. arm_r8 : dword;
  276. arm_r9 : dword;
  277. arm_r10 : dword;
  278. arm_fp : dword;
  279. arm_ip : dword;
  280. arm_sp : dword;
  281. arm_lr : dword;
  282. arm_pc : dword;
  283. arm_cpsr : dword;
  284. fault_address : dword;
  285. end;
  286. { from include/asm-ppc/signal.h }
  287. stack_t = record
  288. ss_sp: pointer;
  289. ss_flags: longint;
  290. ss_size: size_t;
  291. end;
  292. { from include/asm-arm/ucontext.h }
  293. pucontext = ^tucontext;
  294. tucontext = record
  295. uc_flags : dword;
  296. uc_link : pucontext;
  297. uc_stack : stack_t;
  298. uc_mcontext : SigContextRec;
  299. uc_sigmask : sigset_t;
  300. end;
  301. {$endif cpuarm}
  302. PSigInfoRec = ^SigInfoRec;
  303. SigInfoRec = record
  304. si_signo: longint;
  305. si_errno: longint;
  306. si_code: longint;
  307. case longint of
  308. 0:
  309. (pad: array[0..SI_PAD_SIZE-1] of longint);
  310. 1: { kill }
  311. ( kill: record
  312. pid: longint; { sender's pid }
  313. uid : longint; { sender's uid }
  314. end );
  315. 2: { POSIX.1b timers }
  316. ( timer : record
  317. timer1 : cardinal;
  318. timer2 : cardinal;
  319. end );
  320. 3: { POSIX.1b signals }
  321. ( rt : record
  322. pid : longint; { sender's pid }
  323. uid : longint; { sender's uid }
  324. sigval : longint;
  325. end );
  326. 4: { SIGCHLD }
  327. ( sigchld : record
  328. pid : longint; { which child }
  329. uid : longint; { sender's uid }
  330. status : longint; { exit code }
  331. utime : timeval;
  332. stime : timeval;
  333. end );
  334. 5: { SIGILL, SIGFPE, SIGSEGV, SIGBUS }
  335. ( sigfault : record
  336. addr : pointer;{ faulting insn/memory ref. }
  337. end );
  338. 6:
  339. ( sigpoll : record
  340. band : longint; { POLL_IN, POLL_OUT, POLL_MSG }
  341. fd : longint;
  342. end );
  343. end;
  344. SignalHandler = Procedure(Sig : Longint);cdecl;
  345. PSignalHandler = ^SignalHandler;
  346. SignalRestorer = Procedure;cdecl;
  347. PSignalRestorer = ^SignalRestorer;
  348. TSigAction = procedure(Sig: Longint; SigContext: SigContextRec);cdecl;
  349. {$ifdef CPUARM}
  350. {$define NEWSIGNAL}
  351. {$endif CPUARM}
  352. {$ifdef CPUx86_64}
  353. {$define NEWSIGNAL}
  354. {$endif CPUx86_64}
  355. SigActionRec = packed record // this is temporary for the migration
  356. {$ifdef posixworkaround}
  357. sa_handler : signalhandler;
  358. {$else}
  359. Handler : record
  360. case byte of
  361. 0: (Sh: SignalHandler);
  362. 1: (Sa: TSigAction);
  363. end;
  364. {$endif}
  365. {$ifdef NEWSIGNAL}
  366. Sa_Flags : cuint;
  367. Sa_restorer : SignalRestorer; { Obsolete - Don't use }
  368. Sa_Mask : SigSet;
  369. {$else NEWSIGNAL}
  370. Sa_Mask : SigSet;
  371. Sa_Flags : Longint;
  372. Sa_restorer : SignalRestorer; { Obsolete - Don't use }
  373. {$endif NEWSIGNAL}
  374. end;
  375. TSigActionRec = SigActionRec;
  376. PSigActionRec = ^SigActionRec;
  377. {
  378. $Log$
  379. Revision 1.19 2004-05-01 15:59:17 florian
  380. * x86_64 exception handling fixed
  381. Revision 1.18 2004/04/27 20:47:00 florian
  382. * tried to fix x86-64 signal handling
  383. Revision 1.17 2004/03/27 14:35:13 florian
  384. * structs for arm adapted
  385. Revision 1.16 2004/02/05 01:16:12 florian
  386. + completed x86-64/linux system unit
  387. Revision 1.15 2004/01/01 16:28:16 jonas
  388. * fixed signal handling
  389. Revision 1.14 2003/11/21 00:40:06 florian
  390. * some arm issues fixed
  391. Revision 1.13 2003/11/02 14:53:06 jonas
  392. + sighand and associated record definitions for ppc. Untested.
  393. Revision 1.12 2003/09/14 20:15:01 marco
  394. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  395. Revision 1.11 2003/09/03 14:09:37 florian
  396. * arm fixes to the common rtl code
  397. * some generic math code fixed
  398. * ...
  399. Revision 1.10 2003/08/21 22:24:52 olle
  400. - removed parameter from fpc_iocheck
  401. Revision 1.9 2002/12/24 21:30:20 mazen
  402. - some writeln(s) removed in compiler
  403. + many files added to RTL
  404. * some errors fixed in RTL
  405. Revision 1.8 2002/12/18 16:43:26 marco
  406. * new unix rtl, linux part.....
  407. Revision 1.7 2002/11/12 14:51:44 marco
  408. * signal.
  409. Revision 1.6 2002/09/07 16:01:19 peter
  410. * old logs removed and tabs fixed
  411. Revision 1.5 2002/07/28 20:43:48 florian
  412. * several fixes for linux/powerpc
  413. * several fixes to MT
  414. }