blob: d9909881ac669739963cfafa95506f4c67487eee [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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
Ingo Molnar7e907f42008-03-06 10:33:08 +01008#include <linux/sched.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +01009#include <linux/mm.h>
Hiroshi Shimamoto5c9b3a02008-11-21 17:36:41 -080010#include <linux/smp.h>
11#include <linux/kernel.h>
12#include <linux/signal.h>
13#include <linux/errno.h>
14#include <linux/wait.h>
15#include <linux/ptrace.h>
16#include <linux/tracehook.h>
17#include <linux/unistd.h>
18#include <linux/stddef.h>
19#include <linux/personality.h>
20#include <linux/uaccess.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/processor.h>
23#include <asm/ucontext.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/i387.h>
Roland McGrath6c3652e2008-01-30 13:30:42 +010025#include <asm/vdso.h>
Hiroshi Shimamoto5c9b3a02008-11-21 17:36:41 -080026
27#ifdef CONFIG_X86_64
28#include <asm/proto.h>
29#include <asm/ia32_unistd.h>
30#include <asm/mce.h>
31#endif /* CONFIG_X86_64 */
32
Hiroshi Shimamotobb579252008-09-05 16:26:55 -070033#include <asm/syscall.h>
Jaswinder Singhbbc1f692008-07-21 21:34:13 +053034#include <asm/syscalls.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010035
Harvey Harrison123a6342008-02-08 12:10:00 -080036#include "sigframe.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
39
Harvey Harrison1a176802008-02-08 12:09:59 -080040#define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \
41 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
42 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
43 X86_EFLAGS_CF)
44
45#ifdef CONFIG_X86_32
46# define FIX_EFLAGS (__FIX_EFLAGS | X86_EFLAGS_RF)
47#else
48# define FIX_EFLAGS __FIX_EFLAGS
49#endif
50
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -080051static const struct {
52 u16 poplmovl;
53 u32 val;
54 u16 int80;
55} __attribute__((packed)) retcode = {
56 0xb858, /* popl %eax; movl $..., %eax */
57 __NR_sigreturn,
58 0x80cd, /* int $0x80 */
59};
60
61static const struct {
62 u8 movl;
63 u32 val;
64 u16 int80;
65 u8 pad;
66} __attribute__((packed)) rt_retcode = {
67 0xb8, /* movl $..., %eax */
68 __NR_rt_sigreturn,
69 0x80cd, /* int $0x80 */
70 0
71};
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/*
74 * Atomically swap in the new signal mask, and wait for a signal.
75 */
76asmlinkage int
77sys_sigsuspend(int history0, int history1, old_sigset_t mask)
78{
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 mask &= _BLOCKABLE;
80 spin_lock_irq(&current->sighand->siglock);
David Howells283828f2006-01-18 17:44:00 -080081 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 siginitset(&current->blocked, mask);
83 recalc_sigpending();
84 spin_unlock_irq(&current->sighand->siglock);
85
David Howells283828f2006-01-18 17:44:00 -080086 current->state = TASK_INTERRUPTIBLE;
87 schedule();
Roland McGrath5a8da0e2008-04-30 00:53:10 -070088 set_restore_sigmask();
Ingo Molnar7e907f42008-03-06 10:33:08 +010089
David Howells283828f2006-01-18 17:44:00 -080090 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
92
Ingo Molnar7e907f42008-03-06 10:33:08 +010093asmlinkage int
Linus Torvalds1da177e2005-04-16 15:20:36 -070094sys_sigaction(int sig, const struct old_sigaction __user *act,
95 struct old_sigaction __user *oact)
96{
97 struct k_sigaction new_ka, old_ka;
98 int ret;
99
100 if (act) {
101 old_sigset_t mask;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
104 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
105 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
106 return -EFAULT;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
109 __get_user(mask, &act->sa_mask);
110 siginitset(&new_ka.sa.sa_mask, mask);
111 }
112
113 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
114
115 if (!ret && oact) {
116 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
117 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
118 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
119 return -EFAULT;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
122 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
123 }
124
125 return ret;
126}
127
Hiroshi Shimamoto666ac7b2008-11-21 17:38:25 -0800128#ifdef CONFIG_X86_32
Ingo Molnar7e907f42008-03-06 10:33:08 +0100129asmlinkage int sys_sigaltstack(unsigned long bx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
Ingo Molnar7e907f42008-03-06 10:33:08 +0100131 /*
132 * This is needed to make gcc realize it doesn't own the
133 * "struct pt_regs"
134 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100135 struct pt_regs *regs = (struct pt_regs *)&bx;
136 const stack_t __user *uss = (const stack_t __user *)bx;
137 stack_t __user *uoss = (stack_t __user *)regs->cx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100139 return do_sigaltstack(uss, uoss, regs->sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140}
Hiroshi Shimamoto666ac7b2008-11-21 17:38:25 -0800141#else /* !CONFIG_X86_32 */
142asmlinkage long
143sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
144 struct pt_regs *regs)
145{
146 return do_sigaltstack(uss, uoss, regs->sp);
147}
148#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Hiroshi Shimamotoa2e8d3d2008-10-02 22:09:20 -0700150#define COPY(x) { \
151 err |= __get_user(regs->x, &sc->x); \
152}
153
154#define COPY_SEG(seg) { \
155 unsigned short tmp; \
156 err |= __get_user(tmp, &sc->seg); \
157 regs->seg = tmp; \
158}
159
Hiroshi Shimamoto3ddd9722008-11-20 18:32:17 -0800160#define COPY_SEG_CPL3(seg) { \
Hiroshi Shimamotoa2e8d3d2008-10-02 22:09:20 -0700161 unsigned short tmp; \
162 err |= __get_user(tmp, &sc->seg); \
163 regs->seg = tmp | 3; \
164}
165
166#define GET_SEG(seg) { \
167 unsigned short tmp; \
168 err |= __get_user(tmp, &sc->seg); \
169 loadsegment(seg, tmp); \
170}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172/*
173 * Do a signal return; undo the signal stack.
174 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175static int
Harvey Harrison866bc132008-02-08 12:10:02 -0800176restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
177 unsigned long *pax)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
Hiroshi Shimamoto69e13ad2008-10-02 22:18:47 -0700179 void __user *buf;
180 unsigned int tmpflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 unsigned int err = 0;
182
183 /* Always make any pending restarted system calls return -EINTR */
184 current_thread_info()->restart_block.fn = do_no_restart_syscall;
185
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700186#ifdef CONFIG_X86_32
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100187 GET_SEG(gs);
188 COPY_SEG(fs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 COPY_SEG(es);
190 COPY_SEG(ds);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700191#endif /* CONFIG_X86_32 */
192
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800193 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
194 COPY(dx); COPY(cx); COPY(ip);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700195
196#ifdef CONFIG_X86_64
197 COPY(r8);
198 COPY(r9);
199 COPY(r10);
200 COPY(r11);
201 COPY(r12);
202 COPY(r13);
203 COPY(r14);
204 COPY(r15);
205#endif /* CONFIG_X86_64 */
206
207#ifdef CONFIG_X86_32
Hiroshi Shimamoto3ddd9722008-11-20 18:32:17 -0800208 COPY_SEG_CPL3(cs);
209 COPY_SEG_CPL3(ss);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700210#else /* !CONFIG_X86_32 */
211 /* Kernel saves and restores only the CS segment register on signals,
212 * which is the bare minimum needed to allow mixed 32/64-bit code.
213 * App's signal handler can save/restore other segments if needed. */
Hiroshi Shimamoto3ddd9722008-11-20 18:32:17 -0800214 COPY_SEG_CPL3(cs);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700215#endif /* CONFIG_X86_32 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100216
Hiroshi Shimamoto69e13ad2008-10-02 22:18:47 -0700217 err |= __get_user(tmpflags, &sc->flags);
218 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
219 regs->orig_ax = -1; /* disable syscall checks */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100220
Hiroshi Shimamoto69e13ad2008-10-02 22:18:47 -0700221 err |= __get_user(buf, &sc->fpstate);
222 err |= restore_i387_xstate(buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Harvey Harrison866bc132008-02-08 12:10:02 -0800224 err |= __get_user(*pax, &sc->ax);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
227
Harvey Harrison866bc132008-02-08 12:10:02 -0800228asmlinkage unsigned long sys_sigreturn(unsigned long __unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Ingo Molnar7e907f42008-03-06 10:33:08 +0100230 struct sigframe __user *frame;
231 struct pt_regs *regs;
Harvey Harrison866bc132008-02-08 12:10:02 -0800232 unsigned long ax;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100233 sigset_t set;
234
235 regs = (struct pt_regs *) &__unused;
236 frame = (struct sigframe __user *)(regs->sp - 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
239 goto badframe;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100240 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 && __copy_from_user(&set.sig[1], &frame->extramask,
242 sizeof(frame->extramask))))
243 goto badframe;
244
245 sigdelsetmask(&set, ~_BLOCKABLE);
246 spin_lock_irq(&current->sighand->siglock);
247 current->blocked = set;
248 recalc_sigpending();
249 spin_unlock_irq(&current->sighand->siglock);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100250
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100251 if (restore_sigcontext(regs, &frame->sc, &ax))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 goto badframe;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100253 return ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255badframe:
Andi Kleen03252912008-01-30 13:33:18 +0100256 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamoto1181f8b2008-07-03 13:12:13 -0700257 printk("%s%s[%d] bad frame in sigreturn frame:"
Ingo Molnar97b44ae2008-03-06 10:43:17 +0100258 "%p ip:%lx sp:%lx oeax:%lx",
Alexey Dobriyan19c58702007-10-18 23:40:41 -0700259 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100260 current->comm, task_pid_nr(current), frame, regs->ip,
261 regs->sp, regs->orig_ax);
Andi Kleen03252912008-01-30 13:33:18 +0100262 print_vma_addr(" in ", regs->ip);
Ingo Molnar97b44ae2008-03-06 10:43:17 +0100263 printk(KERN_CONT "\n");
Andi Kleen03252912008-01-30 13:33:18 +0100264 }
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +0200265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 force_sig(SIGSEGV, current);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 return 0;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100269}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700271static long do_rt_sigreturn(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
Harvey Harrison2d19c452008-02-08 12:10:00 -0800273 struct rt_sigframe __user *frame;
Harvey Harrison866bc132008-02-08 12:10:02 -0800274 unsigned long ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 sigset_t set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Harvey Harrison2d19c452008-02-08 12:10:00 -0800277 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
279 goto badframe;
280 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
281 goto badframe;
282
283 sigdelsetmask(&set, ~_BLOCKABLE);
284 spin_lock_irq(&current->sighand->siglock);
285 current->blocked = set;
286 recalc_sigpending();
287 spin_unlock_irq(&current->sighand->siglock);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100288
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100289 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 goto badframe;
291
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100292 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 goto badframe;
294
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100295 return ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297badframe:
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700298 signal_fault(regs, frame, "rt_sigreturn");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 return 0;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100300}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700302asmlinkage int sys_rt_sigreturn(unsigned long __unused)
303{
304 struct pt_regs *regs = (struct pt_regs *)&__unused;
305
306 return do_rt_sigreturn(regs);
307}
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/*
310 * Set up a signal frame.
311 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312static int
Suresh Siddhaab513702008-07-29 10:29:22 -0700313setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 struct pt_regs *regs, unsigned long mask)
315{
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800316 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800318#ifdef CONFIG_X86_32
319 {
320 unsigned int tmp;
321
322 savesegment(gs, tmp);
323 err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
324 }
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100325 err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100326 err |= __put_user(regs->es, (unsigned int __user *)&sc->es);
327 err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds);
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800328#endif /* CONFIG_X86_32 */
329
H. Peter Anvin742fa542008-01-30 13:30:56 +0100330 err |= __put_user(regs->di, &sc->di);
331 err |= __put_user(regs->si, &sc->si);
332 err |= __put_user(regs->bp, &sc->bp);
333 err |= __put_user(regs->sp, &sc->sp);
334 err |= __put_user(regs->bx, &sc->bx);
335 err |= __put_user(regs->dx, &sc->dx);
336 err |= __put_user(regs->cx, &sc->cx);
337 err |= __put_user(regs->ax, &sc->ax);
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800338#ifdef CONFIG_X86_64
339 err |= __put_user(regs->r8, &sc->r8);
340 err |= __put_user(regs->r9, &sc->r9);
341 err |= __put_user(regs->r10, &sc->r10);
342 err |= __put_user(regs->r11, &sc->r11);
343 err |= __put_user(regs->r12, &sc->r12);
344 err |= __put_user(regs->r13, &sc->r13);
345 err |= __put_user(regs->r14, &sc->r14);
346 err |= __put_user(regs->r15, &sc->r15);
347#endif /* CONFIG_X86_64 */
348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 err |= __put_user(current->thread.trap_no, &sc->trapno);
350 err |= __put_user(current->thread.error_code, &sc->err);
H. Peter Anvin742fa542008-01-30 13:30:56 +0100351 err |= __put_user(regs->ip, &sc->ip);
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800352#ifdef CONFIG_X86_32
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100353 err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs);
H. Peter Anvin742fa542008-01-30 13:30:56 +0100354 err |= __put_user(regs->flags, &sc->flags);
355 err |= __put_user(regs->sp, &sc->sp_at_signal);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100356 err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss);
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800357#else /* !CONFIG_X86_32 */
358 err |= __put_user(regs->flags, &sc->flags);
359 err |= __put_user(regs->cs, &sc->cs);
360 err |= __put_user(0, &sc->gs);
361 err |= __put_user(0, &sc->fs);
362#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Hiroshi Shimamoto4b336692008-11-05 18:30:25 -0800364 err |= __put_user(fpstate, &sc->fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366 /* non-iBCS2 extensions.. */
367 err |= __put_user(mask, &sc->oldmask);
368 err |= __put_user(current->thread.cr2, &sc->cr2);
369
370 return err;
371}
372
373/*
374 * Determine which stack to use..
375 */
376static inline void __user *
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700377get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
Suresh Siddhaab513702008-07-29 10:29:22 -0700378 void **fpstate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100380 unsigned long sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382 /* Default to using normal stack */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100383 sp = regs->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Roland McGrath83bd0102008-01-30 13:30:06 +0100385 /*
386 * If we are on the alternate signal stack and would overflow it, don't.
387 * Return an always-bogus address instead so we will die with SIGSEGV.
388 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100389 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
Roland McGrath83bd0102008-01-30 13:30:06 +0100390 return (void __user *) -1L;
391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 /* This is the X/Open sanctioned signal stack switching. */
393 if (ka->sa.sa_flags & SA_ONSTACK) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100394 if (sas_ss_flags(sp) == 0)
395 sp = current->sas_ss_sp + current->sas_ss_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100396 } else {
397 /* This is the legacy signal stack switching. */
398 if ((regs->ss & 0xffff) != __USER_DS &&
399 !(ka->sa.sa_flags & SA_RESTORER) &&
400 ka->sa.sa_restorer)
401 sp = (unsigned long) ka->sa.sa_restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
403
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700404 if (used_math()) {
405 sp = sp - sig_xstate_size;
406 *fpstate = (struct _fpstate *) sp;
Hiroshi Shimamoto4b336692008-11-05 18:30:25 -0800407 if (save_i387_xstate(*fpstate) < 0)
408 return (void __user *)-1L;
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700409 }
410
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100411 sp -= frame_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100412 /*
413 * Align the stack pointer according to the i386 ABI,
414 * i.e. so that on function entry ((sp + 4) & 15) == 0.
415 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100416 sp = ((sp + 4) & -16ul) - 4;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100417
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100418 return (void __user *) sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419}
420
Ingo Molnar7e907f42008-03-06 10:33:08 +0100421static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700422__setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
423 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 struct sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100426 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700428 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700430 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700433 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700435 if (__put_user(sig, &frame->sig))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700436 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700438 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700439 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 if (_NSIG_WORDS > 1) {
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700442 if (__copy_to_user(&frame->extramask, &set->sig[1],
443 sizeof(frame->extramask)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700444 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 }
446
Roland McGrath1a3e4ca2008-04-09 01:29:27 -0700447 if (current->mm->context.vdso)
Roland McGrath6c3652e2008-01-30 13:30:42 +0100448 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100449 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100450 restorer = &frame->retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 if (ka->sa.sa_flags & SA_RESTORER)
452 restorer = ka->sa.sa_restorer;
453
454 /* Set up to return from userspace. */
455 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100458 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 *
460 * WE DO NOT USE IT ANY MORE! It's only left here for historical
461 * reasons and because gdb uses it as a signature to notice
462 * signal handler stack frames.
463 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800464 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700467 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100470 regs->sp = (unsigned long)frame;
471 regs->ip = (unsigned long)ka->sa.sa_handler;
472 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800473 regs->dx = 0;
474 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100476 regs->ds = __USER_DS;
477 regs->es = __USER_DS;
478 regs->ss = __USER_DS;
479 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
David Howells283828f2006-01-18 17:44:00 -0800481 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482}
483
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700484static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
485 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100488 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700490 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700492 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700495 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700497 err |= __put_user(sig, &frame->sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 err |= __put_user(&frame->info, &frame->pinfo);
499 err |= __put_user(&frame->uc, &frame->puc);
500 err |= copy_siginfo_to_user(&frame->info, info);
501 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700502 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
504 /* Create the ucontext. */
Suresh Siddhac37b5ef2008-07-29 10:29:25 -0700505 if (cpu_has_xsave)
506 err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags);
507 else
508 err |= __put_user(0, &frame->uc.uc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 err |= __put_user(0, &frame->uc.uc_link);
510 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100511 err |= __put_user(sas_ss_flags(regs->sp),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 &frame->uc.uc_stack.ss_flags);
513 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700514 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
Ingo Molnar7e907f42008-03-06 10:33:08 +0100515 regs, set->sig[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
517 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700518 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 /* Set up to return from userspace. */
Roland McGrath6c3652e2008-01-30 13:30:42 +0100521 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 if (ka->sa.sa_flags & SA_RESTORER)
523 restorer = ka->sa.sa_restorer;
524 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100527 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 *
529 * WE DO NOT USE IT ANY MORE! It's only left here for historical
530 * reasons and because gdb uses it as a signature to notice
531 * signal handler stack frames.
532 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800533 err |= __put_user(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700536 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
538 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100539 regs->sp = (unsigned long)frame;
540 regs->ip = (unsigned long)ka->sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700541 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100542 regs->dx = (unsigned long)&frame->info;
543 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100545 regs->ds = __USER_DS;
546 regs->es = __USER_DS;
547 regs->ss = __USER_DS;
548 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
David Howells283828f2006-01-18 17:44:00 -0800550 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551}
552
553/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100554 * OK, we're invoking a handler:
555 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700556static int signr_convert(int sig)
557{
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700558#ifdef CONFIG_X86_32
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700559 struct thread_info *info = current_thread_info();
560
561 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
562 return info->exec_domain->signal_invmap[sig];
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700563#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700564 return sig;
565}
566
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700567#ifdef CONFIG_X86_32
568
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700569#define is_ia32 1
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700570#define ia32_setup_frame __setup_frame
571#define ia32_setup_rt_frame __setup_rt_frame
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700572
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700573#else /* !CONFIG_X86_32 */
574
575#ifdef CONFIG_IA32_EMULATION
576#define is_ia32 test_thread_flag(TIF_IA32)
577#else /* !CONFIG_IA32_EMULATION */
578#define is_ia32 0
579#endif /* CONFIG_IA32_EMULATION */
580
581#endif /* CONFIG_X86_32 */
582
Roland McGrath7c1def12005-06-23 00:08:21 -0700583static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700584setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
585 sigset_t *set, struct pt_regs *regs)
586{
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700587 int usig = signr_convert(sig);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700588 int ret;
589
590 /* Set up the stack frame */
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700591 if (is_ia32) {
592 if (ka->sa.sa_flags & SA_SIGINFO)
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700593 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700594 else
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700595 ret = ia32_setup_frame(usig, ka, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700596 } else
597 ret = __setup_rt_frame(sig, ka, info, set, regs);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700598
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700599 if (ret) {
600 force_sigsegv(sig, current);
601 return -EFAULT;
602 }
603
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700604 return ret;
605}
606
607static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800609 sigset_t *oldset, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
Roland McGrath7c1def12005-06-23 00:08:21 -0700611 int ret;
612
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700614 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700616 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800617 case -ERESTART_RESTARTBLOCK:
618 case -ERESTARTNOHAND:
619 regs->ax = -EINTR;
620 break;
621
622 case -ERESTARTSYS:
623 if (!(ka->sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100624 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800626 }
627 /* fallthrough */
628 case -ERESTARTNOINTR:
629 regs->ax = regs->orig_ax;
630 regs->ip -= 2;
631 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 }
633 }
634
635 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100636 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
637 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100639 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100640 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100641 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700643 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
Ingo Molnar7e907f42008-03-06 10:33:08 +0100645 if (ret)
646 return ret;
Roland McGrath7c1def12005-06-23 00:08:21 -0700647
Hiroshi Shimamoto86d32372008-09-23 17:22:32 -0700648#ifdef CONFIG_X86_64
649 /*
650 * This has nothing to do with segment registers,
651 * despite the name. This magic affects uaccess.h
652 * macros' behavior. Reset it to the normal setting.
653 */
654 set_fs(USER_DS);
655#endif
656
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700657 /*
658 * Clear the direction flag as per the ABI for function entry.
659 */
660 regs->flags &= ~X86_EFLAGS_DF;
661
662 /*
663 * Clear TF when entering the signal handler, but
664 * notify any tracer that was single-stepping it.
665 * The tracer may want to single-step inside the
666 * handler too.
667 */
668 regs->flags &= ~X86_EFLAGS_TF;
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700669
Ingo Molnar7e907f42008-03-06 10:33:08 +0100670 spin_lock_irq(&current->sighand->siglock);
671 sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
672 if (!(ka->sa.sa_flags & SA_NODEFER))
673 sigaddset(&current->blocked, sig);
674 recalc_sigpending();
675 spin_unlock_irq(&current->sighand->siglock);
676
Roland McGrath36a03302008-03-14 17:46:38 -0700677 tracehook_signal_handler(sig, info, ka, regs,
678 test_thread_flag(TIF_SINGLESTEP));
679
Ingo Molnar7e907f42008-03-06 10:33:08 +0100680 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700683#ifdef CONFIG_X86_32
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700684#define NR_restart_syscall __NR_restart_syscall
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700685#else /* !CONFIG_X86_32 */
686#define NR_restart_syscall \
687 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
688#endif /* CONFIG_X86_32 */
689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690/*
691 * Note that 'init' is a special process: it doesn't get signals it doesn't
692 * want to handle. Thus you cannot kill init even with a SIGKILL even by
693 * mistake.
694 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100695static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800697 struct k_sigaction ka;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 siginfo_t info;
699 int signr;
David Howells283828f2006-01-18 17:44:00 -0800700 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
702 /*
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800703 * We want the common case to go fast, which is why we may in certain
704 * cases get here from kernel mode. Just return without doing anything
705 * if so.
706 * X86_32: vm86 regs switched out by assembly code before reaching
707 * here, so testing against kernel CS suffices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 */
Vincent Hanquez717b5942005-06-23 00:08:45 -0700709 if (!user_mode(regs))
David Howells283828f2006-01-18 17:44:00 -0800710 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700712 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
David Howells283828f2006-01-18 17:44:00 -0800713 oldset = &current->saved_sigmask;
714 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 oldset = &current->blocked;
716
717 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
718 if (signr > 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100719 /*
720 * Re-enable any watchpoints before delivering the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 * signal to user space. The processor register will
722 * have been cleared if the watchpoint triggered
723 * inside the kernel.
724 */
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800725 if (current->thread.debugreg7)
Roland McGrath0f534092008-01-30 13:30:59 +0100726 set_debugreg(current->thread.debugreg7, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Ingo Molnar7e907f42008-03-06 10:33:08 +0100728 /* Whee! Actually deliver the signal. */
David Howells283828f2006-01-18 17:44:00 -0800729 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100730 /*
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700731 * A signal was successfully delivered; the saved
David Howells283828f2006-01-18 17:44:00 -0800732 * sigmask will have been stored in the signal frame,
733 * and will be restored by sigreturn, so we can simply
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700734 * clear the TS_RESTORE_SIGMASK flag.
Ingo Molnar7e907f42008-03-06 10:33:08 +0100735 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700736 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800737 }
David Howells283828f2006-01-18 17:44:00 -0800738 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 }
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700742 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700744 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800745 case -ERESTARTNOHAND:
746 case -ERESTARTSYS:
747 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100748 regs->ax = regs->orig_ax;
749 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800750 break;
751
752 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700753 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100754 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800755 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 }
757 }
David Howells283828f2006-01-18 17:44:00 -0800758
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800759 /*
760 * If there's no signal to deliver, we just put the saved sigmask
761 * back.
762 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700763 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
764 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800765 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
766 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767}
768
769/*
770 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800771 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100773void
774do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700776#if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
777 /* notify userspace of pending MCEs */
778 if (thread_info_flags & _TIF_MCE_NOTIFY)
779 mce_notify_user();
780#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
781
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700783 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800784 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100785
Roland McGrath59e52132008-04-19 19:10:57 -0700786 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
787 clear_thread_flag(TIF_NOTIFY_RESUME);
788 tracehook_notify_resume(regs);
789 }
790
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700791#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 clear_thread_flag(TIF_IRET);
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700793#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700795
796void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
797{
798 struct task_struct *me = current;
799
800 if (show_unhandled_signals && printk_ratelimit()) {
801 printk(KERN_INFO
802 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
803 me->comm, me->pid, where, frame,
804 regs->ip, regs->sp, regs->orig_ax);
805 print_vma_addr(" in ", regs->ip);
806 printk(KERN_CONT "\n");
807 }
808
809 force_sig(SIGSEGV, me);
810}