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