blob: b3f30d2a21781da5d2697861dabf38d52d4417f6 [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
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080073#define COPY(x) { \
74 err |= __get_user(regs->x, &sc->x); \
75}
76
77#define COPY_SEG(seg) { \
78 unsigned short tmp; \
79 err |= __get_user(tmp, &sc->seg); \
80 regs->seg = tmp; \
81}
82
83#define COPY_SEG_CPL3(seg) { \
84 unsigned short tmp; \
85 err |= __get_user(tmp, &sc->seg); \
86 regs->seg = tmp | 3; \
87}
88
89#define GET_SEG(seg) { \
90 unsigned short tmp; \
91 err |= __get_user(tmp, &sc->seg); \
92 loadsegment(seg, tmp); \
93}
94
95static int
96restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
97 unsigned long *pax)
98{
99 void __user *buf;
100 unsigned int tmpflags;
101 unsigned int err = 0;
102
103 /* Always make any pending restarted system calls return -EINTR */
104 current_thread_info()->restart_block.fn = do_no_restart_syscall;
105
106#ifdef CONFIG_X86_32
107 GET_SEG(gs);
108 COPY_SEG(fs);
109 COPY_SEG(es);
110 COPY_SEG(ds);
111#endif /* CONFIG_X86_32 */
112
113 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
114 COPY(dx); COPY(cx); COPY(ip);
115
116#ifdef CONFIG_X86_64
117 COPY(r8);
118 COPY(r9);
119 COPY(r10);
120 COPY(r11);
121 COPY(r12);
122 COPY(r13);
123 COPY(r14);
124 COPY(r15);
125#endif /* CONFIG_X86_64 */
126
127#ifdef CONFIG_X86_32
128 COPY_SEG_CPL3(cs);
129 COPY_SEG_CPL3(ss);
130#else /* !CONFIG_X86_32 */
131 /* Kernel saves and restores only the CS segment register on signals,
132 * which is the bare minimum needed to allow mixed 32/64-bit code.
133 * App's signal handler can save/restore other segments if needed. */
134 COPY_SEG_CPL3(cs);
135#endif /* CONFIG_X86_32 */
136
137 err |= __get_user(tmpflags, &sc->flags);
138 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
139 regs->orig_ax = -1; /* disable syscall checks */
140
141 err |= __get_user(buf, &sc->fpstate);
142 err |= restore_i387_xstate(buf);
143
144 err |= __get_user(*pax, &sc->ax);
145 return err;
146}
147
148static int
149setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
150 struct pt_regs *regs, unsigned long mask)
151{
152 int err = 0;
153
154#ifdef CONFIG_X86_32
155 {
156 unsigned int tmp;
157
158 savesegment(gs, tmp);
159 err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
160 }
161 err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs);
162 err |= __put_user(regs->es, (unsigned int __user *)&sc->es);
163 err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds);
164#endif /* CONFIG_X86_32 */
165
166 err |= __put_user(regs->di, &sc->di);
167 err |= __put_user(regs->si, &sc->si);
168 err |= __put_user(regs->bp, &sc->bp);
169 err |= __put_user(regs->sp, &sc->sp);
170 err |= __put_user(regs->bx, &sc->bx);
171 err |= __put_user(regs->dx, &sc->dx);
172 err |= __put_user(regs->cx, &sc->cx);
173 err |= __put_user(regs->ax, &sc->ax);
174#ifdef CONFIG_X86_64
175 err |= __put_user(regs->r8, &sc->r8);
176 err |= __put_user(regs->r9, &sc->r9);
177 err |= __put_user(regs->r10, &sc->r10);
178 err |= __put_user(regs->r11, &sc->r11);
179 err |= __put_user(regs->r12, &sc->r12);
180 err |= __put_user(regs->r13, &sc->r13);
181 err |= __put_user(regs->r14, &sc->r14);
182 err |= __put_user(regs->r15, &sc->r15);
183#endif /* CONFIG_X86_64 */
184
185 err |= __put_user(current->thread.trap_no, &sc->trapno);
186 err |= __put_user(current->thread.error_code, &sc->err);
187 err |= __put_user(regs->ip, &sc->ip);
188#ifdef CONFIG_X86_32
189 err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs);
190 err |= __put_user(regs->flags, &sc->flags);
191 err |= __put_user(regs->sp, &sc->sp_at_signal);
192 err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss);
193#else /* !CONFIG_X86_32 */
194 err |= __put_user(regs->flags, &sc->flags);
195 err |= __put_user(regs->cs, &sc->cs);
196 err |= __put_user(0, &sc->gs);
197 err |= __put_user(0, &sc->fs);
198#endif /* CONFIG_X86_32 */
199
200 err |= __put_user(fpstate, &sc->fpstate);
201
202 /* non-iBCS2 extensions.. */
203 err |= __put_user(mask, &sc->oldmask);
204 err |= __put_user(current->thread.cr2, &sc->cr2);
205
206 return err;
207}
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209/*
210 * Atomically swap in the new signal mask, and wait for a signal.
211 */
212asmlinkage int
213sys_sigsuspend(int history0, int history1, old_sigset_t mask)
214{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 mask &= _BLOCKABLE;
216 spin_lock_irq(&current->sighand->siglock);
David Howells283828f2006-01-18 17:44:00 -0800217 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 siginitset(&current->blocked, mask);
219 recalc_sigpending();
220 spin_unlock_irq(&current->sighand->siglock);
221
David Howells283828f2006-01-18 17:44:00 -0800222 current->state = TASK_INTERRUPTIBLE;
223 schedule();
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700224 set_restore_sigmask();
Ingo Molnar7e907f42008-03-06 10:33:08 +0100225
David Howells283828f2006-01-18 17:44:00 -0800226 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
Ingo Molnar7e907f42008-03-06 10:33:08 +0100229asmlinkage int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230sys_sigaction(int sig, const struct old_sigaction __user *act,
231 struct old_sigaction __user *oact)
232{
233 struct k_sigaction new_ka, old_ka;
234 int ret;
235
236 if (act) {
237 old_sigset_t mask;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
240 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
241 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
242 return -EFAULT;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
245 __get_user(mask, &act->sa_mask);
246 siginitset(&new_ka.sa.sa_mask, mask);
247 }
248
249 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
250
251 if (!ret && oact) {
252 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
253 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
254 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
255 return -EFAULT;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
258 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
259 }
260
261 return ret;
262}
263
Hiroshi Shimamoto666ac7b2008-11-21 17:38:25 -0800264#ifdef CONFIG_X86_32
Ingo Molnar7e907f42008-03-06 10:33:08 +0100265asmlinkage int sys_sigaltstack(unsigned long bx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
Ingo Molnar7e907f42008-03-06 10:33:08 +0100267 /*
268 * This is needed to make gcc realize it doesn't own the
269 * "struct pt_regs"
270 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100271 struct pt_regs *regs = (struct pt_regs *)&bx;
272 const stack_t __user *uss = (const stack_t __user *)bx;
273 stack_t __user *uoss = (stack_t __user *)regs->cx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100275 return do_sigaltstack(uss, uoss, regs->sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
Hiroshi Shimamoto666ac7b2008-11-21 17:38:25 -0800277#else /* !CONFIG_X86_32 */
278asmlinkage long
279sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
280 struct pt_regs *regs)
281{
282 return do_sigaltstack(uss, uoss, regs->sp);
283}
284#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286/*
287 * Do a signal return; undo the signal stack.
288 */
Harvey Harrison866bc132008-02-08 12:10:02 -0800289asmlinkage unsigned long sys_sigreturn(unsigned long __unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
Ingo Molnar7e907f42008-03-06 10:33:08 +0100291 struct sigframe __user *frame;
292 struct pt_regs *regs;
Harvey Harrison866bc132008-02-08 12:10:02 -0800293 unsigned long ax;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100294 sigset_t set;
295
296 regs = (struct pt_regs *) &__unused;
297 frame = (struct sigframe __user *)(regs->sp - 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
300 goto badframe;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100301 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 && __copy_from_user(&set.sig[1], &frame->extramask,
303 sizeof(frame->extramask))))
304 goto badframe;
305
306 sigdelsetmask(&set, ~_BLOCKABLE);
307 spin_lock_irq(&current->sighand->siglock);
308 current->blocked = set;
309 recalc_sigpending();
310 spin_unlock_irq(&current->sighand->siglock);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100311
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100312 if (restore_sigcontext(regs, &frame->sc, &ax))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 goto badframe;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100314 return ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316badframe:
Andi Kleen03252912008-01-30 13:33:18 +0100317 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamoto1181f8b2008-07-03 13:12:13 -0700318 printk("%s%s[%d] bad frame in sigreturn frame:"
Ingo Molnar97b44ae2008-03-06 10:43:17 +0100319 "%p ip:%lx sp:%lx oeax:%lx",
Alexey Dobriyan19c58702007-10-18 23:40:41 -0700320 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100321 current->comm, task_pid_nr(current), frame, regs->ip,
322 regs->sp, regs->orig_ax);
Andi Kleen03252912008-01-30 13:33:18 +0100323 print_vma_addr(" in ", regs->ip);
Ingo Molnar97b44ae2008-03-06 10:43:17 +0100324 printk(KERN_CONT "\n");
Andi Kleen03252912008-01-30 13:33:18 +0100325 }
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +0200326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 force_sig(SIGSEGV, current);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 return 0;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100330}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700332static long do_rt_sigreturn(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333{
Harvey Harrison2d19c452008-02-08 12:10:00 -0800334 struct rt_sigframe __user *frame;
Harvey Harrison866bc132008-02-08 12:10:02 -0800335 unsigned long ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 sigset_t set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Harvey Harrison2d19c452008-02-08 12:10:00 -0800338 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
340 goto badframe;
341 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
342 goto badframe;
343
344 sigdelsetmask(&set, ~_BLOCKABLE);
345 spin_lock_irq(&current->sighand->siglock);
346 current->blocked = set;
347 recalc_sigpending();
348 spin_unlock_irq(&current->sighand->siglock);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100349
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100350 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 goto badframe;
352
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100353 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 goto badframe;
355
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100356 return ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358badframe:
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700359 signal_fault(regs, frame, "rt_sigreturn");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 return 0;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100361}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Hiroshi Shimamoto2456d732008-11-21 17:38:57 -0800363#ifdef CONFIG_X86_32
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700364asmlinkage int sys_rt_sigreturn(unsigned long __unused)
365{
366 struct pt_regs *regs = (struct pt_regs *)&__unused;
367
368 return do_rt_sigreturn(regs);
369}
Hiroshi Shimamoto2456d732008-11-21 17:38:57 -0800370#else /* !CONFIG_X86_32 */
371asmlinkage long sys_rt_sigreturn(struct pt_regs *regs)
372{
373 return do_rt_sigreturn(regs);
374}
375#endif /* CONFIG_X86_32 */
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377/*
378 * Set up a signal frame.
379 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
381/*
382 * Determine which stack to use..
383 */
384static inline void __user *
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700385get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
Suresh Siddhaab513702008-07-29 10:29:22 -0700386 void **fpstate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100388 unsigned long sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
390 /* Default to using normal stack */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100391 sp = regs->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Roland McGrath83bd0102008-01-30 13:30:06 +0100393 /*
394 * If we are on the alternate signal stack and would overflow it, don't.
395 * Return an always-bogus address instead so we will die with SIGSEGV.
396 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100397 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
Roland McGrath83bd0102008-01-30 13:30:06 +0100398 return (void __user *) -1L;
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 /* This is the X/Open sanctioned signal stack switching. */
401 if (ka->sa.sa_flags & SA_ONSTACK) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100402 if (sas_ss_flags(sp) == 0)
403 sp = current->sas_ss_sp + current->sas_ss_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100404 } else {
405 /* This is the legacy signal stack switching. */
406 if ((regs->ss & 0xffff) != __USER_DS &&
407 !(ka->sa.sa_flags & SA_RESTORER) &&
408 ka->sa.sa_restorer)
409 sp = (unsigned long) ka->sa.sa_restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 }
411
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700412 if (used_math()) {
413 sp = sp - sig_xstate_size;
414 *fpstate = (struct _fpstate *) sp;
Hiroshi Shimamoto4b336692008-11-05 18:30:25 -0800415 if (save_i387_xstate(*fpstate) < 0)
416 return (void __user *)-1L;
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700417 }
418
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100419 sp -= frame_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100420 /*
421 * Align the stack pointer according to the i386 ABI,
422 * i.e. so that on function entry ((sp + 4) & 15) == 0.
423 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100424 sp = ((sp + 4) & -16ul) - 4;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100425
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100426 return (void __user *) sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
Ingo Molnar7e907f42008-03-06 10:33:08 +0100429static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700430__setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
431 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 struct sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100434 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700436 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700438 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700441 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700443 if (__put_user(sig, &frame->sig))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700444 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700446 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700447 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
449 if (_NSIG_WORDS > 1) {
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700450 if (__copy_to_user(&frame->extramask, &set->sig[1],
451 sizeof(frame->extramask)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700452 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
454
Roland McGrath1a3e4ca2008-04-09 01:29:27 -0700455 if (current->mm->context.vdso)
Roland McGrath6c3652e2008-01-30 13:30:42 +0100456 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100457 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100458 restorer = &frame->retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 if (ka->sa.sa_flags & SA_RESTORER)
460 restorer = ka->sa.sa_restorer;
461
462 /* Set up to return from userspace. */
463 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100466 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 *
468 * WE DO NOT USE IT ANY MORE! It's only left here for historical
469 * reasons and because gdb uses it as a signature to notice
470 * signal handler stack frames.
471 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800472 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700475 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
477 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100478 regs->sp = (unsigned long)frame;
479 regs->ip = (unsigned long)ka->sa.sa_handler;
480 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800481 regs->dx = 0;
482 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100484 regs->ds = __USER_DS;
485 regs->es = __USER_DS;
486 regs->ss = __USER_DS;
487 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
David Howells283828f2006-01-18 17:44:00 -0800489 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490}
491
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700492static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
493 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100496 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700498 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700500 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700503 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700505 err |= __put_user(sig, &frame->sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 err |= __put_user(&frame->info, &frame->pinfo);
507 err |= __put_user(&frame->uc, &frame->puc);
508 err |= copy_siginfo_to_user(&frame->info, info);
509 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700510 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 /* Create the ucontext. */
Suresh Siddhac37b5ef2008-07-29 10:29:25 -0700513 if (cpu_has_xsave)
514 err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags);
515 else
516 err |= __put_user(0, &frame->uc.uc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 err |= __put_user(0, &frame->uc.uc_link);
518 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100519 err |= __put_user(sas_ss_flags(regs->sp),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 &frame->uc.uc_stack.ss_flags);
521 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700522 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
Ingo Molnar7e907f42008-03-06 10:33:08 +0100523 regs, set->sig[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
525 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700526 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 /* Set up to return from userspace. */
Roland McGrath6c3652e2008-01-30 13:30:42 +0100529 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 if (ka->sa.sa_flags & SA_RESTORER)
531 restorer = ka->sa.sa_restorer;
532 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100535 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 *
537 * WE DO NOT USE IT ANY MORE! It's only left here for historical
538 * reasons and because gdb uses it as a signature to notice
539 * signal handler stack frames.
540 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800541 err |= __put_user(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700544 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
546 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100547 regs->sp = (unsigned long)frame;
548 regs->ip = (unsigned long)ka->sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700549 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100550 regs->dx = (unsigned long)&frame->info;
551 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100553 regs->ds = __USER_DS;
554 regs->es = __USER_DS;
555 regs->ss = __USER_DS;
556 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
David Howells283828f2006-01-18 17:44:00 -0800558 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559}
560
561/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100562 * OK, we're invoking a handler:
563 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700564static int signr_convert(int sig)
565{
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700566#ifdef CONFIG_X86_32
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700567 struct thread_info *info = current_thread_info();
568
569 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
570 return info->exec_domain->signal_invmap[sig];
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700571#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700572 return sig;
573}
574
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700575#ifdef CONFIG_X86_32
576
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700577#define is_ia32 1
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700578#define ia32_setup_frame __setup_frame
579#define ia32_setup_rt_frame __setup_rt_frame
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700580
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700581#else /* !CONFIG_X86_32 */
582
583#ifdef CONFIG_IA32_EMULATION
584#define is_ia32 test_thread_flag(TIF_IA32)
585#else /* !CONFIG_IA32_EMULATION */
586#define is_ia32 0
587#endif /* CONFIG_IA32_EMULATION */
588
589#endif /* CONFIG_X86_32 */
590
Roland McGrath7c1def12005-06-23 00:08:21 -0700591static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700592setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
593 sigset_t *set, struct pt_regs *regs)
594{
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700595 int usig = signr_convert(sig);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700596 int ret;
597
598 /* Set up the stack frame */
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700599 if (is_ia32) {
600 if (ka->sa.sa_flags & SA_SIGINFO)
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700601 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700602 else
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700603 ret = ia32_setup_frame(usig, ka, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700604 } else
605 ret = __setup_rt_frame(sig, ka, info, set, regs);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700606
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700607 if (ret) {
608 force_sigsegv(sig, current);
609 return -EFAULT;
610 }
611
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700612 return ret;
613}
614
615static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800617 sigset_t *oldset, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618{
Roland McGrath7c1def12005-06-23 00:08:21 -0700619 int ret;
620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700622 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700624 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800625 case -ERESTART_RESTARTBLOCK:
626 case -ERESTARTNOHAND:
627 regs->ax = -EINTR;
628 break;
629
630 case -ERESTARTSYS:
631 if (!(ka->sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100632 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800634 }
635 /* fallthrough */
636 case -ERESTARTNOINTR:
637 regs->ax = regs->orig_ax;
638 regs->ip -= 2;
639 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
641 }
642
643 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100644 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
645 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100647 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100648 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100649 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700651 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Ingo Molnar7e907f42008-03-06 10:33:08 +0100653 if (ret)
654 return ret;
Roland McGrath7c1def12005-06-23 00:08:21 -0700655
Hiroshi Shimamoto86d32372008-09-23 17:22:32 -0700656#ifdef CONFIG_X86_64
657 /*
658 * This has nothing to do with segment registers,
659 * despite the name. This magic affects uaccess.h
660 * macros' behavior. Reset it to the normal setting.
661 */
662 set_fs(USER_DS);
663#endif
664
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700665 /*
666 * Clear the direction flag as per the ABI for function entry.
667 */
668 regs->flags &= ~X86_EFLAGS_DF;
669
670 /*
671 * Clear TF when entering the signal handler, but
672 * notify any tracer that was single-stepping it.
673 * The tracer may want to single-step inside the
674 * handler too.
675 */
676 regs->flags &= ~X86_EFLAGS_TF;
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700677
Ingo Molnar7e907f42008-03-06 10:33:08 +0100678 spin_lock_irq(&current->sighand->siglock);
679 sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
680 if (!(ka->sa.sa_flags & SA_NODEFER))
681 sigaddset(&current->blocked, sig);
682 recalc_sigpending();
683 spin_unlock_irq(&current->sighand->siglock);
684
Roland McGrath36a03302008-03-14 17:46:38 -0700685 tracehook_signal_handler(sig, info, ka, regs,
686 test_thread_flag(TIF_SINGLESTEP));
687
Ingo Molnar7e907f42008-03-06 10:33:08 +0100688 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700691#ifdef CONFIG_X86_32
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700692#define NR_restart_syscall __NR_restart_syscall
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700693#else /* !CONFIG_X86_32 */
694#define NR_restart_syscall \
695 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
696#endif /* CONFIG_X86_32 */
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698/*
699 * Note that 'init' is a special process: it doesn't get signals it doesn't
700 * want to handle. Thus you cannot kill init even with a SIGKILL even by
701 * mistake.
702 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100703static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704{
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800705 struct k_sigaction ka;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 siginfo_t info;
707 int signr;
David Howells283828f2006-01-18 17:44:00 -0800708 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
710 /*
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800711 * We want the common case to go fast, which is why we may in certain
712 * cases get here from kernel mode. Just return without doing anything
713 * if so.
714 * X86_32: vm86 regs switched out by assembly code before reaching
715 * here, so testing against kernel CS suffices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 */
Vincent Hanquez717b5942005-06-23 00:08:45 -0700717 if (!user_mode(regs))
David Howells283828f2006-01-18 17:44:00 -0800718 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700720 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
David Howells283828f2006-01-18 17:44:00 -0800721 oldset = &current->saved_sigmask;
722 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 oldset = &current->blocked;
724
725 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
726 if (signr > 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100727 /*
728 * Re-enable any watchpoints before delivering the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 * signal to user space. The processor register will
730 * have been cleared if the watchpoint triggered
731 * inside the kernel.
732 */
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800733 if (current->thread.debugreg7)
Roland McGrath0f534092008-01-30 13:30:59 +0100734 set_debugreg(current->thread.debugreg7, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Ingo Molnar7e907f42008-03-06 10:33:08 +0100736 /* Whee! Actually deliver the signal. */
David Howells283828f2006-01-18 17:44:00 -0800737 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100738 /*
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700739 * A signal was successfully delivered; the saved
David Howells283828f2006-01-18 17:44:00 -0800740 * sigmask will have been stored in the signal frame,
741 * and will be restored by sigreturn, so we can simply
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700742 * clear the TS_RESTORE_SIGMASK flag.
Ingo Molnar7e907f42008-03-06 10:33:08 +0100743 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700744 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800745 }
David Howells283828f2006-01-18 17:44:00 -0800746 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 }
748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700750 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700752 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800753 case -ERESTARTNOHAND:
754 case -ERESTARTSYS:
755 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100756 regs->ax = regs->orig_ax;
757 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800758 break;
759
760 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700761 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100762 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800763 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
765 }
David Howells283828f2006-01-18 17:44:00 -0800766
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800767 /*
768 * If there's no signal to deliver, we just put the saved sigmask
769 * back.
770 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700771 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
772 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800773 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775}
776
777/*
778 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800779 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100781void
782do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783{
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700784#if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
785 /* notify userspace of pending MCEs */
786 if (thread_info_flags & _TIF_MCE_NOTIFY)
787 mce_notify_user();
788#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700791 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800792 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100793
Roland McGrath59e52132008-04-19 19:10:57 -0700794 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
795 clear_thread_flag(TIF_NOTIFY_RESUME);
796 tracehook_notify_resume(regs);
797 }
798
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700799#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 clear_thread_flag(TIF_IRET);
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700801#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700803
804void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
805{
806 struct task_struct *me = current;
807
808 if (show_unhandled_signals && printk_ratelimit()) {
809 printk(KERN_INFO
810 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
811 me->comm, me->pid, where, frame,
812 regs->ip, regs->sp, regs->orig_ax);
813 print_vma_addr(" in ", regs->ip);
814 printk(KERN_CONT "\n");
815 }
816
817 force_sig(SIGSEGV, me);
818}