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