blob: 514171ac0d0304b020fb03e77c7ea643fa4a1de5 [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 */
Ingo Molnar7e907f42008-03-06 10:33:08 +01007#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/personality.h>
Andi Kleen9fbbd4d2007-02-13 13:26:26 +010010#include <linux/binfmts.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010011#include <linux/suspend.h>
12#include <linux/kernel.h>
13#include <linux/ptrace.h>
14#include <linux/signal.h>
15#include <linux/stddef.h>
16#include <linux/unistd.h>
17#include <linux/errno.h>
18#include <linux/sched.h>
19#include <linux/wait.h>
Roland McGrath36a03302008-03-14 17:46:38 -070020#include <linux/tracehook.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010021#include <linux/elf.h>
22#include <linux/smp.h>
23#include <linux/mm.h>
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/processor.h>
26#include <asm/ucontext.h>
27#include <asm/uaccess.h>
28#include <asm/i387.h>
Roland McGrath6c3652e2008-01-30 13:30:42 +010029#include <asm/vdso.h>
Hiroshi Shimamotobb579252008-09-05 16:26:55 -070030#include <asm/syscall.h>
Jaswinder Singhbbc1f692008-07-21 21:34:13 +053031#include <asm/syscalls.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010032
Harvey Harrison123a6342008-02-08 12:10:00 -080033#include "sigframe.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
36
Harvey Harrison1a176802008-02-08 12:09:59 -080037#define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \
38 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
39 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
40 X86_EFLAGS_CF)
41
42#ifdef CONFIG_X86_32
43# define FIX_EFLAGS (__FIX_EFLAGS | X86_EFLAGS_RF)
44#else
45# define FIX_EFLAGS __FIX_EFLAGS
46#endif
47
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -080048static const struct {
49 u16 poplmovl;
50 u32 val;
51 u16 int80;
52} __attribute__((packed)) retcode = {
53 0xb858, /* popl %eax; movl $..., %eax */
54 __NR_sigreturn,
55 0x80cd, /* int $0x80 */
56};
57
58static const struct {
59 u8 movl;
60 u32 val;
61 u16 int80;
62 u8 pad;
63} __attribute__((packed)) rt_retcode = {
64 0xb8, /* movl $..., %eax */
65 __NR_rt_sigreturn,
66 0x80cd, /* int $0x80 */
67 0
68};
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070/*
71 * Atomically swap in the new signal mask, and wait for a signal.
72 */
73asmlinkage int
74sys_sigsuspend(int history0, int history1, old_sigset_t mask)
75{
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 mask &= _BLOCKABLE;
77 spin_lock_irq(&current->sighand->siglock);
David Howells283828f2006-01-18 17:44:00 -080078 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 siginitset(&current->blocked, mask);
80 recalc_sigpending();
81 spin_unlock_irq(&current->sighand->siglock);
82
David Howells283828f2006-01-18 17:44:00 -080083 current->state = TASK_INTERRUPTIBLE;
84 schedule();
Roland McGrath5a8da0e2008-04-30 00:53:10 -070085 set_restore_sigmask();
Ingo Molnar7e907f42008-03-06 10:33:08 +010086
David Howells283828f2006-01-18 17:44:00 -080087 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89
Ingo Molnar7e907f42008-03-06 10:33:08 +010090asmlinkage int
Linus Torvalds1da177e2005-04-16 15:20:36 -070091sys_sigaction(int sig, const struct old_sigaction __user *act,
92 struct old_sigaction __user *oact)
93{
94 struct k_sigaction new_ka, old_ka;
95 int ret;
96
97 if (act) {
98 old_sigset_t mask;
Ingo Molnar7e907f42008-03-06 10:33:08 +010099
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
101 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
102 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
103 return -EFAULT;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
106 __get_user(mask, &act->sa_mask);
107 siginitset(&new_ka.sa.sa_mask, mask);
108 }
109
110 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
111
112 if (!ret && oact) {
113 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
114 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
115 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
116 return -EFAULT;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
119 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
120 }
121
122 return ret;
123}
124
Ingo Molnar7e907f42008-03-06 10:33:08 +0100125asmlinkage int sys_sigaltstack(unsigned long bx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Ingo Molnar7e907f42008-03-06 10:33:08 +0100127 /*
128 * This is needed to make gcc realize it doesn't own the
129 * "struct pt_regs"
130 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100131 struct pt_regs *regs = (struct pt_regs *)&bx;
132 const stack_t __user *uss = (const stack_t __user *)bx;
133 stack_t __user *uoss = (stack_t __user *)regs->cx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100135 return do_sigaltstack(uss, uoss, regs->sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137
Hiroshi Shimamotoa2e8d3d2008-10-02 22:09:20 -0700138#define COPY(x) { \
139 err |= __get_user(regs->x, &sc->x); \
140}
141
142#define COPY_SEG(seg) { \
143 unsigned short tmp; \
144 err |= __get_user(tmp, &sc->seg); \
145 regs->seg = tmp; \
146}
147
148#define COPY_SEG_STRICT(seg) { \
149 unsigned short tmp; \
150 err |= __get_user(tmp, &sc->seg); \
151 regs->seg = tmp | 3; \
152}
153
154#define GET_SEG(seg) { \
155 unsigned short tmp; \
156 err |= __get_user(tmp, &sc->seg); \
157 loadsegment(seg, tmp); \
158}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160/*
161 * Do a signal return; undo the signal stack.
162 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163static int
Harvey Harrison866bc132008-02-08 12:10:02 -0800164restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
165 unsigned long *pax)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Hiroshi Shimamoto69e13ad2008-10-02 22:18:47 -0700167 void __user *buf;
168 unsigned int tmpflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 unsigned int err = 0;
170
171 /* Always make any pending restarted system calls return -EINTR */
172 current_thread_info()->restart_block.fn = do_no_restart_syscall;
173
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700174#ifdef CONFIG_X86_32
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100175 GET_SEG(gs);
176 COPY_SEG(fs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 COPY_SEG(es);
178 COPY_SEG(ds);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700179#endif /* CONFIG_X86_32 */
180
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800181 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
182 COPY(dx); COPY(cx); COPY(ip);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700183
184#ifdef CONFIG_X86_64
185 COPY(r8);
186 COPY(r9);
187 COPY(r10);
188 COPY(r11);
189 COPY(r12);
190 COPY(r13);
191 COPY(r14);
192 COPY(r15);
193#endif /* CONFIG_X86_64 */
194
195#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 COPY_SEG_STRICT(cs);
197 COPY_SEG_STRICT(ss);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700198#else /* !CONFIG_X86_32 */
199 /* Kernel saves and restores only the CS segment register on signals,
200 * which is the bare minimum needed to allow mixed 32/64-bit code.
201 * App's signal handler can save/restore other segments if needed. */
202 COPY_SEG_STRICT(cs);
203#endif /* CONFIG_X86_32 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100204
Hiroshi Shimamoto69e13ad2008-10-02 22:18:47 -0700205 err |= __get_user(tmpflags, &sc->flags);
206 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
207 regs->orig_ax = -1; /* disable syscall checks */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100208
Hiroshi Shimamoto69e13ad2008-10-02 22:18:47 -0700209 err |= __get_user(buf, &sc->fpstate);
210 err |= restore_i387_xstate(buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Harvey Harrison866bc132008-02-08 12:10:02 -0800212 err |= __get_user(*pax, &sc->ax);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
215
Harvey Harrison866bc132008-02-08 12:10:02 -0800216asmlinkage unsigned long sys_sigreturn(unsigned long __unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Ingo Molnar7e907f42008-03-06 10:33:08 +0100218 struct sigframe __user *frame;
219 struct pt_regs *regs;
Harvey Harrison866bc132008-02-08 12:10:02 -0800220 unsigned long ax;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100221 sigset_t set;
222
223 regs = (struct pt_regs *) &__unused;
224 frame = (struct sigframe __user *)(regs->sp - 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
227 goto badframe;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100228 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 && __copy_from_user(&set.sig[1], &frame->extramask,
230 sizeof(frame->extramask))))
231 goto badframe;
232
233 sigdelsetmask(&set, ~_BLOCKABLE);
234 spin_lock_irq(&current->sighand->siglock);
235 current->blocked = set;
236 recalc_sigpending();
237 spin_unlock_irq(&current->sighand->siglock);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100238
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100239 if (restore_sigcontext(regs, &frame->sc, &ax))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 goto badframe;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100241 return ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243badframe:
Andi Kleen03252912008-01-30 13:33:18 +0100244 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamoto1181f8b2008-07-03 13:12:13 -0700245 printk("%s%s[%d] bad frame in sigreturn frame:"
Ingo Molnar97b44ae2008-03-06 10:43:17 +0100246 "%p ip:%lx sp:%lx oeax:%lx",
Alexey Dobriyan19c58702007-10-18 23:40:41 -0700247 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100248 current->comm, task_pid_nr(current), frame, regs->ip,
249 regs->sp, regs->orig_ax);
Andi Kleen03252912008-01-30 13:33:18 +0100250 print_vma_addr(" in ", regs->ip);
Ingo Molnar97b44ae2008-03-06 10:43:17 +0100251 printk(KERN_CONT "\n");
Andi Kleen03252912008-01-30 13:33:18 +0100252 }
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +0200253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 force_sig(SIGSEGV, current);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 return 0;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100257}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700259static long do_rt_sigreturn(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Harvey Harrison2d19c452008-02-08 12:10:00 -0800261 struct rt_sigframe __user *frame;
Harvey Harrison866bc132008-02-08 12:10:02 -0800262 unsigned long ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 sigset_t set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Harvey Harrison2d19c452008-02-08 12:10:00 -0800265 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
267 goto badframe;
268 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
269 goto badframe;
270
271 sigdelsetmask(&set, ~_BLOCKABLE);
272 spin_lock_irq(&current->sighand->siglock);
273 current->blocked = set;
274 recalc_sigpending();
275 spin_unlock_irq(&current->sighand->siglock);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100276
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100277 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 goto badframe;
279
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100280 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 goto badframe;
282
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100283 return ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285badframe:
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700286 signal_fault(regs, frame, "rt_sigreturn");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 return 0;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100288}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700290asmlinkage int sys_rt_sigreturn(unsigned long __unused)
291{
292 struct pt_regs *regs = (struct pt_regs *)&__unused;
293
294 return do_rt_sigreturn(regs);
295}
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297/*
298 * Set up a signal frame.
299 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300static int
Suresh Siddhaab513702008-07-29 10:29:22 -0700301setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 struct pt_regs *regs, unsigned long mask)
303{
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800304 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800306#ifdef CONFIG_X86_32
307 {
308 unsigned int tmp;
309
310 savesegment(gs, tmp);
311 err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
312 }
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100313 err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100314 err |= __put_user(regs->es, (unsigned int __user *)&sc->es);
315 err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds);
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800316#endif /* CONFIG_X86_32 */
317
H. Peter Anvin742fa542008-01-30 13:30:56 +0100318 err |= __put_user(regs->di, &sc->di);
319 err |= __put_user(regs->si, &sc->si);
320 err |= __put_user(regs->bp, &sc->bp);
321 err |= __put_user(regs->sp, &sc->sp);
322 err |= __put_user(regs->bx, &sc->bx);
323 err |= __put_user(regs->dx, &sc->dx);
324 err |= __put_user(regs->cx, &sc->cx);
325 err |= __put_user(regs->ax, &sc->ax);
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800326#ifdef CONFIG_X86_64
327 err |= __put_user(regs->r8, &sc->r8);
328 err |= __put_user(regs->r9, &sc->r9);
329 err |= __put_user(regs->r10, &sc->r10);
330 err |= __put_user(regs->r11, &sc->r11);
331 err |= __put_user(regs->r12, &sc->r12);
332 err |= __put_user(regs->r13, &sc->r13);
333 err |= __put_user(regs->r14, &sc->r14);
334 err |= __put_user(regs->r15, &sc->r15);
335#endif /* CONFIG_X86_64 */
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 err |= __put_user(current->thread.trap_no, &sc->trapno);
338 err |= __put_user(current->thread.error_code, &sc->err);
H. Peter Anvin742fa542008-01-30 13:30:56 +0100339 err |= __put_user(regs->ip, &sc->ip);
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800340#ifdef CONFIG_X86_32
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100341 err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs);
H. Peter Anvin742fa542008-01-30 13:30:56 +0100342 err |= __put_user(regs->flags, &sc->flags);
343 err |= __put_user(regs->sp, &sc->sp_at_signal);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100344 err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss);
Hiroshi Shimamoto15002fa2008-11-07 19:25:36 -0800345#else /* !CONFIG_X86_32 */
346 err |= __put_user(regs->flags, &sc->flags);
347 err |= __put_user(regs->cs, &sc->cs);
348 err |= __put_user(0, &sc->gs);
349 err |= __put_user(0, &sc->fs);
350#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Hiroshi Shimamoto4b336692008-11-05 18:30:25 -0800352 err |= __put_user(fpstate, &sc->fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 /* non-iBCS2 extensions.. */
355 err |= __put_user(mask, &sc->oldmask);
356 err |= __put_user(current->thread.cr2, &sc->cr2);
357
358 return err;
359}
360
361/*
362 * Determine which stack to use..
363 */
364static inline void __user *
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700365get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
Suresh Siddhaab513702008-07-29 10:29:22 -0700366 void **fpstate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100368 unsigned long sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370 /* Default to using normal stack */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100371 sp = regs->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Roland McGrath83bd0102008-01-30 13:30:06 +0100373 /*
374 * If we are on the alternate signal stack and would overflow it, don't.
375 * Return an always-bogus address instead so we will die with SIGSEGV.
376 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100377 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
Roland McGrath83bd0102008-01-30 13:30:06 +0100378 return (void __user *) -1L;
379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 /* This is the X/Open sanctioned signal stack switching. */
381 if (ka->sa.sa_flags & SA_ONSTACK) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100382 if (sas_ss_flags(sp) == 0)
383 sp = current->sas_ss_sp + current->sas_ss_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100384 } else {
385 /* This is the legacy signal stack switching. */
386 if ((regs->ss & 0xffff) != __USER_DS &&
387 !(ka->sa.sa_flags & SA_RESTORER) &&
388 ka->sa.sa_restorer)
389 sp = (unsigned long) ka->sa.sa_restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 }
391
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700392 if (used_math()) {
393 sp = sp - sig_xstate_size;
394 *fpstate = (struct _fpstate *) sp;
Hiroshi Shimamoto4b336692008-11-05 18:30:25 -0800395 if (save_i387_xstate(*fpstate) < 0)
396 return (void __user *)-1L;
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700397 }
398
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100399 sp -= frame_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100400 /*
401 * Align the stack pointer according to the i386 ABI,
402 * i.e. so that on function entry ((sp + 4) & 15) == 0.
403 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100404 sp = ((sp + 4) & -16ul) - 4;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100405
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100406 return (void __user *) sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407}
408
Ingo Molnar7e907f42008-03-06 10:33:08 +0100409static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700410__setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
411 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 struct sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100414 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700416 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700418 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700421 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700423 if (__put_user(sig, &frame->sig))
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 (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700427 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429 if (_NSIG_WORDS > 1) {
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700430 if (__copy_to_user(&frame->extramask, &set->sig[1],
431 sizeof(frame->extramask)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700432 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 }
434
Roland McGrath1a3e4ca2008-04-09 01:29:27 -0700435 if (current->mm->context.vdso)
Roland McGrath6c3652e2008-01-30 13:30:42 +0100436 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100437 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100438 restorer = &frame->retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 if (ka->sa.sa_flags & SA_RESTORER)
440 restorer = ka->sa.sa_restorer;
441
442 /* Set up to return from userspace. */
443 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100446 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 *
448 * WE DO NOT USE IT ANY MORE! It's only left here for historical
449 * reasons and because gdb uses it as a signature to notice
450 * signal handler stack frames.
451 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800452 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
454 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700455 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
457 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100458 regs->sp = (unsigned long)frame;
459 regs->ip = (unsigned long)ka->sa.sa_handler;
460 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800461 regs->dx = 0;
462 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100464 regs->ds = __USER_DS;
465 regs->es = __USER_DS;
466 regs->ss = __USER_DS;
467 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
David Howells283828f2006-01-18 17:44:00 -0800469 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470}
471
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700472static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
473 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100476 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700478 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700480 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700483 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700485 err |= __put_user(sig, &frame->sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 err |= __put_user(&frame->info, &frame->pinfo);
487 err |= __put_user(&frame->uc, &frame->puc);
488 err |= copy_siginfo_to_user(&frame->info, info);
489 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700490 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 /* Create the ucontext. */
Suresh Siddhac37b5ef2008-07-29 10:29:25 -0700493 if (cpu_has_xsave)
494 err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags);
495 else
496 err |= __put_user(0, &frame->uc.uc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 err |= __put_user(0, &frame->uc.uc_link);
498 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100499 err |= __put_user(sas_ss_flags(regs->sp),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 &frame->uc.uc_stack.ss_flags);
501 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700502 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
Ingo Molnar7e907f42008-03-06 10:33:08 +0100503 regs, set->sig[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
505 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700506 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508 /* Set up to return from userspace. */
Roland McGrath6c3652e2008-01-30 13:30:42 +0100509 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 if (ka->sa.sa_flags & SA_RESTORER)
511 restorer = ka->sa.sa_restorer;
512 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100515 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 *
517 * WE DO NOT USE IT ANY MORE! It's only left here for historical
518 * reasons and because gdb uses it as a signature to notice
519 * signal handler stack frames.
520 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800521 err |= __put_user(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700524 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100527 regs->sp = (unsigned long)frame;
528 regs->ip = (unsigned long)ka->sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700529 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100530 regs->dx = (unsigned long)&frame->info;
531 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100533 regs->ds = __USER_DS;
534 regs->es = __USER_DS;
535 regs->ss = __USER_DS;
536 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
David Howells283828f2006-01-18 17:44:00 -0800538 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539}
540
541/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100542 * OK, we're invoking a handler:
543 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700544static int signr_convert(int sig)
545{
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700546#ifdef CONFIG_X86_32
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700547 struct thread_info *info = current_thread_info();
548
549 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
550 return info->exec_domain->signal_invmap[sig];
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700551#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700552 return sig;
553}
554
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700555#ifdef CONFIG_X86_32
556
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700557#define is_ia32 1
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700558#define ia32_setup_frame __setup_frame
559#define ia32_setup_rt_frame __setup_rt_frame
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700560
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700561#else /* !CONFIG_X86_32 */
562
563#ifdef CONFIG_IA32_EMULATION
564#define is_ia32 test_thread_flag(TIF_IA32)
565#else /* !CONFIG_IA32_EMULATION */
566#define is_ia32 0
567#endif /* CONFIG_IA32_EMULATION */
568
569#endif /* CONFIG_X86_32 */
570
Roland McGrath7c1def12005-06-23 00:08:21 -0700571static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700572setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
573 sigset_t *set, struct pt_regs *regs)
574{
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700575 int usig = signr_convert(sig);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700576 int ret;
577
578 /* Set up the stack frame */
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700579 if (is_ia32) {
580 if (ka->sa.sa_flags & SA_SIGINFO)
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700581 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700582 else
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700583 ret = ia32_setup_frame(usig, ka, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700584 } else
585 ret = __setup_rt_frame(sig, ka, info, set, regs);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700586
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700587 if (ret) {
588 force_sigsegv(sig, current);
589 return -EFAULT;
590 }
591
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700592 return ret;
593}
594
595static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800597 sigset_t *oldset, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
Roland McGrath7c1def12005-06-23 00:08:21 -0700599 int ret;
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700602 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700604 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800605 case -ERESTART_RESTARTBLOCK:
606 case -ERESTARTNOHAND:
607 regs->ax = -EINTR;
608 break;
609
610 case -ERESTARTSYS:
611 if (!(ka->sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100612 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800614 }
615 /* fallthrough */
616 case -ERESTARTNOINTR:
617 regs->ax = regs->orig_ax;
618 regs->ip -= 2;
619 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
621 }
622
623 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100624 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
625 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100627 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100628 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100629 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700631 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Ingo Molnar7e907f42008-03-06 10:33:08 +0100633 if (ret)
634 return ret;
Roland McGrath7c1def12005-06-23 00:08:21 -0700635
Hiroshi Shimamoto86d32372008-09-23 17:22:32 -0700636#ifdef CONFIG_X86_64
637 /*
638 * This has nothing to do with segment registers,
639 * despite the name. This magic affects uaccess.h
640 * macros' behavior. Reset it to the normal setting.
641 */
642 set_fs(USER_DS);
643#endif
644
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700645 /*
646 * Clear the direction flag as per the ABI for function entry.
647 */
648 regs->flags &= ~X86_EFLAGS_DF;
649
650 /*
651 * Clear TF when entering the signal handler, but
652 * notify any tracer that was single-stepping it.
653 * The tracer may want to single-step inside the
654 * handler too.
655 */
656 regs->flags &= ~X86_EFLAGS_TF;
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700657
Ingo Molnar7e907f42008-03-06 10:33:08 +0100658 spin_lock_irq(&current->sighand->siglock);
659 sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
660 if (!(ka->sa.sa_flags & SA_NODEFER))
661 sigaddset(&current->blocked, sig);
662 recalc_sigpending();
663 spin_unlock_irq(&current->sighand->siglock);
664
Roland McGrath36a03302008-03-14 17:46:38 -0700665 tracehook_signal_handler(sig, info, ka, regs,
666 test_thread_flag(TIF_SINGLESTEP));
667
Ingo Molnar7e907f42008-03-06 10:33:08 +0100668 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669}
670
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700671#ifdef CONFIG_X86_32
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700672#define NR_restart_syscall __NR_restart_syscall
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700673#else /* !CONFIG_X86_32 */
674#define NR_restart_syscall \
675 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
676#endif /* CONFIG_X86_32 */
677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678/*
679 * Note that 'init' is a special process: it doesn't get signals it doesn't
680 * want to handle. Thus you cannot kill init even with a SIGKILL even by
681 * mistake.
682 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100683static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684{
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800685 struct k_sigaction ka;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 siginfo_t info;
687 int signr;
David Howells283828f2006-01-18 17:44:00 -0800688 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
690 /*
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800691 * We want the common case to go fast, which is why we may in certain
692 * cases get here from kernel mode. Just return without doing anything
693 * if so.
694 * X86_32: vm86 regs switched out by assembly code before reaching
695 * here, so testing against kernel CS suffices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 */
Vincent Hanquez717b5942005-06-23 00:08:45 -0700697 if (!user_mode(regs))
David Howells283828f2006-01-18 17:44:00 -0800698 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700700 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
David Howells283828f2006-01-18 17:44:00 -0800701 oldset = &current->saved_sigmask;
702 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 oldset = &current->blocked;
704
705 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
706 if (signr > 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100707 /*
708 * Re-enable any watchpoints before delivering the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 * signal to user space. The processor register will
710 * have been cleared if the watchpoint triggered
711 * inside the kernel.
712 */
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800713 if (current->thread.debugreg7)
Roland McGrath0f534092008-01-30 13:30:59 +0100714 set_debugreg(current->thread.debugreg7, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Ingo Molnar7e907f42008-03-06 10:33:08 +0100716 /* Whee! Actually deliver the signal. */
David Howells283828f2006-01-18 17:44:00 -0800717 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100718 /*
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700719 * A signal was successfully delivered; the saved
David Howells283828f2006-01-18 17:44:00 -0800720 * sigmask will have been stored in the signal frame,
721 * and will be restored by sigreturn, so we can simply
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700722 * clear the TS_RESTORE_SIGMASK flag.
Ingo Molnar7e907f42008-03-06 10:33:08 +0100723 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700724 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800725 }
David Howells283828f2006-01-18 17:44:00 -0800726 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 }
728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700730 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700732 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800733 case -ERESTARTNOHAND:
734 case -ERESTARTSYS:
735 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100736 regs->ax = regs->orig_ax;
737 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800738 break;
739
740 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700741 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100742 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800743 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 }
745 }
David Howells283828f2006-01-18 17:44:00 -0800746
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800747 /*
748 * If there's no signal to deliver, we just put the saved sigmask
749 * back.
750 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700751 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
752 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800753 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755}
756
757/*
758 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800759 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100761void
762do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763{
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700764#if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
765 /* notify userspace of pending MCEs */
766 if (thread_info_flags & _TIF_MCE_NOTIFY)
767 mce_notify_user();
768#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
769
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700771 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800772 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100773
Roland McGrath59e52132008-04-19 19:10:57 -0700774 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
775 clear_thread_flag(TIF_NOTIFY_RESUME);
776 tracehook_notify_resume(regs);
777 }
778
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700779#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 clear_thread_flag(TIF_IRET);
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700781#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700783
784void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
785{
786 struct task_struct *me = current;
787
788 if (show_unhandled_signals && printk_ratelimit()) {
789 printk(KERN_INFO
790 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
791 me->comm, me->pid, where, frame,
792 regs->ip, regs->sp, regs->orig_ax);
793 print_vma_addr(" in ", regs->ip);
794 printk(KERN_CONT "\n");
795 }
796
797 force_sig(SIGSEGV, me);
798}