sighnd.inc 3.0 KB

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