David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 1 | /* MN10300 Signal handling |
| 2 | * |
| 3 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public Licence |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the Licence, or (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/sched.h> |
| 13 | #include <linux/mm.h> |
| 14 | #include <linux/smp.h> |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/signal.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/wait.h> |
| 19 | #include <linux/ptrace.h> |
| 20 | #include <linux/unistd.h> |
| 21 | #include <linux/stddef.h> |
| 22 | #include <linux/tty.h> |
| 23 | #include <linux/personality.h> |
| 24 | #include <linux/suspend.h> |
David Howells | 5d28996 | 2009-06-11 13:08:37 +0100 | [diff] [blame] | 25 | #include <linux/tracehook.h> |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 26 | #include <asm/cacheflush.h> |
| 27 | #include <asm/ucontext.h> |
| 28 | #include <asm/uaccess.h> |
| 29 | #include <asm/fpu.h> |
| 30 | #include "sigframe.h" |
| 31 | |
| 32 | #define DEBUG_SIG 0 |
| 33 | |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 34 | /* |
| 35 | * atomically swap in the new signal mask, and wait for a signal. |
| 36 | */ |
| 37 | asmlinkage long sys_sigsuspend(int history0, int history1, old_sigset_t mask) |
| 38 | { |
Al Viro | 68f3f16 | 2012-05-21 21:42:32 -0400 | [diff] [blame] | 39 | sigset_t blocked; |
| 40 | siginitset(&blocked, mask); |
| 41 | return sigsuspend(&blocked); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /* |
| 45 | * set signal action syscall |
| 46 | */ |
| 47 | asmlinkage long sys_sigaction(int sig, |
| 48 | const struct old_sigaction __user *act, |
| 49 | struct old_sigaction __user *oact) |
| 50 | { |
| 51 | struct k_sigaction new_ka, old_ka; |
| 52 | int ret; |
| 53 | |
| 54 | if (act) { |
| 55 | old_sigset_t mask; |
| 56 | if (verify_area(VERIFY_READ, act, sizeof(*act)) || |
| 57 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || |
Al Viro | 60bdb72 | 2010-09-26 19:29:12 +0100 | [diff] [blame] | 58 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) || |
| 59 | __get_user(new_ka.sa.sa_flags, &act->sa_flags) || |
| 60 | __get_user(mask, &act->sa_mask)) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 61 | return -EFAULT; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 62 | siginitset(&new_ka.sa.sa_mask, mask); |
| 63 | } |
| 64 | |
| 65 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
| 66 | |
| 67 | if (!ret && oact) { |
| 68 | if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) || |
| 69 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || |
Al Viro | 60bdb72 | 2010-09-26 19:29:12 +0100 | [diff] [blame] | 70 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) || |
| 71 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags) || |
| 72 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask)) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 73 | return -EFAULT; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | return ret; |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * set alternate signal stack syscall |
| 81 | */ |
| 82 | asmlinkage long sys_sigaltstack(const stack_t __user *uss, stack_t *uoss) |
| 83 | { |
David Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 84 | return do_sigaltstack(uss, uoss, current_frame()->sp); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* |
| 88 | * do a signal return; undo the signal stack. |
| 89 | */ |
| 90 | static int restore_sigcontext(struct pt_regs *regs, |
| 91 | struct sigcontext __user *sc, long *_d0) |
| 92 | { |
| 93 | unsigned int err = 0; |
| 94 | |
Al Viro | c05628b | 2010-09-26 19:28:52 +0100 | [diff] [blame] | 95 | /* Always make any pending restarted system calls return -EINTR */ |
| 96 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 97 | |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 98 | if (is_using_fpu(current)) |
| 99 | fpu_kill_state(current); |
| 100 | |
| 101 | #define COPY(x) err |= __get_user(regs->x, &sc->x) |
| 102 | COPY(d1); COPY(d2); COPY(d3); |
| 103 | COPY(a0); COPY(a1); COPY(a2); COPY(a3); |
| 104 | COPY(e0); COPY(e1); COPY(e2); COPY(e3); |
| 105 | COPY(e4); COPY(e5); COPY(e6); COPY(e7); |
| 106 | COPY(lar); COPY(lir); |
| 107 | COPY(mdr); COPY(mdrq); |
| 108 | COPY(mcvf); COPY(mcrl); COPY(mcrh); |
| 109 | COPY(sp); COPY(pc); |
| 110 | #undef COPY |
| 111 | |
| 112 | { |
| 113 | unsigned int tmpflags; |
| 114 | #ifndef CONFIG_MN10300_USING_JTAG |
| 115 | #define USER_EPSW (EPSW_FLAG_Z | EPSW_FLAG_N | EPSW_FLAG_C | EPSW_FLAG_V | \ |
| 116 | EPSW_T | EPSW_nAR) |
| 117 | #else |
| 118 | #define USER_EPSW (EPSW_FLAG_Z | EPSW_FLAG_N | EPSW_FLAG_C | EPSW_FLAG_V | \ |
| 119 | EPSW_nAR) |
| 120 | #endif |
| 121 | err |= __get_user(tmpflags, &sc->epsw); |
| 122 | regs->epsw = (regs->epsw & ~USER_EPSW) | |
| 123 | (tmpflags & USER_EPSW); |
| 124 | regs->orig_d0 = -1; /* disable syscall checks */ |
| 125 | } |
| 126 | |
| 127 | { |
| 128 | struct fpucontext *buf; |
| 129 | err |= __get_user(buf, &sc->fpucontext); |
| 130 | if (buf) { |
| 131 | if (verify_area(VERIFY_READ, buf, sizeof(*buf))) |
| 132 | goto badframe; |
| 133 | err |= fpu_restore_sigcontext(buf); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | err |= __get_user(*_d0, &sc->d0); |
| 138 | return err; |
| 139 | |
| 140 | badframe: |
| 141 | return 1; |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * standard signal return syscall |
| 146 | */ |
| 147 | asmlinkage long sys_sigreturn(void) |
| 148 | { |
David Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 149 | struct sigframe __user *frame; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 150 | sigset_t set; |
| 151 | long d0; |
| 152 | |
David Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 153 | frame = (struct sigframe __user *) current_frame()->sp; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 154 | if (verify_area(VERIFY_READ, frame, sizeof(*frame))) |
| 155 | goto badframe; |
| 156 | if (__get_user(set.sig[0], &frame->sc.oldmask)) |
| 157 | goto badframe; |
| 158 | |
| 159 | if (_NSIG_WORDS > 1 && |
| 160 | __copy_from_user(&set.sig[1], &frame->extramask, |
| 161 | sizeof(frame->extramask))) |
| 162 | goto badframe; |
| 163 | |
Matt Fleming | 00f3578 | 2012-05-11 10:57:59 +1000 | [diff] [blame] | 164 | set_current_blocked(&set); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 165 | |
David Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 166 | if (restore_sigcontext(current_frame(), &frame->sc, &d0)) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 167 | goto badframe; |
| 168 | |
| 169 | return d0; |
| 170 | |
| 171 | badframe: |
| 172 | force_sig(SIGSEGV, current); |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | /* |
| 177 | * realtime signal return syscall |
| 178 | */ |
| 179 | asmlinkage long sys_rt_sigreturn(void) |
| 180 | { |
David Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 181 | struct rt_sigframe __user *frame; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 182 | sigset_t set; |
David Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 183 | long d0; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 184 | |
David Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 185 | frame = (struct rt_sigframe __user *) current_frame()->sp; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 186 | if (verify_area(VERIFY_READ, frame, sizeof(*frame))) |
| 187 | goto badframe; |
| 188 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) |
| 189 | goto badframe; |
| 190 | |
Matt Fleming | 00f3578 | 2012-05-11 10:57:59 +1000 | [diff] [blame] | 191 | set_current_blocked(&set); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 192 | |
David Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 193 | if (restore_sigcontext(current_frame(), &frame->uc.uc_mcontext, &d0)) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 194 | goto badframe; |
| 195 | |
David Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 196 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, current_frame()->sp) == |
| 197 | -EFAULT) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 198 | goto badframe; |
| 199 | |
| 200 | return d0; |
| 201 | |
| 202 | badframe: |
| 203 | force_sig(SIGSEGV, current); |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * store the userspace context into a signal frame |
| 209 | */ |
| 210 | static int setup_sigcontext(struct sigcontext __user *sc, |
| 211 | struct fpucontext *fpuctx, |
| 212 | struct pt_regs *regs, |
| 213 | unsigned long mask) |
| 214 | { |
| 215 | int tmp, err = 0; |
| 216 | |
| 217 | #define COPY(x) err |= __put_user(regs->x, &sc->x) |
| 218 | COPY(d0); COPY(d1); COPY(d2); COPY(d3); |
| 219 | COPY(a0); COPY(a1); COPY(a2); COPY(a3); |
| 220 | COPY(e0); COPY(e1); COPY(e2); COPY(e3); |
| 221 | COPY(e4); COPY(e5); COPY(e6); COPY(e7); |
| 222 | COPY(lar); COPY(lir); |
| 223 | COPY(mdr); COPY(mdrq); |
| 224 | COPY(mcvf); COPY(mcrl); COPY(mcrh); |
| 225 | COPY(sp); COPY(epsw); COPY(pc); |
| 226 | #undef COPY |
| 227 | |
| 228 | tmp = fpu_setup_sigcontext(fpuctx); |
| 229 | if (tmp < 0) |
| 230 | err = 1; |
| 231 | else |
| 232 | err |= __put_user(tmp ? fpuctx : NULL, &sc->fpucontext); |
| 233 | |
| 234 | /* non-iBCS2 extensions.. */ |
| 235 | err |= __put_user(mask, &sc->oldmask); |
| 236 | |
| 237 | return err; |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | * determine which stack to use.. |
| 242 | */ |
| 243 | static inline void __user *get_sigframe(struct k_sigaction *ka, |
| 244 | struct pt_regs *regs, |
| 245 | size_t frame_size) |
| 246 | { |
| 247 | unsigned long sp; |
| 248 | |
| 249 | /* default to using normal stack */ |
| 250 | sp = regs->sp; |
| 251 | |
| 252 | /* this is the X/Open sanctioned signal stack switching. */ |
| 253 | if (ka->sa.sa_flags & SA_ONSTACK) { |
Mark Salter | 4c03ee7 | 2010-01-08 14:43:14 -0800 | [diff] [blame] | 254 | if (sas_ss_flags(sp) == 0) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 255 | sp = current->sas_ss_sp + current->sas_ss_size; |
| 256 | } |
| 257 | |
| 258 | return (void __user *) ((sp - frame_size) & ~7UL); |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * set up a normal signal frame |
| 263 | */ |
| 264 | static int setup_frame(int sig, struct k_sigaction *ka, sigset_t *set, |
| 265 | struct pt_regs *regs) |
| 266 | { |
| 267 | struct sigframe __user *frame; |
| 268 | int rsig; |
| 269 | |
| 270 | frame = get_sigframe(ka, regs, sizeof(*frame)); |
| 271 | |
| 272 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
| 273 | goto give_sigsegv; |
| 274 | |
| 275 | rsig = sig; |
| 276 | if (sig < 32 && |
| 277 | current_thread_info()->exec_domain && |
| 278 | current_thread_info()->exec_domain->signal_invmap) |
| 279 | rsig = current_thread_info()->exec_domain->signal_invmap[sig]; |
| 280 | |
| 281 | if (__put_user(rsig, &frame->sig) < 0 || |
| 282 | __put_user(&frame->sc, &frame->psc) < 0) |
| 283 | goto give_sigsegv; |
| 284 | |
| 285 | if (setup_sigcontext(&frame->sc, &frame->fpuctx, regs, set->sig[0])) |
| 286 | goto give_sigsegv; |
| 287 | |
| 288 | if (_NSIG_WORDS > 1) { |
| 289 | if (__copy_to_user(frame->extramask, &set->sig[1], |
| 290 | sizeof(frame->extramask))) |
| 291 | goto give_sigsegv; |
| 292 | } |
| 293 | |
| 294 | /* set up to return from userspace. If provided, use a stub already in |
| 295 | * userspace */ |
| 296 | if (ka->sa.sa_flags & SA_RESTORER) { |
| 297 | if (__put_user(ka->sa.sa_restorer, &frame->pretcode)) |
| 298 | goto give_sigsegv; |
| 299 | } else { |
| 300 | if (__put_user((void (*)(void))frame->retcode, |
| 301 | &frame->pretcode)) |
| 302 | goto give_sigsegv; |
| 303 | /* this is mov $,d0; syscall 0 */ |
| 304 | if (__put_user(0x2c, (char *)(frame->retcode + 0)) || |
| 305 | __put_user(__NR_sigreturn, (char *)(frame->retcode + 1)) || |
| 306 | __put_user(0x00, (char *)(frame->retcode + 2)) || |
| 307 | __put_user(0xf0, (char *)(frame->retcode + 3)) || |
| 308 | __put_user(0xe0, (char *)(frame->retcode + 4))) |
| 309 | goto give_sigsegv; |
| 310 | flush_icache_range((unsigned long) frame->retcode, |
| 311 | (unsigned long) frame->retcode + 5); |
| 312 | } |
| 313 | |
| 314 | /* set up registers for signal handler */ |
| 315 | regs->sp = (unsigned long) frame; |
| 316 | regs->pc = (unsigned long) ka->sa.sa_handler; |
| 317 | regs->d0 = sig; |
| 318 | regs->d1 = (unsigned long) &frame->sc; |
| 319 | |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 320 | /* the tracer may want to single-step inside the handler */ |
| 321 | if (test_thread_flag(TIF_SINGLESTEP)) |
| 322 | ptrace_notify(SIGTRAP); |
| 323 | |
| 324 | #if DEBUG_SIG |
| 325 | printk(KERN_DEBUG "SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n", |
| 326 | sig, current->comm, current->pid, frame, regs->pc, |
| 327 | frame->pretcode); |
| 328 | #endif |
| 329 | |
| 330 | return 0; |
| 331 | |
| 332 | give_sigsegv: |
Al Viro | e46924d | 2010-09-26 19:28:32 +0100 | [diff] [blame] | 333 | force_sigsegv(sig, current); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 334 | return -EFAULT; |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | * set up a realtime signal frame |
| 339 | */ |
| 340 | static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
| 341 | sigset_t *set, struct pt_regs *regs) |
| 342 | { |
| 343 | struct rt_sigframe __user *frame; |
| 344 | int rsig; |
| 345 | |
| 346 | frame = get_sigframe(ka, regs, sizeof(*frame)); |
| 347 | |
| 348 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
| 349 | goto give_sigsegv; |
| 350 | |
| 351 | rsig = sig; |
| 352 | if (sig < 32 && |
| 353 | current_thread_info()->exec_domain && |
| 354 | current_thread_info()->exec_domain->signal_invmap) |
| 355 | rsig = current_thread_info()->exec_domain->signal_invmap[sig]; |
| 356 | |
| 357 | if (__put_user(rsig, &frame->sig) || |
| 358 | __put_user(&frame->info, &frame->pinfo) || |
| 359 | __put_user(&frame->uc, &frame->puc) || |
| 360 | copy_siginfo_to_user(&frame->info, info)) |
| 361 | goto give_sigsegv; |
| 362 | |
| 363 | /* create the ucontext. */ |
| 364 | if (__put_user(0, &frame->uc.uc_flags) || |
| 365 | __put_user(0, &frame->uc.uc_link) || |
| 366 | __put_user((void *)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp) || |
| 367 | __put_user(sas_ss_flags(regs->sp), &frame->uc.uc_stack.ss_flags) || |
| 368 | __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size) || |
| 369 | setup_sigcontext(&frame->uc.uc_mcontext, |
| 370 | &frame->fpuctx, regs, set->sig[0]) || |
| 371 | __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 already in |
| 375 | * userspace */ |
| 376 | if (ka->sa.sa_flags & SA_RESTORER) { |
| 377 | if (__put_user(ka->sa.sa_restorer, &frame->pretcode)) |
| 378 | goto give_sigsegv; |
| 379 | } else { |
| 380 | if (__put_user((void(*)(void))frame->retcode, |
| 381 | &frame->pretcode) || |
| 382 | /* This is mov $,d0; syscall 0 */ |
| 383 | __put_user(0x2c, (char *)(frame->retcode + 0)) || |
| 384 | __put_user(__NR_rt_sigreturn, |
| 385 | (char *)(frame->retcode + 1)) || |
| 386 | __put_user(0x00, (char *)(frame->retcode + 2)) || |
| 387 | __put_user(0xf0, (char *)(frame->retcode + 3)) || |
| 388 | __put_user(0xe0, (char *)(frame->retcode + 4))) |
| 389 | goto give_sigsegv; |
| 390 | |
| 391 | flush_icache_range((u_long) frame->retcode, |
| 392 | (u_long) frame->retcode + 5); |
| 393 | } |
| 394 | |
| 395 | /* Set up registers for signal handler */ |
| 396 | regs->sp = (unsigned long) frame; |
| 397 | regs->pc = (unsigned long) ka->sa.sa_handler; |
| 398 | regs->d0 = sig; |
| 399 | regs->d1 = (long) &frame->info; |
| 400 | |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 401 | /* the tracer may want to single-step inside the handler */ |
| 402 | if (test_thread_flag(TIF_SINGLESTEP)) |
| 403 | ptrace_notify(SIGTRAP); |
| 404 | |
| 405 | #if DEBUG_SIG |
| 406 | printk(KERN_DEBUG "SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n", |
| 407 | sig, current->comm, current->pid, frame, regs->pc, |
| 408 | frame->pretcode); |
| 409 | #endif |
| 410 | |
| 411 | return 0; |
| 412 | |
| 413 | give_sigsegv: |
Al Viro | e46924d | 2010-09-26 19:28:32 +0100 | [diff] [blame] | 414 | force_sigsegv(sig, current); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 415 | return -EFAULT; |
| 416 | } |
| 417 | |
Al Viro | 00cbf60 | 2010-09-26 19:28:42 +0100 | [diff] [blame] | 418 | static inline void stepback(struct pt_regs *regs) |
| 419 | { |
| 420 | regs->pc -= 2; |
| 421 | regs->orig_d0 = -1; |
| 422 | } |
| 423 | |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 424 | /* |
| 425 | * handle the actual delivery of a signal to userspace |
| 426 | */ |
| 427 | static int handle_signal(int sig, |
| 428 | siginfo_t *info, struct k_sigaction *ka, |
Al Viro | b7f9a11 | 2012-05-02 09:59:21 -0400 | [diff] [blame] | 429 | struct pt_regs *regs) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 430 | { |
Al Viro | b7f9a11 | 2012-05-02 09:59:21 -0400 | [diff] [blame] | 431 | sigset_t *oldset = sigmask_to_save(); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 432 | int ret; |
| 433 | |
| 434 | /* Are we from a system call? */ |
| 435 | if (regs->orig_d0 >= 0) { |
| 436 | /* If so, check system call restarting.. */ |
| 437 | switch (regs->d0) { |
| 438 | case -ERESTART_RESTARTBLOCK: |
| 439 | case -ERESTARTNOHAND: |
| 440 | regs->d0 = -EINTR; |
| 441 | break; |
| 442 | |
| 443 | case -ERESTARTSYS: |
| 444 | if (!(ka->sa.sa_flags & SA_RESTART)) { |
| 445 | regs->d0 = -EINTR; |
| 446 | break; |
| 447 | } |
| 448 | |
| 449 | /* fallthrough */ |
| 450 | case -ERESTARTNOINTR: |
| 451 | regs->d0 = regs->orig_d0; |
Al Viro | 00cbf60 | 2010-09-26 19:28:42 +0100 | [diff] [blame] | 452 | stepback(regs); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
| 456 | /* Set up the stack frame */ |
| 457 | if (ka->sa.sa_flags & SA_SIGINFO) |
| 458 | ret = setup_rt_frame(sig, ka, info, oldset, regs); |
| 459 | else |
| 460 | ret = setup_frame(sig, ka, oldset, regs); |
Al Viro | a610d6e | 2012-05-21 23:42:15 -0400 | [diff] [blame] | 461 | if (ret) |
| 462 | return; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 463 | |
Al Viro | efee984 | 2012-04-28 02:04:15 -0400 | [diff] [blame] | 464 | signal_delivered(sig, info, ka, regs, |
Al Viro | a610d6e | 2012-05-21 23:42:15 -0400 | [diff] [blame] | 465 | test_thread_flag(TIF_SINGLESTEP)); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /* |
| 469 | * handle a potential signal |
| 470 | */ |
| 471 | static void do_signal(struct pt_regs *regs) |
| 472 | { |
| 473 | struct k_sigaction ka; |
| 474 | siginfo_t info; |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 475 | int signr; |
| 476 | |
| 477 | /* we want the common case to go fast, which is why we may in certain |
| 478 | * cases get here from kernel mode */ |
| 479 | if (!user_mode(regs)) |
| 480 | return; |
| 481 | |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 482 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); |
| 483 | if (signr > 0) { |
Al Viro | b7f9a11 | 2012-05-02 09:59:21 -0400 | [diff] [blame] | 484 | if (handle_signal(signr, &info, &ka, regs) == 0) { |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | return; |
| 488 | } |
| 489 | |
| 490 | /* did we come from a system call? */ |
| 491 | if (regs->orig_d0 >= 0) { |
| 492 | /* restart the system call - no handlers present */ |
| 493 | switch (regs->d0) { |
| 494 | case -ERESTARTNOHAND: |
| 495 | case -ERESTARTSYS: |
| 496 | case -ERESTARTNOINTR: |
| 497 | regs->d0 = regs->orig_d0; |
Al Viro | 00cbf60 | 2010-09-26 19:28:42 +0100 | [diff] [blame] | 498 | stepback(regs); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 499 | break; |
| 500 | |
| 501 | case -ERESTART_RESTARTBLOCK: |
| 502 | regs->d0 = __NR_restart_syscall; |
Al Viro | 00cbf60 | 2010-09-26 19:28:42 +0100 | [diff] [blame] | 503 | stepback(regs); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 504 | break; |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | /* if there's no signal to deliver, we just put the saved sigmask |
| 509 | * back */ |
Al Viro | 51a7b44 | 2012-05-21 23:33:55 -0400 | [diff] [blame] | 510 | restore_saved_sigmask(); |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /* |
| 514 | * notification of userspace execution resumption |
| 515 | * - triggered by current->work.notify_resume |
| 516 | */ |
| 517 | asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags) |
| 518 | { |
| 519 | /* Pending single-step? */ |
| 520 | if (thread_info_flags & _TIF_SINGLESTEP) { |
| 521 | #ifndef CONFIG_MN10300_USING_JTAG |
| 522 | regs->epsw |= EPSW_T; |
| 523 | clear_thread_flag(TIF_SINGLESTEP); |
| 524 | #else |
| 525 | BUG(); /* no h/w single-step if using JTAG unit */ |
| 526 | #endif |
| 527 | } |
| 528 | |
| 529 | /* deal with pending signal delivery */ |
Al Viro | 6fd84c0 | 2012-05-23 15:28:58 -0400 | [diff] [blame] | 530 | if (thread_info_flags & _TIF_SIGPENDING) |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 531 | do_signal(regs); |
David Howells | 5d28996 | 2009-06-11 13:08:37 +0100 | [diff] [blame] | 532 | |
| 533 | if (thread_info_flags & _TIF_NOTIFY_RESUME) { |
| 534 | clear_thread_flag(TIF_NOTIFY_RESUME); |
David Howells | 7c7fcf7 | 2010-10-27 17:29:01 +0100 | [diff] [blame] | 535 | tracehook_notify_resume(current_frame()); |
David Howells | 5d28996 | 2009-06-11 13:08:37 +0100 | [diff] [blame] | 536 | } |
David Howells | b920de1 | 2008-02-08 04:19:31 -0800 | [diff] [blame] | 537 | } |