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