| 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> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/sched.h> | 
|  | 12 | #include <linux/mm.h> | 
|  | 13 | #include <linux/personality.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/errno.h> | 
|  | 19 | #include <linux/wait.h> | 
|  | 20 | #include <linux/ptrace.h> | 
|  | 21 | #include <linux/unistd.h> | 
|  | 22 | #include <linux/compiler.h> | 
|  | 23 |  | 
| Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 24 | #include <asm/abi.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/asm.h> | 
|  | 26 | #include <linux/bitops.h> | 
|  | 27 | #include <asm/cacheflush.h> | 
|  | 28 | #include <asm/fpu.h> | 
|  | 29 | #include <asm/sim.h> | 
|  | 30 | #include <asm/uaccess.h> | 
|  | 31 | #include <asm/ucontext.h> | 
|  | 32 | #include <asm/cpu-features.h> | 
| Ralf Baechle | 02416dc | 2005-06-15 13:00:12 +0000 | [diff] [blame] | 33 | #include <asm/war.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 |  | 
|  | 35 | #include "signal-common.h" | 
|  | 36 |  | 
|  | 37 | #define DEBUG_SIG 0 | 
|  | 38 |  | 
|  | 39 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) | 
|  | 40 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | /* | 
|  | 42 | * Atomically swap in the new signal mask, and wait for a signal. | 
|  | 43 | */ | 
|  | 44 |  | 
|  | 45 | #ifdef CONFIG_TRAD_SIGNALS | 
|  | 46 | save_static_function(sys_sigsuspend); | 
|  | 47 | __attribute_used__ noinline static int | 
|  | 48 | _sys_sigsuspend(nabi_no_regargs struct pt_regs regs) | 
|  | 49 | { | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 50 | sigset_t newset; | 
| Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 51 | sigset_t __user *uset; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 |  | 
| Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 53 | uset = (sigset_t __user *) regs.regs[4]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | if (copy_from_user(&newset, uset, sizeof(sigset_t))) | 
|  | 55 | return -EFAULT; | 
|  | 56 | sigdelsetmask(&newset, ~_BLOCKABLE); | 
|  | 57 |  | 
|  | 58 | spin_lock_irq(¤t->sighand->siglock); | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 59 | current->saved_sigmask = current->blocked; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | current->blocked = newset; | 
|  | 61 | recalc_sigpending(); | 
|  | 62 | spin_unlock_irq(¤t->sighand->siglock); | 
|  | 63 |  | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 64 | current->state = TASK_INTERRUPTIBLE; | 
|  | 65 | schedule(); | 
|  | 66 | set_thread_flag(TIF_RESTORE_SIGMASK); | 
|  | 67 | return -ERESTARTNOHAND; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } | 
|  | 69 | #endif | 
|  | 70 |  | 
|  | 71 | save_static_function(sys_rt_sigsuspend); | 
|  | 72 | __attribute_used__ noinline static int | 
|  | 73 | _sys_rt_sigsuspend(nabi_no_regargs struct pt_regs regs) | 
|  | 74 | { | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 75 | sigset_t newset; | 
| Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 76 | sigset_t __user *unewset; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | size_t sigsetsize; | 
|  | 78 |  | 
|  | 79 | /* XXX Don't preclude handling different sized sigset_t's.  */ | 
|  | 80 | sigsetsize = regs.regs[5]; | 
|  | 81 | if (sigsetsize != sizeof(sigset_t)) | 
|  | 82 | return -EINVAL; | 
|  | 83 |  | 
| Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 84 | unewset = (sigset_t __user *) regs.regs[4]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | if (copy_from_user(&newset, unewset, sizeof(newset))) | 
|  | 86 | return -EFAULT; | 
|  | 87 | sigdelsetmask(&newset, ~_BLOCKABLE); | 
|  | 88 |  | 
|  | 89 | spin_lock_irq(¤t->sighand->siglock); | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 90 | current->saved_sigmask = current->blocked; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | current->blocked = newset; | 
|  | 92 | recalc_sigpending(); | 
|  | 93 | spin_unlock_irq(¤t->sighand->siglock); | 
|  | 94 |  | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 95 | current->state = TASK_INTERRUPTIBLE; | 
|  | 96 | schedule(); | 
|  | 97 | set_thread_flag(TIF_RESTORE_SIGMASK); | 
|  | 98 | return -ERESTARTNOHAND; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } | 
|  | 100 |  | 
|  | 101 | #ifdef CONFIG_TRAD_SIGNALS | 
| Atsushi Nemoto | 9c6031c | 2006-02-19 23:46:44 +0900 | [diff] [blame] | 102 | asmlinkage int sys_sigaction(int sig, const struct sigaction __user *act, | 
|  | 103 | struct sigaction __user *oact) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { | 
|  | 105 | struct k_sigaction new_ka, old_ka; | 
|  | 106 | int ret; | 
|  | 107 | int err = 0; | 
|  | 108 |  | 
|  | 109 | if (act) { | 
|  | 110 | old_sigset_t mask; | 
|  | 111 |  | 
|  | 112 | if (!access_ok(VERIFY_READ, act, sizeof(*act))) | 
|  | 113 | return -EFAULT; | 
|  | 114 | err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler); | 
|  | 115 | err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags); | 
|  | 116 | err |= __get_user(mask, &act->sa_mask.sig[0]); | 
|  | 117 | if (err) | 
|  | 118 | return -EFAULT; | 
|  | 119 |  | 
|  | 120 | siginitset(&new_ka.sa.sa_mask, mask); | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); | 
|  | 124 |  | 
|  | 125 | if (!ret && oact) { | 
|  | 126 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact))) | 
|  | 127 | return -EFAULT; | 
|  | 128 | err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags); | 
|  | 129 | err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler); | 
|  | 130 | err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig); | 
|  | 131 | err |= __put_user(0, &oact->sa_mask.sig[1]); | 
|  | 132 | err |= __put_user(0, &oact->sa_mask.sig[2]); | 
|  | 133 | err |= __put_user(0, &oact->sa_mask.sig[3]); | 
|  | 134 | if (err) | 
|  | 135 | return -EFAULT; | 
|  | 136 | } | 
|  | 137 |  | 
|  | 138 | return ret; | 
|  | 139 | } | 
|  | 140 | #endif | 
|  | 141 |  | 
|  | 142 | asmlinkage int sys_sigaltstack(nabi_no_regargs struct pt_regs regs) | 
|  | 143 | { | 
| Ralf Baechle | fe00f94 | 2005-03-01 19:22:29 +0000 | [diff] [blame] | 144 | const stack_t __user *uss = (const stack_t __user *) regs.regs[4]; | 
|  | 145 | stack_t __user *uoss = (stack_t __user *) regs.regs[5]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | unsigned long usp = regs.regs[29]; | 
|  | 147 |  | 
|  | 148 | return do_sigaltstack(uss, uoss, usp); | 
|  | 149 | } | 
|  | 150 |  | 
| Ralf Baechle | 02416dc | 2005-06-15 13:00:12 +0000 | [diff] [blame] | 151 | /* | 
|  | 152 | * Horribly complicated - with the bloody RM9000 workarounds enabled | 
|  | 153 | * the signal trampolines is moving to the end of the structure so we can | 
|  | 154 | * increase the alignment without breaking software compatibility. | 
|  | 155 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | #ifdef CONFIG_TRAD_SIGNALS | 
|  | 157 | struct sigframe { | 
|  | 158 | u32 sf_ass[4];			/* argument save space for o32 */ | 
| Ralf Baechle | 02416dc | 2005-06-15 13:00:12 +0000 | [diff] [blame] | 159 | #if ICACHE_REFILLS_WORKAROUND_WAR | 
|  | 160 | u32 sf_pad[2]; | 
|  | 161 | #else | 
|  | 162 | u32 sf_code[2];			/* signal trampoline */ | 
|  | 163 | #endif | 
|  | 164 | struct sigcontext sf_sc; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | sigset_t sf_mask; | 
| Ralf Baechle | 02416dc | 2005-06-15 13:00:12 +0000 | [diff] [blame] | 166 | #if ICACHE_REFILLS_WORKAROUND_WAR | 
|  | 167 | u32 sf_code[8] ____cacheline_aligned;	/* signal trampoline */ | 
|  | 168 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | }; | 
|  | 170 | #endif | 
|  | 171 |  | 
|  | 172 | struct rt_sigframe { | 
|  | 173 | u32 rs_ass[4];			/* argument save space for o32 */ | 
| Ralf Baechle | 02416dc | 2005-06-15 13:00:12 +0000 | [diff] [blame] | 174 | #if ICACHE_REFILLS_WORKAROUND_WAR | 
|  | 175 | u32 rs_pad[2]; | 
|  | 176 | #else | 
|  | 177 | u32 rs_code[2];			/* signal trampoline */ | 
|  | 178 | #endif | 
|  | 179 | struct siginfo rs_info; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | struct ucontext rs_uc; | 
| Ralf Baechle | 02416dc | 2005-06-15 13:00:12 +0000 | [diff] [blame] | 181 | #if ICACHE_REFILLS_WORKAROUND_WAR | 
|  | 182 | u32 rs_code[8] ____cacheline_aligned;	/* signal trampoline */ | 
|  | 183 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | }; | 
|  | 185 |  | 
|  | 186 | #ifdef CONFIG_TRAD_SIGNALS | 
|  | 187 | save_static_function(sys_sigreturn); | 
|  | 188 | __attribute_used__ noinline static void | 
|  | 189 | _sys_sigreturn(nabi_no_regargs struct pt_regs regs) | 
|  | 190 | { | 
| Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 191 | struct sigframe __user *frame; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | sigset_t blocked; | 
|  | 193 |  | 
| Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 194 | frame = (struct sigframe __user *) regs.regs[29]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | 
|  | 196 | goto badframe; | 
|  | 197 | if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked))) | 
|  | 198 | goto badframe; | 
|  | 199 |  | 
|  | 200 | sigdelsetmask(&blocked, ~_BLOCKABLE); | 
|  | 201 | spin_lock_irq(¤t->sighand->siglock); | 
|  | 202 | current->blocked = blocked; | 
|  | 203 | recalc_sigpending(); | 
|  | 204 | spin_unlock_irq(¤t->sighand->siglock); | 
|  | 205 |  | 
|  | 206 | if (restore_sigcontext(®s, &frame->sf_sc)) | 
|  | 207 | goto badframe; | 
|  | 208 |  | 
|  | 209 | /* | 
|  | 210 | * Don't let your children do this ... | 
|  | 211 | */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | __asm__ __volatile__( | 
|  | 213 | "move\t$29, %0\n\t" | 
|  | 214 | "j\tsyscall_exit" | 
|  | 215 | :/* no outputs */ | 
|  | 216 | :"r" (®s)); | 
|  | 217 | /* Unreached */ | 
|  | 218 |  | 
|  | 219 | badframe: | 
|  | 220 | force_sig(SIGSEGV, current); | 
|  | 221 | } | 
| Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 222 | #endif /* CONFIG_TRAD_SIGNALS */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 |  | 
|  | 224 | save_static_function(sys_rt_sigreturn); | 
|  | 225 | __attribute_used__ noinline static void | 
|  | 226 | _sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs) | 
|  | 227 | { | 
| Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 228 | struct rt_sigframe __user *frame; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | sigset_t set; | 
|  | 230 | stack_t st; | 
|  | 231 |  | 
| Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 232 | frame = (struct rt_sigframe __user *) regs.regs[29]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | 
|  | 234 | goto badframe; | 
|  | 235 | if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set))) | 
|  | 236 | goto badframe; | 
|  | 237 |  | 
|  | 238 | sigdelsetmask(&set, ~_BLOCKABLE); | 
|  | 239 | spin_lock_irq(¤t->sighand->siglock); | 
|  | 240 | current->blocked = set; | 
|  | 241 | recalc_sigpending(); | 
|  | 242 | spin_unlock_irq(¤t->sighand->siglock); | 
|  | 243 |  | 
|  | 244 | if (restore_sigcontext(®s, &frame->rs_uc.uc_mcontext)) | 
|  | 245 | goto badframe; | 
|  | 246 |  | 
|  | 247 | if (__copy_from_user(&st, &frame->rs_uc.uc_stack, sizeof(st))) | 
|  | 248 | goto badframe; | 
|  | 249 | /* It is more difficult to avoid calling this function than to | 
|  | 250 | call it and ignore errors.  */ | 
| Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 251 | do_sigaltstack((stack_t __user *)&st, NULL, regs.regs[29]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 |  | 
|  | 253 | /* | 
|  | 254 | * Don't let your children do this ... | 
|  | 255 | */ | 
|  | 256 | __asm__ __volatile__( | 
|  | 257 | "move\t$29, %0\n\t" | 
|  | 258 | "j\tsyscall_exit" | 
|  | 259 | :/* no outputs */ | 
|  | 260 | :"r" (®s)); | 
|  | 261 | /* Unreached */ | 
|  | 262 |  | 
|  | 263 | badframe: | 
|  | 264 | force_sig(SIGSEGV, current); | 
|  | 265 | } | 
|  | 266 |  | 
|  | 267 | #ifdef CONFIG_TRAD_SIGNALS | 
| Ralf Baechle | 129bc8f | 2005-07-11 20:45:51 +0000 | [diff] [blame] | 268 | int setup_frame(struct k_sigaction * ka, struct pt_regs *regs, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | int signr, sigset_t *set) | 
|  | 270 | { | 
| Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 271 | struct sigframe __user *frame; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | int err = 0; | 
|  | 273 |  | 
|  | 274 | frame = get_sigframe(ka, regs, sizeof(*frame)); | 
|  | 275 | if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame))) | 
|  | 276 | goto give_sigsegv; | 
|  | 277 |  | 
| Ralf Baechle | 02416dc | 2005-06-15 13:00:12 +0000 | [diff] [blame] | 278 | install_sigtramp(frame->sf_code, __NR_sigreturn); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 |  | 
|  | 280 | err |= setup_sigcontext(regs, &frame->sf_sc); | 
|  | 281 | err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set)); | 
|  | 282 | if (err) | 
|  | 283 | goto give_sigsegv; | 
|  | 284 |  | 
|  | 285 | /* | 
|  | 286 | * Arguments to signal handler: | 
|  | 287 | * | 
|  | 288 | *   a0 = signal number | 
|  | 289 | *   a1 = 0 (should be cause) | 
|  | 290 | *   a2 = pointer to struct sigcontext | 
|  | 291 | * | 
|  | 292 | * $25 and c0_epc point to the signal handler, $29 points to the | 
|  | 293 | * struct sigframe. | 
|  | 294 | */ | 
|  | 295 | regs->regs[ 4] = signr; | 
|  | 296 | regs->regs[ 5] = 0; | 
|  | 297 | regs->regs[ 6] = (unsigned long) &frame->sf_sc; | 
|  | 298 | regs->regs[29] = (unsigned long) frame; | 
|  | 299 | regs->regs[31] = (unsigned long) frame->sf_code; | 
|  | 300 | regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler; | 
|  | 301 |  | 
|  | 302 | #if DEBUG_SIG | 
|  | 303 | printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n", | 
|  | 304 | current->comm, current->pid, | 
|  | 305 | frame, regs->cp0_epc, frame->regs[31]); | 
|  | 306 | #endif | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 307 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 |  | 
|  | 309 | give_sigsegv: | 
|  | 310 | force_sigsegv(signr, current); | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 311 | return -EFAULT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } | 
|  | 313 | #endif | 
|  | 314 |  | 
| Ralf Baechle | 129bc8f | 2005-07-11 20:45:51 +0000 | [diff] [blame] | 315 | int setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | int signr, sigset_t *set, siginfo_t *info) | 
|  | 317 | { | 
| Atsushi Nemoto | 9bbf28a3 | 2006-02-01 01:41:09 +0900 | [diff] [blame] | 318 | struct rt_sigframe __user *frame; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | int err = 0; | 
|  | 320 |  | 
|  | 321 | frame = get_sigframe(ka, regs, sizeof(*frame)); | 
|  | 322 | if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame))) | 
|  | 323 | goto give_sigsegv; | 
|  | 324 |  | 
| Ralf Baechle | 02416dc | 2005-06-15 13:00:12 +0000 | [diff] [blame] | 325 | install_sigtramp(frame->rs_code, __NR_rt_sigreturn); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 |  | 
|  | 327 | /* Create siginfo.  */ | 
|  | 328 | err |= copy_siginfo_to_user(&frame->rs_info, info); | 
|  | 329 |  | 
|  | 330 | /* Create the ucontext.  */ | 
|  | 331 | err |= __put_user(0, &frame->rs_uc.uc_flags); | 
| Atsushi Nemoto | 5665a0a | 2006-02-02 01:26:34 +0900 | [diff] [blame] | 332 | err |= __put_user(NULL, &frame->rs_uc.uc_link); | 
| Atsushi Nemoto | 9c6031c | 2006-02-19 23:46:44 +0900 | [diff] [blame] | 333 | err |= __put_user((void __user *)current->sas_ss_sp, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | &frame->rs_uc.uc_stack.ss_sp); | 
|  | 335 | err |= __put_user(sas_ss_flags(regs->regs[29]), | 
|  | 336 | &frame->rs_uc.uc_stack.ss_flags); | 
|  | 337 | err |= __put_user(current->sas_ss_size, | 
|  | 338 | &frame->rs_uc.uc_stack.ss_size); | 
|  | 339 | err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext); | 
|  | 340 | err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set)); | 
|  | 341 |  | 
|  | 342 | if (err) | 
|  | 343 | goto give_sigsegv; | 
|  | 344 |  | 
|  | 345 | /* | 
|  | 346 | * Arguments to signal handler: | 
|  | 347 | * | 
|  | 348 | *   a0 = signal number | 
|  | 349 | *   a1 = 0 (should be cause) | 
|  | 350 | *   a2 = pointer to ucontext | 
|  | 351 | * | 
|  | 352 | * $25 and c0_epc point to the signal handler, $29 points to | 
|  | 353 | * the struct rt_sigframe. | 
|  | 354 | */ | 
|  | 355 | regs->regs[ 4] = signr; | 
|  | 356 | regs->regs[ 5] = (unsigned long) &frame->rs_info; | 
|  | 357 | regs->regs[ 6] = (unsigned long) &frame->rs_uc; | 
|  | 358 | regs->regs[29] = (unsigned long) frame; | 
|  | 359 | regs->regs[31] = (unsigned long) frame->rs_code; | 
|  | 360 | regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler; | 
|  | 361 |  | 
|  | 362 | #if DEBUG_SIG | 
|  | 363 | printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n", | 
|  | 364 | current->comm, current->pid, | 
|  | 365 | frame, regs->cp0_epc, regs->regs[31]); | 
|  | 366 | #endif | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 367 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 |  | 
|  | 369 | give_sigsegv: | 
|  | 370 | force_sigsegv(signr, current); | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 371 | return -EFAULT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } | 
|  | 373 |  | 
| Ralf Baechle | 129bc8f | 2005-07-11 20:45:51 +0000 | [diff] [blame] | 374 | static inline int handle_signal(unsigned long sig, siginfo_t *info, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs) | 
|  | 376 | { | 
| Ralf Baechle | 129bc8f | 2005-07-11 20:45:51 +0000 | [diff] [blame] | 377 | int ret; | 
|  | 378 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | switch(regs->regs[0]) { | 
|  | 380 | case ERESTART_RESTARTBLOCK: | 
|  | 381 | case ERESTARTNOHAND: | 
|  | 382 | regs->regs[2] = EINTR; | 
|  | 383 | break; | 
|  | 384 | case ERESTARTSYS: | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 385 | if (!(ka->sa.sa_flags & SA_RESTART)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | regs->regs[2] = EINTR; | 
|  | 387 | break; | 
|  | 388 | } | 
|  | 389 | /* fallthrough */ | 
|  | 390 | case ERESTARTNOINTR:		/* Userland will reload $v0.  */ | 
|  | 391 | regs->regs[7] = regs->regs[26]; | 
|  | 392 | regs->cp0_epc -= 8; | 
|  | 393 | } | 
|  | 394 |  | 
|  | 395 | regs->regs[0] = 0;		/* Don't deal with this again.  */ | 
|  | 396 |  | 
| Ralf Baechle | e50c0a8 | 2005-05-31 11:49:19 +0000 | [diff] [blame] | 397 | if (sig_uses_siginfo(ka)) | 
| Ralf Baechle | 129bc8f | 2005-07-11 20:45:51 +0000 | [diff] [blame] | 398 | ret = current->thread.abi->setup_rt_frame(ka, regs, sig, oldset, info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | else | 
| Ralf Baechle | 129bc8f | 2005-07-11 20:45:51 +0000 | [diff] [blame] | 400 | ret = current->thread.abi->setup_frame(ka, regs, sig, oldset); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 |  | 
| Steven Rostedt | 69be8f1 | 2005-08-29 11:44:09 -0400 | [diff] [blame] | 402 | spin_lock_irq(¤t->sighand->siglock); | 
|  | 403 | sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask); | 
|  | 404 | if (!(ka->sa.sa_flags & SA_NODEFER)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | sigaddset(¤t->blocked,sig); | 
| Steven Rostedt | 69be8f1 | 2005-08-29 11:44:09 -0400 | [diff] [blame] | 406 | recalc_sigpending(); | 
|  | 407 | spin_unlock_irq(¤t->sighand->siglock); | 
| Ralf Baechle | 129bc8f | 2005-07-11 20:45:51 +0000 | [diff] [blame] | 408 |  | 
|  | 409 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } | 
|  | 411 |  | 
| Ralf Baechle | 40ac5d4 | 2006-02-08 13:38:18 +0000 | [diff] [blame] | 412 | void do_signal(struct pt_regs *regs) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { | 
|  | 414 | struct k_sigaction ka; | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 415 | sigset_t *oldset; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | siginfo_t info; | 
|  | 417 | int signr; | 
|  | 418 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | /* | 
|  | 420 | * We want the common case to go fast, which is why we may in certain | 
|  | 421 | * cases get here from kernel mode. Just return without doing anything | 
|  | 422 | * if so. | 
|  | 423 | */ | 
|  | 424 | if (!user_mode(regs)) | 
| Ralf Baechle | 40ac5d4 | 2006-02-08 13:38:18 +0000 | [diff] [blame] | 425 | return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 |  | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 427 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) | 
|  | 428 | oldset = ¤t->saved_sigmask; | 
|  | 429 | else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | oldset = ¤t->blocked; | 
|  | 431 |  | 
|  | 432 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 433 | if (signr > 0) { | 
|  | 434 | /* Whee!  Actually deliver the signal.  */ | 
|  | 435 | if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { | 
|  | 436 | /* | 
|  | 437 | * A signal was successfully delivered; the saved | 
|  | 438 | * sigmask will have been stored in the signal frame, | 
|  | 439 | * and will be restored by sigreturn, so we can simply | 
|  | 440 | * clear the TIF_RESTORE_SIGMASK flag. | 
|  | 441 | */ | 
|  | 442 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) | 
|  | 443 | clear_thread_flag(TIF_RESTORE_SIGMASK); | 
|  | 444 | } | 
| Ralf Baechle | 45887e1 | 2006-08-03 21:54:13 +0100 | [diff] [blame] | 445 |  | 
|  | 446 | return; | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 447 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | /* | 
|  | 450 | * Who's code doesn't conform to the restartable syscall convention | 
|  | 451 | * dies here!!!  The li instruction, a single machine instruction, | 
|  | 452 | * must directly be followed by the syscall instruction. | 
|  | 453 | */ | 
|  | 454 | if (regs->regs[0]) { | 
|  | 455 | if (regs->regs[2] == ERESTARTNOHAND || | 
|  | 456 | regs->regs[2] == ERESTARTSYS || | 
|  | 457 | regs->regs[2] == ERESTARTNOINTR) { | 
|  | 458 | regs->regs[7] = regs->regs[26]; | 
|  | 459 | regs->cp0_epc -= 8; | 
|  | 460 | } | 
|  | 461 | if (regs->regs[2] == ERESTART_RESTARTBLOCK) { | 
|  | 462 | regs->regs[2] = __NR_restart_syscall; | 
|  | 463 | regs->regs[7] = regs->regs[26]; | 
|  | 464 | regs->cp0_epc -= 4; | 
|  | 465 | } | 
| Ralf Baechle | 13fdd31 | 2006-08-08 03:47:01 +0100 | [diff] [blame] | 466 | regs->regs[0] = 0;	/* Don't deal with this again.  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | } | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 468 |  | 
|  | 469 | /* | 
|  | 470 | * If there's no signal to deliver, we just put the saved sigmask | 
|  | 471 | * back | 
|  | 472 | */ | 
|  | 473 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) { | 
|  | 474 | clear_thread_flag(TIF_RESTORE_SIGMASK); | 
|  | 475 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); | 
|  | 476 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } | 
|  | 478 |  | 
|  | 479 | /* | 
|  | 480 | * notification of userspace execution resumption | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 481 | * - triggered by the TIF_WORK_MASK flags | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | */ | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 483 | asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | __u32 thread_info_flags) | 
|  | 485 | { | 
|  | 486 | /* deal with pending signal delivery */ | 
| Ralf Baechle | 7b3e2fc | 2006-02-08 12:58:41 +0000 | [diff] [blame] | 487 | if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) | 
|  | 488 | current->thread.abi->do_signal(regs); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |