sighnd.inc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. const
  14. FPU_All = $7f;
  15. function GetFPUState(const SigContext : TSigContext) : longint;
  16. begin
  17. if assigned(SigContext.fpstate) then
  18. GetfpuState:=SigContext.fpstate^.sw;
  19. {$ifdef SYSTEM_DEBUG}
  20. writeln('xx:',sigcontext.en_tw,' ',sigcontext.en_cw);
  21. {$endif SYSTEM_DEBUG}
  22. {$ifdef SYSTEM_DEBUG}
  23. Writeln(stderr,'FpuState = ',GetFpuState);
  24. {$endif SYSTEM_DEBUG}
  25. end;
  26. procedure SignalToRunerror(sig : longint; SigInfo: PSigInfo; UContext: Pucontext);cdecl;
  27. var
  28. res,fpustate : word;
  29. begin
  30. res:=0;
  31. case sig of
  32. SIGFPE :
  33. begin
  34. { this is not allways necessary but I don't know yet
  35. how to tell if it is or not PM }
  36. res:=200;
  37. fpustate:=GetFPUState(UContext^.uc_mcontext);
  38. if (FpuState and FPU_All) <> 0 then
  39. begin
  40. { first check the more precise options }
  41. if (FpuState and FPU_DivisionByZero)<>0 then
  42. res:=200
  43. else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow or FPU_Invalid))<>0 Then
  44. res:=207
  45. else if (FpuState and FPU_Overflow)<>0 then
  46. res:=205
  47. else if (FpuState and FPU_Underflow)<>0 then
  48. res:=206
  49. else if (FpuState and FPU_Denormal)<>0 then
  50. res:=216
  51. else
  52. res:=207; {'Coprocessor Error'}
  53. end;
  54. sysResetFPU;
  55. end;
  56. SIGBUS:
  57. res:=214;
  58. SIGILL,
  59. SIGSEGV :
  60. res:=216;
  61. end;
  62. reenable_signal(sig);
  63. { give runtime error at the position where the signal was raised }
  64. if res<>0 then
  65. HandleErrorAddrFrame(res,pointer(UContext^.uc_mcontext.eip),pointer(UContext^.uc_mcontext.ebp));
  66. end;