signal.inc 13 KB

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