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: PSigInfo; uContext: PSigContext);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^.uc_mcontext.fpu.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:=208
  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^.uc_mcontext.fpu do
  44. begin
  45. status := status and not FPU_ExceptionMask;
  46. end;
  47. SysResetFPU;
  48. end;
  49. SIGBUS:
  50. begin
  51. res:=214;
  52. end;
  53. SIGILL:
  54. begin
  55. // FIXME
  56. { if sse_check then
  57. begin
  58. os_supports_sse := false;
  59. res := 0;
  60. inc(ucontext^.eip, 3);
  61. end
  62. else}
  63. res:=216;
  64. end;
  65. SIGSEGV :
  66. begin
  67. res:=216;
  68. end;
  69. SIGINT:
  70. begin
  71. res:=217;
  72. end;
  73. SIGQUIT:
  74. begin
  75. res:=233;
  76. end;
  77. end;
  78. reenable_signal(sig);
  79. { give runtime error at the position where the signal was raised }
  80. if res<>0 then
  81. begin
  82. HandleErrorAddrFrame(res, pointer(ucontext^.uc_mcontext.rip),
  83. pointer(ucontext^.uc_mcontext.rbp));
  84. end;
  85. end;