sighnd.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. function GetHandleErrorAddrFrameAddr: pointer;
  14. begin
  15. result:=@HandleErrorAddrFrame;
  16. end;
  17. {$ifndef CPUTHUMB}
  18. Procedure SignalToHandleErrorAddrFrame_ARM(Errno : longint;addr : CodePointer; frame : Pointer); nostackframe; assembler;
  19. asm
  20. {$if FPC_VERSION >= 30200}
  21. .code 32
  22. {$endif}
  23. // the address is of the faulting instruction, and sigreturn will
  24. // skip it -> start with a nop
  25. nop
  26. push {r0,r1,r2,r3}
  27. bl GetHandleErrorAddrFrameAddr
  28. // overwrite last stack slot with new return address
  29. str r0, [sp,#12]
  30. // lr := addr
  31. ldr lr, [sp,#4]
  32. pop {r0,r1,r2,pc}
  33. .text
  34. end;
  35. {$endif not CPUTHUMB}
  36. {$if FPC_VERSION >= 30200}
  37. Procedure SignalToHandleErrorAddrFrame_Thumb(Errno : longint;addr : CodePointer; frame : Pointer); nostackframe; assembler;
  38. asm
  39. .thumb_func
  40. .code 16
  41. // the address is of the faulting instruction, and sigreturn will
  42. // skip it -> start with a nop
  43. nop
  44. push {r0,r1,r2,r3}
  45. bl GetHandleErrorAddrFrameAddr
  46. // overwrite last stack slot with new return address
  47. str r0, [sp,#12]
  48. // lr := addr
  49. ldr r0, [sp,#4]
  50. mov lr, r0
  51. pop {r0,r1,r2,pc}
  52. .text
  53. end;
  54. {$endif}
  55. procedure SignalToRunerror(Sig: longint; { _a2,_a3,_a4 : dword; } SigContext: PSigInfo; uContext : PuContext); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
  56. var
  57. res : word;
  58. begin
  59. res:=0;
  60. case sig of
  61. SIGFPE :
  62. begin
  63. { don't know how to find the different causes, maybe via xer? }
  64. res := 207;
  65. SysResetFPU;
  66. end;
  67. SIGILL:
  68. {$ifdef FPC_SYSTEM_FPC_MOVE}
  69. if in_edsp_test then
  70. begin
  71. res:=0;
  72. cpu_has_edsp:=false;
  73. inc(uContext^.uc_mcontext.arm_pc,4);
  74. end
  75. else
  76. {$endif FPC_SYSTEM_FPC_MOVE}
  77. res:=216;
  78. SIGSEGV :
  79. res:=216;
  80. SIGBUS:
  81. res:=214;
  82. SIGINT:
  83. res:=217;
  84. SIGQUIT:
  85. res:=233;
  86. end;
  87. { give runtime error at the position where the signal was raised }
  88. if res<>0 then
  89. begin
  90. ucontext^.uc_mcontext.arm_r0:=res;
  91. ucontext^.uc_mcontext.arm_r1:=uContext^.uc_mcontext.arm_pc;
  92. ucontext^.uc_mcontext.arm_r2:=uContext^.uc_mcontext.arm_fp;
  93. {$if FPC_VERSION >= 30200}
  94. {$ifndef CPUTHUMB}
  95. if (ucontext^.uc_mcontext.arm_cpsr and (1 shl 5))=0 then
  96. begin
  97. ucontext^.uc_mcontext.arm_pc:=ptruint(@SignalToHandleErrorAddrFrame_ARM);
  98. end
  99. else
  100. {$endif not CPUTHUMB}
  101. begin
  102. ucontext^.uc_mcontext.arm_pc:=ptruint(@SignalToHandleErrorAddrFrame_Thumb);
  103. end;
  104. {$else}
  105. ucontext^.uc_mcontext.arm_pc:=ptruint(@SignalToHandleErrorAddrFrame_ARM);
  106. {$endif}
  107. end;
  108. end;