signal.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka,
  15. int has_handler)
  16. {
  17. unsigned long ret = regs->gpr[3];
  18. int restart = 1;
  19. /* syscall ? */
  20. if (TRAP(regs) != 0x0C00)
  21. return;
  22. /* error signalled ? */
  23. if (!(regs->ccr & 0x10000000))
  24. return;
  25. switch (ret) {
  26. case ERESTART_RESTARTBLOCK:
  27. case ERESTARTNOHAND:
  28. /* ERESTARTNOHAND means that the syscall should only be
  29. * restarted if there was no handler for the signal, and since
  30. * we only get here if there is a handler, we dont restart.
  31. */
  32. restart = !has_handler;
  33. break;
  34. case ERESTARTSYS:
  35. /* ERESTARTSYS means to restart the syscall if there is no
  36. * handler or the handler was registered with SA_RESTART
  37. */
  38. restart = !has_handler || (ka->sa.sa_flags & SA_RESTART) != 0;
  39. break;
  40. case ERESTARTNOINTR:
  41. /* ERESTARTNOINTR means that the syscall should be
  42. * called again after the signal handler returns.
  43. */
  44. break;
  45. default:
  46. return;
  47. }
  48. if (restart) {
  49. if (ret == ERESTART_RESTARTBLOCK)
  50. regs->gpr[0] = __NR_restart_syscall;
  51. else
  52. regs->gpr[3] = regs->orig_gpr3;
  53. regs->nip -= 4;
  54. regs->result = 0;
  55. } else {
  56. regs->result = -EINTR;
  57. regs->gpr[3] = EINTR;
  58. regs->ccr |= 0x10000000;
  59. }
  60. }