blob: 53425c681f2b0de67d42f0aa4dd064fd4e210e9d [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
Hiroshi Shimamoto41af86f2008-12-17 18:50:32 -080038#include <asm/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
Tejun Heod9a89a22009-02-09 22:17:40 +090053#define COPY(x) do { \
54 get_user_ex(regs->x, &sc->x); \
55} while (0)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080056
Tejun Heod9a89a22009-02-09 22:17:40 +090057#define GET_SEG(seg) ({ \
58 unsigned short tmp; \
59 get_user_ex(tmp, &sc->seg); \
60 tmp; \
61})
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080062
Tejun Heod9a89a22009-02-09 22:17:40 +090063#define COPY_SEG(seg) do { \
64 regs->seg = GET_SEG(seg); \
65} while (0)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080066
Tejun Heod9a89a22009-02-09 22:17:40 +090067#define COPY_SEG_CPL3(seg) do { \
68 regs->seg = GET_SEG(seg) | 3; \
69} while (0)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080070
71static int
72restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
73 unsigned long *pax)
74{
75 void __user *buf;
76 unsigned int tmpflags;
77 unsigned int err = 0;
78
79 /* Always make any pending restarted system calls return -EINTR */
80 current_thread_info()->restart_block.fn = do_no_restart_syscall;
81
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080082 get_user_try {
83
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080084#ifdef CONFIG_X86_32
Tejun Heod9a89a22009-02-09 22:17:40 +090085 set_user_gs(regs, GET_SEG(gs));
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080086 COPY_SEG(fs);
87 COPY_SEG(es);
88 COPY_SEG(ds);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080089#endif /* CONFIG_X86_32 */
90
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080091 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
92 COPY(dx); COPY(cx); COPY(ip);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080093
94#ifdef CONFIG_X86_64
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080095 COPY(r8);
96 COPY(r9);
97 COPY(r10);
98 COPY(r11);
99 COPY(r12);
100 COPY(r13);
101 COPY(r14);
102 COPY(r15);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800103#endif /* CONFIG_X86_64 */
104
105#ifdef CONFIG_X86_32
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800106 COPY_SEG_CPL3(cs);
107 COPY_SEG_CPL3(ss);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800108#else /* !CONFIG_X86_32 */
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800109 /* Kernel saves and restores only the CS segment register on signals,
110 * which is the bare minimum needed to allow mixed 32/64-bit code.
111 * App's signal handler can save/restore other segments if needed. */
112 COPY_SEG_CPL3(cs);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800113#endif /* CONFIG_X86_32 */
114
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800115 get_user_ex(tmpflags, &sc->flags);
116 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
117 regs->orig_ax = -1; /* disable syscall checks */
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800118
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800119 get_user_ex(buf, &sc->fpstate);
120 err |= restore_i387_xstate(buf);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800121
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800122 get_user_ex(*pax, &sc->ax);
123 } get_user_catch(err);
124
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800125 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
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800134 put_user_try {
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800135
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800136#ifdef CONFIG_X86_32
Tejun Heod9a89a22009-02-09 22:17:40 +0900137 put_user_ex(get_user_gs(regs), (unsigned int __user *)&sc->gs);
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800138 put_user_ex(regs->fs, (unsigned int __user *)&sc->fs);
139 put_user_ex(regs->es, (unsigned int __user *)&sc->es);
140 put_user_ex(regs->ds, (unsigned int __user *)&sc->ds);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800141#endif /* CONFIG_X86_32 */
142
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800143 put_user_ex(regs->di, &sc->di);
144 put_user_ex(regs->si, &sc->si);
145 put_user_ex(regs->bp, &sc->bp);
146 put_user_ex(regs->sp, &sc->sp);
147 put_user_ex(regs->bx, &sc->bx);
148 put_user_ex(regs->dx, &sc->dx);
149 put_user_ex(regs->cx, &sc->cx);
150 put_user_ex(regs->ax, &sc->ax);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800151#ifdef CONFIG_X86_64
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800152 put_user_ex(regs->r8, &sc->r8);
153 put_user_ex(regs->r9, &sc->r9);
154 put_user_ex(regs->r10, &sc->r10);
155 put_user_ex(regs->r11, &sc->r11);
156 put_user_ex(regs->r12, &sc->r12);
157 put_user_ex(regs->r13, &sc->r13);
158 put_user_ex(regs->r14, &sc->r14);
159 put_user_ex(regs->r15, &sc->r15);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800160#endif /* CONFIG_X86_64 */
161
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800162 put_user_ex(current->thread.trap_no, &sc->trapno);
163 put_user_ex(current->thread.error_code, &sc->err);
164 put_user_ex(regs->ip, &sc->ip);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800165#ifdef CONFIG_X86_32
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800166 put_user_ex(regs->cs, (unsigned int __user *)&sc->cs);
167 put_user_ex(regs->flags, &sc->flags);
168 put_user_ex(regs->sp, &sc->sp_at_signal);
169 put_user_ex(regs->ss, (unsigned int __user *)&sc->ss);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800170#else /* !CONFIG_X86_32 */
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800171 put_user_ex(regs->flags, &sc->flags);
172 put_user_ex(regs->cs, &sc->cs);
173 put_user_ex(0, &sc->gs);
174 put_user_ex(0, &sc->fs);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800175#endif /* CONFIG_X86_32 */
176
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800177 put_user_ex(fpstate, &sc->fpstate);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800178
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800179 /* non-iBCS2 extensions.. */
180 put_user_ex(mask, &sc->oldmask);
181 put_user_ex(current->thread.cr2, &sc->cr2);
182 } put_user_catch(err);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800183
184 return err;
185}
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 * Set up a signal frame.
189 */
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800190
191/*
192 * Determine which stack to use..
193 */
194static inline void __user *
195get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
196 void __user **fpstate)
197{
198 /* Default to using normal stack */
199 unsigned long sp = regs->sp;
200
201#ifdef CONFIG_X86_64
202 /* redzone */
203 sp -= 128;
204#endif /* CONFIG_X86_64 */
205
206 /*
207 * If we are on the alternate signal stack and would overflow it, don't.
208 * Return an always-bogus address instead so we will die with SIGSEGV.
209 */
210 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
211 return (void __user *) -1L;
212
213 /* This is the X/Open sanctioned signal stack switching. */
214 if (ka->sa.sa_flags & SA_ONSTACK) {
215 if (sas_ss_flags(sp) == 0)
216 sp = current->sas_ss_sp + current->sas_ss_size;
217 } else {
218#ifdef CONFIG_X86_32
219 /* This is the legacy signal stack switching. */
220 if ((regs->ss & 0xffff) != __USER_DS &&
221 !(ka->sa.sa_flags & SA_RESTORER) &&
222 ka->sa.sa_restorer)
223 sp = (unsigned long) ka->sa.sa_restorer;
224#endif /* CONFIG_X86_32 */
225 }
226
227 if (used_math()) {
228 sp -= sig_xstate_size;
229#ifdef CONFIG_X86_32
230 *fpstate = (void __user *) sp;
231#else /* !CONFIG_X86_32 */
232 *fpstate = (void __user *)round_down(sp, 64);
233#endif /* CONFIG_X86_32 */
234
235 if (save_i387_xstate(*fpstate) < 0)
236 return (void __user *)-1L;
237 }
238
239 sp -= frame_size;
240#ifdef CONFIG_X86_32
241 /*
242 * Align the stack pointer according to the i386 ABI,
243 * i.e. so that on function entry ((sp + 4) & 15) == 0.
244 */
245 sp = ((sp + 4) & -16ul) - 4;
246#else /* !CONFIG_X86_32 */
247 sp = round_down(sp, 16) - 8;
248#endif
249
250 return (void __user *) sp;
251}
252
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800253#ifdef CONFIG_X86_32
254static const struct {
255 u16 poplmovl;
256 u32 val;
257 u16 int80;
258} __attribute__((packed)) retcode = {
259 0xb858, /* popl %eax; movl $..., %eax */
260 __NR_sigreturn,
261 0x80cd, /* int $0x80 */
262};
263
264static const struct {
265 u8 movl;
266 u32 val;
267 u16 int80;
268 u8 pad;
269} __attribute__((packed)) rt_retcode = {
270 0xb8, /* movl $..., %eax */
271 __NR_rt_sigreturn,
272 0x80cd, /* int $0x80 */
273 0
274};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Ingo Molnar7e907f42008-03-06 10:33:08 +0100276static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700277__setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
278 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 struct sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100281 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700283 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700285 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700288 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700290 if (__put_user(sig, &frame->sig))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700291 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700293 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700294 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 if (_NSIG_WORDS > 1) {
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700297 if (__copy_to_user(&frame->extramask, &set->sig[1],
298 sizeof(frame->extramask)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700299 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 }
301
Roland McGrath1a3e4ca2008-04-09 01:29:27 -0700302 if (current->mm->context.vdso)
Roland McGrath6c3652e2008-01-30 13:30:42 +0100303 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100304 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100305 restorer = &frame->retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 if (ka->sa.sa_flags & SA_RESTORER)
307 restorer = ka->sa.sa_restorer;
308
309 /* Set up to return from userspace. */
310 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100313 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 *
315 * WE DO NOT USE IT ANY MORE! It's only left here for historical
316 * reasons and because gdb uses it as a signature to notice
317 * signal handler stack frames.
318 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800319 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700322 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100325 regs->sp = (unsigned long)frame;
326 regs->ip = (unsigned long)ka->sa.sa_handler;
327 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800328 regs->dx = 0;
329 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100331 regs->ds = __USER_DS;
332 regs->es = __USER_DS;
333 regs->ss = __USER_DS;
334 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
David Howells283828f2006-01-18 17:44:00 -0800336 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
338
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700339static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
340 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100343 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700345 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700347 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700350 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800352 put_user_try {
353 put_user_ex(sig, &frame->sig);
354 put_user_ex(&frame->info, &frame->pinfo);
355 put_user_ex(&frame->uc, &frame->puc);
356 err |= copy_siginfo_to_user(&frame->info, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800358 /* Create the ucontext. */
359 if (cpu_has_xsave)
360 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
361 else
362 put_user_ex(0, &frame->uc.uc_flags);
363 put_user_ex(0, &frame->uc.uc_link);
364 put_user_ex(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
365 put_user_ex(sas_ss_flags(regs->sp),
366 &frame->uc.uc_stack.ss_flags);
367 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
368 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
369 regs, set->sig[0]);
370 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800372 /* Set up to return from userspace. */
373 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
374 if (ka->sa.sa_flags & SA_RESTORER)
375 restorer = ka->sa.sa_restorer;
376 put_user_ex(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100377
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800378 /*
379 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
380 *
381 * WE DO NOT USE IT ANY MORE! It's only left here for historical
382 * reasons and because gdb uses it as a signature to notice
383 * signal handler stack frames.
384 */
385 put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
386 } put_user_catch(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700389 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100392 regs->sp = (unsigned long)frame;
393 regs->ip = (unsigned long)ka->sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700394 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100395 regs->dx = (unsigned long)&frame->info;
396 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100398 regs->ds = __USER_DS;
399 regs->es = __USER_DS;
400 regs->ss = __USER_DS;
401 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
David Howells283828f2006-01-18 17:44:00 -0800403 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404}
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800405#else /* !CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800406static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
407 sigset_t *set, struct pt_regs *regs)
408{
409 struct rt_sigframe __user *frame;
410 void __user *fp = NULL;
411 int err = 0;
412 struct task_struct *me = current;
413
Hiroshi Shimamoto97286a22009-02-27 10:28:48 -0800414 frame = get_sigframe(ka, regs, sizeof(struct rt_sigframe), &fp);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800415
416 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
417 return -EFAULT;
418
419 if (ka->sa.sa_flags & SA_SIGINFO) {
420 if (copy_siginfo_to_user(&frame->info, info))
421 return -EFAULT;
422 }
423
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800424 put_user_try {
425 /* Create the ucontext. */
426 if (cpu_has_xsave)
427 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
428 else
429 put_user_ex(0, &frame->uc.uc_flags);
430 put_user_ex(0, &frame->uc.uc_link);
431 put_user_ex(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
432 put_user_ex(sas_ss_flags(regs->sp),
433 &frame->uc.uc_stack.ss_flags);
434 put_user_ex(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
435 err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
436 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800437
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800438 /* Set up to return from userspace. If provided, use a stub
439 already in userspace. */
440 /* x86-64 should always use SA_RESTORER. */
441 if (ka->sa.sa_flags & SA_RESTORER) {
442 put_user_ex(ka->sa.sa_restorer, &frame->pretcode);
443 } else {
444 /* could use a vstub here */
445 err |= -EFAULT;
446 }
447 } put_user_catch(err);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800448
449 if (err)
450 return -EFAULT;
451
452 /* Set up registers for signal handler */
453 regs->di = sig;
454 /* In case the signal handler was declared without prototypes */
455 regs->ax = 0;
456
457 /* This also works for non SA_SIGINFO handlers because they expect the
458 next argument after the signal number on the stack. */
459 regs->si = (unsigned long)&frame->info;
460 regs->dx = (unsigned long)&frame->uc;
461 regs->ip = (unsigned long) ka->sa.sa_handler;
462
463 regs->sp = (unsigned long)frame;
464
465 /* Set up the CS register to run signal handlers in 64-bit mode,
466 even if the handler happens to be interrupting 32-bit code. */
467 regs->cs = __USER_CS;
468
469 return 0;
470}
471#endif /* CONFIG_X86_32 */
472
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800473#ifdef CONFIG_X86_32
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800474/*
475 * Atomically swap in the new signal mask, and wait for a signal.
476 */
477asmlinkage int
478sys_sigsuspend(int history0, int history1, old_sigset_t mask)
479{
480 mask &= _BLOCKABLE;
481 spin_lock_irq(&current->sighand->siglock);
482 current->saved_sigmask = current->blocked;
483 siginitset(&current->blocked, mask);
484 recalc_sigpending();
485 spin_unlock_irq(&current->sighand->siglock);
486
487 current->state = TASK_INTERRUPTIBLE;
488 schedule();
489 set_restore_sigmask();
490
491 return -ERESTARTNOHAND;
492}
493
494asmlinkage int
495sys_sigaction(int sig, const struct old_sigaction __user *act,
496 struct old_sigaction __user *oact)
497{
498 struct k_sigaction new_ka, old_ka;
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800499 int ret = 0;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800500
501 if (act) {
502 old_sigset_t mask;
503
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800504 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800505 return -EFAULT;
506
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800507 get_user_try {
508 get_user_ex(new_ka.sa.sa_handler, &act->sa_handler);
509 get_user_ex(new_ka.sa.sa_flags, &act->sa_flags);
510 get_user_ex(mask, &act->sa_mask);
511 get_user_ex(new_ka.sa.sa_restorer, &act->sa_restorer);
512 } get_user_catch(ret);
513
514 if (ret)
515 return -EFAULT;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800516 siginitset(&new_ka.sa.sa_mask, mask);
517 }
518
519 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
520
521 if (!ret && oact) {
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800522 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800523 return -EFAULT;
524
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800525 put_user_try {
526 put_user_ex(old_ka.sa.sa_handler, &oact->sa_handler);
527 put_user_ex(old_ka.sa.sa_flags, &oact->sa_flags);
528 put_user_ex(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
529 put_user_ex(old_ka.sa.sa_restorer, &oact->sa_restorer);
530 } put_user_catch(ret);
531
532 if (ret)
533 return -EFAULT;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800534 }
535
536 return ret;
537}
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800538#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800539
540#ifdef CONFIG_X86_32
Brian Gerstb12bdaf2009-02-11 16:43:58 -0500541int sys_sigaltstack(struct pt_regs *regs)
542{
543 const stack_t __user *uss = (const stack_t __user *)regs->bx;
544 stack_t __user *uoss = (stack_t __user *)regs->cx;
545
546 return do_sigaltstack(uss, uoss, regs->sp);
547}
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800548#else /* !CONFIG_X86_32 */
549asmlinkage long
550sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
551 struct pt_regs *regs)
552{
553 return do_sigaltstack(uss, uoss, regs->sp);
554}
Brian Gerstb12bdaf2009-02-11 16:43:58 -0500555#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800556
557/*
558 * Do a signal return; undo the signal stack.
559 */
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800560#ifdef CONFIG_X86_32
Brian Gerstb12bdaf2009-02-11 16:43:58 -0500561unsigned long sys_sigreturn(struct pt_regs *regs)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800562{
563 struct sigframe __user *frame;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800564 unsigned long ax;
565 sigset_t set;
566
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800567 frame = (struct sigframe __user *)(regs->sp - 8);
568
569 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
570 goto badframe;
571 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
572 && __copy_from_user(&set.sig[1], &frame->extramask,
573 sizeof(frame->extramask))))
574 goto badframe;
575
576 sigdelsetmask(&set, ~_BLOCKABLE);
577 spin_lock_irq(&current->sighand->siglock);
578 current->blocked = set;
579 recalc_sigpending();
580 spin_unlock_irq(&current->sighand->siglock);
581
582 if (restore_sigcontext(regs, &frame->sc, &ax))
583 goto badframe;
584 return ax;
585
586badframe:
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800587 signal_fault(regs, frame, "sigreturn");
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800588
589 return 0;
590}
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800591#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800592
H. Peter Anvin74452502009-02-11 16:31:40 -0800593long sys_rt_sigreturn(struct pt_regs *regs)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800594{
595 struct rt_sigframe __user *frame;
596 unsigned long ax;
597 sigset_t set;
598
599 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
600 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
601 goto badframe;
602 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
603 goto badframe;
604
605 sigdelsetmask(&set, ~_BLOCKABLE);
606 spin_lock_irq(&current->sighand->siglock);
607 current->blocked = set;
608 recalc_sigpending();
609 spin_unlock_irq(&current->sighand->siglock);
610
611 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
612 goto badframe;
613
614 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
615 goto badframe;
616
617 return ax;
618
619badframe:
620 signal_fault(regs, frame, "rt_sigreturn");
621 return 0;
622}
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100625 * OK, we're invoking a handler:
626 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700627static int signr_convert(int sig)
628{
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700629#ifdef CONFIG_X86_32
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700630 struct thread_info *info = current_thread_info();
631
632 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
633 return info->exec_domain->signal_invmap[sig];
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700634#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700635 return sig;
636}
637
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700638#ifdef CONFIG_X86_32
639
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700640#define is_ia32 1
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700641#define ia32_setup_frame __setup_frame
642#define ia32_setup_rt_frame __setup_rt_frame
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700643
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700644#else /* !CONFIG_X86_32 */
645
646#ifdef CONFIG_IA32_EMULATION
647#define is_ia32 test_thread_flag(TIF_IA32)
648#else /* !CONFIG_IA32_EMULATION */
649#define is_ia32 0
650#endif /* CONFIG_IA32_EMULATION */
651
Hiroshi Shimamotof5223762008-12-17 18:47:17 -0800652int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
653 sigset_t *set, struct pt_regs *regs);
654int ia32_setup_frame(int sig, struct k_sigaction *ka,
655 sigset_t *set, struct pt_regs *regs);
656
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700657#endif /* CONFIG_X86_32 */
658
Roland McGrath7c1def12005-06-23 00:08:21 -0700659static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700660setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
661 sigset_t *set, struct pt_regs *regs)
662{
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700663 int usig = signr_convert(sig);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700664 int ret;
665
666 /* Set up the stack frame */
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700667 if (is_ia32) {
668 if (ka->sa.sa_flags & SA_SIGINFO)
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700669 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700670 else
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700671 ret = ia32_setup_frame(usig, ka, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700672 } else
673 ret = __setup_rt_frame(sig, ka, info, set, regs);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700674
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700675 if (ret) {
676 force_sigsegv(sig, current);
677 return -EFAULT;
678 }
679
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700680 return ret;
681}
682
683static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800685 sigset_t *oldset, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
Roland McGrath7c1def12005-06-23 00:08:21 -0700687 int ret;
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700690 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700692 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800693 case -ERESTART_RESTARTBLOCK:
694 case -ERESTARTNOHAND:
695 regs->ax = -EINTR;
696 break;
697
698 case -ERESTARTSYS:
699 if (!(ka->sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100700 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800702 }
703 /* fallthrough */
704 case -ERESTARTNOINTR:
705 regs->ax = regs->orig_ax;
706 regs->ip -= 2;
707 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 }
709 }
710
711 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100712 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
713 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100715 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100716 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100717 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700719 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Ingo Molnar7e907f42008-03-06 10:33:08 +0100721 if (ret)
722 return ret;
Roland McGrath7c1def12005-06-23 00:08:21 -0700723
Hiroshi Shimamoto86d32372008-09-23 17:22:32 -0700724#ifdef CONFIG_X86_64
725 /*
726 * This has nothing to do with segment registers,
727 * despite the name. This magic affects uaccess.h
728 * macros' behavior. Reset it to the normal setting.
729 */
730 set_fs(USER_DS);
731#endif
732
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700733 /*
734 * Clear the direction flag as per the ABI for function entry.
735 */
736 regs->flags &= ~X86_EFLAGS_DF;
737
738 /*
739 * Clear TF when entering the signal handler, but
740 * notify any tracer that was single-stepping it.
741 * The tracer may want to single-step inside the
742 * handler too.
743 */
744 regs->flags &= ~X86_EFLAGS_TF;
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700745
Ingo Molnar7e907f42008-03-06 10:33:08 +0100746 spin_lock_irq(&current->sighand->siglock);
747 sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
748 if (!(ka->sa.sa_flags & SA_NODEFER))
749 sigaddset(&current->blocked, sig);
750 recalc_sigpending();
751 spin_unlock_irq(&current->sighand->siglock);
752
Roland McGrath36a03302008-03-14 17:46:38 -0700753 tracehook_signal_handler(sig, info, ka, regs,
754 test_thread_flag(TIF_SINGLESTEP));
755
Ingo Molnar7e907f42008-03-06 10:33:08 +0100756 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757}
758
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700759#ifdef CONFIG_X86_32
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700760#define NR_restart_syscall __NR_restart_syscall
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700761#else /* !CONFIG_X86_32 */
762#define NR_restart_syscall \
763 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
764#endif /* CONFIG_X86_32 */
765
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766/*
767 * Note that 'init' is a special process: it doesn't get signals it doesn't
768 * want to handle. Thus you cannot kill init even with a SIGKILL even by
769 * mistake.
770 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100771static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800773 struct k_sigaction ka;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 siginfo_t info;
775 int signr;
David Howells283828f2006-01-18 17:44:00 -0800776 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 /*
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800779 * We want the common case to go fast, which is why we may in certain
780 * cases get here from kernel mode. Just return without doing anything
781 * if so.
782 * X86_32: vm86 regs switched out by assembly code before reaching
783 * here, so testing against kernel CS suffices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 */
Vincent Hanquez717b5942005-06-23 00:08:45 -0700785 if (!user_mode(regs))
David Howells283828f2006-01-18 17:44:00 -0800786 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700788 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
David Howells283828f2006-01-18 17:44:00 -0800789 oldset = &current->saved_sigmask;
790 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 oldset = &current->blocked;
792
793 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
794 if (signr > 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100795 /*
796 * Re-enable any watchpoints before delivering the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 * signal to user space. The processor register will
798 * have been cleared if the watchpoint triggered
799 * inside the kernel.
800 */
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800801 if (current->thread.debugreg7)
Roland McGrath0f534092008-01-30 13:30:59 +0100802 set_debugreg(current->thread.debugreg7, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Ingo Molnar7e907f42008-03-06 10:33:08 +0100804 /* Whee! Actually deliver the signal. */
David Howells283828f2006-01-18 17:44:00 -0800805 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100806 /*
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700807 * A signal was successfully delivered; the saved
David Howells283828f2006-01-18 17:44:00 -0800808 * sigmask will have been stored in the signal frame,
809 * and will be restored by sigreturn, so we can simply
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700810 * clear the TS_RESTORE_SIGMASK flag.
Ingo Molnar7e907f42008-03-06 10:33:08 +0100811 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700812 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800813 }
David Howells283828f2006-01-18 17:44:00 -0800814 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 }
816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700818 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700820 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800821 case -ERESTARTNOHAND:
822 case -ERESTARTSYS:
823 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100824 regs->ax = regs->orig_ax;
825 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800826 break;
827
828 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700829 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100830 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800831 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 }
833 }
David Howells283828f2006-01-18 17:44:00 -0800834
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800835 /*
836 * If there's no signal to deliver, we just put the saved sigmask
837 * back.
838 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700839 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
840 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800841 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
842 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843}
844
845/*
846 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800847 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100849void
850do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700852#if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
853 /* notify userspace of pending MCEs */
854 if (thread_info_flags & _TIF_MCE_NOTIFY)
855 mce_notify_user();
856#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700859 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800860 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100861
Roland McGrath59e52132008-04-19 19:10:57 -0700862 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
863 clear_thread_flag(TIF_NOTIFY_RESUME);
864 tracehook_notify_resume(regs);
865 }
866
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700867#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 clear_thread_flag(TIF_IRET);
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700869#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700871
872void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
873{
874 struct task_struct *me = current;
875
876 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800877 printk("%s"
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700878 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800879 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700880 me->comm, me->pid, where, frame,
881 regs->ip, regs->sp, regs->orig_ax);
882 print_vma_addr(" in ", regs->ip);
883 printk(KERN_CONT "\n");
884 }
885
886 force_sig(SIGSEGV, me);
887}