tw12704a.pp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. { %norun }
  2. { %target=darwin,linux,freebsd,solaris,beos,haiku }
  3. {$mode delphi}
  4. {$ifdef darwin}
  5. {$PIC+}
  6. {$endif darwin}
  7. {$ifdef CPUX86_64}
  8. {$ifndef WINDOWS}
  9. {$PIC+}
  10. {$endif WINDOWS}
  11. {$endif CPUX86_64}
  12. library tw12704a;
  13. uses
  14. SysUtils;
  15. procedure initsignals;
  16. var
  17. p: pointer;
  18. i: longint;
  19. begin
  20. // check that none of the handlers have been yet by the library's init code
  21. for i:=RTL_SIGINT to RTL_SIGLAST do
  22. if (InquireSignal(i) <> ssNotHooked) then
  23. halt(1);
  24. // hook standard signals
  25. HookSignal(RTL_SIGDEFAULT);
  26. for i:=RTL_SIGINT to RTL_SIGLAST do
  27. case i of
  28. RTL_SIGINT,
  29. RTL_SIGQUIT:
  30. if (InquireSignal(i) <> ssNotHooked) then
  31. halt(2);
  32. RTL_SIGFPE,
  33. RTL_SIGSEGV,
  34. RTL_SIGILL,
  35. RTL_SIGBUS:
  36. if (InquireSignal(i) <> ssHooked) then
  37. halt(3);
  38. else
  39. halt(4);
  40. end;
  41. // unhook sigill
  42. UnHookSignal(RTL_SIGILL);
  43. for i:=RTL_SIGINT to RTL_SIGLAST do
  44. case i of
  45. RTL_SIGINT,
  46. RTL_SIGILL,
  47. RTL_SIGQUIT:
  48. if (InquireSignal(i) <> ssNotHooked) then
  49. halt(5);
  50. RTL_SIGFPE,
  51. RTL_SIGSEGV,
  52. RTL_SIGBUS:
  53. if (InquireSignal(i) <> ssHooked) then
  54. halt(6);
  55. end;
  56. // check whether installed signal handler actually works
  57. (*
  58. try
  59. p:=nil;
  60. longint(p^):=1;
  61. except
  62. end;
  63. *)
  64. end;
  65. procedure testsignals; cdecl;
  66. var
  67. i: longint;
  68. begin
  69. // called from program -> it has overridden our signal handlers
  70. // when this routine is called, it will have unhooked sigbus, so
  71. // that one should still belong to us
  72. // we previously unhooked sigill, so that one should still be
  73. // unhooked as far as we are concerned
  74. for i:=RTL_SIGINT to RTL_SIGLAST do
  75. case i of
  76. RTL_SIGINT,
  77. RTL_SIGILL,
  78. RTL_SIGQUIT:
  79. if (InquireSignal(i) <> ssNothooked) then
  80. halt(7);
  81. RTL_SIGFPE,
  82. RTL_SIGSEGV:
  83. if (InquireSignal(i) <> ssOverridden) then
  84. halt(8);
  85. RTL_SIGBUS:
  86. if (InquireSignal(i) <> ssHooked) then
  87. halt(9);
  88. end;
  89. end;
  90. exports
  91. testsignals;
  92. begin
  93. initsignals;
  94. end.