Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/sh/kernel/signal.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * |
| 6 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson |
| 7 | * |
| 8 | * SuperH version: Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima |
| 9 | * |
| 10 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/sched.h> |
| 12 | #include <linux/mm.h> |
| 13 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kernel.h> |
| 15 | #include <linux/signal.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/wait.h> |
| 18 | #include <linux/ptrace.h> |
| 19 | #include <linux/unistd.h> |
| 20 | #include <linux/stddef.h> |
| 21 | #include <linux/tty.h> |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 22 | #include <linux/elf.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/personality.h> |
| 24 | #include <linux/binfmts.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 25 | #include <linux/freezer.h> |
Paul Mundt | b66d51c | 2007-06-01 17:26:13 +0900 | [diff] [blame] | 26 | #include <linux/io.h> |
Paul Mundt | ab99c73 | 2008-07-30 19:55:30 +0900 | [diff] [blame] | 27 | #include <linux/tracehook.h> |
Paul Mundt | bd07999 | 2007-05-08 14:50:59 +0900 | [diff] [blame] | 28 | #include <asm/system.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/ucontext.h> |
| 30 | #include <asm/uaccess.h> |
| 31 | #include <asm/pgtable.h> |
| 32 | #include <asm/cacheflush.h> |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 33 | #include <asm/syscalls.h> |
Paul Mundt | 9bbafce | 2008-03-26 19:02:47 +0900 | [diff] [blame] | 34 | #include <asm/fpu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) |
| 37 | |
Paul Mundt | 3bc24a1 | 2008-05-19 13:40:12 +0900 | [diff] [blame] | 38 | struct fdpic_func_descriptor { |
| 39 | unsigned long text; |
| 40 | unsigned long GOT; |
| 41 | }; |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /* |
| 44 | * Atomically swap in the new signal mask, and wait for a signal. |
| 45 | */ |
| 46 | asmlinkage int |
| 47 | sys_sigsuspend(old_sigset_t mask, |
| 48 | unsigned long r5, unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 49 | struct pt_regs __regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | mask &= _BLOCKABLE; |
| 52 | spin_lock_irq(¤t->sighand->siglock); |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 53 | current->saved_sigmask = current->blocked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | siginitset(¤t->blocked, mask); |
| 55 | recalc_sigpending(); |
| 56 | spin_unlock_irq(¤t->sighand->siglock); |
| 57 | |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 58 | current->state = TASK_INTERRUPTIBLE; |
| 59 | schedule(); |
| 60 | set_thread_flag(TIF_RESTORE_SIGMASK); |
| 61 | return -ERESTARTNOHAND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 64 | asmlinkage int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | sys_sigaction(int sig, const struct old_sigaction __user *act, |
| 66 | struct old_sigaction __user *oact) |
| 67 | { |
| 68 | struct k_sigaction new_ka, old_ka; |
| 69 | int ret; |
| 70 | |
| 71 | if (act) { |
| 72 | old_sigset_t mask; |
| 73 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || |
| 74 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || |
| 75 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer)) |
| 76 | return -EFAULT; |
| 77 | __get_user(new_ka.sa.sa_flags, &act->sa_flags); |
| 78 | __get_user(mask, &act->sa_mask); |
| 79 | siginitset(&new_ka.sa.sa_mask, mask); |
| 80 | } |
| 81 | |
| 82 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
| 83 | |
| 84 | if (!ret && oact) { |
| 85 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || |
| 86 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || |
| 87 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer)) |
| 88 | return -EFAULT; |
| 89 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags); |
| 90 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); |
| 91 | } |
| 92 | |
| 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | asmlinkage int |
| 97 | sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, |
| 98 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 99 | struct pt_regs __regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 101 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
| 102 | |
| 103 | return do_sigaltstack(uss, uoss, regs->regs[15]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | |
| 107 | /* |
| 108 | * Do a signal return; undo the signal stack. |
| 109 | */ |
| 110 | |
| 111 | #define MOVW(n) (0x9300|((n)-2)) /* Move mem word at PC+n to R3 */ |
Yoshinori Sato | 11cbb70 | 2006-12-07 18:07:27 +0900 | [diff] [blame] | 112 | #if defined(CONFIG_CPU_SH2) |
Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 113 | #define TRAP_NOARG 0xc320 /* Syscall w/no args (NR in R3) */ |
| 114 | #else |
| 115 | #define TRAP_NOARG 0xc310 /* Syscall w/no args (NR in R3) */ |
| 116 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | #define OR_R0_R0 0x200b /* or r0,r0 (insert to avoid hardware bug) */ |
| 118 | |
| 119 | struct sigframe |
| 120 | { |
| 121 | struct sigcontext sc; |
| 122 | unsigned long extramask[_NSIG_WORDS-1]; |
| 123 | u16 retcode[8]; |
| 124 | }; |
| 125 | |
| 126 | struct rt_sigframe |
| 127 | { |
| 128 | struct siginfo info; |
| 129 | struct ucontext uc; |
| 130 | u16 retcode[8]; |
| 131 | }; |
| 132 | |
| 133 | #ifdef CONFIG_SH_FPU |
| 134 | static inline int restore_sigcontext_fpu(struct sigcontext __user *sc) |
| 135 | { |
| 136 | struct task_struct *tsk = current; |
| 137 | |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 138 | if (!(current_cpu_data.flags & CPU_HAS_FPU)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | return 0; |
| 140 | |
| 141 | set_used_math(); |
| 142 | return __copy_from_user(&tsk->thread.fpu.hard, &sc->sc_fpregs[0], |
| 143 | sizeof(long)*(16*2+2)); |
| 144 | } |
| 145 | |
| 146 | static inline int save_sigcontext_fpu(struct sigcontext __user *sc, |
| 147 | struct pt_regs *regs) |
| 148 | { |
| 149 | struct task_struct *tsk = current; |
| 150 | |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 151 | if (!(current_cpu_data.flags & CPU_HAS_FPU)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | return 0; |
| 153 | |
| 154 | if (!used_math()) { |
| 155 | __put_user(0, &sc->sc_ownedfp); |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | __put_user(1, &sc->sc_ownedfp); |
| 160 | |
| 161 | /* This will cause a "finit" to be triggered by the next |
| 162 | attempted FPU operation by the 'current' process. |
| 163 | */ |
| 164 | clear_used_math(); |
| 165 | |
| 166 | unlazy_fpu(tsk, regs); |
| 167 | return __copy_to_user(&sc->sc_fpregs[0], &tsk->thread.fpu.hard, |
| 168 | sizeof(long)*(16*2+2)); |
| 169 | } |
| 170 | #endif /* CONFIG_SH_FPU */ |
| 171 | |
| 172 | static int |
| 173 | restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *r0_p) |
| 174 | { |
| 175 | unsigned int err = 0; |
| 176 | |
| 177 | #define COPY(x) err |= __get_user(regs->x, &sc->sc_##x) |
| 178 | COPY(regs[1]); |
| 179 | COPY(regs[2]); COPY(regs[3]); |
| 180 | COPY(regs[4]); COPY(regs[5]); |
| 181 | COPY(regs[6]); COPY(regs[7]); |
| 182 | COPY(regs[8]); COPY(regs[9]); |
| 183 | COPY(regs[10]); COPY(regs[11]); |
| 184 | COPY(regs[12]); COPY(regs[13]); |
| 185 | COPY(regs[14]); COPY(regs[15]); |
| 186 | COPY(gbr); COPY(mach); |
| 187 | COPY(macl); COPY(pr); |
| 188 | COPY(sr); COPY(pc); |
| 189 | #undef COPY |
| 190 | |
| 191 | #ifdef CONFIG_SH_FPU |
Paul Mundt | 11c1965 | 2006-12-25 10:19:56 +0900 | [diff] [blame] | 192 | if (current_cpu_data.flags & CPU_HAS_FPU) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | int owned_fp; |
| 194 | struct task_struct *tsk = current; |
| 195 | |
| 196 | regs->sr |= SR_FD; /* Release FPU */ |
| 197 | clear_fpu(tsk, regs); |
| 198 | clear_used_math(); |
| 199 | __get_user (owned_fp, &sc->sc_ownedfp); |
| 200 | if (owned_fp) |
| 201 | err |= restore_sigcontext_fpu(sc); |
| 202 | } |
| 203 | #endif |
| 204 | |
| 205 | regs->tra = -1; /* disable syscall checks */ |
| 206 | err |= __get_user(*r0_p, &sc->sc_regs[0]); |
| 207 | return err; |
| 208 | } |
| 209 | |
| 210 | asmlinkage int sys_sigreturn(unsigned long r4, unsigned long r5, |
| 211 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 212 | struct pt_regs __regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 214 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
| 215 | struct sigframe __user *frame = (struct sigframe __user *)regs->regs[15]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | sigset_t set; |
| 217 | int r0; |
| 218 | |
Paul Mundt | 1bec157 | 2008-09-24 14:37:35 +0900 | [diff] [blame] | 219 | /* Always make any pending restarted system calls return -EINTR */ |
| 220 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 223 | goto badframe; |
| 224 | |
| 225 | if (__get_user(set.sig[0], &frame->sc.oldmask) |
| 226 | || (_NSIG_WORDS > 1 |
| 227 | && __copy_from_user(&set.sig[1], &frame->extramask, |
| 228 | sizeof(frame->extramask)))) |
| 229 | goto badframe; |
| 230 | |
| 231 | sigdelsetmask(&set, ~_BLOCKABLE); |
| 232 | |
| 233 | spin_lock_irq(¤t->sighand->siglock); |
| 234 | current->blocked = set; |
| 235 | recalc_sigpending(); |
| 236 | spin_unlock_irq(¤t->sighand->siglock); |
| 237 | |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 238 | if (restore_sigcontext(regs, &frame->sc, &r0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | goto badframe; |
| 240 | return r0; |
| 241 | |
| 242 | badframe: |
| 243 | force_sig(SIGSEGV, current); |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | asmlinkage int sys_rt_sigreturn(unsigned long r4, unsigned long r5, |
| 248 | unsigned long r6, unsigned long r7, |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 249 | struct pt_regs __regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | { |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 251 | struct pt_regs *regs = RELOC_HIDE(&__regs, 0); |
| 252 | struct rt_sigframe __user *frame = (struct rt_sigframe __user *)regs->regs[15]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | sigset_t set; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | int r0; |
| 255 | |
Paul Mundt | 1bec157 | 2008-09-24 14:37:35 +0900 | [diff] [blame] | 256 | /* Always make any pending restarted system calls return -EINTR */ |
| 257 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 260 | goto badframe; |
| 261 | |
| 262 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) |
| 263 | goto badframe; |
| 264 | |
| 265 | sigdelsetmask(&set, ~_BLOCKABLE); |
| 266 | spin_lock_irq(¤t->sighand->siglock); |
| 267 | current->blocked = set; |
| 268 | recalc_sigpending(); |
| 269 | spin_unlock_irq(¤t->sighand->siglock); |
| 270 | |
Stuart Menefy | f0bc814 | 2006-11-21 11:16:57 +0900 | [diff] [blame] | 271 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | goto badframe; |
| 273 | |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 274 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, |
| 275 | regs->regs[15]) == -EFAULT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | goto badframe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | return r0; |
| 279 | |
| 280 | badframe: |
| 281 | force_sig(SIGSEGV, current); |
| 282 | return 0; |
Paul Mundt | 3aeb884 | 2007-06-19 12:33:21 +0900 | [diff] [blame] | 283 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | /* |
| 286 | * Set up a signal frame. |
| 287 | */ |
| 288 | |
| 289 | static int |
| 290 | setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, |
| 291 | unsigned long mask) |
| 292 | { |
| 293 | int err = 0; |
| 294 | |
| 295 | #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x) |
| 296 | COPY(regs[0]); COPY(regs[1]); |
| 297 | COPY(regs[2]); COPY(regs[3]); |
| 298 | COPY(regs[4]); COPY(regs[5]); |
| 299 | COPY(regs[6]); COPY(regs[7]); |
| 300 | COPY(regs[8]); COPY(regs[9]); |
| 301 | COPY(regs[10]); COPY(regs[11]); |
| 302 | COPY(regs[12]); COPY(regs[13]); |
| 303 | COPY(regs[14]); COPY(regs[15]); |
| 304 | COPY(gbr); COPY(mach); |
| 305 | COPY(macl); COPY(pr); |
| 306 | COPY(sr); COPY(pc); |
| 307 | #undef COPY |
| 308 | |
| 309 | #ifdef CONFIG_SH_FPU |
| 310 | err |= save_sigcontext_fpu(sc, regs); |
| 311 | #endif |
| 312 | |
| 313 | /* non-iBCS2 extensions.. */ |
| 314 | err |= __put_user(mask, &sc->oldmask); |
| 315 | |
| 316 | return err; |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * Determine which stack to use.. |
| 321 | */ |
| 322 | static inline void __user * |
| 323 | get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size) |
| 324 | { |
| 325 | if (ka->sa.sa_flags & SA_ONSTACK) { |
| 326 | if (sas_ss_flags(sp) == 0) |
| 327 | sp = current->sas_ss_sp + current->sas_ss_size; |
| 328 | } |
| 329 | |
| 330 | return (void __user *)((sp - frame_size) & -8ul); |
| 331 | } |
| 332 | |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 333 | /* These symbols are defined with the addresses in the vsyscall page. |
| 334 | See vsyscall-trapa.S. */ |
| 335 | extern void __user __kernel_sigreturn; |
| 336 | extern void __user __kernel_rt_sigreturn; |
| 337 | |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 338 | static int setup_frame(int sig, struct k_sigaction *ka, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | sigset_t *set, struct pt_regs *regs) |
| 340 | { |
| 341 | struct sigframe __user *frame; |
| 342 | int err = 0; |
| 343 | int signal; |
| 344 | |
| 345 | frame = get_sigframe(ka, regs->regs[15], sizeof(*frame)); |
| 346 | |
| 347 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
| 348 | goto give_sigsegv; |
| 349 | |
| 350 | signal = current_thread_info()->exec_domain |
| 351 | && current_thread_info()->exec_domain->signal_invmap |
| 352 | && sig < 32 |
| 353 | ? current_thread_info()->exec_domain->signal_invmap[sig] |
| 354 | : sig; |
| 355 | |
| 356 | err |= setup_sigcontext(&frame->sc, regs, set->sig[0]); |
| 357 | |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 358 | if (_NSIG_WORDS > 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | err |= __copy_to_user(frame->extramask, &set->sig[1], |
| 360 | sizeof(frame->extramask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | |
| 362 | /* Set up to return from userspace. If provided, use a stub |
| 363 | already in userspace. */ |
| 364 | if (ka->sa.sa_flags & SA_RESTORER) { |
| 365 | regs->pr = (unsigned long) ka->sa.sa_restorer; |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 366 | #ifdef CONFIG_VSYSCALL |
| 367 | } else if (likely(current->mm->context.vdso)) { |
| 368 | regs->pr = VDSO_SYM(&__kernel_sigreturn); |
| 369 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } else { |
| 371 | /* Generate return code (system call to sigreturn) */ |
| 372 | err |= __put_user(MOVW(7), &frame->retcode[0]); |
Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 373 | err |= __put_user(TRAP_NOARG, &frame->retcode[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | err |= __put_user(OR_R0_R0, &frame->retcode[2]); |
| 375 | err |= __put_user(OR_R0_R0, &frame->retcode[3]); |
| 376 | err |= __put_user(OR_R0_R0, &frame->retcode[4]); |
| 377 | err |= __put_user(OR_R0_R0, &frame->retcode[5]); |
| 378 | err |= __put_user(OR_R0_R0, &frame->retcode[6]); |
| 379 | err |= __put_user((__NR_sigreturn), &frame->retcode[7]); |
| 380 | regs->pr = (unsigned long) frame->retcode; |
Stuart Menefy | f2fb4e4 | 2008-07-02 17:51:23 +0900 | [diff] [blame] | 381 | flush_icache_range(regs->pr, regs->pr + sizeof(frame->retcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | if (err) |
| 385 | goto give_sigsegv; |
| 386 | |
| 387 | /* Set up registers for signal handler */ |
| 388 | regs->regs[15] = (unsigned long) frame; |
| 389 | regs->regs[4] = signal; /* Arg for signal handler */ |
| 390 | regs->regs[5] = 0; |
| 391 | regs->regs[6] = (unsigned long) &frame->sc; |
Paul Mundt | 3bc24a1 | 2008-05-19 13:40:12 +0900 | [diff] [blame] | 392 | |
| 393 | if (current->personality & FDPIC_FUNCPTRS) { |
| 394 | struct fdpic_func_descriptor __user *funcptr = |
| 395 | (struct fdpic_func_descriptor __user *)ka->sa.sa_handler; |
| 396 | |
| 397 | __get_user(regs->pc, &funcptr->text); |
| 398 | __get_user(regs->regs[12], &funcptr->GOT); |
| 399 | } else |
| 400 | regs->pc = (unsigned long)ka->sa.sa_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
| 402 | set_fs(USER_DS); |
| 403 | |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 404 | pr_debug("SIG deliver (%s:%d): sp=%p pc=%08lx pr=%08lx\n", |
Alexey Dobriyan | 19c5870 | 2007-10-18 23:40:41 -0700 | [diff] [blame] | 405 | current->comm, task_pid_nr(current), frame, regs->pc, regs->pr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 407 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
| 409 | give_sigsegv: |
| 410 | force_sigsegv(sig, current); |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 411 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 414 | static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | sigset_t *set, struct pt_regs *regs) |
| 416 | { |
| 417 | struct rt_sigframe __user *frame; |
| 418 | int err = 0; |
| 419 | int signal; |
| 420 | |
| 421 | frame = get_sigframe(ka, regs->regs[15], sizeof(*frame)); |
| 422 | |
| 423 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
| 424 | goto give_sigsegv; |
| 425 | |
| 426 | signal = current_thread_info()->exec_domain |
| 427 | && current_thread_info()->exec_domain->signal_invmap |
| 428 | && sig < 32 |
| 429 | ? current_thread_info()->exec_domain->signal_invmap[sig] |
| 430 | : sig; |
| 431 | |
| 432 | err |= copy_siginfo_to_user(&frame->info, info); |
| 433 | |
| 434 | /* Create the ucontext. */ |
| 435 | err |= __put_user(0, &frame->uc.uc_flags); |
Paul Mundt | fa43972 | 2008-09-04 18:53:58 +0900 | [diff] [blame] | 436 | err |= __put_user(NULL, &frame->uc.uc_link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | err |= __put_user((void *)current->sas_ss_sp, |
| 438 | &frame->uc.uc_stack.ss_sp); |
| 439 | err |= __put_user(sas_ss_flags(regs->regs[15]), |
| 440 | &frame->uc.uc_stack.ss_flags); |
| 441 | err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); |
| 442 | err |= setup_sigcontext(&frame->uc.uc_mcontext, |
| 443 | regs, set->sig[0]); |
| 444 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
| 445 | |
| 446 | /* Set up to return from userspace. If provided, use a stub |
| 447 | already in userspace. */ |
| 448 | if (ka->sa.sa_flags & SA_RESTORER) { |
| 449 | regs->pr = (unsigned long) ka->sa.sa_restorer; |
Paul Mundt | 19f9a34 | 2006-09-27 18:33:49 +0900 | [diff] [blame] | 450 | #ifdef CONFIG_VSYSCALL |
| 451 | } else if (likely(current->mm->context.vdso)) { |
| 452 | regs->pr = VDSO_SYM(&__kernel_rt_sigreturn); |
| 453 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } else { |
| 455 | /* Generate return code (system call to rt_sigreturn) */ |
| 456 | err |= __put_user(MOVW(7), &frame->retcode[0]); |
Yoshinori Sato | 9d4436a | 2006-11-05 15:40:13 +0900 | [diff] [blame] | 457 | err |= __put_user(TRAP_NOARG, &frame->retcode[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | err |= __put_user(OR_R0_R0, &frame->retcode[2]); |
| 459 | err |= __put_user(OR_R0_R0, &frame->retcode[3]); |
| 460 | err |= __put_user(OR_R0_R0, &frame->retcode[4]); |
| 461 | err |= __put_user(OR_R0_R0, &frame->retcode[5]); |
| 462 | err |= __put_user(OR_R0_R0, &frame->retcode[6]); |
| 463 | err |= __put_user((__NR_rt_sigreturn), &frame->retcode[7]); |
| 464 | regs->pr = (unsigned long) frame->retcode; |
| 465 | } |
| 466 | |
| 467 | if (err) |
| 468 | goto give_sigsegv; |
| 469 | |
| 470 | /* Set up registers for signal handler */ |
| 471 | regs->regs[15] = (unsigned long) frame; |
| 472 | regs->regs[4] = signal; /* Arg for signal handler */ |
| 473 | regs->regs[5] = (unsigned long) &frame->info; |
| 474 | regs->regs[6] = (unsigned long) &frame->uc; |
Paul Mundt | 3bc24a1 | 2008-05-19 13:40:12 +0900 | [diff] [blame] | 475 | |
| 476 | if (current->personality & FDPIC_FUNCPTRS) { |
| 477 | struct fdpic_func_descriptor __user *funcptr = |
| 478 | (struct fdpic_func_descriptor __user *)ka->sa.sa_handler; |
| 479 | |
| 480 | __get_user(regs->pc, &funcptr->text); |
| 481 | __get_user(regs->regs[12], &funcptr->GOT); |
| 482 | } else |
| 483 | regs->pc = (unsigned long)ka->sa.sa_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | set_fs(USER_DS); |
| 486 | |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 487 | pr_debug("SIG deliver (%s:%d): sp=%p pc=%08lx pr=%08lx\n", |
Alexey Dobriyan | 19c5870 | 2007-10-18 23:40:41 -0700 | [diff] [blame] | 488 | current->comm, task_pid_nr(current), frame, regs->pc, regs->pr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Chris Smith | 09b5a10 | 2008-07-02 15:17:11 +0900 | [diff] [blame] | 490 | flush_icache_range(regs->pr, regs->pr + sizeof(frame->retcode)); |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 491 | |
| 492 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
| 494 | give_sigsegv: |
| 495 | force_sigsegv(sig, current); |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 496 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Paul Mundt | f8b890a | 2008-09-12 22:08:20 +0900 | [diff] [blame] | 499 | static inline void |
| 500 | handle_syscall_restart(unsigned long save_r0, struct pt_regs *regs, |
| 501 | struct sigaction *sa) |
| 502 | { |
| 503 | /* If we're not from a syscall, bail out */ |
| 504 | if (regs->tra < 0) |
| 505 | return; |
| 506 | |
| 507 | /* check for system call restart.. */ |
| 508 | switch (regs->regs[0]) { |
| 509 | case -ERESTART_RESTARTBLOCK: |
| 510 | case -ERESTARTNOHAND: |
| 511 | no_system_call_restart: |
| 512 | regs->regs[0] = -EINTR; |
| 513 | regs->sr |= 1; |
| 514 | break; |
| 515 | |
| 516 | case -ERESTARTSYS: |
| 517 | if (!(sa->sa_flags & SA_RESTART)) |
| 518 | goto no_system_call_restart; |
| 519 | /* fallthrough */ |
| 520 | case -ERESTARTNOINTR: |
| 521 | regs->regs[0] = save_r0; |
| 522 | regs->pc -= instruction_size(ctrl_inw(regs->pc - 4)); |
| 523 | break; |
| 524 | } |
| 525 | } |
| 526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | /* |
| 528 | * OK, we're invoking a handler |
| 529 | */ |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 530 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info, |
Kaz Kojima | 69a3314 | 2007-06-18 10:08:20 +0900 | [diff] [blame] | 532 | sigset_t *oldset, struct pt_regs *regs, unsigned int save_r0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | { |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 534 | int ret; |
| 535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | /* Set up the stack frame */ |
| 537 | if (ka->sa.sa_flags & SA_SIGINFO) |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 538 | ret = setup_rt_frame(sig, ka, info, oldset, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | else |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 540 | ret = setup_frame(sig, ka, oldset, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
| 542 | if (ka->sa.sa_flags & SA_ONESHOT) |
| 543 | ka->sa.sa_handler = SIG_DFL; |
| 544 | |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 545 | if (ret == 0) { |
| 546 | spin_lock_irq(¤t->sighand->siglock); |
| 547 | sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask); |
| 548 | if (!(ka->sa.sa_flags & SA_NODEFER)) |
| 549 | sigaddset(¤t->blocked,sig); |
| 550 | recalc_sigpending(); |
| 551 | spin_unlock_irq(¤t->sighand->siglock); |
| 552 | } |
| 553 | |
| 554 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | /* |
| 558 | * Note that 'init' is a special process: it doesn't get signals it doesn't |
| 559 | * want to handle. Thus you cannot kill init even with a SIGKILL even by |
| 560 | * mistake. |
| 561 | * |
| 562 | * Note that we go through the signals twice: once to check the signals that |
| 563 | * the kernel can handle, and then we build all the user-level signal handling |
| 564 | * stack-frames in one go after that. |
| 565 | */ |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 566 | static void do_signal(struct pt_regs *regs, unsigned int save_r0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | { |
| 568 | siginfo_t info; |
| 569 | int signr; |
| 570 | struct k_sigaction ka; |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 571 | sigset_t *oldset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
| 573 | /* |
| 574 | * We want the common case to go fast, which |
| 575 | * is why we may in certain cases get here from |
| 576 | * kernel mode. Just return without doing anything |
| 577 | * if so. |
| 578 | */ |
| 579 | if (!user_mode(regs)) |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 580 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Nigel Cunningham | 0e6c1f5 | 2005-07-27 11:43:34 -0700 | [diff] [blame] | 582 | if (try_to_freeze()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | goto no_signal; |
| 584 | |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 585 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) |
| 586 | oldset = ¤t->saved_sigmask; |
| 587 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | oldset = ¤t->blocked; |
| 589 | |
| 590 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); |
| 591 | if (signr > 0) { |
Paul Mundt | f8b890a | 2008-09-12 22:08:20 +0900 | [diff] [blame] | 592 | if (regs->sr & 1) |
| 593 | handle_syscall_restart(save_r0, regs, &ka.sa); |
| 594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | /* Whee! Actually deliver the signal. */ |
Paul Mundt | 3aeb884 | 2007-06-19 12:33:21 +0900 | [diff] [blame] | 596 | if (handle_signal(signr, &ka, &info, oldset, |
| 597 | regs, save_r0) == 0) { |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 598 | /* a signal was successfully delivered; the saved |
| 599 | * sigmask will have been stored in the signal frame, |
| 600 | * and will be restored by sigreturn, so we can simply |
| 601 | * clear the TIF_RESTORE_SIGMASK flag */ |
| 602 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) |
| 603 | clear_thread_flag(TIF_RESTORE_SIGMASK); |
Paul Mundt | ab99c73 | 2008-07-30 19:55:30 +0900 | [diff] [blame] | 604 | |
| 605 | tracehook_signal_handler(signr, &info, &ka, regs, |
| 606 | test_thread_flag(TIF_SINGLESTEP)); |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 607 | } |
Ryusuke Sakato | c8bfa1f | 2007-02-23 13:22:56 +0900 | [diff] [blame] | 608 | |
| 609 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Paul Mundt | ab99c73 | 2008-07-30 19:55:30 +0900 | [diff] [blame] | 612 | no_signal: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | /* Did we come from a system call? */ |
| 614 | if (regs->tra >= 0) { |
| 615 | /* Restart the system call - no handlers present */ |
| 616 | if (regs->regs[0] == -ERESTARTNOHAND || |
| 617 | regs->regs[0] == -ERESTARTSYS || |
Paul Mundt | 0b89293 | 2006-09-27 17:22:49 +0900 | [diff] [blame] | 618 | regs->regs[0] == -ERESTARTNOINTR) { |
Ryusuke Sakato | c8bfa1f | 2007-02-23 13:22:56 +0900 | [diff] [blame] | 619 | regs->regs[0] = save_r0; |
Paul Mundt | 53f983a | 2007-05-08 15:31:48 +0900 | [diff] [blame] | 620 | regs->pc -= instruction_size(ctrl_inw(regs->pc - 4)); |
Paul Mundt | 0b89293 | 2006-09-27 17:22:49 +0900 | [diff] [blame] | 621 | } else if (regs->regs[0] == -ERESTART_RESTARTBLOCK) { |
Paul Mundt | 53f983a | 2007-05-08 15:31:48 +0900 | [diff] [blame] | 622 | regs->pc -= instruction_size(ctrl_inw(regs->pc - 4)); |
Paul Mundt | 0b89293 | 2006-09-27 17:22:49 +0900 | [diff] [blame] | 623 | regs->regs[3] = __NR_restart_syscall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
| 625 | } |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 626 | |
| 627 | /* if there's no signal to deliver, we just put the saved sigmask |
| 628 | * back */ |
| 629 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) { |
| 630 | clear_thread_flag(TIF_RESTORE_SIGMASK); |
| 631 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned int save_r0, |
Paul Mundt | ab99c73 | 2008-07-30 19:55:30 +0900 | [diff] [blame] | 636 | unsigned long thread_info_flags) |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 637 | { |
| 638 | /* deal with pending signal delivery */ |
Paul Mundt | ab99c73 | 2008-07-30 19:55:30 +0900 | [diff] [blame] | 639 | if (thread_info_flags & _TIF_SIGPENDING) |
Paul Mundt | 9f23e7e | 2006-09-27 17:27:00 +0900 | [diff] [blame] | 640 | do_signal(regs, save_r0); |
Paul Mundt | ab99c73 | 2008-07-30 19:55:30 +0900 | [diff] [blame] | 641 | |
| 642 | if (thread_info_flags & _TIF_NOTIFY_RESUME) { |
| 643 | clear_thread_flag(TIF_NOTIFY_RESUME); |
| 644 | tracehook_notify_resume(regs); |
| 645 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |