sighnd.inc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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) : word;
  16. begin
  17. if assigned(SigContext.fpstate) then
  18. GetfpuState:=SigContext.fpstate^.swd
  19. else
  20. GetFPUState:=0;
  21. {$ifdef SYSTEM_DEBUG}
  22. writeln('xx:',sigcontext.twd,' ',sigcontext.cwd);
  23. {$endif SYSTEM_DEBUG}
  24. {$ifdef SYSTEM_DEBUG}
  25. Writeln(stderr,'FpuState = ',result);
  26. {$endif SYSTEM_DEBUG}
  27. end;
  28. procedure SignalToRunerror(sig : longint; SigInfo: PSigInfo; SigContext: PSigContext); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
  29. var
  30. res,fpustate : word;
  31. begin
  32. res:=0;
  33. case sig of
  34. SIGFPE :
  35. begin
  36. { this is not allways necessary but I don't know yet
  37. how to tell if it is or not PM }
  38. res:=200;
  39. fpustate:=GetFPUState(SigContext^);
  40. if (FpuState and FPU_All) <> 0 then
  41. begin
  42. { first check the more precise options }
  43. if (FpuState and FPU_DivisionByZero)<>0 then
  44. res:=200
  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 if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow or FPU_Invalid))<>0 Then
  52. res:=207
  53. else
  54. res:=207; {'Coprocessor Error'}
  55. end;
  56. SysResetFPU;
  57. end;
  58. SIGILL,
  59. SIGBUS,
  60. SIGSEGV:
  61. res:=216;
  62. SIGINT:
  63. res:=217;
  64. SIGQUIT:
  65. res:=233;
  66. end;
  67. reenable_signal(sig);
  68. if res<>0 then
  69. HandleErrorAddrFrame(res,pointer(SigContext^.rip),pointer(SigContext^.rbp));
  70. end;