blob: 848c2d64a28903c7a97a2b33b83e1bb873a41f20 [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
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -08003 * Copyright (C) 2000, 2001, 2002 Andi Kleen SuSE Labs
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
6 * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -08007 * 2000-2002 x86-64 support by Andi Kleen
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
Ingo Molnar7e907f42008-03-06 10:33:08 +010010#include <linux/sched.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010011#include <linux/mm.h>
Hiroshi Shimamoto5c9b3a02008-11-21 17:36:41 -080012#include <linux/smp.h>
13#include <linux/kernel.h>
14#include <linux/signal.h>
15#include <linux/errno.h>
16#include <linux/wait.h>
17#include <linux/ptrace.h>
18#include <linux/tracehook.h>
19#include <linux/unistd.h>
20#include <linux/stddef.h>
21#include <linux/personality.h>
22#include <linux/uaccess.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/processor.h>
25#include <asm/ucontext.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/i387.h>
Roland McGrath6c3652e2008-01-30 13:30:42 +010027#include <asm/vdso.h>
Hiroshi Shimamoto5c9b3a02008-11-21 17:36:41 -080028
29#ifdef CONFIG_X86_64
30#include <asm/proto.h>
31#include <asm/ia32_unistd.h>
32#include <asm/mce.h>
33#endif /* CONFIG_X86_64 */
34
Hiroshi Shimamotobb579252008-09-05 16:26:55 -070035#include <asm/syscall.h>
Jaswinder Singhbbc1f692008-07-21 21:34:13 +053036#include <asm/syscalls.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010037
Harvey Harrison123a6342008-02-08 12:10:00 -080038#include "sigframe.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
41
Harvey Harrison1a176802008-02-08 12:09:59 -080042#define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \
43 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
44 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
45 X86_EFLAGS_CF)
46
47#ifdef CONFIG_X86_32
48# define FIX_EFLAGS (__FIX_EFLAGS | X86_EFLAGS_RF)
49#else
50# define FIX_EFLAGS __FIX_EFLAGS
51#endif
52
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080053#define COPY(x) { \
54 err |= __get_user(regs->x, &sc->x); \
55}
56
57#define COPY_SEG(seg) { \
58 unsigned short tmp; \
59 err |= __get_user(tmp, &sc->seg); \
60 regs->seg = tmp; \
61}
62
63#define COPY_SEG_CPL3(seg) { \
64 unsigned short tmp; \
65 err |= __get_user(tmp, &sc->seg); \
66 regs->seg = tmp | 3; \
67}
68
69#define GET_SEG(seg) { \
70 unsigned short tmp; \
71 err |= __get_user(tmp, &sc->seg); \
72 loadsegment(seg, tmp); \
73}
74
75static int
76restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
77 unsigned long *pax)
78{
79 void __user *buf;
80 unsigned int tmpflags;
81 unsigned int err = 0;
82
83 /* Always make any pending restarted system calls return -EINTR */
84 current_thread_info()->restart_block.fn = do_no_restart_syscall;
85
86#ifdef CONFIG_X86_32
87 GET_SEG(gs);
88 COPY_SEG(fs);
89 COPY_SEG(es);
90 COPY_SEG(ds);
91#endif /* CONFIG_X86_32 */
92
93 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
94 COPY(dx); COPY(cx); COPY(ip);
95
96#ifdef CONFIG_X86_64
97 COPY(r8);
98 COPY(r9);
99 COPY(r10);
100 COPY(r11);
101 COPY(r12);
102 COPY(r13);
103 COPY(r14);
104 COPY(r15);
105#endif /* CONFIG_X86_64 */
106
107#ifdef CONFIG_X86_32
108 COPY_SEG_CPL3(cs);
109 COPY_SEG_CPL3(ss);
110#else /* !CONFIG_X86_32 */
111 /* Kernel saves and restores only the CS segment register on signals,
112 * which is the bare minimum needed to allow mixed 32/64-bit code.
113 * App's signal handler can save/restore other segments if needed. */
114 COPY_SEG_CPL3(cs);
115#endif /* CONFIG_X86_32 */
116
117 err |= __get_user(tmpflags, &sc->flags);
118 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
119 regs->orig_ax = -1; /* disable syscall checks */
120
121 err |= __get_user(buf, &sc->fpstate);
122 err |= restore_i387_xstate(buf);
123
124 err |= __get_user(*pax, &sc->ax);
125 return err;
126}
127
128static int
129setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
130 struct pt_regs *regs, unsigned long mask)
131{
132 int err = 0;
133
134#ifdef CONFIG_X86_32
135 {
136 unsigned int tmp;
137
138 savesegment(gs, tmp);
139 err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
140 }
141 err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs);
142 err |= __put_user(regs->es, (unsigned int __user *)&sc->es);
143 err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds);
144#endif /* CONFIG_X86_32 */
145
146 err |= __put_user(regs->di, &sc->di);
147 err |= __put_user(regs->si, &sc->si);
148 err |= __put_user(regs->bp, &sc->bp);
149 err |= __put_user(regs->sp, &sc->sp);
150 err |= __put_user(regs->bx, &sc->bx);
151 err |= __put_user(regs->dx, &sc->dx);
152 err |= __put_user(regs->cx, &sc->cx);
153 err |= __put_user(regs->ax, &sc->ax);
154#ifdef CONFIG_X86_64
155 err |= __put_user(regs->r8, &sc->r8);
156 err |= __put_user(regs->r9, &sc->r9);
157 err |= __put_user(regs->r10, &sc->r10);
158 err |= __put_user(regs->r11, &sc->r11);
159 err |= __put_user(regs->r12, &sc->r12);
160 err |= __put_user(regs->r13, &sc->r13);
161 err |= __put_user(regs->r14, &sc->r14);
162 err |= __put_user(regs->r15, &sc->r15);
163#endif /* CONFIG_X86_64 */
164
165 err |= __put_user(current->thread.trap_no, &sc->trapno);
166 err |= __put_user(current->thread.error_code, &sc->err);
167 err |= __put_user(regs->ip, &sc->ip);
168#ifdef CONFIG_X86_32
169 err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs);
170 err |= __put_user(regs->flags, &sc->flags);
171 err |= __put_user(regs->sp, &sc->sp_at_signal);
172 err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss);
173#else /* !CONFIG_X86_32 */
174 err |= __put_user(regs->flags, &sc->flags);
175 err |= __put_user(regs->cs, &sc->cs);
176 err |= __put_user(0, &sc->gs);
177 err |= __put_user(0, &sc->fs);
178#endif /* CONFIG_X86_32 */
179
180 err |= __put_user(fpstate, &sc->fpstate);
181
182 /* non-iBCS2 extensions.. */
183 err |= __put_user(mask, &sc->oldmask);
184 err |= __put_user(current->thread.cr2, &sc->cr2);
185
186 return err;
187}
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 * Set up a signal frame.
191 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800192#ifdef CONFIG_X86_32
193static const struct {
194 u16 poplmovl;
195 u32 val;
196 u16 int80;
197} __attribute__((packed)) retcode = {
198 0xb858, /* popl %eax; movl $..., %eax */
199 __NR_sigreturn,
200 0x80cd, /* int $0x80 */
201};
202
203static const struct {
204 u8 movl;
205 u32 val;
206 u16 int80;
207 u8 pad;
208} __attribute__((packed)) rt_retcode = {
209 0xb8, /* movl $..., %eax */
210 __NR_rt_sigreturn,
211 0x80cd, /* int $0x80 */
212 0
213};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215/*
216 * Determine which stack to use..
217 */
218static inline void __user *
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700219get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
Suresh Siddhaab513702008-07-29 10:29:22 -0700220 void **fpstate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100222 unsigned long sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224 /* Default to using normal stack */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100225 sp = regs->sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Roland McGrath83bd0102008-01-30 13:30:06 +0100227 /*
228 * If we are on the alternate signal stack and would overflow it, don't.
229 * Return an always-bogus address instead so we will die with SIGSEGV.
230 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100231 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
Roland McGrath83bd0102008-01-30 13:30:06 +0100232 return (void __user *) -1L;
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 /* This is the X/Open sanctioned signal stack switching. */
235 if (ka->sa.sa_flags & SA_ONSTACK) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100236 if (sas_ss_flags(sp) == 0)
237 sp = current->sas_ss_sp + current->sas_ss_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100238 } else {
239 /* This is the legacy signal stack switching. */
240 if ((regs->ss & 0xffff) != __USER_DS &&
241 !(ka->sa.sa_flags & SA_RESTORER) &&
242 ka->sa.sa_restorer)
243 sp = (unsigned long) ka->sa.sa_restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 }
245
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700246 if (used_math()) {
247 sp = sp - sig_xstate_size;
248 *fpstate = (struct _fpstate *) sp;
Hiroshi Shimamoto4b336692008-11-05 18:30:25 -0800249 if (save_i387_xstate(*fpstate) < 0)
250 return (void __user *)-1L;
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700251 }
252
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100253 sp -= frame_size;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100254 /*
255 * Align the stack pointer according to the i386 ABI,
256 * i.e. so that on function entry ((sp + 4) & 15) == 0.
257 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100258 sp = ((sp + 4) & -16ul) - 4;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100259
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100260 return (void __user *) sp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261}
262
Ingo Molnar7e907f42008-03-06 10:33:08 +0100263static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700264__setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
265 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 struct sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100268 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700270 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700272 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700275 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700277 if (__put_user(sig, &frame->sig))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700278 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700280 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700281 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283 if (_NSIG_WORDS > 1) {
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700284 if (__copy_to_user(&frame->extramask, &set->sig[1],
285 sizeof(frame->extramask)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700286 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 }
288
Roland McGrath1a3e4ca2008-04-09 01:29:27 -0700289 if (current->mm->context.vdso)
Roland McGrath6c3652e2008-01-30 13:30:42 +0100290 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100291 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100292 restorer = &frame->retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 if (ka->sa.sa_flags & SA_RESTORER)
294 restorer = ka->sa.sa_restorer;
295
296 /* Set up to return from userspace. */
297 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100300 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 *
302 * WE DO NOT USE IT ANY MORE! It's only left here for historical
303 * reasons and because gdb uses it as a signature to notice
304 * signal handler stack frames.
305 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800306 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700309 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100312 regs->sp = (unsigned long)frame;
313 regs->ip = (unsigned long)ka->sa.sa_handler;
314 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800315 regs->dx = 0;
316 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100318 regs->ds = __USER_DS;
319 regs->es = __USER_DS;
320 regs->ss = __USER_DS;
321 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
David Howells283828f2006-01-18 17:44:00 -0800323 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324}
325
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700326static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
327 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100330 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700332 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700334 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700337 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700339 err |= __put_user(sig, &frame->sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 err |= __put_user(&frame->info, &frame->pinfo);
341 err |= __put_user(&frame->uc, &frame->puc);
342 err |= copy_siginfo_to_user(&frame->info, info);
343 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700344 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 /* Create the ucontext. */
Suresh Siddhac37b5ef2008-07-29 10:29:25 -0700347 if (cpu_has_xsave)
348 err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags);
349 else
350 err |= __put_user(0, &frame->uc.uc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 err |= __put_user(0, &frame->uc.uc_link);
352 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100353 err |= __put_user(sas_ss_flags(regs->sp),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 &frame->uc.uc_stack.ss_flags);
355 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700356 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
Ingo Molnar7e907f42008-03-06 10:33:08 +0100357 regs, set->sig[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
359 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700360 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 /* Set up to return from userspace. */
Roland McGrath6c3652e2008-01-30 13:30:42 +0100363 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 if (ka->sa.sa_flags & SA_RESTORER)
365 restorer = ka->sa.sa_restorer;
366 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100369 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 *
371 * WE DO NOT USE IT ANY MORE! It's only left here for historical
372 * reasons and because gdb uses it as a signature to notice
373 * signal handler stack frames.
374 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800375 err |= __put_user(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700378 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
380 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100381 regs->sp = (unsigned long)frame;
382 regs->ip = (unsigned long)ka->sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700383 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100384 regs->dx = (unsigned long)&frame->info;
385 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100387 regs->ds = __USER_DS;
388 regs->es = __USER_DS;
389 regs->ss = __USER_DS;
390 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
David Howells283828f2006-01-18 17:44:00 -0800392 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393}
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800394#else /* !CONFIG_X86_32 */
395/*
396 * Determine which stack to use..
397 */
398static void __user *
399get_stack(struct k_sigaction *ka, unsigned long sp, unsigned long size)
400{
401 /* Default to using normal stack - redzone*/
402 sp -= 128;
403
404 /* This is the X/Open sanctioned signal stack switching. */
405 if (ka->sa.sa_flags & SA_ONSTACK) {
406 if (sas_ss_flags(sp) == 0)
407 sp = current->sas_ss_sp + current->sas_ss_size;
408 }
409
410 return (void __user *)round_down(sp - size, 64);
411}
412
413static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
414 sigset_t *set, struct pt_regs *regs)
415{
416 struct rt_sigframe __user *frame;
417 void __user *fp = NULL;
418 int err = 0;
419 struct task_struct *me = current;
420
421 if (used_math()) {
422 fp = get_stack(ka, regs->sp, sig_xstate_size);
423 frame = (void __user *)round_down(
424 (unsigned long)fp - sizeof(struct rt_sigframe), 16) - 8;
425
426 if (save_i387_xstate(fp) < 0)
427 return -EFAULT;
428 } else
429 frame = get_stack(ka, regs->sp, sizeof(struct rt_sigframe)) - 8;
430
431 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
432 return -EFAULT;
433
434 if (ka->sa.sa_flags & SA_SIGINFO) {
435 if (copy_siginfo_to_user(&frame->info, info))
436 return -EFAULT;
437 }
438
439 /* Create the ucontext. */
440 if (cpu_has_xsave)
441 err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags);
442 else
443 err |= __put_user(0, &frame->uc.uc_flags);
444 err |= __put_user(0, &frame->uc.uc_link);
445 err |= __put_user(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
446 err |= __put_user(sas_ss_flags(regs->sp),
447 &frame->uc.uc_stack.ss_flags);
448 err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
449 err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
450 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
451
452 /* Set up to return from userspace. If provided, use a stub
453 already in userspace. */
454 /* x86-64 should always use SA_RESTORER. */
455 if (ka->sa.sa_flags & SA_RESTORER) {
456 err |= __put_user(ka->sa.sa_restorer, &frame->pretcode);
457 } else {
458 /* could use a vstub here */
459 return -EFAULT;
460 }
461
462 if (err)
463 return -EFAULT;
464
465 /* Set up registers for signal handler */
466 regs->di = sig;
467 /* In case the signal handler was declared without prototypes */
468 regs->ax = 0;
469
470 /* This also works for non SA_SIGINFO handlers because they expect the
471 next argument after the signal number on the stack. */
472 regs->si = (unsigned long)&frame->info;
473 regs->dx = (unsigned long)&frame->uc;
474 regs->ip = (unsigned long) ka->sa.sa_handler;
475
476 regs->sp = (unsigned long)frame;
477
478 /* Set up the CS register to run signal handlers in 64-bit mode,
479 even if the handler happens to be interrupting 32-bit code. */
480 regs->cs = __USER_CS;
481
482 return 0;
483}
484#endif /* CONFIG_X86_32 */
485
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800486#ifdef CONFIG_X86_32
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800487/*
488 * Atomically swap in the new signal mask, and wait for a signal.
489 */
490asmlinkage int
491sys_sigsuspend(int history0, int history1, old_sigset_t mask)
492{
493 mask &= _BLOCKABLE;
494 spin_lock_irq(&current->sighand->siglock);
495 current->saved_sigmask = current->blocked;
496 siginitset(&current->blocked, mask);
497 recalc_sigpending();
498 spin_unlock_irq(&current->sighand->siglock);
499
500 current->state = TASK_INTERRUPTIBLE;
501 schedule();
502 set_restore_sigmask();
503
504 return -ERESTARTNOHAND;
505}
506
507asmlinkage int
508sys_sigaction(int sig, const struct old_sigaction __user *act,
509 struct old_sigaction __user *oact)
510{
511 struct k_sigaction new_ka, old_ka;
512 int ret;
513
514 if (act) {
515 old_sigset_t mask;
516
517 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
518 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
519 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
520 return -EFAULT;
521
522 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
523 __get_user(mask, &act->sa_mask);
524 siginitset(&new_ka.sa.sa_mask, mask);
525 }
526
527 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
528
529 if (!ret && oact) {
530 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
531 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
532 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
533 return -EFAULT;
534
535 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
536 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
537 }
538
539 return ret;
540}
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800541#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800542
543#ifdef CONFIG_X86_32
544asmlinkage int sys_sigaltstack(unsigned long bx)
545{
546 /*
547 * This is needed to make gcc realize it doesn't own the
548 * "struct pt_regs"
549 */
550 struct pt_regs *regs = (struct pt_regs *)&bx;
551 const stack_t __user *uss = (const stack_t __user *)bx;
552 stack_t __user *uoss = (stack_t __user *)regs->cx;
553
554 return do_sigaltstack(uss, uoss, regs->sp);
555}
556#else /* !CONFIG_X86_32 */
557asmlinkage long
558sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
559 struct pt_regs *regs)
560{
561 return do_sigaltstack(uss, uoss, regs->sp);
562}
563#endif /* CONFIG_X86_32 */
564
565/*
566 * Do a signal return; undo the signal stack.
567 */
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800568#ifdef CONFIG_X86_32
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800569asmlinkage unsigned long sys_sigreturn(unsigned long __unused)
570{
571 struct sigframe __user *frame;
572 struct pt_regs *regs;
573 unsigned long ax;
574 sigset_t set;
575
576 regs = (struct pt_regs *) &__unused;
577 frame = (struct sigframe __user *)(regs->sp - 8);
578
579 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
580 goto badframe;
581 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
582 && __copy_from_user(&set.sig[1], &frame->extramask,
583 sizeof(frame->extramask))))
584 goto badframe;
585
586 sigdelsetmask(&set, ~_BLOCKABLE);
587 spin_lock_irq(&current->sighand->siglock);
588 current->blocked = set;
589 recalc_sigpending();
590 spin_unlock_irq(&current->sighand->siglock);
591
592 if (restore_sigcontext(regs, &frame->sc, &ax))
593 goto badframe;
594 return ax;
595
596badframe:
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800597 signal_fault(regs, frame, "sigreturn");
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800598
599 return 0;
600}
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800601#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800602
603static long do_rt_sigreturn(struct pt_regs *regs)
604{
605 struct rt_sigframe __user *frame;
606 unsigned long ax;
607 sigset_t set;
608
609 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
610 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
611 goto badframe;
612 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
613 goto badframe;
614
615 sigdelsetmask(&set, ~_BLOCKABLE);
616 spin_lock_irq(&current->sighand->siglock);
617 current->blocked = set;
618 recalc_sigpending();
619 spin_unlock_irq(&current->sighand->siglock);
620
621 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
622 goto badframe;
623
624 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
625 goto badframe;
626
627 return ax;
628
629badframe:
630 signal_fault(regs, frame, "rt_sigreturn");
631 return 0;
632}
633
634#ifdef CONFIG_X86_32
Hiroshi Shimamoto42174582008-12-05 17:17:09 -0800635asmlinkage int sys_rt_sigreturn(struct pt_regs regs)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800636{
Hiroshi Shimamoto42174582008-12-05 17:17:09 -0800637 return do_rt_sigreturn(&regs);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800638}
639#else /* !CONFIG_X86_32 */
640asmlinkage long sys_rt_sigreturn(struct pt_regs *regs)
641{
642 return do_rt_sigreturn(regs);
643}
644#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100647 * OK, we're invoking a handler:
648 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700649static int signr_convert(int sig)
650{
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700651#ifdef CONFIG_X86_32
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700652 struct thread_info *info = current_thread_info();
653
654 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
655 return info->exec_domain->signal_invmap[sig];
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700656#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700657 return sig;
658}
659
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700660#ifdef CONFIG_X86_32
661
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700662#define is_ia32 1
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700663#define ia32_setup_frame __setup_frame
664#define ia32_setup_rt_frame __setup_rt_frame
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700665
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700666#else /* !CONFIG_X86_32 */
667
668#ifdef CONFIG_IA32_EMULATION
669#define is_ia32 test_thread_flag(TIF_IA32)
670#else /* !CONFIG_IA32_EMULATION */
671#define is_ia32 0
672#endif /* CONFIG_IA32_EMULATION */
673
Hiroshi Shimamotof5223762008-12-17 18:47:17 -0800674int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
675 sigset_t *set, struct pt_regs *regs);
676int ia32_setup_frame(int sig, struct k_sigaction *ka,
677 sigset_t *set, struct pt_regs *regs);
678
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700679#endif /* CONFIG_X86_32 */
680
Roland McGrath7c1def12005-06-23 00:08:21 -0700681static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700682setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
683 sigset_t *set, struct pt_regs *regs)
684{
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700685 int usig = signr_convert(sig);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700686 int ret;
687
688 /* Set up the stack frame */
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700689 if (is_ia32) {
690 if (ka->sa.sa_flags & SA_SIGINFO)
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700691 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700692 else
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700693 ret = ia32_setup_frame(usig, ka, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700694 } else
695 ret = __setup_rt_frame(sig, ka, info, set, regs);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700696
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700697 if (ret) {
698 force_sigsegv(sig, current);
699 return -EFAULT;
700 }
701
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700702 return ret;
703}
704
705static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800707 sigset_t *oldset, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
Roland McGrath7c1def12005-06-23 00:08:21 -0700709 int ret;
710
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700712 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700714 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800715 case -ERESTART_RESTARTBLOCK:
716 case -ERESTARTNOHAND:
717 regs->ax = -EINTR;
718 break;
719
720 case -ERESTARTSYS:
721 if (!(ka->sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100722 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800724 }
725 /* fallthrough */
726 case -ERESTARTNOINTR:
727 regs->ax = regs->orig_ax;
728 regs->ip -= 2;
729 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 }
731 }
732
733 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100734 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
735 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100737 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100738 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100739 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700741 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Ingo Molnar7e907f42008-03-06 10:33:08 +0100743 if (ret)
744 return ret;
Roland McGrath7c1def12005-06-23 00:08:21 -0700745
Hiroshi Shimamoto86d32372008-09-23 17:22:32 -0700746#ifdef CONFIG_X86_64
747 /*
748 * This has nothing to do with segment registers,
749 * despite the name. This magic affects uaccess.h
750 * macros' behavior. Reset it to the normal setting.
751 */
752 set_fs(USER_DS);
753#endif
754
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700755 /*
756 * Clear the direction flag as per the ABI for function entry.
757 */
758 regs->flags &= ~X86_EFLAGS_DF;
759
760 /*
761 * Clear TF when entering the signal handler, but
762 * notify any tracer that was single-stepping it.
763 * The tracer may want to single-step inside the
764 * handler too.
765 */
766 regs->flags &= ~X86_EFLAGS_TF;
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700767
Ingo Molnar7e907f42008-03-06 10:33:08 +0100768 spin_lock_irq(&current->sighand->siglock);
769 sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
770 if (!(ka->sa.sa_flags & SA_NODEFER))
771 sigaddset(&current->blocked, sig);
772 recalc_sigpending();
773 spin_unlock_irq(&current->sighand->siglock);
774
Roland McGrath36a03302008-03-14 17:46:38 -0700775 tracehook_signal_handler(sig, info, ka, regs,
776 test_thread_flag(TIF_SINGLESTEP));
777
Ingo Molnar7e907f42008-03-06 10:33:08 +0100778 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779}
780
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700781#ifdef CONFIG_X86_32
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700782#define NR_restart_syscall __NR_restart_syscall
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700783#else /* !CONFIG_X86_32 */
784#define NR_restart_syscall \
785 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
786#endif /* CONFIG_X86_32 */
787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788/*
789 * Note that 'init' is a special process: it doesn't get signals it doesn't
790 * want to handle. Thus you cannot kill init even with a SIGKILL even by
791 * mistake.
792 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100793static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794{
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800795 struct k_sigaction ka;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 siginfo_t info;
797 int signr;
David Howells283828f2006-01-18 17:44:00 -0800798 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800 /*
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800801 * We want the common case to go fast, which is why we may in certain
802 * cases get here from kernel mode. Just return without doing anything
803 * if so.
804 * X86_32: vm86 regs switched out by assembly code before reaching
805 * here, so testing against kernel CS suffices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 */
Vincent Hanquez717b5942005-06-23 00:08:45 -0700807 if (!user_mode(regs))
David Howells283828f2006-01-18 17:44:00 -0800808 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700810 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
David Howells283828f2006-01-18 17:44:00 -0800811 oldset = &current->saved_sigmask;
812 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 oldset = &current->blocked;
814
815 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
816 if (signr > 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100817 /*
818 * Re-enable any watchpoints before delivering the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 * signal to user space. The processor register will
820 * have been cleared if the watchpoint triggered
821 * inside the kernel.
822 */
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800823 if (current->thread.debugreg7)
Roland McGrath0f534092008-01-30 13:30:59 +0100824 set_debugreg(current->thread.debugreg7, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
Ingo Molnar7e907f42008-03-06 10:33:08 +0100826 /* Whee! Actually deliver the signal. */
David Howells283828f2006-01-18 17:44:00 -0800827 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100828 /*
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700829 * A signal was successfully delivered; the saved
David Howells283828f2006-01-18 17:44:00 -0800830 * sigmask will have been stored in the signal frame,
831 * and will be restored by sigreturn, so we can simply
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700832 * clear the TS_RESTORE_SIGMASK flag.
Ingo Molnar7e907f42008-03-06 10:33:08 +0100833 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700834 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800835 }
David Howells283828f2006-01-18 17:44:00 -0800836 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 }
838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700840 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700842 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800843 case -ERESTARTNOHAND:
844 case -ERESTARTSYS:
845 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100846 regs->ax = regs->orig_ax;
847 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800848 break;
849
850 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700851 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100852 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800853 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 }
855 }
David Howells283828f2006-01-18 17:44:00 -0800856
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800857 /*
858 * If there's no signal to deliver, we just put the saved sigmask
859 * back.
860 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700861 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
862 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800863 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
864 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865}
866
867/*
868 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800869 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100871void
872do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873{
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700874#if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
875 /* notify userspace of pending MCEs */
876 if (thread_info_flags & _TIF_MCE_NOTIFY)
877 mce_notify_user();
878#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
879
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700881 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800882 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100883
Roland McGrath59e52132008-04-19 19:10:57 -0700884 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
885 clear_thread_flag(TIF_NOTIFY_RESUME);
886 tracehook_notify_resume(regs);
887 }
888
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700889#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 clear_thread_flag(TIF_IRET);
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700891#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700893
894void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
895{
896 struct task_struct *me = current;
897
898 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800899 printk("%s"
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700900 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800901 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700902 me->comm, me->pid, where, frame,
903 regs->ip, regs->sp, regs->orig_ax);
904 print_vma_addr(" in ", regs->ip);
905 printk(KERN_CONT "\n");
906 }
907
908 force_sig(SIGSEGV, me);
909}