sighnd.inc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt,
  5. member of the Free Pascal development team.
  6. Signal handler is arch dependant due to processor to language
  7. exception conversion.
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. const
  15. FPU_All = $7f;
  16. function GetFPUState(const SigContext : SigContextRec) : longint;
  17. begin
  18. if assigned(SigContext.fpstate) then
  19. GetfpuState:=SigContext.fpstate^.sw;
  20. {$ifdef SYSTEM_DEBUG}
  21. writeln('xx:',sigcontext.en_tw,' ',sigcontext.en_cw);
  22. {$endif SYSTEM_DEBUG}
  23. {$ifdef SYSTEM_DEBUG}
  24. Writeln(stderr,'FpuState = ',GetFpuState);
  25. {$endif SYSTEM_DEBUG}
  26. end;
  27. procedure SignalToRunerror(Sig: longint; SigContext: SigContextRec); cdecl;
  28. var
  29. res,fpustate : word;
  30. begin
  31. res:=0;
  32. case sig of
  33. SIGFPE :
  34. begin
  35. { this is not allways necessary but I don't know yet
  36. how to tell if it is or not PM }
  37. res:=200;
  38. fpustate:=GetFPUState(SigContext);
  39. if (FpuState and FPU_All) <> 0 then
  40. begin
  41. { first check the more precise options }
  42. if (FpuState and FPU_DivisionByZero)<>0 then
  43. res:=200
  44. else if (FpuState and FPU_Overflow)<>0 then
  45. res:=205
  46. else if (FpuState and FPU_Underflow)<>0 then
  47. res:=206
  48. else if (FpuState and FPU_Denormal)<>0 then
  49. res:=216
  50. else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow))<>0 Then
  51. res:=207
  52. else if (FpuState and FPU_Invalid)<>0 then
  53. res:=216
  54. else
  55. res:=207; {'Coprocessor Error'}
  56. end;
  57. sysResetFPU;
  58. end;
  59. SIGILL,
  60. SIGBUS,
  61. SIGSEGV :
  62. res:=216;
  63. end;
  64. { give runtime error at the position where the signal was raised }
  65. if res<>0 then
  66. HandleErrorAddrFrame(res,pointer(SigContext.eip),pointer(SigContext.ebp));
  67. end;
  68. {
  69. $Log$
  70. Revision 1.2 2003-11-01 01:58:11 marco
  71. * more small fixes.
  72. Revision 1.1 2003/11/01 01:27:20 marco
  73. * initial version from 1.0.x branch
  74. }