Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* signal.c: FRV specific bits of signal handling |
| 2 | * |
| 3 | * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * - Derived from arch/m68k/kernel/signal.c |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/sched.h> |
| 14 | #include <linux/mm.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/personality.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame^] | 24 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/ucontext.h> |
| 26 | #include <asm/uaccess.h> |
| 27 | #include <asm/cacheflush.h> |
| 28 | |
| 29 | #define DEBUG_SIG 0 |
| 30 | |
| 31 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) |
| 32 | |
| 33 | struct fdpic_func_descriptor { |
| 34 | unsigned long text; |
| 35 | unsigned long GOT; |
| 36 | }; |
| 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | /* |
| 39 | * Atomically swap in the new signal mask, and wait for a signal. |
| 40 | */ |
| 41 | asmlinkage int sys_sigsuspend(int history0, int history1, old_sigset_t mask) |
| 42 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | mask &= _BLOCKABLE; |
| 44 | spin_lock_irq(¤t->sighand->siglock); |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 45 | current->saved_sigmask = current->blocked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | siginitset(¤t->blocked, mask); |
| 47 | recalc_sigpending(); |
| 48 | spin_unlock_irq(¤t->sighand->siglock); |
| 49 | |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 50 | current->state = TASK_INTERRUPTIBLE; |
| 51 | schedule(); |
| 52 | set_thread_flag(TIF_RESTORE_SIGMASK); |
| 53 | return -ERESTARTNOHAND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | asmlinkage int sys_sigaction(int sig, |
| 57 | const struct old_sigaction __user *act, |
| 58 | struct old_sigaction __user *oact) |
| 59 | { |
| 60 | struct k_sigaction new_ka, old_ka; |
| 61 | int ret; |
| 62 | |
| 63 | if (act) { |
| 64 | old_sigset_t mask; |
| 65 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || |
| 66 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || |
| 67 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer)) |
| 68 | return -EFAULT; |
| 69 | __get_user(new_ka.sa.sa_flags, &act->sa_flags); |
| 70 | __get_user(mask, &act->sa_mask); |
| 71 | siginitset(&new_ka.sa.sa_mask, mask); |
| 72 | } |
| 73 | |
| 74 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
| 75 | |
| 76 | if (!ret && oact) { |
| 77 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || |
| 78 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || |
| 79 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer)) |
| 80 | return -EFAULT; |
| 81 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags); |
| 82 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); |
| 83 | } |
| 84 | |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | asmlinkage |
| 89 | int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss) |
| 90 | { |
| 91 | return do_sigaltstack(uss, uoss, __frame->sp); |
| 92 | } |
| 93 | |
| 94 | |
| 95 | /* |
| 96 | * Do a signal return; undo the signal stack. |
| 97 | */ |
| 98 | |
| 99 | struct sigframe |
| 100 | { |
Al Viro | 9e4d11f | 2006-06-23 02:04:04 -0700 | [diff] [blame] | 101 | __sigrestore_t pretcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | int sig; |
| 103 | struct sigcontext sc; |
| 104 | unsigned long extramask[_NSIG_WORDS-1]; |
| 105 | uint32_t retcode[2]; |
| 106 | }; |
| 107 | |
| 108 | struct rt_sigframe |
| 109 | { |
Al Viro | 9e4d11f | 2006-06-23 02:04:04 -0700 | [diff] [blame] | 110 | __sigrestore_t pretcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | int sig; |
Al Viro | 9e4d11f | 2006-06-23 02:04:04 -0700 | [diff] [blame] | 112 | struct siginfo __user *pinfo; |
| 113 | void __user *puc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | struct siginfo info; |
| 115 | struct ucontext uc; |
| 116 | uint32_t retcode[2]; |
| 117 | }; |
| 118 | |
| 119 | static int restore_sigcontext(struct sigcontext __user *sc, int *_gr8) |
| 120 | { |
| 121 | struct user_context *user = current->thread.user; |
| 122 | unsigned long tbr, psr; |
| 123 | |
| 124 | tbr = user->i.tbr; |
| 125 | psr = user->i.psr; |
| 126 | if (copy_from_user(user, &sc->sc_context, sizeof(sc->sc_context))) |
| 127 | goto badframe; |
| 128 | user->i.tbr = tbr; |
| 129 | user->i.psr = psr; |
| 130 | |
| 131 | restore_user_regs(user); |
| 132 | |
| 133 | user->i.syscallno = -1; /* disable syscall checks */ |
| 134 | |
| 135 | *_gr8 = user->i.gr[8]; |
| 136 | return 0; |
| 137 | |
| 138 | badframe: |
| 139 | return 1; |
| 140 | } |
| 141 | |
| 142 | asmlinkage int sys_sigreturn(void) |
| 143 | { |
| 144 | struct sigframe __user *frame = (struct sigframe __user *) __frame->sp; |
| 145 | sigset_t set; |
| 146 | int gr8; |
| 147 | |
| 148 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 149 | goto badframe; |
| 150 | if (__get_user(set.sig[0], &frame->sc.sc_oldmask)) |
| 151 | goto badframe; |
| 152 | |
| 153 | if (_NSIG_WORDS > 1 && |
| 154 | __copy_from_user(&set.sig[1], &frame->extramask, sizeof(frame->extramask))) |
| 155 | goto badframe; |
| 156 | |
| 157 | sigdelsetmask(&set, ~_BLOCKABLE); |
| 158 | spin_lock_irq(¤t->sighand->siglock); |
| 159 | current->blocked = set; |
| 160 | recalc_sigpending(); |
| 161 | spin_unlock_irq(¤t->sighand->siglock); |
| 162 | |
| 163 | if (restore_sigcontext(&frame->sc, &gr8)) |
| 164 | goto badframe; |
| 165 | return gr8; |
| 166 | |
| 167 | badframe: |
| 168 | force_sig(SIGSEGV, current); |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | asmlinkage int sys_rt_sigreturn(void) |
| 173 | { |
| 174 | struct rt_sigframe __user *frame = (struct rt_sigframe __user *) __frame->sp; |
| 175 | sigset_t set; |
| 176 | int gr8; |
| 177 | |
| 178 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 179 | goto badframe; |
| 180 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) |
| 181 | goto badframe; |
| 182 | |
| 183 | sigdelsetmask(&set, ~_BLOCKABLE); |
| 184 | spin_lock_irq(¤t->sighand->siglock); |
| 185 | current->blocked = set; |
| 186 | recalc_sigpending(); |
| 187 | spin_unlock_irq(¤t->sighand->siglock); |
| 188 | |
| 189 | if (restore_sigcontext(&frame->uc.uc_mcontext, &gr8)) |
| 190 | goto badframe; |
| 191 | |
| 192 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, __frame->sp) == -EFAULT) |
| 193 | goto badframe; |
| 194 | |
| 195 | return gr8; |
| 196 | |
| 197 | badframe: |
| 198 | force_sig(SIGSEGV, current); |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | /* |
| 203 | * Set up a signal frame |
| 204 | */ |
| 205 | static int setup_sigcontext(struct sigcontext __user *sc, unsigned long mask) |
| 206 | { |
| 207 | save_user_regs(current->thread.user); |
| 208 | |
| 209 | if (copy_to_user(&sc->sc_context, current->thread.user, sizeof(sc->sc_context)) != 0) |
| 210 | goto badframe; |
| 211 | |
| 212 | /* non-iBCS2 extensions.. */ |
| 213 | if (__put_user(mask, &sc->sc_oldmask) < 0) |
| 214 | goto badframe; |
| 215 | |
| 216 | return 0; |
| 217 | |
| 218 | badframe: |
| 219 | return 1; |
| 220 | } |
| 221 | |
| 222 | /*****************************************************************************/ |
| 223 | /* |
| 224 | * Determine which stack to use.. |
| 225 | */ |
| 226 | static inline void __user *get_sigframe(struct k_sigaction *ka, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | size_t frame_size) |
| 228 | { |
| 229 | unsigned long sp; |
| 230 | |
| 231 | /* Default to using normal stack */ |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 232 | sp = __frame->sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
| 234 | /* This is the X/Open sanctioned signal stack switching. */ |
| 235 | if (ka->sa.sa_flags & SA_ONSTACK) { |
Laurent MEYER | d09042d | 2006-06-23 02:05:36 -0700 | [diff] [blame] | 236 | if (! sas_ss_flags(sp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | sp = current->sas_ss_sp + current->sas_ss_size; |
| 238 | } |
| 239 | |
| 240 | return (void __user *) ((sp - frame_size) & ~7UL); |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } /* end get_sigframe() */ |
| 243 | |
| 244 | /*****************************************************************************/ |
| 245 | /* |
| 246 | * |
| 247 | */ |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 248 | static int setup_frame(int sig, struct k_sigaction *ka, sigset_t *set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | { |
| 250 | struct sigframe __user *frame; |
| 251 | int rsig; |
| 252 | |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 253 | frame = get_sigframe(ka, sizeof(*frame)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
| 256 | goto give_sigsegv; |
| 257 | |
| 258 | rsig = sig; |
| 259 | if (sig < 32 && |
| 260 | __current_thread_info->exec_domain && |
| 261 | __current_thread_info->exec_domain->signal_invmap) |
| 262 | rsig = __current_thread_info->exec_domain->signal_invmap[sig]; |
| 263 | |
| 264 | if (__put_user(rsig, &frame->sig) < 0) |
| 265 | goto give_sigsegv; |
| 266 | |
| 267 | if (setup_sigcontext(&frame->sc, set->sig[0])) |
| 268 | goto give_sigsegv; |
| 269 | |
| 270 | if (_NSIG_WORDS > 1) { |
| 271 | if (__copy_to_user(frame->extramask, &set->sig[1], |
| 272 | sizeof(frame->extramask))) |
| 273 | goto give_sigsegv; |
| 274 | } |
| 275 | |
| 276 | /* Set up to return from userspace. If provided, use a stub |
| 277 | * already in userspace. */ |
| 278 | if (ka->sa.sa_flags & SA_RESTORER) { |
| 279 | if (__put_user(ka->sa.sa_restorer, &frame->pretcode) < 0) |
| 280 | goto give_sigsegv; |
| 281 | } |
| 282 | else { |
| 283 | /* Set up the following code on the stack: |
| 284 | * setlos #__NR_sigreturn,gr7 |
| 285 | * tira gr0,0 |
| 286 | */ |
Al Viro | 9e4d11f | 2006-06-23 02:04:04 -0700 | [diff] [blame] | 287 | if (__put_user((__sigrestore_t)frame->retcode, &frame->pretcode) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | __put_user(0x8efc0000|__NR_sigreturn, &frame->retcode[0]) || |
| 289 | __put_user(0xc0700000, &frame->retcode[1])) |
| 290 | goto give_sigsegv; |
| 291 | |
| 292 | flush_icache_range((unsigned long) frame->retcode, |
| 293 | (unsigned long) (frame->retcode + 2)); |
| 294 | } |
| 295 | |
| 296 | /* set up registers for signal handler */ |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 297 | __frame->sp = (unsigned long) frame; |
| 298 | __frame->lr = (unsigned long) &frame->retcode; |
| 299 | __frame->gr8 = sig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | if (get_personality & FDPIC_FUNCPTRS) { |
| 302 | struct fdpic_func_descriptor __user *funcptr = |
Al Viro | 9e4d11f | 2006-06-23 02:04:04 -0700 | [diff] [blame] | 303 | (struct fdpic_func_descriptor __user *) ka->sa.sa_handler; |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 304 | __get_user(__frame->pc, &funcptr->text); |
| 305 | __get_user(__frame->gr15, &funcptr->GOT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } else { |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 307 | __frame->pc = (unsigned long) ka->sa.sa_handler; |
| 308 | __frame->gr15 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | set_fs(USER_DS); |
| 312 | |
David Howells | 8efc0ab | 2006-01-06 00:11:44 -0800 | [diff] [blame] | 313 | /* the tracer may want to single-step inside the handler */ |
| 314 | if (test_thread_flag(TIF_SINGLESTEP)) |
| 315 | ptrace_notify(SIGTRAP); |
| 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | #if DEBUG_SIG |
| 318 | printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n", |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 319 | sig, current->comm, current->pid, frame, __frame->pc, |
David Howells | 8efc0ab | 2006-01-06 00:11:44 -0800 | [diff] [blame] | 320 | frame->pretcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | #endif |
| 322 | |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 323 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | give_sigsegv: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | force_sig(SIGSEGV, current); |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 327 | return -EFAULT; |
David Howells | 8efc0ab | 2006-01-06 00:11:44 -0800 | [diff] [blame] | 328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } /* end setup_frame() */ |
| 330 | |
| 331 | /*****************************************************************************/ |
| 332 | /* |
| 333 | * |
| 334 | */ |
David Howells | 8efc0ab | 2006-01-06 00:11:44 -0800 | [diff] [blame] | 335 | static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 336 | sigset_t *set) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
| 338 | struct rt_sigframe __user *frame; |
| 339 | int rsig; |
| 340 | |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 341 | frame = get_sigframe(ka, sizeof(*frame)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
| 344 | goto give_sigsegv; |
| 345 | |
| 346 | rsig = sig; |
| 347 | if (sig < 32 && |
| 348 | __current_thread_info->exec_domain && |
| 349 | __current_thread_info->exec_domain->signal_invmap) |
| 350 | rsig = __current_thread_info->exec_domain->signal_invmap[sig]; |
| 351 | |
| 352 | if (__put_user(rsig, &frame->sig) || |
| 353 | __put_user(&frame->info, &frame->pinfo) || |
| 354 | __put_user(&frame->uc, &frame->puc)) |
| 355 | goto give_sigsegv; |
| 356 | |
| 357 | if (copy_siginfo_to_user(&frame->info, info)) |
| 358 | goto give_sigsegv; |
| 359 | |
| 360 | /* Create the ucontext. */ |
| 361 | if (__put_user(0, &frame->uc.uc_flags) || |
Al Viro | 9e4d11f | 2006-06-23 02:04:04 -0700 | [diff] [blame] | 362 | __put_user(NULL, &frame->uc.uc_link) || |
| 363 | __put_user((void __user *)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp) || |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 364 | __put_user(sas_ss_flags(__frame->sp), &frame->uc.uc_stack.ss_flags) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size)) |
| 366 | goto give_sigsegv; |
| 367 | |
| 368 | if (setup_sigcontext(&frame->uc.uc_mcontext, set->sig[0])) |
| 369 | goto give_sigsegv; |
| 370 | |
| 371 | if (__copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set))) |
| 372 | goto give_sigsegv; |
| 373 | |
| 374 | /* Set up to return from userspace. If provided, use a stub |
| 375 | * already in userspace. */ |
| 376 | if (ka->sa.sa_flags & SA_RESTORER) { |
| 377 | if (__put_user(ka->sa.sa_restorer, &frame->pretcode)) |
| 378 | goto give_sigsegv; |
| 379 | } |
| 380 | else { |
| 381 | /* Set up the following code on the stack: |
| 382 | * setlos #__NR_sigreturn,gr7 |
| 383 | * tira gr0,0 |
| 384 | */ |
Al Viro | 9e4d11f | 2006-06-23 02:04:04 -0700 | [diff] [blame] | 385 | if (__put_user((__sigrestore_t)frame->retcode, &frame->pretcode) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | __put_user(0x8efc0000|__NR_rt_sigreturn, &frame->retcode[0]) || |
| 387 | __put_user(0xc0700000, &frame->retcode[1])) |
| 388 | goto give_sigsegv; |
| 389 | |
| 390 | flush_icache_range((unsigned long) frame->retcode, |
| 391 | (unsigned long) (frame->retcode + 2)); |
| 392 | } |
| 393 | |
| 394 | /* Set up registers for signal handler */ |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 395 | __frame->sp = (unsigned long) frame; |
| 396 | __frame->lr = (unsigned long) &frame->retcode; |
| 397 | __frame->gr8 = sig; |
| 398 | __frame->gr9 = (unsigned long) &frame->info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | if (get_personality & FDPIC_FUNCPTRS) { |
Al Viro | 9e4d11f | 2006-06-23 02:04:04 -0700 | [diff] [blame] | 401 | struct fdpic_func_descriptor __user *funcptr = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | (struct fdpic_func_descriptor __user *) ka->sa.sa_handler; |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 403 | __get_user(__frame->pc, &funcptr->text); |
| 404 | __get_user(__frame->gr15, &funcptr->GOT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } else { |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 406 | __frame->pc = (unsigned long) ka->sa.sa_handler; |
| 407 | __frame->gr15 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | set_fs(USER_DS); |
| 411 | |
David Howells | 8efc0ab | 2006-01-06 00:11:44 -0800 | [diff] [blame] | 412 | /* the tracer may want to single-step inside the handler */ |
| 413 | if (test_thread_flag(TIF_SINGLESTEP)) |
| 414 | ptrace_notify(SIGTRAP); |
| 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | #if DEBUG_SIG |
| 417 | printk("SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n", |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 418 | sig, current->comm, current->pid, frame, __frame->pc, |
David Howells | 8efc0ab | 2006-01-06 00:11:44 -0800 | [diff] [blame] | 419 | frame->pretcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | #endif |
| 421 | |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 422 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
| 424 | give_sigsegv: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | force_sig(SIGSEGV, current); |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 426 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
| 428 | } /* end setup_rt_frame() */ |
| 429 | |
| 430 | /*****************************************************************************/ |
| 431 | /* |
| 432 | * OK, we're invoking a handler |
| 433 | */ |
David Howells | 8efc0ab | 2006-01-06 00:11:44 -0800 | [diff] [blame] | 434 | static int handle_signal(unsigned long sig, siginfo_t *info, |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 435 | struct k_sigaction *ka, sigset_t *oldset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
David Howells | 8efc0ab | 2006-01-06 00:11:44 -0800 | [diff] [blame] | 437 | int ret; |
| 438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | /* Are we from a system call? */ |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 440 | if (in_syscall(__frame)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | /* If so, check system call restarting.. */ |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 442 | switch (__frame->gr8) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | case -ERESTART_RESTARTBLOCK: |
| 444 | case -ERESTARTNOHAND: |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 445 | __frame->gr8 = -EINTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | break; |
| 447 | |
| 448 | case -ERESTARTSYS: |
| 449 | if (!(ka->sa.sa_flags & SA_RESTART)) { |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 450 | __frame->gr8 = -EINTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | break; |
| 452 | } |
David Howells | 8efc0ab | 2006-01-06 00:11:44 -0800 | [diff] [blame] | 453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | /* fallthrough */ |
| 455 | case -ERESTARTNOINTR: |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 456 | __frame->gr8 = __frame->orig_gr8; |
| 457 | __frame->pc -= 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | |
| 461 | /* Set up the stack frame */ |
| 462 | if (ka->sa.sa_flags & SA_SIGINFO) |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 463 | ret = setup_rt_frame(sig, ka, info, oldset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | else |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 465 | ret = setup_frame(sig, ka, oldset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 467 | if (ret == 0) { |
David Howells | 8efc0ab | 2006-01-06 00:11:44 -0800 | [diff] [blame] | 468 | spin_lock_irq(¤t->sighand->siglock); |
| 469 | sigorsets(¤t->blocked, ¤t->blocked, |
| 470 | &ka->sa.sa_mask); |
| 471 | if (!(ka->sa.sa_flags & SA_NODEFER)) |
| 472 | sigaddset(¤t->blocked, sig); |
| 473 | recalc_sigpending(); |
| 474 | spin_unlock_irq(¤t->sighand->siglock); |
| 475 | } |
| 476 | |
| 477 | return ret; |
| 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | } /* end handle_signal() */ |
| 480 | |
| 481 | /*****************************************************************************/ |
| 482 | /* |
| 483 | * Note that 'init' is a special process: it doesn't get signals it doesn't |
| 484 | * want to handle. Thus you cannot kill init even with a SIGKILL even by |
| 485 | * mistake. |
| 486 | */ |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 487 | static void do_signal(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { |
| 489 | struct k_sigaction ka; |
| 490 | siginfo_t info; |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 491 | sigset_t *oldset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | int signr; |
| 493 | |
| 494 | /* |
| 495 | * We want the common case to go fast, which |
| 496 | * is why we may in certain cases get here from |
| 497 | * kernel mode. Just return without doing anything |
| 498 | * if so. |
| 499 | */ |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 500 | if (!user_mode(__frame)) |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 501 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
Christoph Lameter | 3e1d1d2 | 2005-06-24 23:13:50 -0700 | [diff] [blame] | 503 | if (try_to_freeze()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | goto no_signal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 506 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) |
| 507 | oldset = ¤t->saved_sigmask; |
| 508 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | oldset = ¤t->blocked; |
| 510 | |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 511 | signr = get_signal_to_deliver(&info, &ka, __frame, NULL); |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 512 | if (signr > 0) { |
| 513 | if (handle_signal(signr, &info, &ka, oldset) == 0) { |
| 514 | /* a signal was successfully delivered; the saved |
| 515 | * sigmask will have been stored in the signal frame, |
| 516 | * and will be restored by sigreturn, so we can simply |
| 517 | * clear the TIF_RESTORE_SIGMASK flag */ |
| 518 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) |
| 519 | clear_thread_flag(TIF_RESTORE_SIGMASK); |
| 520 | } |
| 521 | |
| 522 | return; |
| 523 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
David Howells | 8efc0ab | 2006-01-06 00:11:44 -0800 | [diff] [blame] | 525 | no_signal: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | /* Did we come from a system call? */ |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 527 | if (__frame->syscallno >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | /* Restart the system call - no handlers present */ |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 529 | switch (__frame->gr8) { |
| 530 | case -ERESTARTNOHAND: |
| 531 | case -ERESTARTSYS: |
| 532 | case -ERESTARTNOINTR: |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 533 | __frame->gr8 = __frame->orig_gr8; |
| 534 | __frame->pc -= 4; |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 535 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 537 | case -ERESTART_RESTARTBLOCK: |
David Howells | fef2b58 | 2006-01-06 00:11:45 -0800 | [diff] [blame] | 538 | __frame->gr8 = __NR_restart_syscall; |
| 539 | __frame->pc -= 4; |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 540 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 544 | /* if there's no signal to deliver, we just put the saved sigmask |
| 545 | * back */ |
| 546 | if (test_thread_flag(TIF_RESTORE_SIGMASK)) { |
| 547 | clear_thread_flag(TIF_RESTORE_SIGMASK); |
| 548 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); |
| 549 | } |
David Howells | 8efc0ab | 2006-01-06 00:11:44 -0800 | [diff] [blame] | 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | } /* end do_signal() */ |
| 552 | |
| 553 | /*****************************************************************************/ |
| 554 | /* |
| 555 | * notification of userspace execution resumption |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 556 | * - triggered by the TIF_WORK_MASK flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | */ |
| 558 | asmlinkage void do_notify_resume(__u32 thread_info_flags) |
| 559 | { |
| 560 | /* pending single-step? */ |
| 561 | if (thread_info_flags & _TIF_SINGLESTEP) |
| 562 | clear_thread_flag(TIF_SINGLESTEP); |
| 563 | |
| 564 | /* deal with pending signal delivery */ |
David Howells | a411aee | 2006-01-18 17:43:59 -0800 | [diff] [blame] | 565 | if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) |
| 566 | do_signal(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 568 | } /* end do_notify_resume() */ |