sighnd.inc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. {
  2. This file is part of the Free Pascal run time library.
  3. (c) 2000-2003 by Marco van de Voort
  4. member of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. Signalhandler for FreeBSD/i386
  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. {
  13. /* SIGFPE */
  14. #define FPE_INTDIV 1 /* Integer divide by zero */
  15. #define FPE_INTOVF 2 /* Integer overflow */
  16. #define FPE_FLTDIV 3 /* Floating point divide by zero */
  17. #define FPE_FLTOVF 4 /* Floating point overflow */
  18. #define FPE_FLTUND 5 /* Floating point underflow */
  19. #define FPE_FLTRES 6 /* Floating point inexact result */
  20. #define FPE_FLTINV 7 /* Invalid Floating point operation */
  21. #define FPE_FLTSUB 8 /* Subscript out of range */
  22. }
  23. const
  24. FPE_IntDiv = 1;
  25. FPE_IntOvf = 2;
  26. FPE_FltDiv = 3;
  27. FPE_FltOvf = 4;
  28. FPE_FltUnd = 5;
  29. FPE_FltRes = 6;
  30. FPE_FltInv = 7;
  31. FPE_FltSub = 8;
  32. procedure SignalToRunerror(Sig: longint;info : PSigInfo;SigContext: PSigContextRec); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
  33. var
  34. res,fpustate : word;
  35. begin
  36. res:=0;
  37. {$ifdef BSD}
  38. {$ifdef cpui386}
  39. fpustate:=0;
  40. asm
  41. fnstsw fpustate
  42. end;
  43. {$endif cpui386}
  44. {$endif BSD}
  45. case sig of
  46. SIGFPE :
  47. begin
  48. { this is not allways necessary but I don't know yet
  49. how to tell if it is or not PM }
  50. res:=200;
  51. if assigned(info) then
  52. fpustate:=info^._info.si_code
  53. else
  54. fpustate:=FPE_IntDiv;
  55. { if (FpuState and FPU_All) <> 0 then }
  56. begin
  57. { first check the more precise options }
  58. if FpuState = FPE_IntDiv then
  59. res:=200
  60. else if (FpuState = FPE_IntOvf) or (FpuState = FPE_FltOvf) then
  61. res:=205
  62. else if FpuState = FPE_FltUnd then
  63. res:=206
  64. { else if FpuState and FPU_Denormal)<>0 then
  65. res:=216 }
  66. else if FpuState = FPE_FltSub then
  67. res:=207
  68. else if FpuState = FPE_FltInv then
  69. res:=216
  70. else
  71. res:=207; {'Coprocessor Error'}
  72. end;
  73. SysResetFPU;
  74. end;
  75. SIGILL,
  76. SIGBUS,
  77. SIGSEGV :
  78. res:=216;
  79. SIGINT:
  80. res:=217;
  81. SIGQUIT:
  82. res:=233;
  83. end;
  84. reenable_signal(sig);
  85. { give runtime error at the position where the signal was raised }
  86. if res<>0 then
  87. begin
  88. {$ifdef cpui386}
  89. if assigned(SigContext) then
  90. HandleErrorAddrFrame(res,pointer(SigContext^.sc_eip),pointer(SigContext^.sc_ebp))
  91. else
  92. HandleErrorAddrFrame(res,nil,nil);
  93. {$endif}
  94. end;
  95. end;