blob: 0f89a4f20db27ed78d47cb81f27e0f25dab208f4 [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 */
Ingo Molnar7e907f42008-03-06 10:33:08 +01009#include <linux/sched.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010010#include <linux/mm.h>
Hiroshi Shimamoto5c9b3a02008-11-21 17:36:41 -080011#include <linux/smp.h>
12#include <linux/kernel.h>
13#include <linux/signal.h>
14#include <linux/errno.h>
15#include <linux/wait.h>
16#include <linux/ptrace.h>
17#include <linux/tracehook.h>
18#include <linux/unistd.h>
19#include <linux/stddef.h>
20#include <linux/personality.h>
21#include <linux/uaccess.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/processor.h>
24#include <asm/ucontext.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/i387.h>
Roland McGrath6c3652e2008-01-30 13:30:42 +010026#include <asm/vdso.h>
Andi Kleen4efc0672009-04-28 19:07:31 +020027#include <asm/mce.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>
Hiroshi Shimamoto5c9b3a02008-11-21 17:36:41 -080032#endif /* CONFIG_X86_64 */
33
Hiroshi Shimamotobb579252008-09-05 16:26:55 -070034#include <asm/syscall.h>
Jaswinder Singhbbc1f692008-07-21 21:34:13 +053035#include <asm/syscalls.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010036
Hiroshi Shimamoto41af86f2008-12-17 18:50:32 -080037#include <asm/sigframe.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
40
Harvey Harrison1a176802008-02-08 12:09:59 -080041#define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \
42 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
43 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
44 X86_EFLAGS_CF)
45
46#ifdef CONFIG_X86_32
47# define FIX_EFLAGS (__FIX_EFLAGS | X86_EFLAGS_RF)
48#else
49# define FIX_EFLAGS __FIX_EFLAGS
50#endif
51
Tejun Heod9a89a22009-02-09 22:17:40 +090052#define COPY(x) do { \
53 get_user_ex(regs->x, &sc->x); \
54} while (0)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080055
Tejun Heod9a89a22009-02-09 22:17:40 +090056#define GET_SEG(seg) ({ \
57 unsigned short tmp; \
58 get_user_ex(tmp, &sc->seg); \
59 tmp; \
60})
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080061
Tejun Heod9a89a22009-02-09 22:17:40 +090062#define COPY_SEG(seg) do { \
63 regs->seg = GET_SEG(seg); \
64} while (0)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080065
Tejun Heod9a89a22009-02-09 22:17:40 +090066#define COPY_SEG_CPL3(seg) do { \
67 regs->seg = GET_SEG(seg) | 3; \
68} while (0)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080069
70static int
71restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
72 unsigned long *pax)
73{
74 void __user *buf;
75 unsigned int tmpflags;
76 unsigned int err = 0;
77
78 /* Always make any pending restarted system calls return -EINTR */
79 current_thread_info()->restart_block.fn = do_no_restart_syscall;
80
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080081 get_user_try {
82
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080083#ifdef CONFIG_X86_32
Tejun Heod9a89a22009-02-09 22:17:40 +090084 set_user_gs(regs, GET_SEG(gs));
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080085 COPY_SEG(fs);
86 COPY_SEG(es);
87 COPY_SEG(ds);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080088#endif /* CONFIG_X86_32 */
89
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080090 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
91 COPY(dx); COPY(cx); COPY(ip);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080092
93#ifdef CONFIG_X86_64
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080094 COPY(r8);
95 COPY(r9);
96 COPY(r10);
97 COPY(r11);
98 COPY(r12);
99 COPY(r13);
100 COPY(r14);
101 COPY(r15);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800102#endif /* CONFIG_X86_64 */
103
104#ifdef CONFIG_X86_32
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800105 COPY_SEG_CPL3(cs);
106 COPY_SEG_CPL3(ss);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800107#else /* !CONFIG_X86_32 */
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800108 /* Kernel saves and restores only the CS segment register on signals,
109 * which is the bare minimum needed to allow mixed 32/64-bit code.
110 * App's signal handler can save/restore other segments if needed. */
111 COPY_SEG_CPL3(cs);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800112#endif /* CONFIG_X86_32 */
113
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800114 get_user_ex(tmpflags, &sc->flags);
115 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
116 regs->orig_ax = -1; /* disable syscall checks */
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800117
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800118 get_user_ex(buf, &sc->fpstate);
119 err |= restore_i387_xstate(buf);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800120
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800121 get_user_ex(*pax, &sc->ax);
122 } get_user_catch(err);
123
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800124 return err;
125}
126
127static int
128setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
129 struct pt_regs *regs, unsigned long mask)
130{
131 int err = 0;
132
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800133 put_user_try {
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800134
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800135#ifdef CONFIG_X86_32
Tejun Heod9a89a22009-02-09 22:17:40 +0900136 put_user_ex(get_user_gs(regs), (unsigned int __user *)&sc->gs);
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800137 put_user_ex(regs->fs, (unsigned int __user *)&sc->fs);
138 put_user_ex(regs->es, (unsigned int __user *)&sc->es);
139 put_user_ex(regs->ds, (unsigned int __user *)&sc->ds);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800140#endif /* CONFIG_X86_32 */
141
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800142 put_user_ex(regs->di, &sc->di);
143 put_user_ex(regs->si, &sc->si);
144 put_user_ex(regs->bp, &sc->bp);
145 put_user_ex(regs->sp, &sc->sp);
146 put_user_ex(regs->bx, &sc->bx);
147 put_user_ex(regs->dx, &sc->dx);
148 put_user_ex(regs->cx, &sc->cx);
149 put_user_ex(regs->ax, &sc->ax);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800150#ifdef CONFIG_X86_64
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800151 put_user_ex(regs->r8, &sc->r8);
152 put_user_ex(regs->r9, &sc->r9);
153 put_user_ex(regs->r10, &sc->r10);
154 put_user_ex(regs->r11, &sc->r11);
155 put_user_ex(regs->r12, &sc->r12);
156 put_user_ex(regs->r13, &sc->r13);
157 put_user_ex(regs->r14, &sc->r14);
158 put_user_ex(regs->r15, &sc->r15);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800159#endif /* CONFIG_X86_64 */
160
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800161 put_user_ex(current->thread.trap_no, &sc->trapno);
162 put_user_ex(current->thread.error_code, &sc->err);
163 put_user_ex(regs->ip, &sc->ip);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800164#ifdef CONFIG_X86_32
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800165 put_user_ex(regs->cs, (unsigned int __user *)&sc->cs);
166 put_user_ex(regs->flags, &sc->flags);
167 put_user_ex(regs->sp, &sc->sp_at_signal);
168 put_user_ex(regs->ss, (unsigned int __user *)&sc->ss);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800169#else /* !CONFIG_X86_32 */
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800170 put_user_ex(regs->flags, &sc->flags);
171 put_user_ex(regs->cs, &sc->cs);
172 put_user_ex(0, &sc->gs);
173 put_user_ex(0, &sc->fs);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800174#endif /* CONFIG_X86_32 */
175
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800176 put_user_ex(fpstate, &sc->fpstate);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800177
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800178 /* non-iBCS2 extensions.. */
179 put_user_ex(mask, &sc->oldmask);
180 put_user_ex(current->thread.cr2, &sc->cr2);
181 } put_user_catch(err);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800182
183 return err;
184}
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 * Set up a signal frame.
188 */
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800189
190/*
191 * Determine which stack to use..
192 */
Hiroshi Shimamoto1fae0272009-02-27 10:30:32 -0800193static unsigned long align_sigframe(unsigned long sp)
194{
195#ifdef CONFIG_X86_32
196 /*
197 * Align the stack pointer according to the i386 ABI,
198 * i.e. so that on function entry ((sp + 4) & 15) == 0.
199 */
200 sp = ((sp + 4) & -16ul) - 4;
201#else /* !CONFIG_X86_32 */
202 sp = round_down(sp, 16) - 8;
203#endif
204 return sp;
205}
206
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800207static inline void __user *
208get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
209 void __user **fpstate)
210{
211 /* Default to using normal stack */
212 unsigned long sp = regs->sp;
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700213 int onsigstack = on_sig_stack(sp);
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800214
215#ifdef CONFIG_X86_64
216 /* redzone */
217 sp -= 128;
218#endif /* CONFIG_X86_64 */
219
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700220 if (!onsigstack) {
221 /* This is the X/Open sanctioned signal stack switching. */
222 if (ka->sa.sa_flags & SA_ONSTACK) {
Hiroshi Shimamoto0f8f3082009-03-26 10:03:08 -0700223 if (current->sas_ss_size)
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700224 sp = current->sas_ss_sp + current->sas_ss_size;
225 } else {
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800226#ifdef CONFIG_X86_32
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700227 /* This is the legacy signal stack switching. */
228 if ((regs->ss & 0xffff) != __USER_DS &&
229 !(ka->sa.sa_flags & SA_RESTORER) &&
230 ka->sa.sa_restorer)
231 sp = (unsigned long) ka->sa.sa_restorer;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800232#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700233 }
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800234 }
235
236 if (used_math()) {
237 sp -= sig_xstate_size;
Hiroshi Shimamoto25051702009-03-02 17:20:01 -0800238#ifdef CONFIG_X86_64
239 sp = round_down(sp, 64);
240#endif /* CONFIG_X86_64 */
241 *fpstate = (void __user *)sp;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800242 }
243
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700244 sp = align_sigframe(sp - frame_size);
245
246 /*
247 * If we are on the alternate signal stack and would overflow it, don't.
248 * Return an always-bogus address instead so we will die with SIGSEGV.
249 */
250 if (onsigstack && !likely(on_sig_stack(sp)))
251 return (void __user *)-1L;
252
253 /* save i387 state */
254 if (used_math() && save_i387_xstate(*fpstate) < 0)
255 return (void __user *)-1L;
256
257 return (void __user *)sp;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800258}
259
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800260#ifdef CONFIG_X86_32
261static const struct {
262 u16 poplmovl;
263 u32 val;
264 u16 int80;
265} __attribute__((packed)) retcode = {
266 0xb858, /* popl %eax; movl $..., %eax */
267 __NR_sigreturn,
268 0x80cd, /* int $0x80 */
269};
270
271static const struct {
272 u8 movl;
273 u32 val;
274 u16 int80;
275 u8 pad;
276} __attribute__((packed)) rt_retcode = {
277 0xb8, /* movl $..., %eax */
278 __NR_rt_sigreturn,
279 0x80cd, /* int $0x80 */
280 0
281};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Ingo Molnar7e907f42008-03-06 10:33:08 +0100283static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700284__setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
285 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 struct sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100288 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700290 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700292 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700295 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700297 if (__put_user(sig, &frame->sig))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700298 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700300 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700301 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303 if (_NSIG_WORDS > 1) {
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700304 if (__copy_to_user(&frame->extramask, &set->sig[1],
305 sizeof(frame->extramask)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700306 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
308
Roland McGrath1a3e4ca2008-04-09 01:29:27 -0700309 if (current->mm->context.vdso)
Roland McGrath6c3652e2008-01-30 13:30:42 +0100310 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100311 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100312 restorer = &frame->retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 if (ka->sa.sa_flags & SA_RESTORER)
314 restorer = ka->sa.sa_restorer;
315
316 /* Set up to return from userspace. */
317 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100320 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 *
322 * WE DO NOT USE IT ANY MORE! It's only left here for historical
323 * reasons and because gdb uses it as a signature to notice
324 * signal handler stack frames.
325 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800326 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700329 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
331 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100332 regs->sp = (unsigned long)frame;
333 regs->ip = (unsigned long)ka->sa.sa_handler;
334 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800335 regs->dx = 0;
336 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100338 regs->ds = __USER_DS;
339 regs->es = __USER_DS;
340 regs->ss = __USER_DS;
341 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
David Howells283828f2006-01-18 17:44:00 -0800343 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344}
345
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700346static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
347 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100350 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700352 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700354 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700357 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800359 put_user_try {
360 put_user_ex(sig, &frame->sig);
361 put_user_ex(&frame->info, &frame->pinfo);
362 put_user_ex(&frame->uc, &frame->puc);
363 err |= copy_siginfo_to_user(&frame->info, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800365 /* Create the ucontext. */
366 if (cpu_has_xsave)
367 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
368 else
369 put_user_ex(0, &frame->uc.uc_flags);
370 put_user_ex(0, &frame->uc.uc_link);
371 put_user_ex(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
372 put_user_ex(sas_ss_flags(regs->sp),
373 &frame->uc.uc_stack.ss_flags);
374 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
375 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
376 regs, set->sig[0]);
377 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800379 /* Set up to return from userspace. */
380 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
381 if (ka->sa.sa_flags & SA_RESTORER)
382 restorer = ka->sa.sa_restorer;
383 put_user_ex(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100384
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800385 /*
386 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
387 *
388 * WE DO NOT USE IT ANY MORE! It's only left here for historical
389 * reasons and because gdb uses it as a signature to notice
390 * signal handler stack frames.
391 */
392 put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
393 } put_user_catch(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
395 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700396 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100399 regs->sp = (unsigned long)frame;
400 regs->ip = (unsigned long)ka->sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700401 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100402 regs->dx = (unsigned long)&frame->info;
403 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100405 regs->ds = __USER_DS;
406 regs->es = __USER_DS;
407 regs->ss = __USER_DS;
408 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
David Howells283828f2006-01-18 17:44:00 -0800410 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411}
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800412#else /* !CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800413static 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
Hiroshi Shimamoto97286a22009-02-27 10:28:48 -0800421 frame = get_sigframe(ka, regs, sizeof(struct rt_sigframe), &fp);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800422
423 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
424 return -EFAULT;
425
426 if (ka->sa.sa_flags & SA_SIGINFO) {
427 if (copy_siginfo_to_user(&frame->info, info))
428 return -EFAULT;
429 }
430
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800431 put_user_try {
432 /* Create the ucontext. */
433 if (cpu_has_xsave)
434 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
435 else
436 put_user_ex(0, &frame->uc.uc_flags);
437 put_user_ex(0, &frame->uc.uc_link);
438 put_user_ex(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
439 put_user_ex(sas_ss_flags(regs->sp),
440 &frame->uc.uc_stack.ss_flags);
441 put_user_ex(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
442 err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
443 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800444
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800445 /* Set up to return from userspace. If provided, use a stub
446 already in userspace. */
447 /* x86-64 should always use SA_RESTORER. */
448 if (ka->sa.sa_flags & SA_RESTORER) {
449 put_user_ex(ka->sa.sa_restorer, &frame->pretcode);
450 } else {
451 /* could use a vstub here */
452 err |= -EFAULT;
453 }
454 } put_user_catch(err);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800455
456 if (err)
457 return -EFAULT;
458
459 /* Set up registers for signal handler */
460 regs->di = sig;
461 /* In case the signal handler was declared without prototypes */
462 regs->ax = 0;
463
464 /* This also works for non SA_SIGINFO handlers because they expect the
465 next argument after the signal number on the stack. */
466 regs->si = (unsigned long)&frame->info;
467 regs->dx = (unsigned long)&frame->uc;
468 regs->ip = (unsigned long) ka->sa.sa_handler;
469
470 regs->sp = (unsigned long)frame;
471
472 /* Set up the CS register to run signal handlers in 64-bit mode,
473 even if the handler happens to be interrupting 32-bit code. */
474 regs->cs = __USER_CS;
475
476 return 0;
477}
478#endif /* CONFIG_X86_32 */
479
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800480#ifdef CONFIG_X86_32
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800481/*
482 * Atomically swap in the new signal mask, and wait for a signal.
483 */
484asmlinkage int
485sys_sigsuspend(int history0, int history1, old_sigset_t mask)
486{
487 mask &= _BLOCKABLE;
488 spin_lock_irq(&current->sighand->siglock);
489 current->saved_sigmask = current->blocked;
490 siginitset(&current->blocked, mask);
491 recalc_sigpending();
492 spin_unlock_irq(&current->sighand->siglock);
493
494 current->state = TASK_INTERRUPTIBLE;
495 schedule();
496 set_restore_sigmask();
497
498 return -ERESTARTNOHAND;
499}
500
501asmlinkage int
502sys_sigaction(int sig, const struct old_sigaction __user *act,
503 struct old_sigaction __user *oact)
504{
505 struct k_sigaction new_ka, old_ka;
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800506 int ret = 0;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800507
508 if (act) {
509 old_sigset_t mask;
510
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800511 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800512 return -EFAULT;
513
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800514 get_user_try {
515 get_user_ex(new_ka.sa.sa_handler, &act->sa_handler);
516 get_user_ex(new_ka.sa.sa_flags, &act->sa_flags);
517 get_user_ex(mask, &act->sa_mask);
518 get_user_ex(new_ka.sa.sa_restorer, &act->sa_restorer);
519 } get_user_catch(ret);
520
521 if (ret)
522 return -EFAULT;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800523 siginitset(&new_ka.sa.sa_mask, mask);
524 }
525
526 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
527
528 if (!ret && oact) {
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800529 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800530 return -EFAULT;
531
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800532 put_user_try {
533 put_user_ex(old_ka.sa.sa_handler, &oact->sa_handler);
534 put_user_ex(old_ka.sa.sa_flags, &oact->sa_flags);
535 put_user_ex(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
536 put_user_ex(old_ka.sa.sa_restorer, &oact->sa_restorer);
537 } put_user_catch(ret);
538
539 if (ret)
540 return -EFAULT;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800541 }
542
543 return ret;
544}
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800545#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800546
547#ifdef CONFIG_X86_32
Brian Gerstb12bdaf2009-02-11 16:43:58 -0500548int sys_sigaltstack(struct pt_regs *regs)
549{
550 const stack_t __user *uss = (const stack_t __user *)regs->bx;
551 stack_t __user *uoss = (stack_t __user *)regs->cx;
552
553 return do_sigaltstack(uss, uoss, regs->sp);
554}
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800555#else /* !CONFIG_X86_32 */
556asmlinkage long
557sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
558 struct pt_regs *regs)
559{
560 return do_sigaltstack(uss, uoss, regs->sp);
561}
Brian Gerstb12bdaf2009-02-11 16:43:58 -0500562#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800563
564/*
565 * Do a signal return; undo the signal stack.
566 */
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800567#ifdef CONFIG_X86_32
Brian Gerstb12bdaf2009-02-11 16:43:58 -0500568unsigned long sys_sigreturn(struct pt_regs *regs)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800569{
570 struct sigframe __user *frame;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800571 unsigned long ax;
572 sigset_t set;
573
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800574 frame = (struct sigframe __user *)(regs->sp - 8);
575
576 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
577 goto badframe;
578 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
579 && __copy_from_user(&set.sig[1], &frame->extramask,
580 sizeof(frame->extramask))))
581 goto badframe;
582
583 sigdelsetmask(&set, ~_BLOCKABLE);
584 spin_lock_irq(&current->sighand->siglock);
585 current->blocked = set;
586 recalc_sigpending();
587 spin_unlock_irq(&current->sighand->siglock);
588
589 if (restore_sigcontext(regs, &frame->sc, &ax))
590 goto badframe;
591 return ax;
592
593badframe:
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800594 signal_fault(regs, frame, "sigreturn");
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800595
596 return 0;
597}
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800598#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800599
H. Peter Anvin74452502009-02-11 16:31:40 -0800600long sys_rt_sigreturn(struct pt_regs *regs)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800601{
602 struct rt_sigframe __user *frame;
603 unsigned long ax;
604 sigset_t set;
605
606 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
607 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
608 goto badframe;
609 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
610 goto badframe;
611
612 sigdelsetmask(&set, ~_BLOCKABLE);
613 spin_lock_irq(&current->sighand->siglock);
614 current->blocked = set;
615 recalc_sigpending();
616 spin_unlock_irq(&current->sighand->siglock);
617
618 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
619 goto badframe;
620
621 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
622 goto badframe;
623
624 return ax;
625
626badframe:
627 signal_fault(regs, frame, "rt_sigreturn");
628 return 0;
629}
630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100632 * OK, we're invoking a handler:
633 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700634static int signr_convert(int sig)
635{
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700636#ifdef CONFIG_X86_32
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700637 struct thread_info *info = current_thread_info();
638
639 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
640 return info->exec_domain->signal_invmap[sig];
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700641#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700642 return sig;
643}
644
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700645#ifdef CONFIG_X86_32
646
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700647#define is_ia32 1
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700648#define ia32_setup_frame __setup_frame
649#define ia32_setup_rt_frame __setup_rt_frame
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700650
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700651#else /* !CONFIG_X86_32 */
652
653#ifdef CONFIG_IA32_EMULATION
654#define is_ia32 test_thread_flag(TIF_IA32)
655#else /* !CONFIG_IA32_EMULATION */
656#define is_ia32 0
657#endif /* CONFIG_IA32_EMULATION */
658
Hiroshi Shimamotof5223762008-12-17 18:47:17 -0800659int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
660 sigset_t *set, struct pt_regs *regs);
661int ia32_setup_frame(int sig, struct k_sigaction *ka,
662 sigset_t *set, struct pt_regs *regs);
663
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700664#endif /* CONFIG_X86_32 */
665
Roland McGrath7c1def12005-06-23 00:08:21 -0700666static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700667setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
668 sigset_t *set, struct pt_regs *regs)
669{
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700670 int usig = signr_convert(sig);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700671 int ret;
672
673 /* Set up the stack frame */
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700674 if (is_ia32) {
675 if (ka->sa.sa_flags & SA_SIGINFO)
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700676 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700677 else
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700678 ret = ia32_setup_frame(usig, ka, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700679 } else
680 ret = __setup_rt_frame(sig, ka, info, set, regs);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700681
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700682 if (ret) {
683 force_sigsegv(sig, current);
684 return -EFAULT;
685 }
686
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700687 return ret;
688}
689
690static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800692 sigset_t *oldset, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
Roland McGrath7c1def12005-06-23 00:08:21 -0700694 int ret;
695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700697 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700699 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800700 case -ERESTART_RESTARTBLOCK:
701 case -ERESTARTNOHAND:
702 regs->ax = -EINTR;
703 break;
704
705 case -ERESTARTSYS:
706 if (!(ka->sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100707 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800709 }
710 /* fallthrough */
711 case -ERESTARTNOINTR:
712 regs->ax = regs->orig_ax;
713 regs->ip -= 2;
714 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 }
716 }
717
718 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100719 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
720 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100722 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100723 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100724 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700726 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Ingo Molnar7e907f42008-03-06 10:33:08 +0100728 if (ret)
729 return ret;
Roland McGrath7c1def12005-06-23 00:08:21 -0700730
Hiroshi Shimamoto86d32372008-09-23 17:22:32 -0700731#ifdef CONFIG_X86_64
732 /*
733 * This has nothing to do with segment registers,
734 * despite the name. This magic affects uaccess.h
735 * macros' behavior. Reset it to the normal setting.
736 */
737 set_fs(USER_DS);
738#endif
739
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700740 /*
741 * Clear the direction flag as per the ABI for function entry.
742 */
743 regs->flags &= ~X86_EFLAGS_DF;
744
745 /*
746 * Clear TF when entering the signal handler, but
747 * notify any tracer that was single-stepping it.
748 * The tracer may want to single-step inside the
749 * handler too.
750 */
751 regs->flags &= ~X86_EFLAGS_TF;
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700752
Ingo Molnar7e907f42008-03-06 10:33:08 +0100753 spin_lock_irq(&current->sighand->siglock);
754 sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
755 if (!(ka->sa.sa_flags & SA_NODEFER))
756 sigaddset(&current->blocked, sig);
757 recalc_sigpending();
758 spin_unlock_irq(&current->sighand->siglock);
759
Roland McGrath36a03302008-03-14 17:46:38 -0700760 tracehook_signal_handler(sig, info, ka, regs,
761 test_thread_flag(TIF_SINGLESTEP));
762
Ingo Molnar7e907f42008-03-06 10:33:08 +0100763 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764}
765
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700766#ifdef CONFIG_X86_32
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700767#define NR_restart_syscall __NR_restart_syscall
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700768#else /* !CONFIG_X86_32 */
769#define NR_restart_syscall \
770 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
771#endif /* CONFIG_X86_32 */
772
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773/*
774 * Note that 'init' is a special process: it doesn't get signals it doesn't
775 * want to handle. Thus you cannot kill init even with a SIGKILL even by
776 * mistake.
777 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100778static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800780 struct k_sigaction ka;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 siginfo_t info;
782 int signr;
David Howells283828f2006-01-18 17:44:00 -0800783 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
785 /*
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800786 * We want the common case to go fast, which is why we may in certain
787 * cases get here from kernel mode. Just return without doing anything
788 * if so.
789 * X86_32: vm86 regs switched out by assembly code before reaching
790 * here, so testing against kernel CS suffices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 */
Vincent Hanquez717b5942005-06-23 00:08:45 -0700792 if (!user_mode(regs))
David Howells283828f2006-01-18 17:44:00 -0800793 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700795 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
David Howells283828f2006-01-18 17:44:00 -0800796 oldset = &current->saved_sigmask;
797 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 oldset = &current->blocked;
799
800 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
801 if (signr > 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100802 /* Whee! Actually deliver the signal. */
David Howells283828f2006-01-18 17:44:00 -0800803 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100804 /*
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700805 * A signal was successfully delivered; the saved
David Howells283828f2006-01-18 17:44:00 -0800806 * sigmask will have been stored in the signal frame,
807 * and will be restored by sigreturn, so we can simply
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700808 * clear the TS_RESTORE_SIGMASK flag.
Ingo Molnar7e907f42008-03-06 10:33:08 +0100809 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700810 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800811 }
David Howells283828f2006-01-18 17:44:00 -0800812 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 }
814
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700816 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700818 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800819 case -ERESTARTNOHAND:
820 case -ERESTARTSYS:
821 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100822 regs->ax = regs->orig_ax;
823 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800824 break;
825
826 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700827 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100828 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800829 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 }
831 }
David Howells283828f2006-01-18 17:44:00 -0800832
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800833 /*
834 * If there's no signal to deliver, we just put the saved sigmask
835 * back.
836 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700837 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
838 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800839 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
840 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841}
842
843/*
844 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800845 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100847void
848do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849{
Andi Kleen4efc0672009-04-28 19:07:31 +0200850#ifdef CONFIG_X86_NEW_MCE
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700851 /* notify userspace of pending MCEs */
852 if (thread_info_flags & _TIF_MCE_NOTIFY)
Andi Kleen9b1beaf2009-05-27 21:56:59 +0200853 mce_notify_process();
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700854#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700857 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800858 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100859
Roland McGrath59e52132008-04-19 19:10:57 -0700860 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
861 clear_thread_flag(TIF_NOTIFY_RESUME);
862 tracehook_notify_resume(regs);
863 }
864
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700865#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 clear_thread_flag(TIF_IRET);
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700867#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700869
870void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
871{
872 struct task_struct *me = current;
873
874 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800875 printk("%s"
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700876 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800877 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700878 me->comm, me->pid, where, frame,
879 regs->ip, regs->sp, regs->orig_ax);
880 print_vma_addr(" in ", regs->ip);
881 printk(KERN_CONT "\n");
882 }
883
884 force_sig(SIGSEGV, me);
885}