sighnd.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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);cdecl;public name '_FPC_DEFAULTSIGHANDLER';
  14. var
  15. res : word;
  16. addr : pointer;
  17. frame : pointer;
  18. begin
  19. res:=0;
  20. addr:=nil;
  21. case sig of
  22. SIGFPE :
  23. begin
  24. addr := siginfo^._sifields._sigfault._addr;
  25. res := 207;
  26. case siginfo^.si_code of
  27. FPE_INTDIV:
  28. res:=200; // maps to EDivByZero
  29. FPE_INTOVF:
  30. res:=215;
  31. FPE_FLTDIV:
  32. res:=208; // maps to EZeroDivide
  33. FPE_FLTOVF:
  34. res:=205;
  35. FPE_FLTUND:
  36. res:=206;
  37. else
  38. res:=207;
  39. end;
  40. end;
  41. SIGILL,
  42. SIGBUS,
  43. SIGSEGV :
  44. begin
  45. addr := siginfo^._sifields._sigfault._addr;
  46. res:=216;
  47. end;
  48. end;
  49. reenable_signal(sig);
  50. { give runtime error at the position where the signal was raised }
  51. if res<>0 then
  52. begin
  53. if assigned(UContext) then
  54. begin
  55. frame:=pointer(ptruint(UContext^.uc_mcontext.sigc_regs[30])); { base pointer }
  56. addr:=pointer(ptruint(UContext^.uc_mcontext.sigc_pc)); { program counter }
  57. if sig=SIGFPE then
  58. begin
  59. { Clear FPU exception bits }
  60. UContext^.uc_mcontext.sigc_fpc_csr := UContext^.uc_mcontext.sigc_fpc_csr
  61. and not (fpu_cause_mask or fpu_flags_mask);
  62. end;
  63. { Change $a0, $a1, $a2 and sig_pc to HandleErrorAddrFrame parameters }
  64. UContext^.uc_mcontext.sigc_regs[4]:=res;
  65. UContext^.uc_mcontext.sigc_regs[5]:=ptrint(addr);
  66. UContext^.uc_mcontext.sigc_regs[6]:=ptrint(frame);
  67. UContext^.uc_mcontext.sigc_pc:=ptrint(@HandleErrorAddrFrame);
  68. {$ifdef FPC_PIC}
  69. { With PIC, we also have to set $t9 to procedure address }
  70. UContext^.uc_mcontext.sigc_regs[25]:=ptrint(@HandleErrorAddrFrame);
  71. {$endif FPC_PIC}
  72. { Let the system call HandleErrorAddrFrame }
  73. exit;
  74. end
  75. else
  76. begin
  77. frame:=nil;
  78. addr:=nil;
  79. end;
  80. if sig=SIGFPE then
  81. set_fsr(get_fsr and not (fpu_cause_mask or fpu_flags_mask));
  82. HandleErrorAddrFrame(res,addr,frame);
  83. end;
  84. end;