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