sighnd.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. code : ptruint;
  35. res,fpustate : word;
  36. begin
  37. res:=0;
  38. {$ifdef BSD}
  39. {$ifdef cpui386}
  40. fpustate:=0;
  41. asm
  42. fnstsw fpustate
  43. end;
  44. {$endif cpui386}
  45. {$endif BSD}
  46. {$ifdef DEBUG}
  47. Writeln(stderr,'Info is 0x',hexstr(ptruint(info),8));
  48. {$endif}
  49. case sig of
  50. SIGFPE :
  51. begin
  52. { this is not allways necessary but I don't know yet
  53. how to tell if it is or not PM }
  54. res:=200;
  55. { In netbsd, the second parameter is a code, not a pointer to a siginfo structure
  56. at least as long as we use sigaction14 }
  57. code:=ptruint(info);
  58. if code < high(fpustate) then
  59. fpustate:=code
  60. else
  61. fpustate:=FPE_IntDiv;
  62. { if (FpuState and FPU_All) <> 0 then }
  63. begin
  64. { first check the more precise options }
  65. if FpuState = FPE_IntDiv then
  66. res:=200
  67. else if (FpuState = FPE_IntOvf) or (FpuState = FPE_FltOvf) then
  68. res:=205
  69. else if FpuState = FPE_FltUnd then
  70. res:=206
  71. { else if FpuState and FPU_Denormal)<>0 then
  72. res:=216 }
  73. else if FpuState = FPE_FltSub then
  74. res:=207
  75. else if FpuState = FPE_FltInv then
  76. res:=216
  77. else
  78. res:=207; {'Coprocessor Error'}
  79. end;
  80. SysResetFPU;
  81. end;
  82. SIGILL,
  83. SIGBUS,
  84. SIGSEGV :
  85. res:=216;
  86. SIGINT:
  87. res:=217;
  88. SIGQUIT:
  89. res:=233;
  90. end;
  91. reenable_signal(sig);
  92. { give runtime error at the position where the signal was raised }
  93. if res<>0 then
  94. begin
  95. {$ifdef cpui386}
  96. if assigned(SigContext) then
  97. HandleErrorAddrFrame(res,pointer(SigContext^.sc_eip),pointer(SigContext^.sc_ebp))
  98. else
  99. HandleErrorAddrFrame(res,nil,nil);
  100. {$endif}
  101. end;
  102. end;