blob: 6a05c74b40845a2de0c56a4fbad7f2912f383d1a [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/*
49 * Atomically swap in the new signal mask, and wait for a signal.
50 */
51asmlinkage int
52sys_sigsuspend(int history0, int history1, old_sigset_t mask)
53{
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 mask &= _BLOCKABLE;
55 spin_lock_irq(&current->sighand->siglock);
David Howells283828f2006-01-18 17:44:00 -080056 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 siginitset(&current->blocked, mask);
58 recalc_sigpending();
59 spin_unlock_irq(&current->sighand->siglock);
60
David Howells283828f2006-01-18 17:44:00 -080061 current->state = TASK_INTERRUPTIBLE;
62 schedule();
Roland McGrath5a8da0e2008-04-30 00:53:10 -070063 set_restore_sigmask();
Ingo Molnar7e907f42008-03-06 10:33:08 +010064
David Howells283828f2006-01-18 17:44:00 -080065 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
Ingo Molnar7e907f42008-03-06 10:33:08 +010068asmlinkage int
Linus Torvalds1da177e2005-04-16 15:20:36 -070069sys_sigaction(int sig, const struct old_sigaction __user *act,
70 struct old_sigaction __user *oact)
71{
72 struct k_sigaction new_ka, old_ka;
73 int ret;
74
75 if (act) {
76 old_sigset_t mask;
Ingo Molnar7e907f42008-03-06 10:33:08 +010077
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
79 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
80 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
81 return -EFAULT;
Ingo Molnar7e907f42008-03-06 10:33:08 +010082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
84 __get_user(mask, &act->sa_mask);
85 siginitset(&new_ka.sa.sa_mask, mask);
86 }
87
88 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
89
90 if (!ret && oact) {
91 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
92 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
93 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
94 return -EFAULT;
Ingo Molnar7e907f42008-03-06 10:33:08 +010095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
97 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
98 }
99
100 return ret;
101}
102
Ingo Molnar7e907f42008-03-06 10:33:08 +0100103asmlinkage int sys_sigaltstack(unsigned long bx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
Ingo Molnar7e907f42008-03-06 10:33:08 +0100105 /*
106 * This is needed to make gcc realize it doesn't own the
107 * "struct pt_regs"
108 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100109 struct pt_regs *regs = (struct pt_regs *)&bx;
110 const stack_t __user *uss = (const stack_t __user *)bx;
111 stack_t __user *uoss = (stack_t __user *)regs->cx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100113 return do_sigaltstack(uss, uoss, regs->sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
Hiroshi Shimamotoa2e8d3d2008-10-02 22:09:20 -0700116#define COPY(x) { \
117 err |= __get_user(regs->x, &sc->x); \
118}
119
120#define COPY_SEG(seg) { \
121 unsigned short tmp; \
122 err |= __get_user(tmp, &sc->seg); \
123 regs->seg = tmp; \
124}
125
126#define COPY_SEG_STRICT(seg) { \
127 unsigned short tmp; \
128 err |= __get_user(tmp, &sc->seg); \
129 regs->seg = tmp | 3; \
130}
131
132#define GET_SEG(seg) { \
133 unsigned short tmp; \
134 err |= __get_user(tmp, &sc->seg); \
135 loadsegment(seg, tmp); \
136}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138/*
139 * Do a signal return; undo the signal stack.
140 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141static int
Harvey Harrison866bc132008-02-08 12:10:02 -0800142restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
143 unsigned long *pax)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
Hiroshi Shimamoto69e13ad2008-10-02 22:18:47 -0700145 void __user *buf;
146 unsigned int tmpflags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 unsigned int err = 0;
148
149 /* Always make any pending restarted system calls return -EINTR */
150 current_thread_info()->restart_block.fn = do_no_restart_syscall;
151
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700152#ifdef CONFIG_X86_32
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100153 GET_SEG(gs);
154 COPY_SEG(fs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 COPY_SEG(es);
156 COPY_SEG(ds);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700157#endif /* CONFIG_X86_32 */
158
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800159 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
160 COPY(dx); COPY(cx); COPY(ip);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700161
162#ifdef CONFIG_X86_64
163 COPY(r8);
164 COPY(r9);
165 COPY(r10);
166 COPY(r11);
167 COPY(r12);
168 COPY(r13);
169 COPY(r14);
170 COPY(r15);
171#endif /* CONFIG_X86_64 */
172
173#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 COPY_SEG_STRICT(cs);
175 COPY_SEG_STRICT(ss);
Hiroshi Shimamoto709110b2008-10-23 17:14:25 -0700176#else /* !CONFIG_X86_32 */
177 /* Kernel saves and restores only the CS segment register on signals,
178 * which is the bare minimum needed to allow mixed 32/64-bit code.
179 * App's signal handler can save/restore other segments if needed. */
180 COPY_SEG_STRICT(cs);
181#endif /* CONFIG_X86_32 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100182
Hiroshi Shimamoto69e13ad2008-10-02 22:18:47 -0700183 err |= __get_user(tmpflags, &sc->flags);
184 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
185 regs->orig_ax = -1; /* disable syscall checks */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100186
Hiroshi Shimamoto69e13ad2008-10-02 22:18:47 -0700187 err |= __get_user(buf, &sc->fpstate);
188 err |= restore_i387_xstate(buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Harvey Harrison866bc132008-02-08 12:10:02 -0800190 err |= __get_user(*pax, &sc->ax);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192}
193
Harvey Harrison866bc132008-02-08 12:10:02 -0800194asmlinkage unsigned long sys_sigreturn(unsigned long __unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Ingo Molnar7e907f42008-03-06 10:33:08 +0100196 struct sigframe __user *frame;
197 struct pt_regs *regs;
Harvey Harrison866bc132008-02-08 12:10:02 -0800198 unsigned long ax;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100199 sigset_t set;
200
201 regs = (struct pt_regs *) &__unused;
202 frame = (struct sigframe __user *)(regs->sp - 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
205 goto badframe;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100206 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 && __copy_from_user(&set.sig[1], &frame->extramask,
208 sizeof(frame->extramask))))
209 goto badframe;
210
211 sigdelsetmask(&set, ~_BLOCKABLE);
212 spin_lock_irq(&current->sighand->siglock);
213 current->blocked = set;
214 recalc_sigpending();
215 spin_unlock_irq(&current->sighand->siglock);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100216
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100217 if (restore_sigcontext(regs, &frame->sc, &ax))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 goto badframe;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100219 return ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221badframe:
Andi Kleen03252912008-01-30 13:33:18 +0100222 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamoto1181f8b2008-07-03 13:12:13 -0700223 printk("%s%s[%d] bad frame in sigreturn frame:"
Ingo Molnar97b44ae2008-03-06 10:43:17 +0100224 "%p ip:%lx sp:%lx oeax:%lx",
Alexey Dobriyan19c58702007-10-18 23:40:41 -0700225 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100226 current->comm, task_pid_nr(current), frame, regs->ip,
227 regs->sp, regs->orig_ax);
Andi Kleen03252912008-01-30 13:33:18 +0100228 print_vma_addr(" in ", regs->ip);
Ingo Molnar97b44ae2008-03-06 10:43:17 +0100229 printk(KERN_CONT "\n");
Andi Kleen03252912008-01-30 13:33:18 +0100230 }
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +0200231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 force_sig(SIGSEGV, current);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return 0;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100235}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700237static long do_rt_sigreturn(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
Harvey Harrison2d19c452008-02-08 12:10:00 -0800239 struct rt_sigframe __user *frame;
Harvey Harrison866bc132008-02-08 12:10:02 -0800240 unsigned long ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 sigset_t set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Harvey Harrison2d19c452008-02-08 12:10:00 -0800243 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
245 goto badframe;
246 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
247 goto badframe;
248
249 sigdelsetmask(&set, ~_BLOCKABLE);
250 spin_lock_irq(&current->sighand->siglock);
251 current->blocked = set;
252 recalc_sigpending();
253 spin_unlock_irq(&current->sighand->siglock);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100254
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100255 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 goto badframe;
257
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100258 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 goto badframe;
260
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100261 return ax;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263badframe:
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700264 signal_fault(regs, frame, "rt_sigreturn");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 return 0;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100266}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Hiroshi Shimamotoe6babb62008-09-12 17:03:31 -0700268asmlinkage int sys_rt_sigreturn(unsigned long __unused)
269{
270 struct pt_regs *regs = (struct pt_regs *)&__unused;
271
272 return do_rt_sigreturn(regs);
273}
274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275/*
276 * Set up a signal frame.
277 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278static int
Suresh Siddhaab513702008-07-29 10:29:22 -0700279setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 struct pt_regs *regs, unsigned long mask)
281{
282 int tmp, err = 0;
283
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100284 err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs);
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100285 savesegment(gs, tmp);
286 err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100288 err |= __put_user(regs->es, (unsigned int __user *)&sc->es);
289 err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds);
H. Peter Anvin742fa542008-01-30 13:30:56 +0100290 err |= __put_user(regs->di, &sc->di);
291 err |= __put_user(regs->si, &sc->si);
292 err |= __put_user(regs->bp, &sc->bp);
293 err |= __put_user(regs->sp, &sc->sp);
294 err |= __put_user(regs->bx, &sc->bx);
295 err |= __put_user(regs->dx, &sc->dx);
296 err |= __put_user(regs->cx, &sc->cx);
297 err |= __put_user(regs->ax, &sc->ax);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 err |= __put_user(current->thread.trap_no, &sc->trapno);
299 err |= __put_user(current->thread.error_code, &sc->err);
H. Peter Anvin742fa542008-01-30 13:30:56 +0100300 err |= __put_user(regs->ip, &sc->ip);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100301 err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs);
H. Peter Anvin742fa542008-01-30 13:30:56 +0100302 err |= __put_user(regs->flags, &sc->flags);
303 err |= __put_user(regs->sp, &sc->sp_at_signal);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100304 err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Hiroshi Shimamoto4b336692008-11-05 18:30:25 -0800306 err |= __put_user(fpstate, &sc->fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 /* non-iBCS2 extensions.. */
309 err |= __put_user(mask, &sc->oldmask);
310 err |= __put_user(current->thread.cr2, &sc->cr2);
311
312 return err;
313}
314
315/*
316 * Determine which stack to use..
317 */
318static inline void __user *
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700319get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
Suresh Siddhaab513702008-07-29 10:29:22 -0700320 void **fpstate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100322 unsigned long sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 /* Default to using normal stack */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100325 sp = regs->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Roland McGrath83bd0102008-01-30 13:30:06 +0100327 /*
328 * If we are on the alternate signal stack and would overflow it, don't.
329 * Return an always-bogus address instead so we will die with SIGSEGV.
330 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100331 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
Roland McGrath83bd0102008-01-30 13:30:06 +0100332 return (void __user *) -1L;
333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 /* This is the X/Open sanctioned signal stack switching. */
335 if (ka->sa.sa_flags & SA_ONSTACK) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100336 if (sas_ss_flags(sp) == 0)
337 sp = current->sas_ss_sp + current->sas_ss_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100338 } else {
339 /* This is the legacy signal stack switching. */
340 if ((regs->ss & 0xffff) != __USER_DS &&
341 !(ka->sa.sa_flags & SA_RESTORER) &&
342 ka->sa.sa_restorer)
343 sp = (unsigned long) ka->sa.sa_restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
345
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700346 if (used_math()) {
347 sp = sp - sig_xstate_size;
348 *fpstate = (struct _fpstate *) sp;
Hiroshi Shimamoto4b336692008-11-05 18:30:25 -0800349 if (save_i387_xstate(*fpstate) < 0)
350 return (void __user *)-1L;
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700351 }
352
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100353 sp -= frame_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100354 /*
355 * Align the stack pointer according to the i386 ABI,
356 * i.e. so that on function entry ((sp + 4) & 15) == 0.
357 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100358 sp = ((sp + 4) & -16ul) - 4;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100359
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100360 return (void __user *) sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361}
362
Ingo Molnar7e907f42008-03-06 10:33:08 +0100363static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700364__setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
365 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 struct sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100368 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700370 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700372 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700375 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700377 if (__put_user(sig, &frame->sig))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700378 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700380 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700381 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 if (_NSIG_WORDS > 1) {
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700384 if (__copy_to_user(&frame->extramask, &set->sig[1],
385 sizeof(frame->extramask)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700386 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 }
388
Roland McGrath1a3e4ca2008-04-09 01:29:27 -0700389 if (current->mm->context.vdso)
Roland McGrath6c3652e2008-01-30 13:30:42 +0100390 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100391 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100392 restorer = &frame->retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 if (ka->sa.sa_flags & SA_RESTORER)
394 restorer = ka->sa.sa_restorer;
395
396 /* Set up to return from userspace. */
397 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100400 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 *
402 * WE DO NOT USE IT ANY MORE! It's only left here for historical
403 * reasons and because gdb uses it as a signature to notice
404 * signal handler stack frames.
405 */
406 err |= __put_user(0xb858, (short __user *)(frame->retcode+0));
407 err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2));
408 err |= __put_user(0x80cd, (short __user *)(frame->retcode+6));
409
410 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700411 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100414 regs->sp = (unsigned long)frame;
415 regs->ip = (unsigned long)ka->sa.sa_handler;
416 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800417 regs->dx = 0;
418 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100420 regs->ds = __USER_DS;
421 regs->es = __USER_DS;
422 regs->ss = __USER_DS;
423 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
David Howells283828f2006-01-18 17:44:00 -0800425 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426}
427
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700428static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
429 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100432 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700434 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700436 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700439 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700441 err |= __put_user(sig, &frame->sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 err |= __put_user(&frame->info, &frame->pinfo);
443 err |= __put_user(&frame->uc, &frame->puc);
444 err |= copy_siginfo_to_user(&frame->info, info);
445 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700446 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 /* Create the ucontext. */
Suresh Siddhac37b5ef2008-07-29 10:29:25 -0700449 if (cpu_has_xsave)
450 err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags);
451 else
452 err |= __put_user(0, &frame->uc.uc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 err |= __put_user(0, &frame->uc.uc_link);
454 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100455 err |= __put_user(sas_ss_flags(regs->sp),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 &frame->uc.uc_stack.ss_flags);
457 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700458 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
Ingo Molnar7e907f42008-03-06 10:33:08 +0100459 regs, set->sig[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
461 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700462 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464 /* Set up to return from userspace. */
Roland McGrath6c3652e2008-01-30 13:30:42 +0100465 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 if (ka->sa.sa_flags & SA_RESTORER)
467 restorer = ka->sa.sa_restorer;
468 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100471 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 *
473 * WE DO NOT USE IT ANY MORE! It's only left here for historical
474 * reasons and because gdb uses it as a signature to notice
475 * signal handler stack frames.
476 */
477 err |= __put_user(0xb8, (char __user *)(frame->retcode+0));
478 err |= __put_user(__NR_rt_sigreturn, (int __user *)(frame->retcode+1));
479 err |= __put_user(0x80cd, (short __user *)(frame->retcode+5));
480
481 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700482 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100485 regs->sp = (unsigned long)frame;
486 regs->ip = (unsigned long)ka->sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700487 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100488 regs->dx = (unsigned long)&frame->info;
489 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100491 regs->ds = __USER_DS;
492 regs->es = __USER_DS;
493 regs->ss = __USER_DS;
494 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
David Howells283828f2006-01-18 17:44:00 -0800496 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497}
498
499/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100500 * OK, we're invoking a handler:
501 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700502static int signr_convert(int sig)
503{
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700504#ifdef CONFIG_X86_32
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700505 struct thread_info *info = current_thread_info();
506
507 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
508 return info->exec_domain->signal_invmap[sig];
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700509#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700510 return sig;
511}
512
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700513#ifdef CONFIG_X86_32
514
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700515#define is_ia32 1
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700516#define ia32_setup_frame __setup_frame
517#define ia32_setup_rt_frame __setup_rt_frame
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700518
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700519#else /* !CONFIG_X86_32 */
520
521#ifdef CONFIG_IA32_EMULATION
522#define is_ia32 test_thread_flag(TIF_IA32)
523#else /* !CONFIG_IA32_EMULATION */
524#define is_ia32 0
525#endif /* CONFIG_IA32_EMULATION */
526
527#endif /* CONFIG_X86_32 */
528
Roland McGrath7c1def12005-06-23 00:08:21 -0700529static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700530setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
531 sigset_t *set, struct pt_regs *regs)
532{
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700533 int usig = signr_convert(sig);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700534 int ret;
535
536 /* Set up the stack frame */
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700537 if (is_ia32) {
538 if (ka->sa.sa_flags & SA_SIGINFO)
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700539 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700540 else
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700541 ret = ia32_setup_frame(usig, ka, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700542 } else
543 ret = __setup_rt_frame(sig, ka, info, set, regs);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700544
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700545 if (ret) {
546 force_sigsegv(sig, current);
547 return -EFAULT;
548 }
549
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700550 return ret;
551}
552
553static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800555 sigset_t *oldset, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556{
Roland McGrath7c1def12005-06-23 00:08:21 -0700557 int ret;
558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700560 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700562 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800563 case -ERESTART_RESTARTBLOCK:
564 case -ERESTARTNOHAND:
565 regs->ax = -EINTR;
566 break;
567
568 case -ERESTARTSYS:
569 if (!(ka->sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100570 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800572 }
573 /* fallthrough */
574 case -ERESTARTNOINTR:
575 regs->ax = regs->orig_ax;
576 regs->ip -= 2;
577 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 }
579 }
580
581 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100582 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
583 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100585 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100586 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100587 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700589 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Ingo Molnar7e907f42008-03-06 10:33:08 +0100591 if (ret)
592 return ret;
Roland McGrath7c1def12005-06-23 00:08:21 -0700593
Hiroshi Shimamoto86d32372008-09-23 17:22:32 -0700594#ifdef CONFIG_X86_64
595 /*
596 * This has nothing to do with segment registers,
597 * despite the name. This magic affects uaccess.h
598 * macros' behavior. Reset it to the normal setting.
599 */
600 set_fs(USER_DS);
601#endif
602
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700603 /*
604 * Clear the direction flag as per the ABI for function entry.
605 */
606 regs->flags &= ~X86_EFLAGS_DF;
607
608 /*
609 * Clear TF when entering the signal handler, but
610 * notify any tracer that was single-stepping it.
611 * The tracer may want to single-step inside the
612 * handler too.
613 */
614 regs->flags &= ~X86_EFLAGS_TF;
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700615
Ingo Molnar7e907f42008-03-06 10:33:08 +0100616 spin_lock_irq(&current->sighand->siglock);
617 sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
618 if (!(ka->sa.sa_flags & SA_NODEFER))
619 sigaddset(&current->blocked, sig);
620 recalc_sigpending();
621 spin_unlock_irq(&current->sighand->siglock);
622
Roland McGrath36a03302008-03-14 17:46:38 -0700623 tracehook_signal_handler(sig, info, ka, regs,
624 test_thread_flag(TIF_SINGLESTEP));
625
Ingo Molnar7e907f42008-03-06 10:33:08 +0100626 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}
628
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700629#ifdef CONFIG_X86_32
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700630#define NR_restart_syscall __NR_restart_syscall
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700631#else /* !CONFIG_X86_32 */
632#define NR_restart_syscall \
633 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
634#endif /* CONFIG_X86_32 */
635
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636/*
637 * Note that 'init' is a special process: it doesn't get signals it doesn't
638 * want to handle. Thus you cannot kill init even with a SIGKILL even by
639 * mistake.
640 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100641static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642{
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800643 struct k_sigaction ka;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 siginfo_t info;
645 int signr;
David Howells283828f2006-01-18 17:44:00 -0800646 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
648 /*
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800649 * We want the common case to go fast, which is why we may in certain
650 * cases get here from kernel mode. Just return without doing anything
651 * if so.
652 * X86_32: vm86 regs switched out by assembly code before reaching
653 * here, so testing against kernel CS suffices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 */
Vincent Hanquez717b5942005-06-23 00:08:45 -0700655 if (!user_mode(regs))
David Howells283828f2006-01-18 17:44:00 -0800656 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700658 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
David Howells283828f2006-01-18 17:44:00 -0800659 oldset = &current->saved_sigmask;
660 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 oldset = &current->blocked;
662
663 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
664 if (signr > 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100665 /*
666 * Re-enable any watchpoints before delivering the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 * signal to user space. The processor register will
668 * have been cleared if the watchpoint triggered
669 * inside the kernel.
670 */
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800671 if (current->thread.debugreg7)
Roland McGrath0f534092008-01-30 13:30:59 +0100672 set_debugreg(current->thread.debugreg7, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Ingo Molnar7e907f42008-03-06 10:33:08 +0100674 /* Whee! Actually deliver the signal. */
David Howells283828f2006-01-18 17:44:00 -0800675 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100676 /*
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700677 * A signal was successfully delivered; the saved
David Howells283828f2006-01-18 17:44:00 -0800678 * sigmask will have been stored in the signal frame,
679 * and will be restored by sigreturn, so we can simply
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700680 * clear the TS_RESTORE_SIGMASK flag.
Ingo Molnar7e907f42008-03-06 10:33:08 +0100681 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700682 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800683 }
David Howells283828f2006-01-18 17:44:00 -0800684 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 }
686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700688 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700690 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800691 case -ERESTARTNOHAND:
692 case -ERESTARTSYS:
693 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100694 regs->ax = regs->orig_ax;
695 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800696 break;
697
698 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700699 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100700 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800701 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 }
703 }
David Howells283828f2006-01-18 17:44:00 -0800704
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800705 /*
706 * If there's no signal to deliver, we just put the saved sigmask
707 * back.
708 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700709 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
710 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800711 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713}
714
715/*
716 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800717 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100719void
720do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721{
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700722#if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
723 /* notify userspace of pending MCEs */
724 if (thread_info_flags & _TIF_MCE_NOTIFY)
725 mce_notify_user();
726#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700729 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800730 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100731
Roland McGrath59e52132008-04-19 19:10:57 -0700732 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
733 clear_thread_flag(TIF_NOTIFY_RESUME);
734 tracehook_notify_resume(regs);
735 }
736
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700737#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 clear_thread_flag(TIF_IRET);
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700739#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700741
742void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
743{
744 struct task_struct *me = current;
745
746 if (show_unhandled_signals && printk_ratelimit()) {
747 printk(KERN_INFO
748 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
749 me->comm, me->pid, where, frame,
750 regs->ip, regs->sp, regs->orig_ax);
751 print_vma_addr(" in ", regs->ip);
752 printk(KERN_CONT "\n");
753 }
754
755 force_sig(SIGSEGV, me);
756}