sighnd.inc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. CONST FPU_ALL=$7F;
  13. {$ifdef cpui386}
  14. function getfpustate(sininfo:psiginfo):longint; {inline;}
  15. begin
  16. if ptruint(sininfo)> high(word) then
  17. getfpustate:=sininfo^.si_code
  18. else
  19. getfpustate:=word(ptruint(sininfo));
  20. end;
  21. function getaltfpustate(sigcontext:psigcontextrec):longint; {inline;}
  22. begin
  23. if assigned(sigcontext) then
  24. getaltfpustate:=sigcontext^.sc_fpustate^.en_sw
  25. else
  26. getaltfpustate:=0;
  27. end;
  28. {$endif}
  29. procedure SignalToRunerror(Sig: longint;sininfo:psiginfo; SigContext: PSigContextRec); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
  30. var
  31. res,fpustate : word;
  32. begin
  33. res:=0;
  34. {$ifdef BSD}
  35. {$ifdef cpui386}
  36. fpustate:=0;
  37. asm
  38. fnstsw fpustate
  39. end;
  40. {$endif cpui386}
  41. {$endif BSD}
  42. case sig of
  43. SIGFPE :
  44. begin
  45. { this is not allways necessary but I don't know yet
  46. how to tell if it is or not PM }
  47. res:=200;
  48. {$ifdef cpui386}
  49. fpustate:=GetaltFPUState(sigcontext);
  50. {$else}
  51. fpustate:=0;
  52. {$endif}
  53. if (FpuState and FPU_All) <> 0 then
  54. begin
  55. { first check the more precise options }
  56. if (FpuState and FPU_DivisionByZero)<>0 then
  57. res:=208
  58. else if (FpuState and FPU_Overflow)<>0 then
  59. res:=205
  60. else if (FpuState and FPU_Underflow)<>0 then
  61. res:=206
  62. else if (FpuState and FPU_Denormal)<>0 then
  63. res:=216
  64. else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow))<>0 then
  65. res:=207
  66. else if (FpuState and FPU_Invalid)<>0 then
  67. res:=216
  68. else
  69. res:=207; {'Coprocessor Error'}
  70. end;
  71. SysResetFPU;
  72. end;
  73. SIGILL,
  74. SIGBUS,
  75. SIGSEGV :
  76. res:=216;
  77. SIGINT:
  78. res:=217;
  79. SIGQUIT:
  80. res:=233;
  81. end;
  82. reenable_signal(sig);
  83. { give runtime error at the position where the signal was raised }
  84. if res<>0 then
  85. begin
  86. {$ifdef cpux86_64}
  87. HandleErrorAddrFrame(res,pointer(SigContext^.sc_rip),pointer(SigContext^.sc_rbp));
  88. {$endif}
  89. end;
  90. end;