sighnd.inc 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. {$ifdef SYSTEM_DEBUG}
  20. writeln('xx:',sigcontext.en_tw,' ',sigcontext.en_cw);
  21. {$endif SYSTEM_DEBUG}
  22. {$ifdef SYSTEM_DEBUG}
  23. Writeln(stderr,'FpuState = ',result);
  24. {$endif SYSTEM_DEBUG}
  25. end;
  26. procedure SignalToRunerror(sig : longint; SigInfo: PSigInfo; SigContext: PSigContext); 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(SigContext^);
  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_Overflow)<>0 then
  44. res:=205
  45. else if (FpuState and FPU_Underflow)<>0 then
  46. res:=206
  47. else if (FpuState and FPU_Denormal)<>0 then
  48. res:=216
  49. else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow))<>0 Then
  50. res:=207
  51. else if (FpuState and FPU_Invalid)<>0 then
  52. res:=216
  53. else
  54. res:=207; {'Coprocessor Error'}
  55. end;
  56. SysResetFPU;
  57. end;
  58. SIGILL,
  59. SIGBUS,
  60. SIGSEGV:
  61. res:=216;
  62. end;
  63. reenable_signal(sig);
  64. if res<>0 then
  65. HandleErrorAddrFrame(res,pointer(SigContext^.rip),pointer(SigContext^.rbp));
  66. end;