signal.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Common signal handling code for both 32 and 64 bits
  3. *
  4. * Copyright (c) 2007 Benjamin Herrenschmidt, IBM Coproration
  5. * Extracted from signal_32.c and signal_64.c
  6. *
  7. * This file is subject to the terms and conditions of the GNU General
  8. * Public License. See the file README.legal in the main directory of
  9. * this archive for more details.
  10. */
  11. #include <linux/ptrace.h>
  12. #include <linux/signal.h>
  13. #include <asm/unistd.h>
  14. #include "signal.h"
  15. /*
  16. * Restore the user process's signal mask
  17. */
  18. void restore_sigmask(sigset_t *set)
  19. {
  20. sigdelsetmask(set, ~_BLOCKABLE);
  21. spin_lock_irq(&current->sighand->siglock);
  22. current->blocked = *set;
  23. recalc_sigpending();
  24. spin_unlock_irq(&current->sighand->siglock);
  25. }
  26. void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka,
  27. int has_handler)
  28. {
  29. unsigned long ret = regs->gpr[3];
  30. int restart = 1;
  31. /* syscall ? */
  32. if (TRAP(regs) != 0x0C00)
  33. return;
  34. /* error signalled ? */
  35. if (!(regs->ccr & 0x10000000))
  36. return;
  37. switch (ret) {
  38. case ERESTART_RESTARTBLOCK:
  39. case ERESTARTNOHAND:
  40. /* ERESTARTNOHAND means that the syscall should only be
  41. * restarted if there was no handler for the signal, and since
  42. * we only get here if there is a handler, we dont restart.
  43. */
  44. restart = !has_handler;
  45. break;
  46. case ERESTARTSYS:
  47. /* ERESTARTSYS means to restart the syscall if there is no
  48. * handler or the handler was registered with SA_RESTART
  49. */
  50. restart = !has_handler || (ka->sa.sa_flags & SA_RESTART) != 0;
  51. break;
  52. case ERESTARTNOINTR:
  53. /* ERESTARTNOINTR means that the syscall should be
  54. * called again after the signal handler returns.
  55. */
  56. break;
  57. default:
  58. return;
  59. }
  60. if (restart) {
  61. if (ret == ERESTART_RESTARTBLOCK)
  62. regs->gpr[0] = __NR_restart_syscall;
  63. else
  64. regs->gpr[3] = regs->orig_gpr3;
  65. regs->nip -= 4;
  66. regs->result = 0;
  67. } else {
  68. regs->result = -EINTR;
  69. regs->gpr[3] = EINTR;
  70. regs->ccr |= 0x10000000;
  71. }
  72. }
  73. long sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
  74. unsigned long r5, unsigned long r6, unsigned long r7,
  75. unsigned long r8, struct pt_regs *regs)
  76. {
  77. return do_sigaltstack(uss, uoss, regs->gpr[1]);
  78. }