sighnd.inc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. { $define SYSTEM_DEBUG}
  14. procedure SignalToRunerror(Sig: longint; SigInfo: PSigInfo; UContext: PUContext); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
  15. const
  16. fpu_ctx_magic = $46505501;
  17. lsx_ctx_magic = $53580001;
  18. lasx_ctx_magic = $41535801;
  19. used_fp = 1 shl 0;
  20. adrerr_rd = 1 shl 30;
  21. adrerr_wr = 1 shl 31;
  22. fcsr_bits_clear_exceptions = $e0ffffff;
  23. var
  24. PCtxInfo : PContext_Info;
  25. PFPU_Ctx : PFPU_Context;
  26. PLSX_Ctx : PLSX_Context;
  27. PLASX_Ctx : PLASX_Context;
  28. PX_Context : pointer;
  29. res : word;
  30. ferr: cUint;
  31. begin
  32. res:=0;
  33. case sig of
  34. SIGFPE:
  35. begin
  36. res:=207;
  37. if (used_fp and uContext^.uc_mcontext.flags)<>0 then
  38. begin
  39. ferr:=0;
  40. PCtxInfo:=PContext_Info(uContext+1);
  41. PX_Context:=PCtxInfo+1;
  42. case (PCtxInfo^.magic) of
  43. fpu_ctx_magic: begin
  44. PFPU_Ctx:=PX_Context;
  45. ferr:=PFPU_Ctx^.fcsr;
  46. PFPU_Ctx^.fcsr:=PFPU_Ctx^.fcsr and fcsr_bits_clear_exceptions;
  47. end;
  48. lsx_ctx_magic: begin
  49. PLSX_Ctx:=PX_Context;
  50. ferr:=PLSX_Ctx^.fcsr;
  51. PLSX_Ctx^.fcsr:=PLSX_Ctx^.fcsr and fcsr_bits_clear_exceptions;
  52. end;
  53. lasx_ctx_magic: begin
  54. PLASX_Ctx:=PX_Context;
  55. ferr:=PLASX_Ctx^.fcsr;
  56. PLASX_Ctx^.fcsr:=PLASX_Ctx^.fcsr and fcsr_bits_clear_exceptions;
  57. end;
  58. end;
  59. ferr:=ferr shr 24;
  60. case ferr of
  61. 1: res:=207;
  62. 2: res:=206;
  63. 4: res:=205;
  64. 8: res:=208;
  65. 16: res:=207;
  66. else
  67. ;
  68. end;
  69. end;
  70. end;
  71. SIGILL:
  72. res:=216;
  73. SIGSEGV :
  74. res:=216;
  75. SIGBUS:
  76. res:=214;
  77. SIGINT:
  78. res:=217;
  79. SIGQUIT:
  80. res:=233;
  81. end;
  82. reenable_signal(sig);
  83. { give runtime error at the position where the signal was raised }
  84. if res<>0 then
  85. HandleErrorAddrFrame(res,
  86. pointer(uContext^.uc_mcontext.pc),
  87. pointer(uContext^.uc_mcontext.regs[22]));
  88. end;