sigtrp.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
  3. See the copyright notice in the ACK home directory, in the file "Copyright".
  4. */
  5. /*
  6. Module: Mapping of Unix signals to EM traps
  7. (only when not using the MON instruction)
  8. Author: Ceriel J.H. Jacobs
  9. Version: $Id$
  10. */
  11. #if !defined(__em22) && !defined(__em24) && !defined(__em44)
  12. #define EM_trap(n) TRP(n) /* define to whatever is needed to cause the trap */
  13. #include <signal.h>
  14. #include <errno.h>
  15. int __signo;
  16. static int __traps[] = {
  17. -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
  18. -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
  19. -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
  20. };
  21. static void
  22. __ctchsig(signo)
  23. {
  24. signal(signo,__ctchsig);
  25. #ifdef __BSD4_2
  26. sigsetmask(sigblock(0) & ~(1<<(signo - 1)));
  27. #endif
  28. __signo = signo;
  29. EM_trap(__traps[signo]);
  30. }
  31. int
  32. sigtrp(trapno, signo)
  33. {
  34. /* Let Unix signal signo cause EM trap trapno to occur.
  35. If trapno = -2, restore default,
  36. If trapno = -3, ignore.
  37. Return old trapnumber.
  38. Careful, this could be -2 or -3; But return value of -1
  39. indicates failure, with error number in errno.
  40. */
  41. extern int errno;
  42. void (*ctch)() = __ctchsig;
  43. void (*oldctch)();
  44. int oldtrap;
  45. if (signo <= 0 || signo >= sizeof(__traps)/sizeof(__traps[0])) {
  46. errno = EINVAL;
  47. return -1;
  48. }
  49. if (trapno == -3)
  50. ctch = SIG_IGN;
  51. else if (trapno == -2)
  52. ctch = SIG_DFL;
  53. else if (trapno >= 0 && trapno <= 252)
  54. ;
  55. else {
  56. errno = EINVAL;
  57. return -1;
  58. }
  59. oldtrap = __traps[signo];
  60. if ((oldctch = signal(signo, ctch)) == (void (*)())-1) /* errno set by signal */
  61. return -1;
  62. else if (oldctch == SIG_IGN) {
  63. signal(signo, SIG_IGN);
  64. }
  65. else __traps[signo] = trapno;
  66. return oldtrap;
  67. }
  68. #endif