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/uaccess.h>
15 #include <asm/unistd.h>
21 static inline int is_32bit_task(void)
23 return test_thread_flag(TIF_32BIT);
26 static inline int is_32bit_task(void)
33 * Allocate space for the signal frame
35 void __user * get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
38 unsigned long oldsp, newsp;
40 /* Default to using normal stack */
43 /* Check for alt stack */
44 if ((ka->sa.sa_flags & SA_ONSTACK) &&
45 current->sas_ss_size && !on_sig_stack(oldsp))
46 oldsp = (current->sas_ss_sp + current->sas_ss_size);
48 /* Get aligned frame */
49 newsp = (oldsp - frame_size) & ~0xFUL;
52 if (!access_ok(VERIFY_WRITE, (void __user *)newsp, oldsp - newsp))
55 return (void __user *)newsp;
60 * Restore the user process's signal mask
62 void restore_sigmask(sigset_t *set)
64 sigdelsetmask(set, ~_BLOCKABLE);
65 spin_lock_irq(¤t->sighand->siglock);
66 current->blocked = *set;
68 spin_unlock_irq(¤t->sighand->siglock);
71 static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka,
74 unsigned long ret = regs->gpr[3];
78 if (TRAP(regs) != 0x0C00)
81 /* error signalled ? */
82 if (!(regs->ccr & 0x10000000))
86 case ERESTART_RESTARTBLOCK:
88 /* ERESTARTNOHAND means that the syscall should only be
89 * restarted if there was no handler for the signal, and since
90 * we only get here if there is a handler, we dont restart.
92 restart = !has_handler;
95 /* ERESTARTSYS means to restart the syscall if there is no
96 * handler or the handler was registered with SA_RESTART
98 restart = !has_handler || (ka->sa.sa_flags & SA_RESTART) != 0;
101 /* ERESTARTNOINTR means that the syscall should be
102 * called again after the signal handler returns.
109 if (ret == ERESTART_RESTARTBLOCK)
110 regs->gpr[0] = __NR_restart_syscall;
112 regs->gpr[3] = regs->orig_gpr3;
116 regs->result = -EINTR;
117 regs->gpr[3] = EINTR;
118 regs->ccr |= 0x10000000;
122 int do_signal(sigset_t *oldset, struct pt_regs *regs)
126 struct k_sigaction ka;
128 int is32 = is_32bit_task();
130 if (test_thread_flag(TIF_RESTORE_SIGMASK))
131 oldset = ¤t->saved_sigmask;
133 oldset = ¤t->blocked;
135 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
137 /* Is there any syscall restart business here ? */
138 check_syscall_restart(regs, &ka, signr > 0);
141 /* No signal to deliver -- put the saved sigmask back */
142 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
143 clear_thread_flag(TIF_RESTORE_SIGMASK);
144 sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL);
146 return 0; /* no signals delivered */
151 * Reenable the DABR before delivering the signal to
152 * user space. The DABR will have been cleared if it
153 * triggered inside the kernel.
155 if (current->thread.dabr)
156 set_dabr(current->thread.dabr);
160 if (ka.sa.sa_flags & SA_SIGINFO)
161 ret = handle_rt_signal32(signr, &ka, &info, oldset,
164 ret = handle_signal32(signr, &ka, &info, oldset,
168 ret = handle_rt_signal64(signr, &ka, &info, oldset, regs);
173 spin_lock_irq(¤t->sighand->siglock);
174 sigorsets(¤t->blocked, ¤t->blocked,
176 if (!(ka.sa.sa_flags & SA_NODEFER))
177 sigaddset(¤t->blocked, signr);
179 spin_unlock_irq(¤t->sighand->siglock);
182 * A signal was successfully delivered; the saved sigmask is in
183 * its frame, and we can clear the TIF_RESTORE_SIGMASK flag.
185 if (test_thread_flag(TIF_RESTORE_SIGMASK))
186 clear_thread_flag(TIF_RESTORE_SIGMASK);
192 long sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
193 unsigned long r5, unsigned long r6, unsigned long r7,
194 unsigned long r8, struct pt_regs *regs)
196 return do_sigaltstack(uss, uoss, regs->gpr[1]);