sighnd.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Michael Van Canneyt,
  4. member of the Free Pascal development team.
  5. Signal handler is arch dependant due to processor to language
  6. exception conversion.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. procedure SignalToRunerror(sig : longint; SigContext: PSigContextRec; uContext: Pvregs);public name '_FPC_DEFAULTSIGHANDLER';cdecl;
  14. var
  15. res,fpustate : word;
  16. begin
  17. res:=0;
  18. case sig of
  19. SIGFPE :
  20. begin
  21. { this is not allways necessary but I don't know yet
  22. how to tell if it is or not PM }
  23. res:=200;
  24. // fp_status always here under BeOS and x86 CPU
  25. // (fp_status is not behind a pointer in the BeOS context record)
  26. FpuState:=ucontext^.xregs.state.old_format.fp_status;
  27. if (FpuState and FPU_ExceptionMask) <> 0 then
  28. begin
  29. { first check the more precise options }
  30. if (FpuState and FPU_DivisionByZero)<>0 then
  31. res:=200
  32. else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow or FPU_Invalid))<>0 Then
  33. res:=207
  34. else if (FpuState and FPU_Overflow)<>0 then
  35. res:=205
  36. else if (FpuState and FPU_Underflow)<>0 then
  37. res:=206
  38. else if (FpuState and FPU_Denormal)<>0 then
  39. res:=216
  40. else
  41. res:=207; {'Coprocessor Error'}
  42. end;
  43. with ucontext^.xregs.state.old_format do
  44. begin
  45. fp_status := fp_status and not FPU_ExceptionMask;
  46. end;
  47. SysResetFPU;
  48. end;
  49. (* SIGBUS: {Same as SIGSEGV under BeOS}
  50. begin
  51. res:=214;
  52. end; *)
  53. SIGILL:
  54. begin
  55. if sse_check then
  56. begin
  57. os_supports_sse := false;
  58. res := 0;
  59. inc(ucontext^.eip, 3);
  60. end
  61. else
  62. res:=216;
  63. end;
  64. SIGSEGV :
  65. begin
  66. res:=216;
  67. end;
  68. SIGINT:
  69. begin
  70. res:=217
  71. end;
  72. SIGQUIT :
  73. begin
  74. res:=233;
  75. end;
  76. end;
  77. reenable_signal(sig);
  78. { give runtime error at the position where the signal was raised }
  79. if res<>0 then
  80. begin
  81. HandleErrorAddrFrame(res, pointer(ucontext^.eip),
  82. pointer(ucontext^.ebp));
  83. end;
  84. end;