sighnd.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. FPE_INTDIV = 1;
  15. FPE_INTOVF = 2;
  16. FPE_FLTDIV = 3;
  17. FPE_FLTOVF = 4;
  18. FPE_FLTUND = 5;
  19. FPE_FLTRES = 6;
  20. FPE_FLTINV = 7;
  21. FPE_FLTSUB = 8;
  22. procedure SignalToRunerror(sig : longint; SigInfo: PSigInfo; SigContext: PSigContext);public name '_FPC_DEFAULTSIGHANDLER';cdecl;
  23. var
  24. res : word;
  25. addr : pointer;
  26. frame : pointer;
  27. begin
  28. res:=0;
  29. if assigned(sigcontext) then
  30. begin
  31. addr := pointer(sigcontext^.uc_mcontext.gregs[REG_PC]);
  32. frame := pointer(sigcontext^.uc_mcontext.gregs[REG_FP])
  33. end
  34. else
  35. begin
  36. addr := nil;
  37. frame := nil;
  38. end;
  39. case sig of
  40. SIGFPE :
  41. begin
  42. case siginfo^.si_code of
  43. FPE_INTDIV:
  44. res:=200;
  45. FPE_INTOVF:
  46. res:=205;
  47. FPE_FLTDIV:
  48. res:=200;
  49. FPE_FLTOVF:
  50. res:=205;
  51. FPE_FLTUND:
  52. res:=206;
  53. else
  54. res:=207;
  55. end;
  56. with sigcontext^.uc_mcontext.fpregs.fpchip_state do
  57. begin
  58. status:=status and not FPU_ExceptionMask;
  59. { Control word is index 0 }
  60. state[0]:=Default8087CW;
  61. { Status word is also index 1 }
  62. state[1]:=status;
  63. { Tag word is index 2 }
  64. state[2]:=$ffff;
  65. end;
  66. end;
  67. SIGILL:
  68. if sse_check then
  69. begin
  70. os_supports_sse:=false;
  71. res:=0;
  72. inc(sigcontext^.uc_mcontext.gregs[REG_EIP],3);
  73. end
  74. else
  75. res:=216;
  76. SIGSEGV :
  77. begin
  78. res:=216;
  79. end;
  80. SIGBUS :
  81. begin
  82. res:=214;
  83. end;
  84. SIGINT:
  85. res:=217;
  86. SIGQUIT:
  87. res:=233;
  88. end;
  89. reenable_signal(sig);
  90. { give runtime error at the position where the signal was raised }
  91. {if res<>0 then
  92. HandleErrorAddrFrame(res,addr,frame);}
  93. { give runtime error at the position where the signal was raised }
  94. if res<>0 then
  95. begin
  96. sigcontext^.uc_mcontext.gregs[REG_EAX] := res;
  97. sigcontext^.uc_mcontext.gregs[REG_EDX] := sigcontext^.uc_mcontext.gregs[REG_EIP];
  98. sigcontext^.uc_mcontext.gregs[REG_ECX] := sigcontext^.uc_mcontext.gregs[REG_EBP];
  99. sigcontext^.uc_mcontext.gregs[REG_EIP] := ptruint(@HandleErrorAddrFrame);
  100. end;
  101. end;