sighnd.inc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. (c) 2000-2003 by Marco van de Voort
  5. member of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. Signalhandler for FreeBSD/i386
  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 FPU_ALL=$7F;
  14. function getfpustate(const Sigcontext:sigcontextRec):longint; {inline;}
  15. begin
  16. getfpustate:=0;
  17. end;
  18. procedure SignalToRunerror(Sig: longint;code:longint; var SigContext: SigContextRec); cdecl;
  19. var
  20. res,fpustate : word;
  21. begin
  22. res:=0;
  23. {$ifdef BSD}
  24. {$ifdef cpui386}
  25. fpustate:=0;
  26. asm
  27. fnstsw fpustate
  28. end;
  29. {$endif cpui386}
  30. {$endif BSD}
  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. { give runtime error at the position where the signal was raised }
  65. if res<>0 then
  66. begin
  67. {$ifdef cpui386}
  68. HandleErrorAddrFrame(res,pointer(SigContext.sc_eip),pointer(SigContext.sc_ebp));
  69. {$endif}
  70. end;
  71. end;
  72. {
  73. $Log$
  74. Revision 1.2 2004-03-04 13:10:32 olle
  75. + added comment to ETXTBSY
  76. * changed i386 -> cpui386, m68k -> cpum68k
  77. Revision 1.1 2004/01/04 15:30:19 marco
  78. * working version
  79. Revision 1.1 2004/01/03 12:29:36 marco
  80. * now separately.
  81. }