Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 3 | * |
| 4 | * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson |
| 5 | * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes |
| 6 | */ |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 7 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/personality.h> |
Andi Kleen | 9fbbd4d | 2007-02-13 13:26:26 +0100 | [diff] [blame] | 10 | #include <linux/binfmts.h> |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 11 | #include <linux/suspend.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/ptrace.h> |
| 14 | #include <linux/signal.h> |
| 15 | #include <linux/stddef.h> |
| 16 | #include <linux/unistd.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/sched.h> |
| 19 | #include <linux/wait.h> |
Roland McGrath | 36a0330 | 2008-03-14 17:46:38 -0700 | [diff] [blame] | 20 | #include <linux/tracehook.h> |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 21 | #include <linux/elf.h> |
| 22 | #include <linux/smp.h> |
| 23 | #include <linux/mm.h> |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/processor.h> |
| 26 | #include <asm/ucontext.h> |
| 27 | #include <asm/uaccess.h> |
| 28 | #include <asm/i387.h> |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 29 | #include <asm/vdso.h> |
Hiroshi Shimamoto | bb57925 | 2008-09-05 16:26:55 -0700 | [diff] [blame] | 30 | #include <asm/syscall.h> |
Jaswinder Singh | bbc1f69 | 2008-07-21 21:34:13 +0530 | [diff] [blame] | 31 | #include <asm/syscalls.h> |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 32 | |
Harvey Harrison | 123a634 | 2008-02-08 12:10:00 -0800 | [diff] [blame] | 33 | #include "sigframe.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) |
| 36 | |
Harvey Harrison | 1a17680 | 2008-02-08 12:09:59 -0800 | [diff] [blame] | 37 | #define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \ |
| 38 | X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \ |
| 39 | X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \ |
| 40 | X86_EFLAGS_CF) |
| 41 | |
| 42 | #ifdef CONFIG_X86_32 |
| 43 | # define FIX_EFLAGS (__FIX_EFLAGS | X86_EFLAGS_RF) |
| 44 | #else |
| 45 | # define FIX_EFLAGS __FIX_EFLAGS |
| 46 | #endif |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | /* |
| 49 | * Atomically swap in the new signal mask, and wait for a signal. |
| 50 | */ |
| 51 | asmlinkage int |
| 52 | sys_sigsuspend(int history0, int history1, old_sigset_t mask) |
| 53 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | mask &= _BLOCKABLE; |
| 55 | spin_lock_irq(¤t->sighand->siglock); |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 56 | current->saved_sigmask = current->blocked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | siginitset(¤t->blocked, mask); |
| 58 | recalc_sigpending(); |
| 59 | spin_unlock_irq(¤t->sighand->siglock); |
| 60 | |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 61 | current->state = TASK_INTERRUPTIBLE; |
| 62 | schedule(); |
Roland McGrath | 5a8da0e | 2008-04-30 00:53:10 -0700 | [diff] [blame] | 63 | set_restore_sigmask(); |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 64 | |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 65 | return -ERESTARTNOHAND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 68 | asmlinkage int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | sys_sigaction(int sig, const struct old_sigaction __user *act, |
| 70 | struct old_sigaction __user *oact) |
| 71 | { |
| 72 | struct k_sigaction new_ka, old_ka; |
| 73 | int ret; |
| 74 | |
| 75 | if (act) { |
| 76 | old_sigset_t mask; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | if (!access_ok(VERIFY_READ, act, sizeof(*act)) || |
| 79 | __get_user(new_ka.sa.sa_handler, &act->sa_handler) || |
| 80 | __get_user(new_ka.sa.sa_restorer, &act->sa_restorer)) |
| 81 | return -EFAULT; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | __get_user(new_ka.sa.sa_flags, &act->sa_flags); |
| 84 | __get_user(mask, &act->sa_mask); |
| 85 | siginitset(&new_ka.sa.sa_mask, mask); |
| 86 | } |
| 87 | |
| 88 | ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); |
| 89 | |
| 90 | if (!ret && oact) { |
| 91 | if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || |
| 92 | __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || |
| 93 | __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer)) |
| 94 | return -EFAULT; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | __put_user(old_ka.sa.sa_flags, &oact->sa_flags); |
| 97 | __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); |
| 98 | } |
| 99 | |
| 100 | return ret; |
| 101 | } |
| 102 | |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 103 | asmlinkage int sys_sigaltstack(unsigned long bx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 105 | /* |
| 106 | * This is needed to make gcc realize it doesn't own the |
| 107 | * "struct pt_regs" |
| 108 | */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 109 | struct pt_regs *regs = (struct pt_regs *)&bx; |
| 110 | const stack_t __user *uss = (const stack_t __user *)bx; |
| 111 | stack_t __user *uoss = (stack_t __user *)regs->cx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 113 | return do_sigaltstack(uss, uoss, regs->sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | |
| 117 | /* |
| 118 | * Do a signal return; undo the signal stack. |
| 119 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | static int |
Harvey Harrison | 866bc13 | 2008-02-08 12:10:02 -0800 | [diff] [blame] | 121 | restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, |
| 122 | unsigned long *pax) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | unsigned int err = 0; |
| 125 | |
| 126 | /* Always make any pending restarted system calls return -EINTR */ |
| 127 | current_thread_info()->restart_block.fn = do_no_restart_syscall; |
| 128 | |
H. Peter Anvin | 742fa54 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 129 | #define COPY(x) err |= __get_user(regs->x, &sc->x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | #define COPY_SEG(seg) \ |
| 132 | { unsigned short tmp; \ |
| 133 | err |= __get_user(tmp, &sc->seg); \ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 134 | regs->seg = tmp; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | #define COPY_SEG_STRICT(seg) \ |
| 137 | { unsigned short tmp; \ |
| 138 | err |= __get_user(tmp, &sc->seg); \ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 139 | regs->seg = tmp|3; } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
| 141 | #define GET_SEG(seg) \ |
| 142 | { unsigned short tmp; \ |
| 143 | err |= __get_user(tmp, &sc->seg); \ |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 144 | loadsegment(seg, tmp); } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Jeremy Fitzhardinge | 464d1a7 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 146 | GET_SEG(gs); |
| 147 | COPY_SEG(fs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | COPY_SEG(es); |
| 149 | COPY_SEG(ds); |
Harvey Harrison | ac66f3f | 2008-02-08 12:09:58 -0800 | [diff] [blame] | 150 | COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx); |
| 151 | COPY(dx); COPY(cx); COPY(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | COPY_SEG_STRICT(cs); |
| 153 | COPY_SEG_STRICT(ss); |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
| 156 | unsigned int tmpflags; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 157 | |
H. Peter Anvin | 742fa54 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 158 | err |= __get_user(tmpflags, &sc->flags); |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 159 | regs->flags = (regs->flags & ~FIX_EFLAGS) | |
| 160 | (tmpflags & FIX_EFLAGS); |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 161 | regs->orig_ax = -1; /* disable syscall checks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | { |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 165 | void __user *buf; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | err |= __get_user(buf, &sc->fpstate); |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 168 | err |= restore_i387_xstate(buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Harvey Harrison | 866bc13 | 2008-02-08 12:10:02 -0800 | [diff] [blame] | 171 | err |= __get_user(*pax, &sc->ax); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Harvey Harrison | 866bc13 | 2008-02-08 12:10:02 -0800 | [diff] [blame] | 175 | asmlinkage unsigned long sys_sigreturn(unsigned long __unused) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 177 | struct sigframe __user *frame; |
| 178 | struct pt_regs *regs; |
Harvey Harrison | 866bc13 | 2008-02-08 12:10:02 -0800 | [diff] [blame] | 179 | unsigned long ax; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 180 | sigset_t set; |
| 181 | |
| 182 | regs = (struct pt_regs *) &__unused; |
| 183 | frame = (struct sigframe __user *)(regs->sp - 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
| 185 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 186 | goto badframe; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 187 | if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | && __copy_from_user(&set.sig[1], &frame->extramask, |
| 189 | sizeof(frame->extramask)))) |
| 190 | goto badframe; |
| 191 | |
| 192 | sigdelsetmask(&set, ~_BLOCKABLE); |
| 193 | spin_lock_irq(¤t->sighand->siglock); |
| 194 | current->blocked = set; |
| 195 | recalc_sigpending(); |
| 196 | spin_unlock_irq(¤t->sighand->siglock); |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 197 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 198 | if (restore_sigcontext(regs, &frame->sc, &ax)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | goto badframe; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 200 | return ax; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | badframe: |
Andi Kleen | 0325291 | 2008-01-30 13:33:18 +0100 | [diff] [blame] | 203 | if (show_unhandled_signals && printk_ratelimit()) { |
Hiroshi Shimamoto | 1181f8b | 2008-07-03 13:12:13 -0700 | [diff] [blame] | 204 | printk("%s%s[%d] bad frame in sigreturn frame:" |
Ingo Molnar | 97b44ae | 2008-03-06 10:43:17 +0100 | [diff] [blame] | 205 | "%p ip:%lx sp:%lx oeax:%lx", |
Alexey Dobriyan | 19c5870 | 2007-10-18 23:40:41 -0700 | [diff] [blame] | 206 | task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG, |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 207 | current->comm, task_pid_nr(current), frame, regs->ip, |
| 208 | regs->sp, regs->orig_ax); |
Andi Kleen | 0325291 | 2008-01-30 13:33:18 +0100 | [diff] [blame] | 209 | print_vma_addr(" in ", regs->ip); |
Ingo Molnar | 97b44ae | 2008-03-06 10:43:17 +0100 | [diff] [blame] | 210 | printk(KERN_CONT "\n"); |
Andi Kleen | 0325291 | 2008-01-30 13:33:18 +0100 | [diff] [blame] | 211 | } |
Masoud Asgharifard Sharbiani | abd4f75 | 2007-07-22 11:12:28 +0200 | [diff] [blame] | 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | force_sig(SIGSEGV, current); |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | return 0; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 216 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
Hiroshi Shimamoto | e6babb6 | 2008-09-12 17:03:31 -0700 | [diff] [blame] | 218 | static long do_rt_sigreturn(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
Harvey Harrison | 2d19c45 | 2008-02-08 12:10:00 -0800 | [diff] [blame] | 220 | struct rt_sigframe __user *frame; |
Harvey Harrison | 866bc13 | 2008-02-08 12:10:02 -0800 | [diff] [blame] | 221 | unsigned long ax; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | sigset_t set; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Harvey Harrison | 2d19c45 | 2008-02-08 12:10:00 -0800 | [diff] [blame] | 224 | frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) |
| 226 | goto badframe; |
| 227 | if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) |
| 228 | goto badframe; |
| 229 | |
| 230 | sigdelsetmask(&set, ~_BLOCKABLE); |
| 231 | spin_lock_irq(¤t->sighand->siglock); |
| 232 | current->blocked = set; |
| 233 | recalc_sigpending(); |
| 234 | spin_unlock_irq(¤t->sighand->siglock); |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 235 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 236 | if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | goto badframe; |
| 238 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 239 | if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | goto badframe; |
| 241 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 242 | return ax; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | badframe: |
Hiroshi Shimamoto | e6babb6 | 2008-09-12 17:03:31 -0700 | [diff] [blame] | 245 | signal_fault(regs, frame, "rt_sigreturn"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | return 0; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Hiroshi Shimamoto | e6babb6 | 2008-09-12 17:03:31 -0700 | [diff] [blame] | 249 | asmlinkage int sys_rt_sigreturn(unsigned long __unused) |
| 250 | { |
| 251 | struct pt_regs *regs = (struct pt_regs *)&__unused; |
| 252 | |
| 253 | return do_rt_sigreturn(regs); |
| 254 | } |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | /* |
| 257 | * Set up a signal frame. |
| 258 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | static int |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 260 | setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | struct pt_regs *regs, unsigned long mask) |
| 262 | { |
| 263 | int tmp, err = 0; |
| 264 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 265 | err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs); |
Jeremy Fitzhardinge | 464d1a7 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 266 | savesegment(gs, tmp); |
| 267 | err |= __put_user(tmp, (unsigned int __user *)&sc->gs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 269 | err |= __put_user(regs->es, (unsigned int __user *)&sc->es); |
| 270 | err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds); |
H. Peter Anvin | 742fa54 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 271 | err |= __put_user(regs->di, &sc->di); |
| 272 | err |= __put_user(regs->si, &sc->si); |
| 273 | err |= __put_user(regs->bp, &sc->bp); |
| 274 | err |= __put_user(regs->sp, &sc->sp); |
| 275 | err |= __put_user(regs->bx, &sc->bx); |
| 276 | err |= __put_user(regs->dx, &sc->dx); |
| 277 | err |= __put_user(regs->cx, &sc->cx); |
| 278 | err |= __put_user(regs->ax, &sc->ax); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | err |= __put_user(current->thread.trap_no, &sc->trapno); |
| 280 | err |= __put_user(current->thread.error_code, &sc->err); |
H. Peter Anvin | 742fa54 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 281 | err |= __put_user(regs->ip, &sc->ip); |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 282 | err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs); |
H. Peter Anvin | 742fa54 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 283 | err |= __put_user(regs->flags, &sc->flags); |
| 284 | err |= __put_user(regs->sp, &sc->sp_at_signal); |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 285 | err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 287 | tmp = save_i387_xstate(fpstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | if (tmp < 0) |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 289 | err = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | else |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 291 | err |= __put_user(tmp ? fpstate : NULL, &sc->fpstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
| 293 | /* non-iBCS2 extensions.. */ |
| 294 | err |= __put_user(mask, &sc->oldmask); |
| 295 | err |= __put_user(current->thread.cr2, &sc->cr2); |
| 296 | |
| 297 | return err; |
| 298 | } |
| 299 | |
| 300 | /* |
| 301 | * Determine which stack to use.. |
| 302 | */ |
| 303 | static inline void __user * |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 304 | get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size, |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 305 | void **fpstate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 307 | unsigned long sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | /* Default to using normal stack */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 310 | sp = regs->sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | |
Roland McGrath | 83bd010 | 2008-01-30 13:30:06 +0100 | [diff] [blame] | 312 | /* |
| 313 | * If we are on the alternate signal stack and would overflow it, don't. |
| 314 | * Return an always-bogus address instead so we will die with SIGSEGV. |
| 315 | */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 316 | if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size))) |
Roland McGrath | 83bd010 | 2008-01-30 13:30:06 +0100 | [diff] [blame] | 317 | return (void __user *) -1L; |
| 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | /* This is the X/Open sanctioned signal stack switching. */ |
| 320 | if (ka->sa.sa_flags & SA_ONSTACK) { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 321 | if (sas_ss_flags(sp) == 0) |
| 322 | sp = current->sas_ss_sp + current->sas_ss_size; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 323 | } else { |
| 324 | /* This is the legacy signal stack switching. */ |
| 325 | if ((regs->ss & 0xffff) != __USER_DS && |
| 326 | !(ka->sa.sa_flags & SA_RESTORER) && |
| 327 | ka->sa.sa_restorer) |
| 328 | sp = (unsigned long) ka->sa.sa_restorer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 331 | if (used_math()) { |
| 332 | sp = sp - sig_xstate_size; |
| 333 | *fpstate = (struct _fpstate *) sp; |
| 334 | } |
| 335 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 336 | sp -= frame_size; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 337 | /* |
| 338 | * Align the stack pointer according to the i386 ABI, |
| 339 | * i.e. so that on function entry ((sp + 4) & 15) == 0. |
| 340 | */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 341 | sp = ((sp + 4) & -16ul) - 4; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 342 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 343 | return (void __user *) sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 346 | static int |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 347 | __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set, |
| 348 | struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | struct sigframe __user *frame; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 351 | void __user *restorer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | int err = 0; |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 353 | void __user *fpstate = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 355 | frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 358 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Hiroshi Shimamoto | 2ba48e1 | 2008-09-12 17:02:53 -0700 | [diff] [blame] | 360 | if (__put_user(sig, &frame->sig)) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 361 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Hiroshi Shimamoto | 2ba48e1 | 2008-09-12 17:02:53 -0700 | [diff] [blame] | 363 | if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0])) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 364 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
| 366 | if (_NSIG_WORDS > 1) { |
Hiroshi Shimamoto | 2ba48e1 | 2008-09-12 17:02:53 -0700 | [diff] [blame] | 367 | if (__copy_to_user(&frame->extramask, &set->sig[1], |
| 368 | sizeof(frame->extramask))) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 369 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
| 371 | |
Roland McGrath | 1a3e4ca | 2008-04-09 01:29:27 -0700 | [diff] [blame] | 372 | if (current->mm->context.vdso) |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 373 | restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn); |
Andi Kleen | 9fbbd4d | 2007-02-13 13:26:26 +0100 | [diff] [blame] | 374 | else |
Jan Engelhardt | ade1af7 | 2008-01-30 13:33:23 +0100 | [diff] [blame] | 375 | restorer = &frame->retcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | if (ka->sa.sa_flags & SA_RESTORER) |
| 377 | restorer = ka->sa.sa_restorer; |
| 378 | |
| 379 | /* Set up to return from userspace. */ |
| 380 | err |= __put_user(restorer, &frame->pretcode); |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | /* |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 383 | * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | * |
| 385 | * WE DO NOT USE IT ANY MORE! It's only left here for historical |
| 386 | * reasons and because gdb uses it as a signature to notice |
| 387 | * signal handler stack frames. |
| 388 | */ |
| 389 | err |= __put_user(0xb858, (short __user *)(frame->retcode+0)); |
| 390 | err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2)); |
| 391 | err |= __put_user(0x80cd, (short __user *)(frame->retcode+6)); |
| 392 | |
| 393 | if (err) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 394 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
| 396 | /* Set up registers for signal handler */ |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 397 | regs->sp = (unsigned long)frame; |
| 398 | regs->ip = (unsigned long)ka->sa.sa_handler; |
| 399 | regs->ax = (unsigned long)sig; |
Harvey Harrison | 92bc205 | 2008-02-08 12:09:56 -0800 | [diff] [blame] | 400 | regs->dx = 0; |
| 401 | regs->cx = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 403 | regs->ds = __USER_DS; |
| 404 | regs->es = __USER_DS; |
| 405 | regs->ss = __USER_DS; |
| 406 | regs->cs = __USER_CS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 408 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 411 | static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
| 412 | sigset_t *set, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | struct rt_sigframe __user *frame; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 415 | void __user *restorer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | int err = 0; |
Suresh Siddha | ab51370 | 2008-07-29 10:29:22 -0700 | [diff] [blame] | 417 | void __user *fpstate = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 419 | frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
| 421 | if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 422 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Hiroshi Shimamoto | 13ad772 | 2008-09-05 16:28:38 -0700 | [diff] [blame] | 424 | err |= __put_user(sig, &frame->sig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | err |= __put_user(&frame->info, &frame->pinfo); |
| 426 | err |= __put_user(&frame->uc, &frame->puc); |
| 427 | err |= copy_siginfo_to_user(&frame->info, info); |
| 428 | if (err) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 429 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | /* Create the ucontext. */ |
Suresh Siddha | c37b5ef | 2008-07-29 10:29:25 -0700 | [diff] [blame] | 432 | if (cpu_has_xsave) |
| 433 | err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags); |
| 434 | else |
| 435 | err |= __put_user(0, &frame->uc.uc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | err |= __put_user(0, &frame->uc.uc_link); |
| 437 | err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 438 | err |= __put_user(sas_ss_flags(regs->sp), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | &frame->uc.uc_stack.ss_flags); |
| 440 | err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); |
Suresh Siddha | 3c1c7f1 | 2008-07-29 10:29:21 -0700 | [diff] [blame] | 441 | err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate, |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 442 | regs, set->sig[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); |
| 444 | if (err) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 445 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
| 447 | /* Set up to return from userspace. */ |
Roland McGrath | 6c3652e | 2008-01-30 13:30:42 +0100 | [diff] [blame] | 448 | restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | if (ka->sa.sa_flags & SA_RESTORER) |
| 450 | restorer = ka->sa.sa_restorer; |
| 451 | err |= __put_user(restorer, &frame->pretcode); |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | /* |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 454 | * This is movl $__NR_rt_sigreturn, %ax ; int $0x80 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | * |
| 456 | * WE DO NOT USE IT ANY MORE! It's only left here for historical |
| 457 | * reasons and because gdb uses it as a signature to notice |
| 458 | * signal handler stack frames. |
| 459 | */ |
| 460 | err |= __put_user(0xb8, (char __user *)(frame->retcode+0)); |
| 461 | err |= __put_user(__NR_rt_sigreturn, (int __user *)(frame->retcode+1)); |
| 462 | err |= __put_user(0x80cd, (short __user *)(frame->retcode+5)); |
| 463 | |
| 464 | if (err) |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 465 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | /* Set up registers for signal handler */ |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 468 | regs->sp = (unsigned long)frame; |
| 469 | regs->ip = (unsigned long)ka->sa.sa_handler; |
Hiroshi Shimamoto | 13ad772 | 2008-09-05 16:28:38 -0700 | [diff] [blame] | 470 | regs->ax = (unsigned long)sig; |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 471 | regs->dx = (unsigned long)&frame->info; |
| 472 | regs->cx = (unsigned long)&frame->uc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 474 | regs->ds = __USER_DS; |
| 475 | regs->es = __USER_DS; |
| 476 | regs->ss = __USER_DS; |
| 477 | regs->cs = __USER_CS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 479 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | /* |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 483 | * OK, we're invoking a handler: |
| 484 | */ |
Hiroshi Shimamoto | 8d8c13b | 2008-09-24 19:10:29 -0700 | [diff] [blame] | 485 | static int signr_convert(int sig) |
| 486 | { |
| 487 | struct thread_info *info = current_thread_info(); |
| 488 | |
| 489 | if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32) |
| 490 | return info->exec_domain->signal_invmap[sig]; |
| 491 | return sig; |
| 492 | } |
| 493 | |
Roland McGrath | 7c1def1 | 2005-06-23 00:08:21 -0700 | [diff] [blame] | 494 | static int |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 495 | setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, |
| 496 | sigset_t *set, struct pt_regs *regs) |
| 497 | { |
Hiroshi Shimamoto | 8d8c13b | 2008-09-24 19:10:29 -0700 | [diff] [blame] | 498 | int usig = signr_convert(sig); |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 499 | int ret; |
| 500 | |
| 501 | /* Set up the stack frame */ |
| 502 | if (ka->sa.sa_flags & SA_SIGINFO) |
Hiroshi Shimamoto | 13ad772 | 2008-09-05 16:28:38 -0700 | [diff] [blame] | 503 | ret = __setup_rt_frame(usig, ka, info, set, regs); |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 504 | else |
Hiroshi Shimamoto | 13ad772 | 2008-09-05 16:28:38 -0700 | [diff] [blame] | 505 | ret = __setup_frame(usig, ka, set, regs); |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 506 | |
Hiroshi Shimamoto | 3d0aedd | 2008-09-12 17:01:09 -0700 | [diff] [blame] | 507 | if (ret) { |
| 508 | force_sigsegv(sig, current); |
| 509 | return -EFAULT; |
| 510 | } |
| 511 | |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 512 | return ret; |
| 513 | } |
| 514 | |
| 515 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, |
Harvey Harrison | ac66f3f | 2008-02-08 12:09:58 -0800 | [diff] [blame] | 517 | sigset_t *oldset, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | { |
Roland McGrath | 7c1def1 | 2005-06-23 00:08:21 -0700 | [diff] [blame] | 519 | int ret; |
| 520 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | /* Are we from a system call? */ |
Hiroshi Shimamoto | bb57925 | 2008-09-05 16:26:55 -0700 | [diff] [blame] | 522 | if (syscall_get_nr(current, regs) >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | /* If so, check system call restarting.. */ |
Hiroshi Shimamoto | bb57925 | 2008-09-05 16:26:55 -0700 | [diff] [blame] | 524 | switch (syscall_get_error(current, regs)) { |
Harvey Harrison | ac66f3f | 2008-02-08 12:09:58 -0800 | [diff] [blame] | 525 | case -ERESTART_RESTARTBLOCK: |
| 526 | case -ERESTARTNOHAND: |
| 527 | regs->ax = -EINTR; |
| 528 | break; |
| 529 | |
| 530 | case -ERESTARTSYS: |
| 531 | if (!(ka->sa.sa_flags & SA_RESTART)) { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 532 | regs->ax = -EINTR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | break; |
Harvey Harrison | ac66f3f | 2008-02-08 12:09:58 -0800 | [diff] [blame] | 534 | } |
| 535 | /* fallthrough */ |
| 536 | case -ERESTARTNOINTR: |
| 537 | regs->ax = regs->orig_ax; |
| 538 | regs->ip -= 2; |
| 539 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | |
| 543 | /* |
Roland McGrath | e1f2877 | 2008-01-30 13:30:50 +0100 | [diff] [blame] | 544 | * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF |
| 545 | * flag so that register information in the sigcontext is correct. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 547 | if (unlikely(regs->flags & X86_EFLAGS_TF) && |
Roland McGrath | e1f2877 | 2008-01-30 13:30:50 +0100 | [diff] [blame] | 548 | likely(test_and_clear_thread_flag(TIF_FORCED_TF))) |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 549 | regs->flags &= ~X86_EFLAGS_TF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Hiroshi Shimamoto | 1d13024 | 2008-09-05 16:28:06 -0700 | [diff] [blame] | 551 | ret = setup_rt_frame(sig, ka, info, oldset, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 553 | if (ret) |
| 554 | return ret; |
Roland McGrath | 7c1def1 | 2005-06-23 00:08:21 -0700 | [diff] [blame] | 555 | |
Hiroshi Shimamoto | 86d3237 | 2008-09-23 17:22:32 -0700 | [diff] [blame] | 556 | #ifdef CONFIG_X86_64 |
| 557 | /* |
| 558 | * This has nothing to do with segment registers, |
| 559 | * despite the name. This magic affects uaccess.h |
| 560 | * macros' behavior. Reset it to the normal setting. |
| 561 | */ |
| 562 | set_fs(USER_DS); |
| 563 | #endif |
| 564 | |
Roland McGrath | 8b9c5ff | 2008-04-19 14:26:54 -0700 | [diff] [blame] | 565 | /* |
| 566 | * Clear the direction flag as per the ABI for function entry. |
| 567 | */ |
| 568 | regs->flags &= ~X86_EFLAGS_DF; |
| 569 | |
| 570 | /* |
| 571 | * Clear TF when entering the signal handler, but |
| 572 | * notify any tracer that was single-stepping it. |
| 573 | * The tracer may want to single-step inside the |
| 574 | * handler too. |
| 575 | */ |
| 576 | regs->flags &= ~X86_EFLAGS_TF; |
Roland McGrath | 8b9c5ff | 2008-04-19 14:26:54 -0700 | [diff] [blame] | 577 | |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 578 | spin_lock_irq(¤t->sighand->siglock); |
| 579 | sigorsets(¤t->blocked, ¤t->blocked, &ka->sa.sa_mask); |
| 580 | if (!(ka->sa.sa_flags & SA_NODEFER)) |
| 581 | sigaddset(¤t->blocked, sig); |
| 582 | recalc_sigpending(); |
| 583 | spin_unlock_irq(¤t->sighand->siglock); |
| 584 | |
Roland McGrath | 36a0330 | 2008-03-14 17:46:38 -0700 | [diff] [blame] | 585 | tracehook_signal_handler(sig, info, ka, regs, |
| 586 | test_thread_flag(TIF_SINGLESTEP)); |
| 587 | |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 588 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Hiroshi Shimamoto | 8fcd8e2 | 2008-09-05 16:27:39 -0700 | [diff] [blame] | 591 | #define NR_restart_syscall __NR_restart_syscall |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | /* |
| 593 | * Note that 'init' is a special process: it doesn't get signals it doesn't |
| 594 | * want to handle. Thus you cannot kill init even with a SIGKILL even by |
| 595 | * mistake. |
| 596 | */ |
Harvey Harrison | 75604d7 | 2008-01-30 13:31:17 +0100 | [diff] [blame] | 597 | static void do_signal(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | { |
Harvey Harrison | ac66f3f | 2008-02-08 12:09:58 -0800 | [diff] [blame] | 599 | struct k_sigaction ka; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | siginfo_t info; |
| 601 | int signr; |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 602 | sigset_t *oldset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
| 604 | /* |
Harvey Harrison | ac66f3f | 2008-02-08 12:09:58 -0800 | [diff] [blame] | 605 | * We want the common case to go fast, which is why we may in certain |
| 606 | * cases get here from kernel mode. Just return without doing anything |
| 607 | * if so. |
| 608 | * X86_32: vm86 regs switched out by assembly code before reaching |
| 609 | * here, so testing against kernel CS suffices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | */ |
Vincent Hanquez | 717b594 | 2005-06-23 00:08:45 -0700 | [diff] [blame] | 611 | if (!user_mode(regs)) |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 612 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Roland McGrath | 5a8da0e | 2008-04-30 00:53:10 -0700 | [diff] [blame] | 614 | if (current_thread_info()->status & TS_RESTORE_SIGMASK) |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 615 | oldset = ¤t->saved_sigmask; |
| 616 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | oldset = ¤t->blocked; |
| 618 | |
| 619 | signr = get_signal_to_deliver(&info, &ka, regs, NULL); |
| 620 | if (signr > 0) { |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 621 | /* |
| 622 | * Re-enable any watchpoints before delivering the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | * signal to user space. The processor register will |
| 624 | * have been cleared if the watchpoint triggered |
| 625 | * inside the kernel. |
| 626 | */ |
Harvey Harrison | ac66f3f | 2008-02-08 12:09:58 -0800 | [diff] [blame] | 627 | if (current->thread.debugreg7) |
Roland McGrath | 0f53409 | 2008-01-30 13:30:59 +0100 | [diff] [blame] | 628 | set_debugreg(current->thread.debugreg7, 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 630 | /* Whee! Actually deliver the signal. */ |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 631 | if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 632 | /* |
Roland McGrath | 5a8da0e | 2008-04-30 00:53:10 -0700 | [diff] [blame] | 633 | * A signal was successfully delivered; the saved |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 634 | * sigmask will have been stored in the signal frame, |
| 635 | * and will be restored by sigreturn, so we can simply |
Roland McGrath | 5a8da0e | 2008-04-30 00:53:10 -0700 | [diff] [blame] | 636 | * clear the TS_RESTORE_SIGMASK flag. |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 637 | */ |
Roland McGrath | 5a8da0e | 2008-04-30 00:53:10 -0700 | [diff] [blame] | 638 | current_thread_info()->status &= ~TS_RESTORE_SIGMASK; |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 639 | } |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 640 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | } |
| 642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | /* Did we come from a system call? */ |
Hiroshi Shimamoto | bb57925 | 2008-09-05 16:26:55 -0700 | [diff] [blame] | 644 | if (syscall_get_nr(current, regs) >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | /* Restart the system call - no handlers present */ |
Hiroshi Shimamoto | bb57925 | 2008-09-05 16:26:55 -0700 | [diff] [blame] | 646 | switch (syscall_get_error(current, regs)) { |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 647 | case -ERESTARTNOHAND: |
| 648 | case -ERESTARTSYS: |
| 649 | case -ERESTARTNOINTR: |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 650 | regs->ax = regs->orig_ax; |
| 651 | regs->ip -= 2; |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 652 | break; |
| 653 | |
| 654 | case -ERESTART_RESTARTBLOCK: |
Hiroshi Shimamoto | 8fcd8e2 | 2008-09-05 16:27:39 -0700 | [diff] [blame] | 655 | regs->ax = NR_restart_syscall; |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 656 | regs->ip -= 2; |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 657 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
| 659 | } |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 660 | |
Harvey Harrison | ac66f3f | 2008-02-08 12:09:58 -0800 | [diff] [blame] | 661 | /* |
| 662 | * If there's no signal to deliver, we just put the saved sigmask |
| 663 | * back. |
| 664 | */ |
Roland McGrath | 5a8da0e | 2008-04-30 00:53:10 -0700 | [diff] [blame] | 665 | if (current_thread_info()->status & TS_RESTORE_SIGMASK) { |
| 666 | current_thread_info()->status &= ~TS_RESTORE_SIGMASK; |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 667 | sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); |
| 668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | /* |
| 672 | * notification of userspace execution resumption |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 673 | * - triggered by the TIF_WORK_MASK flags |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | */ |
Ingo Molnar | 7e907f4 | 2008-03-06 10:33:08 +0100 | [diff] [blame] | 675 | void |
| 676 | do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | { |
Hiroshi Shimamoto | ee847c5 | 2008-09-23 17:21:45 -0700 | [diff] [blame] | 678 | #if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE) |
| 679 | /* notify userspace of pending MCEs */ |
| 680 | if (thread_info_flags & _TIF_MCE_NOTIFY) |
| 681 | mce_notify_user(); |
| 682 | #endif /* CONFIG_X86_64 && CONFIG_X86_MCE */ |
| 683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | /* deal with pending signal delivery */ |
Roland McGrath | 5a8da0e | 2008-04-30 00:53:10 -0700 | [diff] [blame] | 685 | if (thread_info_flags & _TIF_SIGPENDING) |
David Howells | 283828f | 2006-01-18 17:44:00 -0800 | [diff] [blame] | 686 | do_signal(regs); |
Peter Zijlstra | 8f4d37e | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 687 | |
Roland McGrath | 59e5213 | 2008-04-19 19:10:57 -0700 | [diff] [blame] | 688 | if (thread_info_flags & _TIF_NOTIFY_RESUME) { |
| 689 | clear_thread_flag(TIF_NOTIFY_RESUME); |
| 690 | tracehook_notify_resume(regs); |
| 691 | } |
| 692 | |
Hiroshi Shimamoto | ee847c5 | 2008-09-23 17:21:45 -0700 | [diff] [blame] | 693 | #ifdef CONFIG_X86_32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | clear_thread_flag(TIF_IRET); |
Hiroshi Shimamoto | ee847c5 | 2008-09-23 17:21:45 -0700 | [diff] [blame] | 695 | #endif /* CONFIG_X86_32 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | } |
Hiroshi Shimamoto | 72fa50f | 2008-09-05 16:27:11 -0700 | [diff] [blame] | 697 | |
| 698 | void signal_fault(struct pt_regs *regs, void __user *frame, char *where) |
| 699 | { |
| 700 | struct task_struct *me = current; |
| 701 | |
| 702 | if (show_unhandled_signals && printk_ratelimit()) { |
| 703 | printk(KERN_INFO |
| 704 | "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx", |
| 705 | me->comm, me->pid, where, frame, |
| 706 | regs->ip, regs->sp, regs->orig_ax); |
| 707 | print_vma_addr(" in ", regs->ip); |
| 708 | printk(KERN_CONT "\n"); |
| 709 | } |
| 710 | |
| 711 | force_sig(SIGSEGV, me); |
| 712 | } |