Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
| 6 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 7 | * Copyright (C) 1994 - 2000 Ralf Baechle |
| 8 | * Copyright (C) 1999, 2000 Silicon Graphics, Inc. |
| 9 | */ |
Ralf Baechle | 02416dc | 2005-06-15 13:00:12 +0000 | [diff] [blame] | 10 | #include <linux/cache.h> |
Ralf Baechle | 1f71792 | 2011-07-27 11:44:47 +0100 | [diff] [blame] | 11 | #include <linux/irqflags.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/sched.h> |
| 13 | #include <linux/mm.h> |
| 14 | #include <linux/personality.h> |
| 15 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/kernel.h> |
| 17 | #include <linux/signal.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/wait.h> |
| 20 | #include <linux/ptrace.h> |
| 21 | #include <linux/unistd.h> |
| 22 | #include <linux/compiler.h> |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 23 | #include <linux/syscalls.h> |
Atsushi Nemoto | faea623 | 2007-04-16 23:19:44 +0900 | [diff] [blame] | 24 | #include <linux/uaccess.h> |
David Howells | 733e5e4 | 2009-09-09 08:30:21 +0100 | [diff] [blame] | 25 | #include <linux/tracehook.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Ralf Baechle | e50c0a8f | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 27 | #include <asm/abi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/asm.h> |
| 29 | #include <linux/bitops.h> |
| 30 | #include <asm/cacheflush.h> |
| 31 | #include <asm/fpu.h> |
| 32 | #include <asm/sim.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/ucontext.h> |
| 34 | #include <asm/cpu-features.h> |
Ralf Baechle | 02416dc | 2005-06-15 13:00:12 +0000 | [diff] [blame] | 35 | #include <asm/war.h> |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 36 | #include <asm/vdso.h> |
David Howells | b81947c | 2012-03-28 18:30:02 +0100 | [diff] [blame^] | 37 | #include <asm/dsp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #include "signal-common.h" |
| 40 | |
Ralf Baechle | 137f6f3 | 2009-11-24 19:35:41 +0000 | [diff] [blame] | 41 | static int (*save_fp_context)(struct sigcontext __user *sc); |
| 42 | static int (*restore_fp_context)(struct sigcontext __user *sc); |
| 43 | |
| 44 | extern asmlinkage int _save_fp_context(struct sigcontext __user *sc); |
| 45 | extern asmlinkage int _restore_fp_context(struct sigcontext __user *sc); |
| 46 | |
| 47 | extern asmlinkage int fpu_emulator_save_context(struct sigcontext __user *sc); |
| 48 | extern asmlinkage int fpu_emulator_restore_context(struct sigcontext __user *sc); |
| 49 | |
Ralf Baechle | 6668058 | 2007-02-13 01:31:48 +0000 | [diff] [blame] | 50 | struct sigframe { |
| 51 | u32 sf_ass[4]; /* argument save space for o32 */ |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 52 | u32 sf_pad[2]; /* Was: signal trampoline */ |
Ralf Baechle | 6668058 | 2007-02-13 01:31:48 +0000 | [diff] [blame] | 53 | struct sigcontext sf_sc; |
| 54 | sigset_t sf_mask; |
| 55 | }; |
| 56 | |
Franck Bui-Huu | c0b9bae | 2007-02-05 15:24:21 +0100 | [diff] [blame] | 57 | struct rt_sigframe { |
| 58 | u32 rs_ass[4]; /* argument save space for o32 */ |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 59 | u32 rs_pad[2]; /* Was: signal trampoline */ |
Franck Bui-Huu | c0b9bae | 2007-02-05 15:24:21 +0100 | [diff] [blame] | 60 | struct siginfo rs_info; |
| 61 | struct ucontext rs_uc; |
| 62 | }; |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | /* |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 65 | * Helper routines |
| 66 | */ |
Atsushi Nemoto | faea623 | 2007-04-16 23:19:44 +0900 | [diff] [blame] | 67 | static int protected_save_fp_context(struct sigcontext __user *sc) |
| 68 | { |
| 69 | int err; |
| 70 | while (1) { |
| 71 | lock_fpu_owner(); |
| 72 | own_fpu_inatomic(1); |
| 73 | err = save_fp_context(sc); /* this might fail */ |
| 74 | unlock_fpu_owner(); |
| 75 | if (likely(!err)) |
| 76 | break; |
| 77 | /* touch the sigcontext and try again */ |
| 78 | err = __put_user(0, &sc->sc_fpregs[0]) | |
| 79 | __put_user(0, &sc->sc_fpregs[31]) | |
| 80 | __put_user(0, &sc->sc_fpc_csr); |
| 81 | if (err) |
| 82 | break; /* really bad sigcontext */ |
| 83 | } |
| 84 | return err; |
| 85 | } |
| 86 | |
| 87 | static int protected_restore_fp_context(struct sigcontext __user *sc) |
| 88 | { |
David Daney | c726b82 | 2011-01-24 14:51:34 -0800 | [diff] [blame] | 89 | int err, tmp __maybe_unused; |
Atsushi Nemoto | faea623 | 2007-04-16 23:19:44 +0900 | [diff] [blame] | 90 | while (1) { |
| 91 | lock_fpu_owner(); |
| 92 | own_fpu_inatomic(0); |
| 93 | err = restore_fp_context(sc); /* this might fail */ |
| 94 | unlock_fpu_owner(); |
| 95 | if (likely(!err)) |
| 96 | break; |
| 97 | /* touch the sigcontext and try again */ |
| 98 | err = __get_user(tmp, &sc->sc_fpregs[0]) | |
| 99 | __get_user(tmp, &sc->sc_fpregs[31]) | |
| 100 | __get_user(tmp, &sc->sc_fpc_csr); |
| 101 | if (err) |
| 102 | break; /* really bad sigcontext */ |
| 103 | } |
| 104 | return err; |
| 105 | } |
| 106 | |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 107 | int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc) |
| 108 | { |
| 109 | int err = 0; |
| 110 | int i; |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 111 | unsigned int used_math; |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 112 | |
| 113 | err |= __put_user(regs->cp0_epc, &sc->sc_pc); |
| 114 | |
| 115 | err |= __put_user(0, &sc->sc_regs[0]); |
| 116 | for (i = 1; i < 32; i++) |
| 117 | err |= __put_user(regs->regs[i], &sc->sc_regs[i]); |
| 118 | |
Franck Bui-Huu | 9693a85 | 2007-02-02 17:41:47 +0100 | [diff] [blame] | 119 | #ifdef CONFIG_CPU_HAS_SMARTMIPS |
| 120 | err |= __put_user(regs->acx, &sc->sc_acx); |
| 121 | #endif |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 122 | err |= __put_user(regs->hi, &sc->sc_mdhi); |
| 123 | err |= __put_user(regs->lo, &sc->sc_mdlo); |
| 124 | if (cpu_has_dsp) { |
| 125 | err |= __put_user(mfhi1(), &sc->sc_hi1); |
| 126 | err |= __put_user(mflo1(), &sc->sc_lo1); |
| 127 | err |= __put_user(mfhi2(), &sc->sc_hi2); |
| 128 | err |= __put_user(mflo2(), &sc->sc_lo2); |
| 129 | err |= __put_user(mfhi3(), &sc->sc_hi3); |
| 130 | err |= __put_user(mflo3(), &sc->sc_lo3); |
| 131 | err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp); |
| 132 | } |
| 133 | |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 134 | used_math = !!used_math(); |
| 135 | err |= __put_user(used_math, &sc->sc_used_math); |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 136 | |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 137 | if (used_math) { |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 138 | /* |
| 139 | * Save FPU state to signal context. Signal handler |
| 140 | * will "inherit" current FPU state. |
| 141 | */ |
Atsushi Nemoto | faea623 | 2007-04-16 23:19:44 +0900 | [diff] [blame] | 142 | err |= protected_save_fp_context(sc); |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 143 | } |
| 144 | return err; |
| 145 | } |
| 146 | |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 147 | int fpcsr_pending(unsigned int __user *fpcsr) |
| 148 | { |
| 149 | int err, sig = 0; |
| 150 | unsigned int csr, enabled; |
| 151 | |
| 152 | err = __get_user(csr, fpcsr); |
| 153 | enabled = FPU_CSR_UNI_X | ((csr & FPU_CSR_ALL_E) << 5); |
| 154 | /* |
| 155 | * If the signal handler set some FPU exceptions, clear it and |
| 156 | * send SIGFPE. |
| 157 | */ |
| 158 | if (csr & enabled) { |
| 159 | csr &= ~enabled; |
| 160 | err |= __put_user(csr, fpcsr); |
| 161 | sig = SIGFPE; |
| 162 | } |
| 163 | return err ?: sig; |
| 164 | } |
| 165 | |
| 166 | static int |
| 167 | check_and_restore_fp_context(struct sigcontext __user *sc) |
| 168 | { |
| 169 | int err, sig; |
| 170 | |
| 171 | err = sig = fpcsr_pending(&sc->sc_fpc_csr); |
| 172 | if (err > 0) |
| 173 | err = 0; |
Atsushi Nemoto | faea623 | 2007-04-16 23:19:44 +0900 | [diff] [blame] | 174 | err |= protected_restore_fp_context(sc); |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 175 | return err ?: sig; |
| 176 | } |
| 177 | |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 178 | int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc) |
| 179 | { |
| 180 | unsigned int used_math; |
| 181 | unsigned long treg; |
| 182 | int err = 0; |
| 183 | int i; |
| 184 | |
| 185 | /* Always make any pending restarted system calls return -EINTR */ |
| 186 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 187 | |
| 188 | err |= __get_user(regs->cp0_epc, &sc->sc_pc); |
Franck Bui-Huu | 9693a85 | 2007-02-02 17:41:47 +0100 | [diff] [blame] | 189 | |
| 190 | #ifdef CONFIG_CPU_HAS_SMARTMIPS |
| 191 | err |= __get_user(regs->acx, &sc->sc_acx); |
| 192 | #endif |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 193 | err |= __get_user(regs->hi, &sc->sc_mdhi); |
| 194 | err |= __get_user(regs->lo, &sc->sc_mdlo); |
| 195 | if (cpu_has_dsp) { |
| 196 | err |= __get_user(treg, &sc->sc_hi1); mthi1(treg); |
| 197 | err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg); |
| 198 | err |= __get_user(treg, &sc->sc_hi2); mthi2(treg); |
| 199 | err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg); |
| 200 | err |= __get_user(treg, &sc->sc_hi3); mthi3(treg); |
| 201 | err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg); |
| 202 | err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK); |
| 203 | } |
| 204 | |
| 205 | for (i = 1; i < 32; i++) |
| 206 | err |= __get_user(regs->regs[i], &sc->sc_regs[i]); |
| 207 | |
| 208 | err |= __get_user(used_math, &sc->sc_used_math); |
| 209 | conditional_used_math(used_math); |
| 210 | |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 211 | if (used_math) { |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 212 | /* restore fpu context if we have used it before */ |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 213 | if (!err) |
| 214 | err = check_and_restore_fp_context(sc); |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 215 | } else { |
| 216 | /* signal handler may have used FPU. Give it up. */ |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 217 | lose_fpu(0); |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 218 | } |
| 219 | |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 220 | return err; |
| 221 | } |
| 222 | |
| 223 | void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, |
| 224 | size_t frame_size) |
| 225 | { |
| 226 | unsigned long sp; |
| 227 | |
| 228 | /* Default to using normal stack */ |
| 229 | sp = regs->regs[29]; |
| 230 | |
| 231 | /* |
| 232 | * FPU emulator may have it's own trampoline active just |
| 233 | * above the user stack, 16-bytes before the next lowest |
| 234 | * 16 byte boundary. Try to avoid trashing it. |
| 235 | */ |
| 236 | sp -= 32; |
| 237 | |
| 238 | /* This is the X/Open sanctioned signal stack switching. */ |
| 239 | if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0)) |
| 240 | sp = current->sas_ss_sp + current->sas_ss_size; |
| 241 | |
| 242 | return (void __user *)((sp - frame_size) & (ICACHE_REFILLS_WORKAROUND_WAR ? ~(cpu_icache_line_size()-1) : ALMASK)); |
| 243 | } |
| 244 | |
Franck Bui-Huu | c3fc4ab | 2007-02-05 15:24:20 +0100 | [diff] [blame] | 245 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | * Atomically swap in the new signal mask, and wait for a signal. |
| 247 | */ |
| 248 | |
| 249 | #ifdef CONFIG_TRAD_SIGNALS |
Franck Bui-Huu | f90080a | 2007-02-05 15:24:27 +0100 | [diff] [blame] | 250 | asmlinkage int sys_sigsuspend(nabi_no_regargs struct pt_regs regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 252 | sigset_t newset; |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 253 | sigset_t __user *uset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 255 | uset = (sigset_t __user *) regs.regs[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | if (copy_from_user(&newset, uset, sizeof(sigset_t))) |
| 257 | return -EFAULT; |
| 258 | sigdelsetmask(&newset, ~_BLOCKABLE); |
| 259 | |
| 260 | spin_lock_irq(¤t->sighand->siglock); |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 261 | current->saved_sigmask = current->blocked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | current->blocked = newset; |
| 263 | recalc_sigpending(); |
| 264 | spin_unlock_irq(¤t->sighand->siglock); |
| 265 | |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 266 | current->state = TASK_INTERRUPTIBLE; |
| 267 | schedule(); |
| 268 | set_thread_flag(TIF_RESTORE_SIGMASK); |
| 269 | return -ERESTARTNOHAND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |
| 271 | #endif |
| 272 | |
Franck Bui-Huu | f90080a | 2007-02-05 15:24:27 +0100 | [diff] [blame] | 273 | asmlinkage int sys_rt_sigsuspend(nabi_no_regargs struct pt_regs regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 275 | sigset_t newset; |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 276 | sigset_t __user *unewset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | size_t sigsetsize; |
| 278 | |
| 279 | /* XXX Don't preclude handling different sized sigset_t's. */ |
| 280 | sigsetsize = regs.regs[5]; |
| 281 | if (sigsetsize != sizeof(sigset_t)) |
| 282 | return -EINVAL; |
| 283 | |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 284 | unewset = (sigset_t __user *) regs.regs[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | if (copy_from_user(&newset, unewset, sizeof(newset))) |
| 286 | return -EFAULT; |
| 287 | sigdelsetmask(&newset, ~_BLOCKABLE); |
| 288 | |
| 289 | spin_lock_irq(¤t->sighand->siglock); |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 290 | current->saved_sigmask = current->blocked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | current->blocked = newset; |
Ralf Baechle | e0daad4 | 2007-02-05 00:10:11 +0000 | [diff] [blame] | 292 | recalc_sigpending(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | spin_unlock_irq(¤t->sighand->siglock); |
| 294 | |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 295 | current->state = TASK_INTERRUPTIBLE; |
| 296 | schedule(); |
| 297 | set_thread_flag(TIF_RESTORE_SIGMASK); |
| 298 | return -ERESTARTNOHAND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | #ifdef CONFIG_TRAD_SIGNALS |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 302 | SYSCALL_DEFINE3(sigaction, int, sig, const struct sigaction __user *, act, |
| 303 | struct sigaction __user *, oact) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
| 305 | struct k_sigaction new_ka, old_ka; |
| 306 | int ret; |
| 307 | int err = 0; |
| 308 | |
| 309 | if (act) { |
| 310 | old_sigset_t mask; |
| 311 | |
| 312 | if (!access_ok(VERIFY_READ, act, sizeof(*act))) |
| 313 | return -EFAULT; |
| 314 | err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler); |
| 315 | err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags); |
| 316 | err |= __get_user(mask, &act->sa_mask.sig[0]); |
| 317 | if (err) |
| 318 | return -EFAULT; |
| 319 | |
| 320 | siginitset(&new_ka.sa.sa_mask, mask); |
| 321 | } |
| 322 | |
| 323 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
| 324 | |
| 325 | if (!ret && oact) { |
| 326 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact))) |
Ralf Baechle | e0daad4 | 2007-02-05 00:10:11 +0000 | [diff] [blame] | 327 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags); |
| 329 | err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler); |
| 330 | err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig); |
| 331 | err |= __put_user(0, &oact->sa_mask.sig[1]); |
| 332 | err |= __put_user(0, &oact->sa_mask.sig[2]); |
| 333 | err |= __put_user(0, &oact->sa_mask.sig[3]); |
| 334 | if (err) |
| 335 | return -EFAULT; |
| 336 | } |
| 337 | |
| 338 | return ret; |
| 339 | } |
| 340 | #endif |
| 341 | |
| 342 | asmlinkage int sys_sigaltstack(nabi_no_regargs struct pt_regs regs) |
| 343 | { |
Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 344 | const stack_t __user *uss = (const stack_t __user *) regs.regs[4]; |
| 345 | stack_t __user *uoss = (stack_t __user *) regs.regs[5]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | unsigned long usp = regs.regs[29]; |
| 347 | |
| 348 | return do_sigaltstack(uss, uoss, usp); |
| 349 | } |
| 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | #ifdef CONFIG_TRAD_SIGNALS |
Franck Bui-Huu | f90080a | 2007-02-05 15:24:27 +0100 | [diff] [blame] | 352 | asmlinkage void sys_sigreturn(nabi_no_regargs struct pt_regs regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | { |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 354 | struct sigframe __user *frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | sigset_t blocked; |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 356 | int sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 358 | frame = (struct sigframe __user *) regs.regs[29]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 360 | goto badframe; |
| 361 | if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked))) |
| 362 | goto badframe; |
| 363 | |
| 364 | sigdelsetmask(&blocked, ~_BLOCKABLE); |
| 365 | spin_lock_irq(¤t->sighand->siglock); |
| 366 | current->blocked = blocked; |
| 367 | recalc_sigpending(); |
| 368 | spin_unlock_irq(¤t->sighand->siglock); |
| 369 | |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 370 | sig = restore_sigcontext(®s, &frame->sf_sc); |
| 371 | if (sig < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | goto badframe; |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 373 | else if (sig) |
| 374 | force_sig(sig, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
| 376 | /* |
| 377 | * Don't let your children do this ... |
| 378 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | __asm__ __volatile__( |
| 380 | "move\t$29, %0\n\t" |
| 381 | "j\tsyscall_exit" |
| 382 | :/* no outputs */ |
| 383 | :"r" (®s)); |
| 384 | /* Unreached */ |
| 385 | |
| 386 | badframe: |
| 387 | force_sig(SIGSEGV, current); |
| 388 | } |
Ralf Baechle | e50c0a8f | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 389 | #endif /* CONFIG_TRAD_SIGNALS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Franck Bui-Huu | f90080a | 2007-02-05 15:24:27 +0100 | [diff] [blame] | 391 | asmlinkage void sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | { |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 393 | struct rt_sigframe __user *frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | sigset_t set; |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 395 | int sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 397 | frame = (struct rt_sigframe __user *) regs.regs[29]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 399 | goto badframe; |
| 400 | if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set))) |
| 401 | goto badframe; |
| 402 | |
| 403 | sigdelsetmask(&set, ~_BLOCKABLE); |
| 404 | spin_lock_irq(¤t->sighand->siglock); |
| 405 | current->blocked = set; |
| 406 | recalc_sigpending(); |
| 407 | spin_unlock_irq(¤t->sighand->siglock); |
| 408 | |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 409 | sig = restore_sigcontext(®s, &frame->rs_uc.uc_mcontext); |
| 410 | if (sig < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | goto badframe; |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 412 | else if (sig) |
| 413 | force_sig(sig, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | /* It is more difficult to avoid calling this function than to |
| 416 | call it and ignore errors. */ |
Al Viro | 4bfb8c5 | 2010-09-28 18:50:57 +0100 | [diff] [blame] | 417 | do_sigaltstack(&frame->rs_uc.uc_stack, NULL, regs.regs[29]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
| 419 | /* |
| 420 | * Don't let your children do this ... |
| 421 | */ |
| 422 | __asm__ __volatile__( |
| 423 | "move\t$29, %0\n\t" |
| 424 | "j\tsyscall_exit" |
| 425 | :/* no outputs */ |
| 426 | :"r" (®s)); |
| 427 | /* Unreached */ |
| 428 | |
| 429 | badframe: |
| 430 | force_sig(SIGSEGV, current); |
| 431 | } |
| 432 | |
| 433 | #ifdef CONFIG_TRAD_SIGNALS |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 434 | static int setup_frame(void *sig_return, struct k_sigaction *ka, |
| 435 | struct pt_regs *regs, int signr, sigset_t *set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 437 | struct sigframe __user *frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | int err = 0; |
| 439 | |
| 440 | frame = get_sigframe(ka, regs, sizeof(*frame)); |
| 441 | if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame))) |
| 442 | goto give_sigsegv; |
| 443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | err |= setup_sigcontext(regs, &frame->sf_sc); |
| 445 | err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set)); |
| 446 | if (err) |
| 447 | goto give_sigsegv; |
| 448 | |
| 449 | /* |
| 450 | * Arguments to signal handler: |
| 451 | * |
| 452 | * a0 = signal number |
| 453 | * a1 = 0 (should be cause) |
| 454 | * a2 = pointer to struct sigcontext |
| 455 | * |
| 456 | * $25 and c0_epc point to the signal handler, $29 points to the |
| 457 | * struct sigframe. |
| 458 | */ |
| 459 | regs->regs[ 4] = signr; |
| 460 | regs->regs[ 5] = 0; |
| 461 | regs->regs[ 6] = (unsigned long) &frame->sf_sc; |
| 462 | regs->regs[29] = (unsigned long) frame; |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 463 | regs->regs[31] = (unsigned long) sig_return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler; |
| 465 | |
Franck Bui-Huu | 722bb63 | 2007-02-05 15:24:24 +0100 | [diff] [blame] | 466 | DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | current->comm, current->pid, |
Franck Bui-Huu | 722bb63 | 2007-02-05 15:24:24 +0100 | [diff] [blame] | 468 | frame, regs->cp0_epc, regs->regs[31]); |
Ralf Baechle | e0daad4 | 2007-02-05 00:10:11 +0000 | [diff] [blame] | 469 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 471 | give_sigsegv: |
| 472 | force_sigsegv(signr, current); |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 473 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | } |
| 475 | #endif |
| 476 | |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 477 | static int setup_rt_frame(void *sig_return, struct k_sigaction *ka, |
| 478 | struct pt_regs *regs, int signr, sigset_t *set, |
| 479 | siginfo_t *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 481 | struct rt_sigframe __user *frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | int err = 0; |
| 483 | |
| 484 | frame = get_sigframe(ka, regs, sizeof(*frame)); |
| 485 | if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame))) |
| 486 | goto give_sigsegv; |
| 487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | /* Create siginfo. */ |
| 489 | err |= copy_siginfo_to_user(&frame->rs_info, info); |
| 490 | |
| 491 | /* Create the ucontext. */ |
| 492 | err |= __put_user(0, &frame->rs_uc.uc_flags); |
Atsushi Nemoto | 5665a0a | 2006-02-02 01:26:34 +0900 | [diff] [blame] | 493 | err |= __put_user(NULL, &frame->rs_uc.uc_link); |
Atsushi Nemoto | 9c6031c | 2006-02-19 23:46:44 +0900 | [diff] [blame] | 494 | err |= __put_user((void __user *)current->sas_ss_sp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | &frame->rs_uc.uc_stack.ss_sp); |
| 496 | err |= __put_user(sas_ss_flags(regs->regs[29]), |
| 497 | &frame->rs_uc.uc_stack.ss_flags); |
| 498 | err |= __put_user(current->sas_ss_size, |
| 499 | &frame->rs_uc.uc_stack.ss_size); |
| 500 | err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext); |
| 501 | err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set)); |
| 502 | |
| 503 | if (err) |
| 504 | goto give_sigsegv; |
| 505 | |
| 506 | /* |
| 507 | * Arguments to signal handler: |
| 508 | * |
| 509 | * a0 = signal number |
| 510 | * a1 = 0 (should be cause) |
| 511 | * a2 = pointer to ucontext |
| 512 | * |
| 513 | * $25 and c0_epc point to the signal handler, $29 points to |
| 514 | * the struct rt_sigframe. |
| 515 | */ |
| 516 | regs->regs[ 4] = signr; |
| 517 | regs->regs[ 5] = (unsigned long) &frame->rs_info; |
| 518 | regs->regs[ 6] = (unsigned long) &frame->rs_uc; |
| 519 | regs->regs[29] = (unsigned long) frame; |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 520 | regs->regs[31] = (unsigned long) sig_return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler; |
| 522 | |
Franck Bui-Huu | 722bb63 | 2007-02-05 15:24:24 +0100 | [diff] [blame] | 523 | DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | current->comm, current->pid, |
| 525 | frame, regs->cp0_epc, regs->regs[31]); |
Franck Bui-Huu | 722bb63 | 2007-02-05 15:24:24 +0100 | [diff] [blame] | 526 | |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 527 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | give_sigsegv: |
| 530 | force_sigsegv(signr, current); |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 531 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Ralf Baechle | 151fd6a | 2007-02-15 11:40:37 +0000 | [diff] [blame] | 534 | struct mips_abi mips_abi = { |
| 535 | #ifdef CONFIG_TRAD_SIGNALS |
| 536 | .setup_frame = setup_frame, |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 537 | .signal_return_offset = offsetof(struct mips_vdso, signal_trampoline), |
Ralf Baechle | 151fd6a | 2007-02-15 11:40:37 +0000 | [diff] [blame] | 538 | #endif |
| 539 | .setup_rt_frame = setup_rt_frame, |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 540 | .rt_signal_return_offset = |
| 541 | offsetof(struct mips_vdso, rt_signal_trampoline), |
Ralf Baechle | 151fd6a | 2007-02-15 11:40:37 +0000 | [diff] [blame] | 542 | .restart = __NR_restart_syscall |
| 543 | }; |
| 544 | |
Franck Bui-Huu | e692eb3 | 2007-02-05 15:24:28 +0100 | [diff] [blame] | 545 | static int handle_signal(unsigned long sig, siginfo_t *info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs) |
| 547 | { |
Ralf Baechle | 129bc8f | 2005-07-11 20:45:51 +0000 | [diff] [blame] | 548 | int ret; |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 549 | struct mips_abi *abi = current->thread.abi; |
| 550 | void *vdso = current->mm->context.vdso; |
Ralf Baechle | 129bc8f | 2005-07-11 20:45:51 +0000 | [diff] [blame] | 551 | |
Al Viro | 8f5a00eb | 2010-09-28 18:50:37 +0100 | [diff] [blame] | 552 | if (regs->regs[0]) { |
| 553 | switch(regs->regs[2]) { |
| 554 | case ERESTART_RESTARTBLOCK: |
| 555 | case ERESTARTNOHAND: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | regs->regs[2] = EINTR; |
| 557 | break; |
Al Viro | 8f5a00eb | 2010-09-28 18:50:37 +0100 | [diff] [blame] | 558 | case ERESTARTSYS: |
| 559 | if (!(ka->sa.sa_flags & SA_RESTART)) { |
| 560 | regs->regs[2] = EINTR; |
| 561 | break; |
| 562 | } |
| 563 | /* fallthrough */ |
| 564 | case ERESTARTNOINTR: |
| 565 | regs->regs[7] = regs->regs[26]; |
| 566 | regs->regs[2] = regs->regs[0]; |
| 567 | regs->cp0_epc -= 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Al Viro | 8f5a00eb | 2010-09-28 18:50:37 +0100 | [diff] [blame] | 570 | regs->regs[0] = 0; /* Don't deal with this again. */ |
| 571 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
Ralf Baechle | e50c0a8f | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 573 | if (sig_uses_siginfo(ka)) |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 574 | ret = abi->setup_rt_frame(vdso + abi->rt_signal_return_offset, |
| 575 | ka, regs, sig, oldset, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | else |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 577 | ret = abi->setup_frame(vdso + abi->signal_return_offset, |
| 578 | ka, regs, sig, oldset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Al Viro | 062ab57 | 2010-09-28 18:50:17 +0100 | [diff] [blame] | 580 | if (ret) |
| 581 | return ret; |
| 582 | |
Steven Rostedt | 69be8f1 | 2005-08-29 11:44:09 -0400 | [diff] [blame] | 583 | spin_lock_irq(¤t->sighand->siglock); |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 584 | sigorsets(¤t->blocked, ¤t->blocked, &ka->sa.sa_mask); |
Steven Rostedt | 69be8f1 | 2005-08-29 11:44:09 -0400 | [diff] [blame] | 585 | if (!(ka->sa.sa_flags & SA_NODEFER)) |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 586 | sigaddset(¤t->blocked, sig); |
Steven Rostedt | 69be8f1 | 2005-08-29 11:44:09 -0400 | [diff] [blame] | 587 | recalc_sigpending(); |
| 588 | spin_unlock_irq(¤t->sighand->siglock); |
Ralf Baechle | 129bc8f | 2005-07-11 20:45:51 +0000 | [diff] [blame] | 589 | |
| 590 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Ralf Baechle | 151fd6a | 2007-02-15 11:40:37 +0000 | [diff] [blame] | 593 | static void do_signal(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | { |
| 595 | struct k_sigaction ka; |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 596 | sigset_t *oldset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | siginfo_t info; |
| 598 | int signr; |
| 599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | /* |
| 601 | * We want the common case to go fast, which is why we may in certain |
| 602 | * cases get here from kernel mode. Just return without doing anything |
| 603 | * if so. |
| 604 | */ |
| 605 | if (!user_mode(regs)) |
Ralf Baechle | 40ac5d4 | 2006-02-08 13:38:18 +0000 | [diff] [blame] | 606 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 608 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) |
| 609 | oldset = ¤t->saved_sigmask; |
| 610 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | oldset = ¤t->blocked; |
| 612 | |
| 613 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 614 | if (signr > 0) { |
| 615 | /* Whee! Actually deliver the signal. */ |
| 616 | if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { |
| 617 | /* |
| 618 | * A signal was successfully delivered; the saved |
| 619 | * sigmask will have been stored in the signal frame, |
| 620 | * and will be restored by sigreturn, so we can simply |
| 621 | * clear the TIF_RESTORE_SIGMASK flag. |
| 622 | */ |
| 623 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) |
| 624 | clear_thread_flag(TIF_RESTORE_SIGMASK); |
| 625 | } |
Ralf Baechle | 45887e1 | 2006-08-03 21:54:13 +0100 | [diff] [blame] | 626 | |
| 627 | return; |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 628 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | if (regs->regs[0]) { |
| 631 | if (regs->regs[2] == ERESTARTNOHAND || |
| 632 | regs->regs[2] == ERESTARTSYS || |
| 633 | regs->regs[2] == ERESTARTNOINTR) { |
Al Viro | 8f5a00eb | 2010-09-28 18:50:37 +0100 | [diff] [blame] | 634 | regs->regs[2] = regs->regs[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | regs->regs[7] = regs->regs[26]; |
Al Viro | 8f5a00eb | 2010-09-28 18:50:37 +0100 | [diff] [blame] | 636 | regs->cp0_epc -= 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
| 638 | if (regs->regs[2] == ERESTART_RESTARTBLOCK) { |
Ralf Baechle | 151fd6a | 2007-02-15 11:40:37 +0000 | [diff] [blame] | 639 | regs->regs[2] = current->thread.abi->restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | regs->regs[7] = regs->regs[26]; |
| 641 | regs->cp0_epc -= 4; |
| 642 | } |
Ralf Baechle | 13fdd31 | 2006-08-08 03:47:01 +0100 | [diff] [blame] | 643 | regs->regs[0] = 0; /* Don't deal with this again. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | } |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 645 | |
| 646 | /* |
| 647 | * If there's no signal to deliver, we just put the saved sigmask |
| 648 | * back |
| 649 | */ |
| 650 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) { |
| 651 | clear_thread_flag(TIF_RESTORE_SIGMASK); |
| 652 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); |
| 653 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | /* |
| 657 | * notification of userspace execution resumption |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 658 | * - triggered by the TIF_WORK_MASK flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | */ |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 660 | asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | __u32 thread_info_flags) |
| 662 | { |
Ralf Baechle | 1f71792 | 2011-07-27 11:44:47 +0100 | [diff] [blame] | 663 | local_irq_enable(); |
| 664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | /* deal with pending signal delivery */ |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 666 | if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) |
Ralf Baechle | 151fd6a | 2007-02-15 11:40:37 +0000 | [diff] [blame] | 667 | do_signal(regs); |
David Howells | d0420c8 | 2009-09-02 09:14:16 +0100 | [diff] [blame] | 668 | |
| 669 | if (thread_info_flags & _TIF_NOTIFY_RESUME) { |
| 670 | clear_thread_flag(TIF_NOTIFY_RESUME); |
| 671 | tracehook_notify_resume(regs); |
David Howells | ee18d64 | 2009-09-02 09:14:21 +0100 | [diff] [blame] | 672 | if (current->replacement_session_keyring) |
| 673 | key_replace_session_keyring(); |
David Howells | d0420c8 | 2009-09-02 09:14:16 +0100 | [diff] [blame] | 674 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | } |
Ralf Baechle | 137f6f3 | 2009-11-24 19:35:41 +0000 | [diff] [blame] | 676 | |
| 677 | #ifdef CONFIG_SMP |
| 678 | static int smp_save_fp_context(struct sigcontext __user *sc) |
| 679 | { |
| 680 | return raw_cpu_has_fpu |
| 681 | ? _save_fp_context(sc) |
| 682 | : fpu_emulator_save_context(sc); |
| 683 | } |
| 684 | |
| 685 | static int smp_restore_fp_context(struct sigcontext __user *sc) |
| 686 | { |
| 687 | return raw_cpu_has_fpu |
| 688 | ? _restore_fp_context(sc) |
| 689 | : fpu_emulator_restore_context(sc); |
| 690 | } |
| 691 | #endif |
| 692 | |
| 693 | static int signal_setup(void) |
| 694 | { |
| 695 | #ifdef CONFIG_SMP |
| 696 | /* For now just do the cpu_has_fpu check when the functions are invoked */ |
| 697 | save_fp_context = smp_save_fp_context; |
| 698 | restore_fp_context = smp_restore_fp_context; |
| 699 | #else |
| 700 | if (cpu_has_fpu) { |
| 701 | save_fp_context = _save_fp_context; |
| 702 | restore_fp_context = _restore_fp_context; |
| 703 | } else { |
| 704 | save_fp_context = fpu_emulator_save_context; |
| 705 | restore_fp_context = fpu_emulator_restore_context; |
| 706 | } |
| 707 | #endif |
| 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | arch_initcall(signal_setup); |