sighnd.inc 2.7 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;
  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;
  29. FPE_INTOVF:
  30. res:=215;
  31. FPE_FLTDIV:
  32. res:=200;
  33. FPE_FLTOVF:
  34. res:=205;
  35. FPE_FLTUND:
  36. res:=206;
  37. FPE_FLTRES,
  38. FPE_FLTINV,
  39. FPE_FLTSUB:
  40. res:=216;
  41. else
  42. res:=207;
  43. end;
  44. end;
  45. SIGILL,
  46. SIGBUS,
  47. SIGSEGV :
  48. begin
  49. addr := siginfo^._sifields._sigfault._addr;
  50. res:=216;
  51. end;
  52. end;
  53. reenable_signal(sig);
  54. { give runtime error at the position where the signal was raised }
  55. if res<>0 then
  56. begin
  57. if assigned(UContext) then
  58. begin
  59. frame:=pointer(ptruint(UContext^.uc_mcontext.sigc_regs[30])); { base pointer }
  60. addr:=pointer(ptruint(UContext^.uc_mcontext.sigc_pc)); { program counter }
  61. if sig=SIGFPE then
  62. begin
  63. { Clear FPU exception bits }
  64. UContext^.uc_mcontext.sigc_fpc_csr := UContext^.uc_mcontext.sigc_fpc_csr
  65. and not (fpu_cause_mask or fpu_flags_mask);
  66. end;
  67. { Change $a1, $a2, $a3 and sig_pc to HandleErrorAddrFrame parameters }
  68. UContext^.uc_mcontext.sigc_regs[4]:=res;
  69. UContext^.uc_mcontext.sigc_regs[5]:=ptrint(addr);
  70. UContext^.uc_mcontext.sigc_regs[6]:=ptrint(frame);
  71. UContext^.uc_mcontext.sigc_pc:=ptrint(@HandleErrorAddrFrame);
  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;