signal.inc 12 KB

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