sighnd.inc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. procedure SignalToRunerror(sig : longint; SigInfo: PSigInfo; UContext: Pucontext);public name '_FPC_DEFAULTSIGHANDLER';cdecl;
  14. var
  15. res,fpustate : word;
  16. begin
  17. res:=0;
  18. case sig of
  19. SIGFPE :
  20. begin
  21. { this is not allways necessary but I don't know yet
  22. how to tell if it is or not PM }
  23. res:=200;
  24. if assigned(ucontext^.uc_mcontext.fpstate) then
  25. begin
  26. FpuState:=ucontext^.uc_mcontext.fpstate^.sw;
  27. if (FpuState and FPU_ExceptionMask) <> 0 then
  28. begin
  29. { first check the more precise options }
  30. if (FpuState and FPU_DivisionByZero)<>0 then
  31. res:=200
  32. else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow or FPU_Invalid))<>0 Then
  33. res:=207
  34. else if (FpuState and FPU_Overflow)<>0 then
  35. res:=205
  36. else if (FpuState and FPU_Underflow)<>0 then
  37. res:=206
  38. else if (FpuState and FPU_Denormal)<>0 then
  39. res:=216
  40. else
  41. res:=207; {'Coprocessor Error'}
  42. end;
  43. with ucontext^.uc_mcontext.fpstate^ do
  44. begin
  45. { Reset Status word }
  46. sw:=sw and not FPU_ExceptionMask;
  47. { Restoree default control word }
  48. cw:=Default8087CW;
  49. { Reset Tag word to $ffff for all empty }
  50. tag:=$ffff;
  51. end;
  52. end;
  53. end;
  54. SIGBUS:
  55. res:=214;
  56. SIGILL:
  57. if sse_check then
  58. begin
  59. os_supports_sse:=false;
  60. res:=0;
  61. inc(ucontext^.uc_mcontext.eip,3);
  62. end
  63. else
  64. res:=216;
  65. SIGSEGV :
  66. res:=216;
  67. SIGINT:
  68. res:=217;
  69. SIGQUIT:
  70. res:=233;
  71. end;
  72. reenable_signal(sig);
  73. { give runtime error at the position where the signal was raised }
  74. if res<>0 then
  75. begin
  76. ucontext^.uc_mcontext.eax := res;
  77. ucontext^.uc_mcontext.edx := ucontext^.uc_mcontext.eip;
  78. ucontext^.uc_mcontext.ecx := ucontext^.uc_mcontext.ebp;
  79. ucontext^.uc_mcontext.eip := ptruint(@HandleErrorAddrFrame);
  80. end;
  81. end;