sighnd.inc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. function getfpustate(const Sigcontext:sigcontextRec):longint; {inline;}
  14. begin
  15. getfpustate:=0;
  16. end;
  17. procedure SignalToRunerror(Sig: longint;code:longint; var SigContext: SigContextRec); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
  18. var
  19. res,fpustate : word;
  20. begin
  21. res:=0;
  22. {$ifdef BSD}
  23. {$ifdef cpui386}
  24. fpustate:=0;
  25. asm
  26. fnstsw fpustate
  27. end;
  28. {$endif cpui386}
  29. {$endif BSD}
  30. case sig of
  31. SIGFPE :
  32. begin
  33. { this is not allways necessary but I don't know yet
  34. how to tell if it is or not PM }
  35. res:=200;
  36. fpustate:=GetFPUState(SigContext);
  37. if (FpuState and FPU_All) <> 0 then
  38. begin
  39. { first check the more precise options }
  40. if (FpuState and FPU_DivisionByZero)<>0 then
  41. res:=200
  42. else if (FpuState and FPU_Overflow)<>0 then
  43. res:=205
  44. else if (FpuState and FPU_Underflow)<>0 then
  45. res:=206
  46. else if (FpuState and FPU_Denormal)<>0 then
  47. res:=216
  48. else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow))<>0 then
  49. res:=207
  50. else if (FpuState and FPU_Invalid)<>0 then
  51. res:=216
  52. else
  53. res:=207; {'Coprocessor Error'}
  54. end;
  55. SysResetFPU;
  56. end;
  57. SIGILL,
  58. SIGBUS,
  59. SIGSEGV :
  60. res:=216;
  61. SIGINT:
  62. res:=217;
  63. SIGQUIT:
  64. res:=233;
  65. end;
  66. reenable_signal(sig);
  67. { give runtime error at the position where the signal was raised }
  68. if res<>0 then
  69. begin
  70. {$ifdef cpui386}
  71. HandleErrorAddrFrame(res,pointer(SigContext.sc_eip),pointer(SigContext.sc_ebp));
  72. {$endif}
  73. end;
  74. end;