2 * Common signal handling code for both 32 and 64 bits
4 * Copyright (c) 2007 Benjamin Herrenschmidt, IBM Coproration
5 * Extracted from signal_32.c and signal_64.c
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.
12 #include <linux/ptrace.h>
13 #include <linux/signal.h>
14 #include <asm/unistd.h>
20 static inline int is_32bit_task(void)
22 return test_thread_flag(TIF_32BIT);
25 static inline int is_32bit_task(void)
33 * Restore the user process's signal mask
35 void restore_sigmask(sigset_t *set)
37 sigdelsetmask(set, ~_BLOCKABLE);
38 spin_lock_irq(¤t->sighand->siglock);
39 current->blocked = *set;
41 spin_unlock_irq(¤t->sighand->siglock);
44 static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka,
47 unsigned long ret = regs->gpr[3];
51 if (TRAP(regs) != 0x0C00)
54 /* error signalled ? */
55 if (!(regs->ccr & 0x10000000))
59 case ERESTART_RESTARTBLOCK:
61 /* ERESTARTNOHAND means that the syscall should only be
62 * restarted if there was no handler for the signal, and since
63 * we only get here if there is a handler, we dont restart.
65 restart = !has_handler;
68 /* ERESTARTSYS means to restart the syscall if there is no
69 * handler or the handler was registered with SA_RESTART
71 restart = !has_handler || (ka->sa.sa_flags & SA_RESTART) != 0;
74 /* ERESTARTNOINTR means that the syscall should be
75 * called again after the signal handler returns.
82 if (ret == ERESTART_RESTARTBLOCK)
83 regs->gpr[0] = __NR_restart_syscall;
85 regs->gpr[3] = regs->orig_gpr3;
89 regs->result = -EINTR;
91 regs->ccr |= 0x10000000;
95 int do_signal(sigset_t *oldset, struct pt_regs *regs)
99 struct k_sigaction ka;
101 int is32 = is_32bit_task();
103 if (test_thread_flag(TIF_RESTORE_SIGMASK))
104 oldset = ¤t->saved_sigmask;
106 oldset = ¤t->blocked;
108 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
110 /* Is there any syscall restart business here ? */
111 check_syscall_restart(regs, &ka, signr > 0);
114 /* No signal to deliver -- put the saved sigmask back */
115 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
116 clear_thread_flag(TIF_RESTORE_SIGMASK);
117 sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL);
119 return 0; /* no signals delivered */
124 * Reenable the DABR before delivering the signal to
125 * user space. The DABR will have been cleared if it
126 * triggered inside the kernel.
128 if (current->thread.dabr)
129 set_dabr(current->thread.dabr);
135 if ((ka.sa.sa_flags & SA_ONSTACK) &&
136 current->sas_ss_size && !on_sig_stack(regs->gpr[1]))
137 newsp = current->sas_ss_sp + current->sas_ss_size;
139 newsp = regs->gpr[1];
141 if (ka.sa.sa_flags & SA_SIGINFO)
142 ret = handle_rt_signal32(signr, &ka, &info, oldset,
145 ret = handle_signal32(signr, &ka, &info, oldset,
149 ret = handle_rt_signal64(signr, &ka, &info, oldset, regs);
154 spin_lock_irq(¤t->sighand->siglock);
155 sigorsets(¤t->blocked, ¤t->blocked,
157 if (!(ka.sa.sa_flags & SA_NODEFER))
158 sigaddset(¤t->blocked, signr);
160 spin_unlock_irq(¤t->sighand->siglock);
163 * A signal was successfully delivered; the saved sigmask is in
164 * its frame, and we can clear the TIF_RESTORE_SIGMASK flag.
166 if (test_thread_flag(TIF_RESTORE_SIGMASK))
167 clear_thread_flag(TIF_RESTORE_SIGMASK);
173 long sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
174 unsigned long r5, unsigned long r6, unsigned long r7,
175 unsigned long r8, struct pt_regs *regs)
177 return do_sigaltstack(uss, uoss, regs->gpr[1]);