sighnd.inc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 signr_to_runerrornr(sig:longint;siginfo:Psiginfo;var addr:pointer):word;
  14. begin
  15. signr_to_runerrornr:=0;
  16. case sig of
  17. SIGFPE :
  18. begin
  19. addr := siginfo^._sifields._sigfault._addr;
  20. case siginfo^.si_code of
  21. FPE_INTDIV:
  22. signr_to_runerrornr:=200;
  23. FPE_INTOVF:
  24. signr_to_runerrornr:=205;
  25. FPE_FLTDIV:
  26. signr_to_runerrornr:=200;
  27. FPE_FLTOVF:
  28. signr_to_runerrornr:=205;
  29. FPE_FLTUND:
  30. signr_to_runerrornr:=206;
  31. else
  32. signr_to_runerrornr:=207;
  33. end;
  34. end;
  35. SIGBUS :
  36. begin
  37. addr := siginfo^._sifields._sigfault._addr;
  38. signr_to_runerrornr:=214;
  39. end;
  40. SIGILL,
  41. SIGSEGV :
  42. begin
  43. addr := siginfo^._sifields._sigfault._addr;
  44. signr_to_runerrornr:=216;
  45. end;
  46. SIGINT:
  47. signr_to_runerrornr:=217;
  48. SIGQUIT:
  49. signr_to_runerrornr:=233;
  50. end;
  51. end;
  52. procedure SignalToAbort(sig : longint; SigInfo: PSigInfo; SigContext: PSigcontext);cdecl;
  53. var
  54. s:string[5];
  55. addr:pointer;
  56. begin
  57. addr:=nil;
  58. exitcode:=signr_to_runerrornr(sig,siginfo,addr);
  59. reenable_signal(sig);
  60. {I had written a small stack dumper, but decided to remove it, because programs that
  61. activate the microexe mode are most likely exe size benchmarks. In the case they are not
  62. they are likely so primitive that it is unlikely that they require a stackdump to debug.
  63. dump_stack_micro(pointer(ucontext^.uc_mcontext.eip));}
  64. {Write runtime error message.}
  65. int_str(exitcode,s); {int_str instead of str pulls in less code}
  66. write_micro('Runtime error '+s+' at $'+
  67. hexstr(longint(addr),8)+ {typecast to longint to prevent pulling in int64 support}
  68. lineending);
  69. haltproc(exitcode);
  70. end;
  71. procedure SignalToRunerror(sig : longint; SigInfo: PSigInfo; SigContext: PSigContext);public name '_FPC_DEFAULTSIGHANDLER';cdecl;
  72. var
  73. res : word;
  74. addr : pointer;
  75. begin
  76. addr:=nil;
  77. res:=signr_to_runerrornr(sig,siginfo,addr);
  78. reenable_signal(sig);
  79. { give runtime error at the position where the signal was raised }
  80. if res<>0 then
  81. HandleErrorAddrFrame(res,addr,nil);
  82. end;