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 |
Martin Michlmayr | dda73d0 | 2006-02-18 15:21:30 +0000 | [diff] [blame] | 7 | * Copyright (C) 1994 - 2000, 2006 Ralf Baechle |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 431dc80 | 2007-02-13 00:05:11 +0000 | [diff] [blame] | 11 | #include <linux/compat.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/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/signal.h> |
| 17 | #include <linux/syscalls.h> |
| 18 | #include <linux/errno.h> |
| 19 | #include <linux/wait.h> |
| 20 | #include <linux/ptrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/suspend.h> |
| 22 | #include <linux/compiler.h> |
Atsushi Nemoto | faea623 | 2007-04-16 23:19:44 +0900 | [diff] [blame] | 23 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 25 | #include <asm/abi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/asm.h> |
Ralf Baechle | 431dc80 | 2007-02-13 00:05:11 +0000 | [diff] [blame] | 27 | #include <asm/compat-signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/bitops.h> |
| 29 | #include <asm/cacheflush.h> |
| 30 | #include <asm/sim.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/ucontext.h> |
| 32 | #include <asm/system.h> |
| 33 | #include <asm/fpu.h> |
Ralf Baechle | 02416dc | 2005-06-15 13:00:12 +0000 | [diff] [blame] | 34 | #include <asm/war.h> |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 35 | #include <asm/vdso.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Franck Bui-Huu | 36a1f2c | 2007-02-05 15:24:22 +0100 | [diff] [blame] | 37 | #include "signal-common.h" |
| 38 | |
Ralf Baechle | 137f6f3 | 2009-11-24 19:35:41 +0000 | [diff] [blame] | 39 | static int (*save_fp_context32)(struct sigcontext32 __user *sc); |
| 40 | static int (*restore_fp_context32)(struct sigcontext32 __user *sc); |
| 41 | |
| 42 | extern asmlinkage int _save_fp_context32(struct sigcontext32 __user *sc); |
| 43 | extern asmlinkage int _restore_fp_context32(struct sigcontext32 __user *sc); |
| 44 | |
| 45 | extern asmlinkage int fpu_emulator_save_context32(struct sigcontext32 __user *sc); |
| 46 | extern asmlinkage int fpu_emulator_restore_context32(struct sigcontext32 __user *sc); |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | /* |
| 49 | * Including <asm/unistd.h> would give use the 64-bit syscall numbers ... |
| 50 | */ |
Ralf Baechle | 151fd6a | 2007-02-15 11:40:37 +0000 | [diff] [blame] | 51 | #define __NR_O32_restart_syscall 4253 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /* 32-bit compatibility types */ |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | typedef unsigned int __sighandler32_t; |
| 56 | typedef void (*vfptr_t)(void); |
| 57 | |
| 58 | struct sigaction32 { |
| 59 | unsigned int sa_flags; |
| 60 | __sighandler32_t sa_handler; |
| 61 | compat_sigset_t sa_mask; |
| 62 | }; |
| 63 | |
| 64 | /* IRIX compatible stack_t */ |
| 65 | typedef struct sigaltstack32 { |
| 66 | s32 ss_sp; |
| 67 | compat_size_t ss_size; |
| 68 | int ss_flags; |
| 69 | } stack32_t; |
| 70 | |
| 71 | struct ucontext32 { |
| 72 | u32 uc_flags; |
| 73 | s32 uc_link; |
| 74 | stack32_t uc_stack; |
| 75 | struct sigcontext32 uc_mcontext; |
Ralf Baechle | 01ee603 | 2007-02-11 18:22:36 +0000 | [diff] [blame] | 76 | compat_sigset_t uc_sigmask; /* mask last for extensibility */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Ralf Baechle | dd02f06 | 2007-02-13 00:50:57 +0000 | [diff] [blame] | 79 | struct sigframe32 { |
| 80 | u32 sf_ass[4]; /* argument save space for o32 */ |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 81 | u32 sf_pad[2]; /* Was: signal trampoline */ |
Ralf Baechle | dd02f06 | 2007-02-13 00:50:57 +0000 | [diff] [blame] | 82 | struct sigcontext32 sf_sc; |
Atsushi Nemoto | 755f21b | 2007-02-14 14:41:01 +0900 | [diff] [blame] | 83 | compat_sigset_t sf_mask; |
Ralf Baechle | dd02f06 | 2007-02-13 00:50:57 +0000 | [diff] [blame] | 84 | }; |
| 85 | |
Franck Bui-Huu | c0b9bae | 2007-02-05 15:24:21 +0100 | [diff] [blame] | 86 | struct rt_sigframe32 { |
| 87 | u32 rs_ass[4]; /* argument save space for o32 */ |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 88 | u32 rs_pad[2]; /* Was: signal trampoline */ |
Franck Bui-Huu | c0b9bae | 2007-02-05 15:24:21 +0100 | [diff] [blame] | 89 | compat_siginfo_t rs_info; |
| 90 | struct ucontext32 rs_uc; |
| 91 | }; |
| 92 | |
Franck Bui-Huu | 9432a9b | 2007-02-05 15:24:25 +0100 | [diff] [blame] | 93 | /* |
| 94 | * sigcontext handlers |
| 95 | */ |
Atsushi Nemoto | faea623 | 2007-04-16 23:19:44 +0900 | [diff] [blame] | 96 | static int protected_save_fp_context32(struct sigcontext32 __user *sc) |
| 97 | { |
| 98 | int err; |
| 99 | while (1) { |
| 100 | lock_fpu_owner(); |
| 101 | own_fpu_inatomic(1); |
| 102 | err = save_fp_context32(sc); /* this might fail */ |
| 103 | unlock_fpu_owner(); |
| 104 | if (likely(!err)) |
| 105 | break; |
| 106 | /* touch the sigcontext and try again */ |
| 107 | err = __put_user(0, &sc->sc_fpregs[0]) | |
| 108 | __put_user(0, &sc->sc_fpregs[31]) | |
| 109 | __put_user(0, &sc->sc_fpc_csr); |
| 110 | if (err) |
| 111 | break; /* really bad sigcontext */ |
| 112 | } |
| 113 | return err; |
| 114 | } |
| 115 | |
| 116 | static int protected_restore_fp_context32(struct sigcontext32 __user *sc) |
| 117 | { |
| 118 | int err, tmp; |
| 119 | while (1) { |
| 120 | lock_fpu_owner(); |
| 121 | own_fpu_inatomic(0); |
| 122 | err = restore_fp_context32(sc); /* this might fail */ |
| 123 | unlock_fpu_owner(); |
| 124 | if (likely(!err)) |
| 125 | break; |
| 126 | /* touch the sigcontext and try again */ |
| 127 | err = __get_user(tmp, &sc->sc_fpregs[0]) | |
| 128 | __get_user(tmp, &sc->sc_fpregs[31]) | |
| 129 | __get_user(tmp, &sc->sc_fpc_csr); |
| 130 | if (err) |
| 131 | break; /* really bad sigcontext */ |
| 132 | } |
| 133 | return err; |
| 134 | } |
| 135 | |
Franck Bui-Huu | 9432a9b | 2007-02-05 15:24:25 +0100 | [diff] [blame] | 136 | static int setup_sigcontext32(struct pt_regs *regs, |
| 137 | struct sigcontext32 __user *sc) |
| 138 | { |
| 139 | int err = 0; |
| 140 | int i; |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 141 | u32 used_math; |
Franck Bui-Huu | 9432a9b | 2007-02-05 15:24:25 +0100 | [diff] [blame] | 142 | |
| 143 | err |= __put_user(regs->cp0_epc, &sc->sc_pc); |
Franck Bui-Huu | 9432a9b | 2007-02-05 15:24:25 +0100 | [diff] [blame] | 144 | |
| 145 | err |= __put_user(0, &sc->sc_regs[0]); |
| 146 | for (i = 1; i < 32; i++) |
| 147 | err |= __put_user(regs->regs[i], &sc->sc_regs[i]); |
| 148 | |
| 149 | err |= __put_user(regs->hi, &sc->sc_mdhi); |
| 150 | err |= __put_user(regs->lo, &sc->sc_mdlo); |
| 151 | if (cpu_has_dsp) { |
| 152 | err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp); |
| 153 | err |= __put_user(mfhi1(), &sc->sc_hi1); |
| 154 | err |= __put_user(mflo1(), &sc->sc_lo1); |
| 155 | err |= __put_user(mfhi2(), &sc->sc_hi2); |
| 156 | err |= __put_user(mflo2(), &sc->sc_lo2); |
| 157 | err |= __put_user(mfhi3(), &sc->sc_hi3); |
| 158 | err |= __put_user(mflo3(), &sc->sc_lo3); |
| 159 | } |
| 160 | |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 161 | used_math = !!used_math(); |
| 162 | err |= __put_user(used_math, &sc->sc_used_math); |
Franck Bui-Huu | 9432a9b | 2007-02-05 15:24:25 +0100 | [diff] [blame] | 163 | |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 164 | if (used_math) { |
Franck Bui-Huu | 9432a9b | 2007-02-05 15:24:25 +0100 | [diff] [blame] | 165 | /* |
| 166 | * Save FPU state to signal context. Signal handler |
| 167 | * will "inherit" current FPU state. |
| 168 | */ |
Atsushi Nemoto | faea623 | 2007-04-16 23:19:44 +0900 | [diff] [blame] | 169 | err |= protected_save_fp_context32(sc); |
Franck Bui-Huu | 9432a9b | 2007-02-05 15:24:25 +0100 | [diff] [blame] | 170 | } |
| 171 | return err; |
| 172 | } |
| 173 | |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 174 | static int |
| 175 | check_and_restore_fp_context32(struct sigcontext32 __user *sc) |
| 176 | { |
| 177 | int err, sig; |
| 178 | |
| 179 | err = sig = fpcsr_pending(&sc->sc_fpc_csr); |
| 180 | if (err > 0) |
| 181 | err = 0; |
Atsushi Nemoto | faea623 | 2007-04-16 23:19:44 +0900 | [diff] [blame] | 182 | err |= protected_restore_fp_context32(sc); |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 183 | return err ?: sig; |
| 184 | } |
| 185 | |
Franck Bui-Huu | 9432a9b | 2007-02-05 15:24:25 +0100 | [diff] [blame] | 186 | static int restore_sigcontext32(struct pt_regs *regs, |
| 187 | struct sigcontext32 __user *sc) |
| 188 | { |
| 189 | u32 used_math; |
| 190 | int err = 0; |
| 191 | s32 treg; |
| 192 | int i; |
| 193 | |
| 194 | /* Always make any pending restarted system calls return -EINTR */ |
| 195 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 196 | |
| 197 | err |= __get_user(regs->cp0_epc, &sc->sc_pc); |
| 198 | err |= __get_user(regs->hi, &sc->sc_mdhi); |
| 199 | err |= __get_user(regs->lo, &sc->sc_mdlo); |
| 200 | if (cpu_has_dsp) { |
| 201 | err |= __get_user(treg, &sc->sc_hi1); mthi1(treg); |
| 202 | err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg); |
| 203 | err |= __get_user(treg, &sc->sc_hi2); mthi2(treg); |
| 204 | err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg); |
| 205 | err |= __get_user(treg, &sc->sc_hi3); mthi3(treg); |
| 206 | err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg); |
| 207 | err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK); |
| 208 | } |
| 209 | |
| 210 | for (i = 1; i < 32; i++) |
| 211 | err |= __get_user(regs->regs[i], &sc->sc_regs[i]); |
| 212 | |
| 213 | err |= __get_user(used_math, &sc->sc_used_math); |
| 214 | conditional_used_math(used_math); |
| 215 | |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 216 | if (used_math) { |
Franck Bui-Huu | 9432a9b | 2007-02-05 15:24:25 +0100 | [diff] [blame] | 217 | /* restore fpu context if we have used it before */ |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 218 | if (!err) |
| 219 | err = check_and_restore_fp_context32(sc); |
Franck Bui-Huu | 9432a9b | 2007-02-05 15:24:25 +0100 | [diff] [blame] | 220 | } else { |
| 221 | /* signal handler may have used FPU. Give it up. */ |
Atsushi Nemoto | 53dc802 | 2007-03-10 01:07:45 +0900 | [diff] [blame] | 222 | lose_fpu(0); |
Franck Bui-Huu | 9432a9b | 2007-02-05 15:24:25 +0100 | [diff] [blame] | 223 | } |
| 224 | |
Franck Bui-Huu | 9432a9b | 2007-02-05 15:24:25 +0100 | [diff] [blame] | 225 | return err; |
| 226 | } |
| 227 | |
| 228 | /* |
| 229 | * |
| 230 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | extern void __put_sigset_unknown_nsig(void); |
| 232 | extern void __get_sigset_unknown_nsig(void); |
| 233 | |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 234 | static inline int put_sigset(const sigset_t *kbuf, compat_sigset_t __user *ubuf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
| 236 | int err = 0; |
| 237 | |
| 238 | if (!access_ok(VERIFY_WRITE, ubuf, sizeof(*ubuf))) |
| 239 | return -EFAULT; |
| 240 | |
| 241 | switch (_NSIG_WORDS) { |
| 242 | default: |
| 243 | __put_sigset_unknown_nsig(); |
| 244 | case 2: |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 245 | err |= __put_user(kbuf->sig[1] >> 32, &ubuf->sig[3]); |
| 246 | err |= __put_user(kbuf->sig[1] & 0xffffffff, &ubuf->sig[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | case 1: |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 248 | err |= __put_user(kbuf->sig[0] >> 32, &ubuf->sig[1]); |
| 249 | err |= __put_user(kbuf->sig[0] & 0xffffffff, &ubuf->sig[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | return err; |
| 253 | } |
| 254 | |
Atsushi Nemoto | 9c6031c | 2006-02-19 23:46:44 +0900 | [diff] [blame] | 255 | static inline int get_sigset(sigset_t *kbuf, const compat_sigset_t __user *ubuf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
| 257 | int err = 0; |
| 258 | unsigned long sig[4]; |
| 259 | |
| 260 | if (!access_ok(VERIFY_READ, ubuf, sizeof(*ubuf))) |
| 261 | return -EFAULT; |
| 262 | |
| 263 | switch (_NSIG_WORDS) { |
| 264 | default: |
| 265 | __get_sigset_unknown_nsig(); |
| 266 | case 2: |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 267 | err |= __get_user(sig[3], &ubuf->sig[3]); |
| 268 | err |= __get_user(sig[2], &ubuf->sig[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | kbuf->sig[1] = sig[2] | (sig[3] << 32); |
| 270 | case 1: |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 271 | err |= __get_user(sig[1], &ubuf->sig[1]); |
| 272 | err |= __get_user(sig[0], &ubuf->sig[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | kbuf->sig[0] = sig[0] | (sig[1] << 32); |
| 274 | } |
| 275 | |
| 276 | return err; |
| 277 | } |
| 278 | |
| 279 | /* |
| 280 | * Atomically swap in the new signal mask, and wait for a signal. |
| 281 | */ |
| 282 | |
Franck Bui-Huu | f90080a | 2007-02-05 15:24:27 +0100 | [diff] [blame] | 283 | asmlinkage int sys32_sigsuspend(nabi_no_regargs struct pt_regs regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
Atsushi Nemoto | 9c6031c | 2006-02-19 23:46:44 +0900 | [diff] [blame] | 285 | compat_sigset_t __user *uset; |
Martin Michlmayr | 68fa383 | 2006-02-18 14:55:45 +0000 | [diff] [blame] | 286 | sigset_t newset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Atsushi Nemoto | 9c6031c | 2006-02-19 23:46:44 +0900 | [diff] [blame] | 288 | uset = (compat_sigset_t __user *) regs.regs[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | if (get_sigset(&newset, uset)) |
| 290 | return -EFAULT; |
| 291 | sigdelsetmask(&newset, ~_BLOCKABLE); |
| 292 | |
| 293 | spin_lock_irq(¤t->sighand->siglock); |
Martin Michlmayr | 68fa383 | 2006-02-18 14:55:45 +0000 | [diff] [blame] | 294 | current->saved_sigmask = current->blocked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | current->blocked = newset; |
| 296 | recalc_sigpending(); |
| 297 | spin_unlock_irq(¤t->sighand->siglock); |
| 298 | |
Martin Michlmayr | 68fa383 | 2006-02-18 14:55:45 +0000 | [diff] [blame] | 299 | current->state = TASK_INTERRUPTIBLE; |
| 300 | schedule(); |
| 301 | set_thread_flag(TIF_RESTORE_SIGMASK); |
| 302 | return -ERESTARTNOHAND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Franck Bui-Huu | f90080a | 2007-02-05 15:24:27 +0100 | [diff] [blame] | 305 | asmlinkage int sys32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
Atsushi Nemoto | 9c6031c | 2006-02-19 23:46:44 +0900 | [diff] [blame] | 307 | compat_sigset_t __user *uset; |
Martin Michlmayr | 68fa383 | 2006-02-18 14:55:45 +0000 | [diff] [blame] | 308 | sigset_t newset; |
Ralf Baechle | 304416d | 2006-02-18 18:20:47 +0000 | [diff] [blame] | 309 | size_t sigsetsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
| 311 | /* XXX Don't preclude handling different sized sigset_t's. */ |
| 312 | sigsetsize = regs.regs[5]; |
| 313 | if (sigsetsize != sizeof(compat_sigset_t)) |
| 314 | return -EINVAL; |
| 315 | |
Atsushi Nemoto | 9c6031c | 2006-02-19 23:46:44 +0900 | [diff] [blame] | 316 | uset = (compat_sigset_t __user *) regs.regs[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | if (get_sigset(&newset, uset)) |
| 318 | return -EFAULT; |
| 319 | sigdelsetmask(&newset, ~_BLOCKABLE); |
| 320 | |
| 321 | spin_lock_irq(¤t->sighand->siglock); |
Martin Michlmayr | 68fa383 | 2006-02-18 14:55:45 +0000 | [diff] [blame] | 322 | current->saved_sigmask = current->blocked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | current->blocked = newset; |
Martin Michlmayr | 6254944 | 2006-02-18 20:06:32 +0000 | [diff] [blame] | 324 | recalc_sigpending(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | spin_unlock_irq(¤t->sighand->siglock); |
| 326 | |
Martin Michlmayr | 68fa383 | 2006-02-18 14:55:45 +0000 | [diff] [blame] | 327 | current->state = TASK_INTERRUPTIBLE; |
| 328 | schedule(); |
| 329 | set_thread_flag(TIF_RESTORE_SIGMASK); |
| 330 | return -ERESTARTNOHAND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 333 | SYSCALL_DEFINE3(32_sigaction, long, sig, const struct sigaction32 __user *, act, |
| 334 | struct sigaction32 __user *, oact) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
| 336 | struct k_sigaction new_ka, old_ka; |
| 337 | int ret; |
| 338 | int err = 0; |
| 339 | |
| 340 | if (act) { |
| 341 | old_sigset_t mask; |
Ralf Baechle | 77c728c | 2005-03-04 19:36:51 +0000 | [diff] [blame] | 342 | s32 handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
| 344 | if (!access_ok(VERIFY_READ, act, sizeof(*act))) |
| 345 | return -EFAULT; |
Ralf Baechle | 77c728c | 2005-03-04 19:36:51 +0000 | [diff] [blame] | 346 | err |= __get_user(handler, &act->sa_handler); |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 347 | new_ka.sa.sa_handler = (void __user *)(s64)handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags); |
| 349 | err |= __get_user(mask, &act->sa_mask.sig[0]); |
| 350 | if (err) |
| 351 | return -EFAULT; |
| 352 | |
| 353 | siginitset(&new_ka.sa.sa_mask, mask); |
| 354 | } |
| 355 | |
| 356 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
| 357 | |
| 358 | if (!ret && oact) { |
| 359 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact))) |
Martin Michlmayr | 6254944 | 2006-02-18 20:06:32 +0000 | [diff] [blame] | 360 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags); |
| 362 | err |= __put_user((u32)(u64)old_ka.sa.sa_handler, |
| 363 | &oact->sa_handler); |
| 364 | err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig); |
Martin Michlmayr | 6254944 | 2006-02-18 20:06:32 +0000 | [diff] [blame] | 365 | err |= __put_user(0, &oact->sa_mask.sig[1]); |
| 366 | err |= __put_user(0, &oact->sa_mask.sig[2]); |
| 367 | err |= __put_user(0, &oact->sa_mask.sig[3]); |
| 368 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return -EFAULT; |
| 370 | } |
| 371 | |
| 372 | return ret; |
| 373 | } |
| 374 | |
| 375 | asmlinkage int sys32_sigaltstack(nabi_no_regargs struct pt_regs regs) |
| 376 | { |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 377 | const stack32_t __user *uss = (const stack32_t __user *) regs.regs[4]; |
| 378 | stack32_t __user *uoss = (stack32_t __user *) regs.regs[5]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | unsigned long usp = regs.regs[29]; |
| 380 | stack_t kss, koss; |
| 381 | int ret, err = 0; |
| 382 | mm_segment_t old_fs = get_fs(); |
| 383 | s32 sp; |
| 384 | |
| 385 | if (uss) { |
| 386 | if (!access_ok(VERIFY_READ, uss, sizeof(*uss))) |
| 387 | return -EFAULT; |
| 388 | err |= __get_user(sp, &uss->ss_sp); |
Atsushi Nemoto | 9c6031c | 2006-02-19 23:46:44 +0900 | [diff] [blame] | 389 | kss.ss_sp = (void __user *) (long) sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | err |= __get_user(kss.ss_size, &uss->ss_size); |
| 391 | err |= __get_user(kss.ss_flags, &uss->ss_flags); |
| 392 | if (err) |
| 393 | return -EFAULT; |
| 394 | } |
| 395 | |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 396 | set_fs(KERNEL_DS); |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 397 | ret = do_sigaltstack(uss ? (stack_t __user *)&kss : NULL, |
| 398 | uoss ? (stack_t __user *)&koss : NULL, usp); |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 399 | set_fs(old_fs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | if (!ret && uoss) { |
| 402 | if (!access_ok(VERIFY_WRITE, uoss, sizeof(*uoss))) |
| 403 | return -EFAULT; |
Atsushi Nemoto | 9c6031c | 2006-02-19 23:46:44 +0900 | [diff] [blame] | 404 | sp = (int) (unsigned long) koss.ss_sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | err |= __put_user(sp, &uoss->ss_sp); |
| 406 | err |= __put_user(koss.ss_size, &uoss->ss_size); |
| 407 | err |= __put_user(koss.ss_flags, &uoss->ss_flags); |
| 408 | if (err) |
| 409 | return -EFAULT; |
| 410 | } |
| 411 | return ret; |
| 412 | } |
| 413 | |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 414 | int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
| 416 | int err; |
| 417 | |
| 418 | if (!access_ok (VERIFY_WRITE, to, sizeof(compat_siginfo_t))) |
| 419 | return -EFAULT; |
| 420 | |
| 421 | /* If you change siginfo_t structure, please be sure |
| 422 | this code is fixed accordingly. |
| 423 | It should never copy any pad contained in the structure |
| 424 | to avoid security leaks, but must copy the generic |
| 425 | 3 ints plus the relevant union member. |
| 426 | This routine must convert siginfo from 64bit to 32bit as well |
| 427 | at the same time. */ |
| 428 | err = __put_user(from->si_signo, &to->si_signo); |
| 429 | err |= __put_user(from->si_errno, &to->si_errno); |
| 430 | err |= __put_user((short)from->si_code, &to->si_code); |
| 431 | if (from->si_code < 0) |
| 432 | err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad, SI_PAD_SIZE); |
| 433 | else { |
| 434 | switch (from->si_code >> 16) { |
Ralf Baechle | a982099 | 2005-02-16 21:24:16 +0000 | [diff] [blame] | 435 | case __SI_TIMER >> 16: |
| 436 | err |= __put_user(from->si_tid, &to->si_tid); |
| 437 | err |= __put_user(from->si_overrun, &to->si_overrun); |
| 438 | err |= __put_user(from->si_int, &to->si_int); |
| 439 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | case __SI_CHLD >> 16: |
| 441 | err |= __put_user(from->si_utime, &to->si_utime); |
| 442 | err |= __put_user(from->si_stime, &to->si_stime); |
| 443 | err |= __put_user(from->si_status, &to->si_status); |
| 444 | default: |
| 445 | err |= __put_user(from->si_pid, &to->si_pid); |
| 446 | err |= __put_user(from->si_uid, &to->si_uid); |
| 447 | break; |
| 448 | case __SI_FAULT >> 16: |
Atsushi Nemoto | 5665a0a | 2006-02-02 01:26:34 +0900 | [diff] [blame] | 449 | err |= __put_user((unsigned long)from->si_addr, &to->si_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | break; |
| 451 | case __SI_POLL >> 16: |
| 452 | err |= __put_user(from->si_band, &to->si_band); |
| 453 | err |= __put_user(from->si_fd, &to->si_fd); |
| 454 | break; |
| 455 | case __SI_RT >> 16: /* This is not generated by the kernel as of now. */ |
| 456 | case __SI_MESGQ >> 16: |
| 457 | err |= __put_user(from->si_pid, &to->si_pid); |
| 458 | err |= __put_user(from->si_uid, &to->si_uid); |
| 459 | err |= __put_user(from->si_int, &to->si_int); |
| 460 | break; |
| 461 | } |
| 462 | } |
| 463 | return err; |
| 464 | } |
| 465 | |
Thomas Bogendoerfer | 5d9a76c | 2008-08-17 16:49:25 +0200 | [diff] [blame] | 466 | int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from) |
| 467 | { |
| 468 | memset(to, 0, sizeof *to); |
| 469 | |
| 470 | if (copy_from_user(to, from, 3*sizeof(int)) || |
| 471 | copy_from_user(to->_sifields._pad, |
| 472 | from->_sifields._pad, SI_PAD_SIZE32)) |
| 473 | return -EFAULT; |
| 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | |
Franck Bui-Huu | f90080a | 2007-02-05 15:24:27 +0100 | [diff] [blame] | 478 | asmlinkage void sys32_sigreturn(nabi_no_regargs struct pt_regs regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
Ralf Baechle | dd02f06 | 2007-02-13 00:50:57 +0000 | [diff] [blame] | 480 | struct sigframe32 __user *frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | sigset_t blocked; |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 482 | int sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
Ralf Baechle | dd02f06 | 2007-02-13 00:50:57 +0000 | [diff] [blame] | 484 | frame = (struct sigframe32 __user *) regs.regs[29]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 486 | goto badframe; |
Ralf Baechle | 431dc80 | 2007-02-13 00:05:11 +0000 | [diff] [blame] | 487 | if (__copy_conv_sigset_from_user(&blocked, &frame->sf_mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | goto badframe; |
| 489 | |
| 490 | sigdelsetmask(&blocked, ~_BLOCKABLE); |
| 491 | spin_lock_irq(¤t->sighand->siglock); |
| 492 | current->blocked = blocked; |
| 493 | recalc_sigpending(); |
| 494 | spin_unlock_irq(¤t->sighand->siglock); |
| 495 | |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 496 | sig = restore_sigcontext32(®s, &frame->sf_sc); |
| 497 | if (sig < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | goto badframe; |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 499 | else if (sig) |
| 500 | force_sig(sig, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
| 502 | /* |
| 503 | * Don't let your children do this ... |
| 504 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | __asm__ __volatile__( |
| 506 | "move\t$29, %0\n\t" |
| 507 | "j\tsyscall_exit" |
| 508 | :/* no outputs */ |
| 509 | :"r" (®s)); |
| 510 | /* Unreached */ |
| 511 | |
| 512 | badframe: |
| 513 | force_sig(SIGSEGV, current); |
| 514 | } |
| 515 | |
Franck Bui-Huu | f90080a | 2007-02-05 15:24:27 +0100 | [diff] [blame] | 516 | asmlinkage void sys32_rt_sigreturn(nabi_no_regargs struct pt_regs regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | { |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 518 | struct rt_sigframe32 __user *frame; |
Ralf Baechle | 1fcf1cc | 2005-04-13 18:18:04 +0000 | [diff] [blame] | 519 | mm_segment_t old_fs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | sigset_t set; |
| 521 | stack_t st; |
| 522 | s32 sp; |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 523 | int sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 525 | frame = (struct rt_sigframe32 __user *) regs.regs[29]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 527 | goto badframe; |
Ralf Baechle | 431dc80 | 2007-02-13 00:05:11 +0000 | [diff] [blame] | 528 | if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | goto badframe; |
| 530 | |
| 531 | sigdelsetmask(&set, ~_BLOCKABLE); |
| 532 | spin_lock_irq(¤t->sighand->siglock); |
| 533 | current->blocked = set; |
| 534 | recalc_sigpending(); |
| 535 | spin_unlock_irq(¤t->sighand->siglock); |
| 536 | |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 537 | sig = restore_sigcontext32(®s, &frame->rs_uc.uc_mcontext); |
| 538 | if (sig < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | goto badframe; |
Atsushi Nemoto | c6a2f46 | 2007-03-10 01:03:48 +0900 | [diff] [blame] | 540 | else if (sig) |
| 541 | force_sig(sig, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
| 543 | /* The ucontext contains a stack32_t, so we must convert! */ |
| 544 | if (__get_user(sp, &frame->rs_uc.uc_stack.ss_sp)) |
| 545 | goto badframe; |
Atsushi Nemoto | 9c6031c | 2006-02-19 23:46:44 +0900 | [diff] [blame] | 546 | st.ss_sp = (void __user *)(long) sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | if (__get_user(st.ss_size, &frame->rs_uc.uc_stack.ss_size)) |
| 548 | goto badframe; |
| 549 | if (__get_user(st.ss_flags, &frame->rs_uc.uc_stack.ss_flags)) |
| 550 | goto badframe; |
| 551 | |
| 552 | /* It is more difficult to avoid calling this function than to |
| 553 | call it and ignore errors. */ |
Ralf Baechle | 1fcf1cc | 2005-04-13 18:18:04 +0000 | [diff] [blame] | 554 | old_fs = get_fs(); |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 555 | set_fs(KERNEL_DS); |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 556 | do_sigaltstack((stack_t __user *)&st, NULL, regs.regs[29]); |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 557 | set_fs(old_fs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | |
| 559 | /* |
| 560 | * Don't let your children do this ... |
| 561 | */ |
| 562 | __asm__ __volatile__( |
| 563 | "move\t$29, %0\n\t" |
| 564 | "j\tsyscall_exit" |
| 565 | :/* no outputs */ |
| 566 | :"r" (®s)); |
| 567 | /* Unreached */ |
| 568 | |
| 569 | badframe: |
| 570 | force_sig(SIGSEGV, current); |
| 571 | } |
| 572 | |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 573 | static int setup_frame_32(void *sig_return, struct k_sigaction *ka, |
| 574 | struct pt_regs *regs, int signr, sigset_t *set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | { |
Ralf Baechle | dd02f06 | 2007-02-13 00:50:57 +0000 | [diff] [blame] | 576 | struct sigframe32 __user *frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | int err = 0; |
| 578 | |
| 579 | frame = get_sigframe(ka, regs, sizeof(*frame)); |
| 580 | if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame))) |
| 581 | goto give_sigsegv; |
| 582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | err |= setup_sigcontext32(regs, &frame->sf_sc); |
Ralf Baechle | 431dc80 | 2007-02-13 00:05:11 +0000 | [diff] [blame] | 584 | err |= __copy_conv_sigset_to_user(&frame->sf_mask, set); |
| 585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | if (err) |
| 587 | goto give_sigsegv; |
| 588 | |
| 589 | /* |
| 590 | * Arguments to signal handler: |
| 591 | * |
| 592 | * a0 = signal number |
| 593 | * a1 = 0 (should be cause) |
| 594 | * a2 = pointer to struct sigcontext |
| 595 | * |
| 596 | * $25 and c0_epc point to the signal handler, $29 points to the |
| 597 | * struct sigframe. |
| 598 | */ |
| 599 | regs->regs[ 4] = signr; |
| 600 | regs->regs[ 5] = 0; |
| 601 | regs->regs[ 6] = (unsigned long) &frame->sf_sc; |
| 602 | regs->regs[29] = (unsigned long) frame; |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 603 | regs->regs[31] = (unsigned long) sig_return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler; |
| 605 | |
Franck Bui-Huu | 722bb63 | 2007-02-05 15:24:24 +0100 | [diff] [blame] | 606 | 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] | 607 | current->comm, current->pid, |
Franck Bui-Huu | 722bb63 | 2007-02-05 15:24:24 +0100 | [diff] [blame] | 608 | frame, regs->cp0_epc, regs->regs[31]); |
| 609 | |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 610 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
| 612 | give_sigsegv: |
| 613 | force_sigsegv(signr, current); |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 614 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | } |
| 616 | |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 617 | static int setup_rt_frame_32(void *sig_return, struct k_sigaction *ka, |
| 618 | struct pt_regs *regs, int signr, sigset_t *set, |
| 619 | siginfo_t *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | { |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 621 | struct rt_sigframe32 __user *frame; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | int err = 0; |
| 623 | s32 sp; |
| 624 | |
| 625 | frame = get_sigframe(ka, regs, sizeof(*frame)); |
| 626 | if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame))) |
| 627 | goto give_sigsegv; |
| 628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | /* Convert (siginfo_t -> compat_siginfo_t) and copy to user. */ |
| 630 | err |= copy_siginfo_to_user32(&frame->rs_info, info); |
| 631 | |
| 632 | /* Create the ucontext. */ |
| 633 | err |= __put_user(0, &frame->rs_uc.uc_flags); |
| 634 | err |= __put_user(0, &frame->rs_uc.uc_link); |
| 635 | sp = (int) (long) current->sas_ss_sp; |
| 636 | err |= __put_user(sp, |
| 637 | &frame->rs_uc.uc_stack.ss_sp); |
| 638 | err |= __put_user(sas_ss_flags(regs->regs[29]), |
| 639 | &frame->rs_uc.uc_stack.ss_flags); |
| 640 | err |= __put_user(current->sas_ss_size, |
| 641 | &frame->rs_uc.uc_stack.ss_size); |
| 642 | err |= setup_sigcontext32(regs, &frame->rs_uc.uc_mcontext); |
Ralf Baechle | 431dc80 | 2007-02-13 00:05:11 +0000 | [diff] [blame] | 643 | err |= __copy_conv_sigset_to_user(&frame->rs_uc.uc_sigmask, set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
| 645 | if (err) |
| 646 | goto give_sigsegv; |
| 647 | |
| 648 | /* |
| 649 | * Arguments to signal handler: |
| 650 | * |
| 651 | * a0 = signal number |
| 652 | * a1 = 0 (should be cause) |
| 653 | * a2 = pointer to ucontext |
| 654 | * |
| 655 | * $25 and c0_epc point to the signal handler, $29 points to |
| 656 | * the struct rt_sigframe32. |
| 657 | */ |
| 658 | regs->regs[ 4] = signr; |
| 659 | regs->regs[ 5] = (unsigned long) &frame->rs_info; |
| 660 | regs->regs[ 6] = (unsigned long) &frame->rs_uc; |
| 661 | regs->regs[29] = (unsigned long) frame; |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 662 | regs->regs[31] = (unsigned long) sig_return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler; |
| 664 | |
Franck Bui-Huu | 722bb63 | 2007-02-05 15:24:24 +0100 | [diff] [blame] | 665 | 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] | 666 | current->comm, current->pid, |
Franck Bui-Huu | 722bb63 | 2007-02-05 15:24:24 +0100 | [diff] [blame] | 667 | frame, regs->cp0_epc, regs->regs[31]); |
| 668 | |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 669 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
| 671 | give_sigsegv: |
| 672 | force_sigsegv(signr, current); |
Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 673 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Ralf Baechle | 151fd6a | 2007-02-15 11:40:37 +0000 | [diff] [blame] | 676 | /* |
| 677 | * o32 compatibility on 64-bit kernels, without DSP ASE |
| 678 | */ |
| 679 | struct mips_abi mips_abi_32 = { |
| 680 | .setup_frame = setup_frame_32, |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 681 | .signal_return_offset = |
| 682 | offsetof(struct mips_vdso, o32_signal_trampoline), |
Ralf Baechle | 151fd6a | 2007-02-15 11:40:37 +0000 | [diff] [blame] | 683 | .setup_rt_frame = setup_rt_frame_32, |
David Daney | d814c28 | 2010-02-18 16:13:05 -0800 | [diff] [blame] | 684 | .rt_signal_return_offset = |
| 685 | offsetof(struct mips_vdso, o32_rt_signal_trampoline), |
Ralf Baechle | 151fd6a | 2007-02-15 11:40:37 +0000 | [diff] [blame] | 686 | .restart = __NR_O32_restart_syscall |
| 687 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 689 | SYSCALL_DEFINE4(32_rt_sigaction, int, sig, |
| 690 | const struct sigaction32 __user *, act, |
| 691 | struct sigaction32 __user *, oact, unsigned int, sigsetsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { |
| 693 | struct k_sigaction new_sa, old_sa; |
| 694 | int ret = -EINVAL; |
| 695 | |
| 696 | /* XXX: Don't preclude handling different sized sigset_t's. */ |
| 697 | if (sigsetsize != sizeof(sigset_t)) |
| 698 | goto out; |
| 699 | |
| 700 | if (act) { |
Ralf Baechle | 77c728c | 2005-03-04 19:36:51 +0000 | [diff] [blame] | 701 | s32 handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | int err = 0; |
| 703 | |
| 704 | if (!access_ok(VERIFY_READ, act, sizeof(*act))) |
| 705 | return -EFAULT; |
Ralf Baechle | 77c728c | 2005-03-04 19:36:51 +0000 | [diff] [blame] | 706 | err |= __get_user(handler, &act->sa_handler); |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 707 | new_sa.sa.sa_handler = (void __user *)(s64)handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | err |= __get_user(new_sa.sa.sa_flags, &act->sa_flags); |
| 709 | err |= get_sigset(&new_sa.sa.sa_mask, &act->sa_mask); |
| 710 | if (err) |
| 711 | return -EFAULT; |
| 712 | } |
| 713 | |
| 714 | ret = do_sigaction(sig, act ? &new_sa : NULL, oact ? &old_sa : NULL); |
| 715 | |
| 716 | if (!ret && oact) { |
| 717 | int err = 0; |
| 718 | |
| 719 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact))) |
| 720 | return -EFAULT; |
| 721 | |
| 722 | err |= __put_user((u32)(u64)old_sa.sa.sa_handler, |
| 723 | &oact->sa_handler); |
| 724 | err |= __put_user(old_sa.sa.sa_flags, &oact->sa_flags); |
| 725 | err |= put_sigset(&old_sa.sa.sa_mask, &oact->sa_mask); |
| 726 | if (err) |
| 727 | return -EFAULT; |
| 728 | } |
| 729 | out: |
| 730 | return ret; |
| 731 | } |
| 732 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 733 | SYSCALL_DEFINE4(32_rt_sigprocmask, int, how, compat_sigset_t __user *, set, |
| 734 | compat_sigset_t __user *, oset, unsigned int, sigsetsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | { |
| 736 | sigset_t old_set, new_set; |
| 737 | int ret; |
| 738 | mm_segment_t old_fs = get_fs(); |
| 739 | |
| 740 | if (set && get_sigset(&new_set, set)) |
| 741 | return -EFAULT; |
| 742 | |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 743 | set_fs(KERNEL_DS); |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 744 | ret = sys_rt_sigprocmask(how, set ? (sigset_t __user *)&new_set : NULL, |
| 745 | oset ? (sigset_t __user *)&old_set : NULL, |
| 746 | sigsetsize); |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 747 | set_fs(old_fs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
| 749 | if (!ret && oset && put_sigset(&old_set, oset)) |
| 750 | return -EFAULT; |
| 751 | |
| 752 | return ret; |
| 753 | } |
| 754 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 755 | SYSCALL_DEFINE2(32_rt_sigpending, compat_sigset_t __user *, uset, |
| 756 | unsigned int, sigsetsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | { |
| 758 | int ret; |
| 759 | sigset_t set; |
| 760 | mm_segment_t old_fs = get_fs(); |
| 761 | |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 762 | set_fs(KERNEL_DS); |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 763 | ret = sys_rt_sigpending((sigset_t __user *)&set, sigsetsize); |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 764 | set_fs(old_fs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
| 766 | if (!ret && put_sigset(&set, uset)) |
| 767 | return -EFAULT; |
| 768 | |
| 769 | return ret; |
| 770 | } |
| 771 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 772 | SYSCALL_DEFINE3(32_rt_sigqueueinfo, int, pid, int, sig, |
| 773 | compat_siginfo_t __user *, uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | { |
| 775 | siginfo_t info; |
| 776 | int ret; |
| 777 | mm_segment_t old_fs = get_fs(); |
| 778 | |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 779 | if (copy_from_user(&info, uinfo, 3*sizeof(int)) || |
| 780 | copy_from_user(info._sifields._pad, uinfo->_sifields._pad, SI_PAD_SIZE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | return -EFAULT; |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 782 | set_fs(KERNEL_DS); |
Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 783 | ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info); |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 784 | set_fs(old_fs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | return ret; |
| 786 | } |
Ralf Baechle | 54f2da7 | 2005-02-16 21:21:29 +0000 | [diff] [blame] | 787 | |
Ralf Baechle | dbda6ac | 2009-02-08 16:00:26 +0000 | [diff] [blame] | 788 | SYSCALL_DEFINE5(32_waitid, int, which, compat_pid_t, pid, |
| 789 | compat_siginfo_t __user *, uinfo, int, options, |
| 790 | struct compat_rusage __user *, uru) |
Ralf Baechle | 54f2da7 | 2005-02-16 21:21:29 +0000 | [diff] [blame] | 791 | { |
| 792 | siginfo_t info; |
| 793 | struct rusage ru; |
| 794 | long ret; |
| 795 | mm_segment_t old_fs = get_fs(); |
| 796 | |
| 797 | info.si_signo = 0; |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 798 | set_fs(KERNEL_DS); |
Ralf Baechle | 54f2da7 | 2005-02-16 21:21:29 +0000 | [diff] [blame] | 799 | ret = sys_waitid(which, pid, (siginfo_t __user *) &info, options, |
| 800 | uru ? (struct rusage __user *) &ru : NULL); |
Ralf Baechle | 49a89ef | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 801 | set_fs(old_fs); |
Ralf Baechle | 54f2da7 | 2005-02-16 21:21:29 +0000 | [diff] [blame] | 802 | |
| 803 | if (ret < 0 || info.si_signo == 0) |
| 804 | return ret; |
| 805 | |
| 806 | if (uru && (ret = put_compat_rusage(&ru, uru))) |
| 807 | return ret; |
| 808 | |
| 809 | BUG_ON(info.si_code & __SI_MASK); |
| 810 | info.si_code |= __SI_CHLD; |
| 811 | return copy_siginfo_to_user32(uinfo, &info); |
| 812 | } |
Ralf Baechle | 137f6f3 | 2009-11-24 19:35:41 +0000 | [diff] [blame] | 813 | |
| 814 | static int signal32_init(void) |
| 815 | { |
| 816 | if (cpu_has_fpu) { |
| 817 | save_fp_context32 = _save_fp_context32; |
| 818 | restore_fp_context32 = _restore_fp_context32; |
| 819 | } else { |
| 820 | save_fp_context32 = fpu_emulator_save_context32; |
| 821 | restore_fp_context32 = fpu_emulator_restore_context32; |
| 822 | } |
| 823 | |
| 824 | return 0; |
| 825 | } |
| 826 | |
| 827 | arch_initcall(signal32_init); |