blob: 0ff8d8750a7d9d69d289f4b78fde29723fd58993 [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
Ingo Molnar7e907f42008-03-06 10:33:08 +0100128asmlinkage int sys_sigaltstack(unsigned long bx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Ingo Molnar7e907f42008-03-06 10:33:08 +0100130 /*
131 * This is needed to make gcc realize it doesn't own the
132 * "struct pt_regs"
133 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100134 struct pt_regs *regs = (struct pt_regs *)&bx;
135 const stack_t __user *uss = (const stack_t __user *)bx;
136 stack_t __user *uoss = (stack_t __user *)regs->cx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100138 return do_sigaltstack(uss, uoss, regs->sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
Hiroshi Shimamotoa2e8d3d2008-10-02 22:09:20 -0700141#define COPY(x) { \
142 err |= __get_user(regs->x, &sc->x); \
143}
144
145#define COPY_SEG(seg) { \
146 unsigned short tmp; \
147 err |= __get_user(tmp, &sc->seg); \
148 regs->seg = tmp; \
149}
150
Hiroshi Shimamoto3ddd9722008-11-20 18:32:17 -0800151#define COPY_SEG_CPL3(seg) { \
Hiroshi Shimamotoa2e8d3d2008-10-02 22:09:20 -0700152 unsigned short tmp; \
153 err |= __get_user(tmp, &sc->seg); \
154 regs->seg = tmp | 3; \
155}
156
157#define GET_SEG(seg) { \
158 unsigned short tmp; \
159 err |= __get_user(tmp, &sc->seg); \
160 loadsegment(seg, tmp); \
161}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163/*
164 * Do a signal return; undo the signal stack.
165 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166static int
Harvey Harrison866bc132008-02-08 12:10:02 -0800167restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
168 unsigned long *pax)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169{
Hiroshi Shimamoto69e13ad2008-10-02 22:18:47 -0700170 void __user *buf;
171 unsigned int tmpflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 unsigned int err = 0;
173
174 /* Always make any pending restarted system calls return -EINTR */
175 current_thread_info()->restart_block.fn = do_no_restart_syscall;
176
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700177#ifdef CONFIG_X86_32
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100178 GET_SEG(gs);
179 COPY_SEG(fs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 COPY_SEG(es);
181 COPY_SEG(ds);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700182#endif /* CONFIG_X86_32 */
183
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800184 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
185 COPY(dx); COPY(cx); COPY(ip);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700186
187#ifdef CONFIG_X86_64
188 COPY(r8);
189 COPY(r9);
190 COPY(r10);
191 COPY(r11);
192 COPY(r12);
193 COPY(r13);
194 COPY(r14);
195 COPY(r15);
196#endif /* CONFIG_X86_64 */
197
198#ifdef CONFIG_X86_32
Hiroshi Shimamoto3ddd9722008-11-20 18:32:17 -0800199 COPY_SEG_CPL3(cs);
200 COPY_SEG_CPL3(ss);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700201#else /* !CONFIG_X86_32 */
202 /* Kernel saves and restores only the CS segment register on signals,
203 * which is the bare minimum needed to allow mixed 32/64-bit code.
204 * App's signal handler can save/restore other segments if needed. */
Hiroshi Shimamoto3ddd9722008-11-20 18:32:17 -0800205 COPY_SEG_CPL3(cs);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700206#endif /* CONFIG_X86_32 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100207
Hiroshi Shimamoto69e13ad2008-10-02 22:18:47 -0700208 err |= __get_user(tmpflags, &sc->flags);
209 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
210 regs->orig_ax = -1; /* disable syscall checks */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100211
Hiroshi Shimamoto69e13ad2008-10-02 22:18:47 -0700212 err |= __get_user(buf, &sc->fpstate);
213 err |= restore_i387_xstate(buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Harvey Harrison866bc132008-02-08 12:10:02 -0800215 err |= __get_user(*pax, &sc->ax);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217}
218
Harvey Harrison866bc132008-02-08 12:10:02 -0800219asmlinkage unsigned long sys_sigreturn(unsigned long __unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Ingo Molnar7e907f42008-03-06 10:33:08 +0100221 struct sigframe __user *frame;
222 struct pt_regs *regs;
Harvey Harrison866bc132008-02-08 12:10:02 -0800223 unsigned long ax;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100224 sigset_t set;
225
226 regs = (struct pt_regs *) &__unused;
227 frame = (struct sigframe __user *)(regs->sp - 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
230 goto badframe;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100231 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 && __copy_from_user(&set.sig[1], &frame->extramask,
233 sizeof(frame->extramask))))
234 goto badframe;
235
236 sigdelsetmask(&set, ~_BLOCKABLE);
237 spin_lock_irq(&current->sighand->siglock);
238 current->blocked = set;
239 recalc_sigpending();
240 spin_unlock_irq(&current->sighand->siglock);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100241
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100242 if (restore_sigcontext(regs, &frame->sc, &ax))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 goto badframe;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100244 return ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
246badframe:
Andi Kleen03252912008-01-30 13:33:18 +0100247 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamoto1181f8b2008-07-03 13:12:13 -0700248 printk("%s%s[%d] bad frame in sigreturn frame:"
Ingo Molnar97b44ae2008-03-06 10:43:17 +0100249 "%p ip:%lx sp:%lx oeax:%lx",
Alexey Dobriyan19c58702007-10-18 23:40:41 -0700250 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100251 current->comm, task_pid_nr(current), frame, regs->ip,
252 regs->sp, regs->orig_ax);
Andi Kleen03252912008-01-30 13:33:18 +0100253 print_vma_addr(" in ", regs->ip);
Ingo Molnar97b44ae2008-03-06 10:43:17 +0100254 printk(KERN_CONT "\n");
Andi Kleen03252912008-01-30 13:33:18 +0100255 }
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +0200256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 force_sig(SIGSEGV, current);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 return 0;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100260}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700262static long do_rt_sigreturn(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Harvey Harrison2d19c452008-02-08 12:10:00 -0800264 struct rt_sigframe __user *frame;
Harvey Harrison866bc132008-02-08 12:10:02 -0800265 unsigned long ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 sigset_t set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Harvey Harrison2d19c452008-02-08 12:10:00 -0800268 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
270 goto badframe;
271 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
272 goto badframe;
273
274 sigdelsetmask(&set, ~_BLOCKABLE);
275 spin_lock_irq(&current->sighand->siglock);
276 current->blocked = set;
277 recalc_sigpending();
278 spin_unlock_irq(&current->sighand->siglock);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100279
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100280 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 goto badframe;
282
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100283 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 goto badframe;
285
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100286 return ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288badframe:
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700289 signal_fault(regs, frame, "rt_sigreturn");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 return 0;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100291}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700293asmlinkage int sys_rt_sigreturn(unsigned long __unused)
294{
295 struct pt_regs *regs = (struct pt_regs *)&__unused;
296
297 return do_rt_sigreturn(regs);
298}
299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300/*
301 * Set up a signal frame.
302 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303static int
Suresh Siddhaab513702008-07-29 10:29:22 -0700304setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 struct pt_regs *regs, unsigned long mask)
306{
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800307 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800309#ifdef CONFIG_X86_32
310 {
311 unsigned int tmp;
312
313 savesegment(gs, tmp);
314 err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
315 }
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100316 err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100317 err |= __put_user(regs->es, (unsigned int __user *)&sc->es);
318 err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds);
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800319#endif /* CONFIG_X86_32 */
320
H. Peter Anvin742fa542008-01-30 13:30:56 +0100321 err |= __put_user(regs->di, &sc->di);
322 err |= __put_user(regs->si, &sc->si);
323 err |= __put_user(regs->bp, &sc->bp);
324 err |= __put_user(regs->sp, &sc->sp);
325 err |= __put_user(regs->bx, &sc->bx);
326 err |= __put_user(regs->dx, &sc->dx);
327 err |= __put_user(regs->cx, &sc->cx);
328 err |= __put_user(regs->ax, &sc->ax);
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800329#ifdef CONFIG_X86_64
330 err |= __put_user(regs->r8, &sc->r8);
331 err |= __put_user(regs->r9, &sc->r9);
332 err |= __put_user(regs->r10, &sc->r10);
333 err |= __put_user(regs->r11, &sc->r11);
334 err |= __put_user(regs->r12, &sc->r12);
335 err |= __put_user(regs->r13, &sc->r13);
336 err |= __put_user(regs->r14, &sc->r14);
337 err |= __put_user(regs->r15, &sc->r15);
338#endif /* CONFIG_X86_64 */
339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 err |= __put_user(current->thread.trap_no, &sc->trapno);
341 err |= __put_user(current->thread.error_code, &sc->err);
H. Peter Anvin742fa542008-01-30 13:30:56 +0100342 err |= __put_user(regs->ip, &sc->ip);
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800343#ifdef CONFIG_X86_32
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100344 err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs);
H. Peter Anvin742fa542008-01-30 13:30:56 +0100345 err |= __put_user(regs->flags, &sc->flags);
346 err |= __put_user(regs->sp, &sc->sp_at_signal);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100347 err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss);
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800348#else /* !CONFIG_X86_32 */
349 err |= __put_user(regs->flags, &sc->flags);
350 err |= __put_user(regs->cs, &sc->cs);
351 err |= __put_user(0, &sc->gs);
352 err |= __put_user(0, &sc->fs);
353#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Hiroshi Shimamoto4b336692008-11-05 18:30:25 -0800355 err |= __put_user(fpstate, &sc->fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 /* non-iBCS2 extensions.. */
358 err |= __put_user(mask, &sc->oldmask);
359 err |= __put_user(current->thread.cr2, &sc->cr2);
360
361 return err;
362}
363
364/*
365 * Determine which stack to use..
366 */
367static inline void __user *
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700368get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
Suresh Siddhaab513702008-07-29 10:29:22 -0700369 void **fpstate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100371 unsigned long sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 /* Default to using normal stack */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100374 sp = regs->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Roland McGrath83bd0102008-01-30 13:30:06 +0100376 /*
377 * If we are on the alternate signal stack and would overflow it, don't.
378 * Return an always-bogus address instead so we will die with SIGSEGV.
379 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100380 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
Roland McGrath83bd0102008-01-30 13:30:06 +0100381 return (void __user *) -1L;
382
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 /* This is the X/Open sanctioned signal stack switching. */
384 if (ka->sa.sa_flags & SA_ONSTACK) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100385 if (sas_ss_flags(sp) == 0)
386 sp = current->sas_ss_sp + current->sas_ss_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100387 } else {
388 /* This is the legacy signal stack switching. */
389 if ((regs->ss & 0xffff) != __USER_DS &&
390 !(ka->sa.sa_flags & SA_RESTORER) &&
391 ka->sa.sa_restorer)
392 sp = (unsigned long) ka->sa.sa_restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 }
394
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700395 if (used_math()) {
396 sp = sp - sig_xstate_size;
397 *fpstate = (struct _fpstate *) sp;
Hiroshi Shimamoto4b336692008-11-05 18:30:25 -0800398 if (save_i387_xstate(*fpstate) < 0)
399 return (void __user *)-1L;
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700400 }
401
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100402 sp -= frame_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100403 /*
404 * Align the stack pointer according to the i386 ABI,
405 * i.e. so that on function entry ((sp + 4) & 15) == 0.
406 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100407 sp = ((sp + 4) & -16ul) - 4;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100408
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100409 return (void __user *) sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410}
411
Ingo Molnar7e907f42008-03-06 10:33:08 +0100412static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700413__setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
414 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 struct sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100417 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700419 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700421 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700424 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700426 if (__put_user(sig, &frame->sig))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700427 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700429 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700430 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432 if (_NSIG_WORDS > 1) {
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700433 if (__copy_to_user(&frame->extramask, &set->sig[1],
434 sizeof(frame->extramask)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700435 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 }
437
Roland McGrath1a3e4ca2008-04-09 01:29:27 -0700438 if (current->mm->context.vdso)
Roland McGrath6c3652e2008-01-30 13:30:42 +0100439 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100440 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100441 restorer = &frame->retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 if (ka->sa.sa_flags & SA_RESTORER)
443 restorer = ka->sa.sa_restorer;
444
445 /* Set up to return from userspace. */
446 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100449 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 *
451 * WE DO NOT USE IT ANY MORE! It's only left here for historical
452 * reasons and because gdb uses it as a signature to notice
453 * signal handler stack frames.
454 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800455 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700458 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100461 regs->sp = (unsigned long)frame;
462 regs->ip = (unsigned long)ka->sa.sa_handler;
463 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800464 regs->dx = 0;
465 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100467 regs->ds = __USER_DS;
468 regs->es = __USER_DS;
469 regs->ss = __USER_DS;
470 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
David Howells283828f2006-01-18 17:44:00 -0800472 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473}
474
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700475static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
476 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100479 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700481 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700483 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700486 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700488 err |= __put_user(sig, &frame->sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 err |= __put_user(&frame->info, &frame->pinfo);
490 err |= __put_user(&frame->uc, &frame->puc);
491 err |= copy_siginfo_to_user(&frame->info, info);
492 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700493 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 /* Create the ucontext. */
Suresh Siddhac37b5ef2008-07-29 10:29:25 -0700496 if (cpu_has_xsave)
497 err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags);
498 else
499 err |= __put_user(0, &frame->uc.uc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 err |= __put_user(0, &frame->uc.uc_link);
501 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100502 err |= __put_user(sas_ss_flags(regs->sp),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 &frame->uc.uc_stack.ss_flags);
504 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700505 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
Ingo Molnar7e907f42008-03-06 10:33:08 +0100506 regs, set->sig[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
508 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700509 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 /* Set up to return from userspace. */
Roland McGrath6c3652e2008-01-30 13:30:42 +0100512 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 if (ka->sa.sa_flags & SA_RESTORER)
514 restorer = ka->sa.sa_restorer;
515 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100518 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 *
520 * WE DO NOT USE IT ANY MORE! It's only left here for historical
521 * reasons and because gdb uses it as a signature to notice
522 * signal handler stack frames.
523 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800524 err |= __put_user(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700527 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
529 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100530 regs->sp = (unsigned long)frame;
531 regs->ip = (unsigned long)ka->sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700532 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100533 regs->dx = (unsigned long)&frame->info;
534 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100536 regs->ds = __USER_DS;
537 regs->es = __USER_DS;
538 regs->ss = __USER_DS;
539 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
David Howells283828f2006-01-18 17:44:00 -0800541 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542}
543
544/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100545 * OK, we're invoking a handler:
546 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700547static int signr_convert(int sig)
548{
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700549#ifdef CONFIG_X86_32
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700550 struct thread_info *info = current_thread_info();
551
552 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
553 return info->exec_domain->signal_invmap[sig];
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700554#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700555 return sig;
556}
557
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700558#ifdef CONFIG_X86_32
559
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700560#define is_ia32 1
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700561#define ia32_setup_frame __setup_frame
562#define ia32_setup_rt_frame __setup_rt_frame
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700563
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700564#else /* !CONFIG_X86_32 */
565
566#ifdef CONFIG_IA32_EMULATION
567#define is_ia32 test_thread_flag(TIF_IA32)
568#else /* !CONFIG_IA32_EMULATION */
569#define is_ia32 0
570#endif /* CONFIG_IA32_EMULATION */
571
572#endif /* CONFIG_X86_32 */
573
Roland McGrath7c1def12005-06-23 00:08:21 -0700574static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700575setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
576 sigset_t *set, struct pt_regs *regs)
577{
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700578 int usig = signr_convert(sig);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700579 int ret;
580
581 /* Set up the stack frame */
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700582 if (is_ia32) {
583 if (ka->sa.sa_flags & SA_SIGINFO)
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700584 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700585 else
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700586 ret = ia32_setup_frame(usig, ka, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700587 } else
588 ret = __setup_rt_frame(sig, ka, info, set, regs);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700589
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700590 if (ret) {
591 force_sigsegv(sig, current);
592 return -EFAULT;
593 }
594
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700595 return ret;
596}
597
598static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800600 sigset_t *oldset, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
Roland McGrath7c1def12005-06-23 00:08:21 -0700602 int ret;
603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700605 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700607 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800608 case -ERESTART_RESTARTBLOCK:
609 case -ERESTARTNOHAND:
610 regs->ax = -EINTR;
611 break;
612
613 case -ERESTARTSYS:
614 if (!(ka->sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100615 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800617 }
618 /* fallthrough */
619 case -ERESTARTNOINTR:
620 regs->ax = regs->orig_ax;
621 regs->ip -= 2;
622 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 }
624 }
625
626 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100627 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
628 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100630 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100631 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100632 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700634 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
Ingo Molnar7e907f42008-03-06 10:33:08 +0100636 if (ret)
637 return ret;
Roland McGrath7c1def12005-06-23 00:08:21 -0700638
Hiroshi Shimamoto86d32372008-09-23 17:22:32 -0700639#ifdef CONFIG_X86_64
640 /*
641 * This has nothing to do with segment registers,
642 * despite the name. This magic affects uaccess.h
643 * macros' behavior. Reset it to the normal setting.
644 */
645 set_fs(USER_DS);
646#endif
647
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700648 /*
649 * Clear the direction flag as per the ABI for function entry.
650 */
651 regs->flags &= ~X86_EFLAGS_DF;
652
653 /*
654 * Clear TF when entering the signal handler, but
655 * notify any tracer that was single-stepping it.
656 * The tracer may want to single-step inside the
657 * handler too.
658 */
659 regs->flags &= ~X86_EFLAGS_TF;
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700660
Ingo Molnar7e907f42008-03-06 10:33:08 +0100661 spin_lock_irq(&current->sighand->siglock);
662 sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
663 if (!(ka->sa.sa_flags & SA_NODEFER))
664 sigaddset(&current->blocked, sig);
665 recalc_sigpending();
666 spin_unlock_irq(&current->sighand->siglock);
667
Roland McGrath36a03302008-03-14 17:46:38 -0700668 tracehook_signal_handler(sig, info, ka, regs,
669 test_thread_flag(TIF_SINGLESTEP));
670
Ingo Molnar7e907f42008-03-06 10:33:08 +0100671 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672}
673
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700674#ifdef CONFIG_X86_32
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700675#define NR_restart_syscall __NR_restart_syscall
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700676#else /* !CONFIG_X86_32 */
677#define NR_restart_syscall \
678 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
679#endif /* CONFIG_X86_32 */
680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681/*
682 * Note that 'init' is a special process: it doesn't get signals it doesn't
683 * want to handle. Thus you cannot kill init even with a SIGKILL even by
684 * mistake.
685 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100686static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800688 struct k_sigaction ka;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 siginfo_t info;
690 int signr;
David Howells283828f2006-01-18 17:44:00 -0800691 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
693 /*
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800694 * We want the common case to go fast, which is why we may in certain
695 * cases get here from kernel mode. Just return without doing anything
696 * if so.
697 * X86_32: vm86 regs switched out by assembly code before reaching
698 * here, so testing against kernel CS suffices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 */
Vincent Hanquez717b5942005-06-23 00:08:45 -0700700 if (!user_mode(regs))
David Howells283828f2006-01-18 17:44:00 -0800701 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700703 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
David Howells283828f2006-01-18 17:44:00 -0800704 oldset = &current->saved_sigmask;
705 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 oldset = &current->blocked;
707
708 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
709 if (signr > 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100710 /*
711 * Re-enable any watchpoints before delivering the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 * signal to user space. The processor register will
713 * have been cleared if the watchpoint triggered
714 * inside the kernel.
715 */
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800716 if (current->thread.debugreg7)
Roland McGrath0f534092008-01-30 13:30:59 +0100717 set_debugreg(current->thread.debugreg7, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Ingo Molnar7e907f42008-03-06 10:33:08 +0100719 /* Whee! Actually deliver the signal. */
David Howells283828f2006-01-18 17:44:00 -0800720 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100721 /*
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700722 * A signal was successfully delivered; the saved
David Howells283828f2006-01-18 17:44:00 -0800723 * sigmask will have been stored in the signal frame,
724 * and will be restored by sigreturn, so we can simply
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700725 * clear the TS_RESTORE_SIGMASK flag.
Ingo Molnar7e907f42008-03-06 10:33:08 +0100726 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700727 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800728 }
David Howells283828f2006-01-18 17:44:00 -0800729 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 }
731
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700733 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700735 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800736 case -ERESTARTNOHAND:
737 case -ERESTARTSYS:
738 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100739 regs->ax = regs->orig_ax;
740 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800741 break;
742
743 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700744 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100745 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800746 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 }
748 }
David Howells283828f2006-01-18 17:44:00 -0800749
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800750 /*
751 * If there's no signal to deliver, we just put the saved sigmask
752 * back.
753 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700754 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
755 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800756 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758}
759
760/*
761 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800762 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100764void
765do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766{
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700767#if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
768 /* notify userspace of pending MCEs */
769 if (thread_info_flags & _TIF_MCE_NOTIFY)
770 mce_notify_user();
771#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
772
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700774 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800775 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100776
Roland McGrath59e52132008-04-19 19:10:57 -0700777 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
778 clear_thread_flag(TIF_NOTIFY_RESUME);
779 tracehook_notify_resume(regs);
780 }
781
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700782#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 clear_thread_flag(TIF_IRET);
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700784#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700786
787void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
788{
789 struct task_struct *me = current;
790
791 if (show_unhandled_signals && printk_ratelimit()) {
792 printk(KERN_INFO
793 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
794 me->comm, me->pid, where, frame,
795 regs->ip, regs->sp, regs->orig_ax);
796 print_vma_addr(" in ", regs->ip);
797 printk(KERN_CONT "\n");
798 }
799
800 force_sig(SIGSEGV, me);
801}