sighnd.inc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. end;
  66. SIGILL:
  67. {$ifdef FPC_SYSTEM_FPC_MOVE}
  68. if in_edsp_test then
  69. begin
  70. res:=0;
  71. cpu_has_edsp:=false;
  72. inc(uContext^.uc_mcontext.arm_pc,4);
  73. end
  74. else
  75. {$endif FPC_SYSTEM_FPC_MOVE}
  76. res:=216;
  77. SIGSEGV :
  78. res:=216;
  79. SIGBUS:
  80. res:=214;
  81. SIGINT:
  82. res:=217;
  83. SIGQUIT:
  84. res:=233;
  85. end;
  86. { give runtime error at the position where the signal was raised }
  87. if res<>0 then
  88. begin
  89. ucontext^.uc_mcontext.arm_r0:=res;
  90. ucontext^.uc_mcontext.arm_r1:=uContext^.uc_mcontext.arm_pc;
  91. ucontext^.uc_mcontext.arm_r2:=uContext^.uc_mcontext.arm_fp;
  92. {$if FPC_VERSION >= 30200}
  93. {$ifndef CPUTHUMB}
  94. if (ucontext^.uc_mcontext.arm_cpsr and (1 shl 5))=0 then
  95. begin
  96. ucontext^.uc_mcontext.arm_pc:=ptruint(@SignalToHandleErrorAddrFrame_ARM);
  97. end
  98. else
  99. {$endif not CPUTHUMB}
  100. begin
  101. ucontext^.uc_mcontext.arm_pc:=ptruint(@SignalToHandleErrorAddrFrame_Thumb);
  102. end;
  103. {$else}
  104. ucontext^.uc_mcontext.arm_pc:=ptruint(@SignalToHandleErrorAddrFrame_ARM);
  105. {$endif}
  106. end;
  107. end;