sighnd.inc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. {
  2. This file is part of the Free Pascal run time library.
  3. (c) 2000-2003 by Marco van de Voort
  4. (c) 2011 by Jonas Maebe
  5. members of the Free Pascal development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. Signalhandler for FreeBSD/i386
  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: cint; info : PSigInfo; SigContext:PSigContext); public name '_FPC_DEFAULTSIGHANDLER'; cdecl;
  14. var
  15. res : word;
  16. begin
  17. res:=0;
  18. case sig of
  19. SIGFPE :
  20. begin
  21. Case Info^.si_code Of
  22. FPE_FLTDIV : Res:=208; { floating point divide by zero }
  23. FPE_INTDIV : Res:=200; { floating point divide by zero }
  24. FPE_FLTOVF : Res:=205; { floating point overflow }
  25. FPE_FLTUND : Res:=206; { floating point underflow }
  26. FPE_FLTRES, { floating point inexact result }
  27. FPE_FLTINV : Res:=207; { invalid floating point operation }
  28. Else
  29. Res:=207; {coprocessor error}
  30. end;
  31. { FPU exceptions are completely disabled by the kernel if one occurred, it }
  32. { seems this is necessary to be able to return to user mode. They can be }
  33. { enabled by executing a sigreturn, however then the exception is triggered }
  34. { again immediately if we don't turn off the "exception occurred" flags }
  35. { in fpscr }
  36. SigContext^.uc_mcontext.fpscr := SigContext^.uc_mcontext.fpscr and not($fffe0700);
  37. end;
  38. SIGILL,
  39. SIGBUS,
  40. SIGSEGV :
  41. res:=216;
  42. SIGINT:
  43. res:=217;
  44. SIGQUIT:
  45. res:=233;
  46. end;
  47. {$ifdef FPC_USE_SIGPROCMASK}
  48. reenable_signal(sig);
  49. {$endif }
  50. { return to trampoline }
  51. if res <> 0 then
  52. begin
  53. SigContext^.uc_mcontext.gpr[3] := res;
  54. SigContext^.uc_mcontext.gpr[4] := SigContext^.uc_mcontext.iar;
  55. SigContext^.uc_mcontext.gpr[5] := SigContext^.uc_mcontext.gpr[1];
  56. { the address of a function is a descriptor, and we need the actual
  57. address here -> dereference }
  58. pointer(SigContext^.uc_mcontext.iar) := ppointer(@HandleErrorAddrFrame)^;
  59. { set corresponding TOC for the routine we are returning to }
  60. pointer(SigContext^.uc_mcontext.gpr[2]) := (ppointer(@HandleErrorAddrFrame)+1)^;
  61. end;
  62. end;