blob: d2cc6428c5875a6103a00757eeeec9ff0831508f [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 */
Hiroshi Shimamoto1fae0272009-02-27 10:30:32 -0800194static unsigned long align_sigframe(unsigned long sp)
195{
196#ifdef CONFIG_X86_32
197 /*
198 * Align the stack pointer according to the i386 ABI,
199 * i.e. so that on function entry ((sp + 4) & 15) == 0.
200 */
201 sp = ((sp + 4) & -16ul) - 4;
202#else /* !CONFIG_X86_32 */
203 sp = round_down(sp, 16) - 8;
204#endif
205 return sp;
206}
207
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800208static inline void __user *
209get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
210 void __user **fpstate)
211{
212 /* Default to using normal stack */
213 unsigned long sp = regs->sp;
214
215#ifdef CONFIG_X86_64
216 /* redzone */
217 sp -= 128;
218#endif /* CONFIG_X86_64 */
219
220 /*
221 * If we are on the alternate signal stack and would overflow it, don't.
222 * Return an always-bogus address instead so we will die with SIGSEGV.
223 */
224 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
225 return (void __user *) -1L;
226
227 /* This is the X/Open sanctioned signal stack switching. */
228 if (ka->sa.sa_flags & SA_ONSTACK) {
229 if (sas_ss_flags(sp) == 0)
230 sp = current->sas_ss_sp + current->sas_ss_size;
231 } else {
232#ifdef CONFIG_X86_32
233 /* This is the legacy signal stack switching. */
234 if ((regs->ss & 0xffff) != __USER_DS &&
235 !(ka->sa.sa_flags & SA_RESTORER) &&
236 ka->sa.sa_restorer)
237 sp = (unsigned long) ka->sa.sa_restorer;
238#endif /* CONFIG_X86_32 */
239 }
240
241 if (used_math()) {
242 sp -= sig_xstate_size;
Hiroshi Shimamoto25051702009-03-02 17:20:01 -0800243#ifdef CONFIG_X86_64
244 sp = round_down(sp, 64);
245#endif /* CONFIG_X86_64 */
246 *fpstate = (void __user *)sp;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800247
248 if (save_i387_xstate(*fpstate) < 0)
249 return (void __user *)-1L;
250 }
251
Hiroshi Shimamoto1fae0272009-02-27 10:30:32 -0800252 return (void __user *)align_sigframe(sp - frame_size);
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800253}
254
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800255#ifdef CONFIG_X86_32
256static const struct {
257 u16 poplmovl;
258 u32 val;
259 u16 int80;
260} __attribute__((packed)) retcode = {
261 0xb858, /* popl %eax; movl $..., %eax */
262 __NR_sigreturn,
263 0x80cd, /* int $0x80 */
264};
265
266static const struct {
267 u8 movl;
268 u32 val;
269 u16 int80;
270 u8 pad;
271} __attribute__((packed)) rt_retcode = {
272 0xb8, /* movl $..., %eax */
273 __NR_rt_sigreturn,
274 0x80cd, /* int $0x80 */
275 0
276};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Ingo Molnar7e907f42008-03-06 10:33:08 +0100278static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700279__setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
280 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 struct sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100283 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700285 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700287 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700290 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700292 if (__put_user(sig, &frame->sig))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700293 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700295 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700296 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 if (_NSIG_WORDS > 1) {
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700299 if (__copy_to_user(&frame->extramask, &set->sig[1],
300 sizeof(frame->extramask)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700301 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
303
Roland McGrath1a3e4ca2008-04-09 01:29:27 -0700304 if (current->mm->context.vdso)
Roland McGrath6c3652e2008-01-30 13:30:42 +0100305 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100306 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100307 restorer = &frame->retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 if (ka->sa.sa_flags & SA_RESTORER)
309 restorer = ka->sa.sa_restorer;
310
311 /* Set up to return from userspace. */
312 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100315 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 *
317 * WE DO NOT USE IT ANY MORE! It's only left here for historical
318 * reasons and because gdb uses it as a signature to notice
319 * signal handler stack frames.
320 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800321 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700324 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100327 regs->sp = (unsigned long)frame;
328 regs->ip = (unsigned long)ka->sa.sa_handler;
329 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800330 regs->dx = 0;
331 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100333 regs->ds = __USER_DS;
334 regs->es = __USER_DS;
335 regs->ss = __USER_DS;
336 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
David Howells283828f2006-01-18 17:44:00 -0800338 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339}
340
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700341static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
342 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100345 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700347 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700349 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700352 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800354 put_user_try {
355 put_user_ex(sig, &frame->sig);
356 put_user_ex(&frame->info, &frame->pinfo);
357 put_user_ex(&frame->uc, &frame->puc);
358 err |= copy_siginfo_to_user(&frame->info, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800360 /* Create the ucontext. */
361 if (cpu_has_xsave)
362 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
363 else
364 put_user_ex(0, &frame->uc.uc_flags);
365 put_user_ex(0, &frame->uc.uc_link);
366 put_user_ex(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
367 put_user_ex(sas_ss_flags(regs->sp),
368 &frame->uc.uc_stack.ss_flags);
369 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
370 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
371 regs, set->sig[0]);
372 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800374 /* Set up to return from userspace. */
375 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
376 if (ka->sa.sa_flags & SA_RESTORER)
377 restorer = ka->sa.sa_restorer;
378 put_user_ex(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100379
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800380 /*
381 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
382 *
383 * WE DO NOT USE IT ANY MORE! It's only left here for historical
384 * reasons and because gdb uses it as a signature to notice
385 * signal handler stack frames.
386 */
387 put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
388 } put_user_catch(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
390 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700391 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100394 regs->sp = (unsigned long)frame;
395 regs->ip = (unsigned long)ka->sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700396 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100397 regs->dx = (unsigned long)&frame->info;
398 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100400 regs->ds = __USER_DS;
401 regs->es = __USER_DS;
402 regs->ss = __USER_DS;
403 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
David Howells283828f2006-01-18 17:44:00 -0800405 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406}
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800407#else /* !CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800408static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
409 sigset_t *set, struct pt_regs *regs)
410{
411 struct rt_sigframe __user *frame;
412 void __user *fp = NULL;
413 int err = 0;
414 struct task_struct *me = current;
415
Hiroshi Shimamoto97286a22009-02-27 10:28:48 -0800416 frame = get_sigframe(ka, regs, sizeof(struct rt_sigframe), &fp);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800417
418 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
419 return -EFAULT;
420
421 if (ka->sa.sa_flags & SA_SIGINFO) {
422 if (copy_siginfo_to_user(&frame->info, info))
423 return -EFAULT;
424 }
425
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800426 put_user_try {
427 /* Create the ucontext. */
428 if (cpu_has_xsave)
429 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
430 else
431 put_user_ex(0, &frame->uc.uc_flags);
432 put_user_ex(0, &frame->uc.uc_link);
433 put_user_ex(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
434 put_user_ex(sas_ss_flags(regs->sp),
435 &frame->uc.uc_stack.ss_flags);
436 put_user_ex(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
437 err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
438 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800439
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800440 /* Set up to return from userspace. If provided, use a stub
441 already in userspace. */
442 /* x86-64 should always use SA_RESTORER. */
443 if (ka->sa.sa_flags & SA_RESTORER) {
444 put_user_ex(ka->sa.sa_restorer, &frame->pretcode);
445 } else {
446 /* could use a vstub here */
447 err |= -EFAULT;
448 }
449 } put_user_catch(err);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800450
451 if (err)
452 return -EFAULT;
453
454 /* Set up registers for signal handler */
455 regs->di = sig;
456 /* In case the signal handler was declared without prototypes */
457 regs->ax = 0;
458
459 /* This also works for non SA_SIGINFO handlers because they expect the
460 next argument after the signal number on the stack. */
461 regs->si = (unsigned long)&frame->info;
462 regs->dx = (unsigned long)&frame->uc;
463 regs->ip = (unsigned long) ka->sa.sa_handler;
464
465 regs->sp = (unsigned long)frame;
466
467 /* Set up the CS register to run signal handlers in 64-bit mode,
468 even if the handler happens to be interrupting 32-bit code. */
469 regs->cs = __USER_CS;
470
471 return 0;
472}
473#endif /* CONFIG_X86_32 */
474
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800475#ifdef CONFIG_X86_32
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800476/*
477 * Atomically swap in the new signal mask, and wait for a signal.
478 */
479asmlinkage int
480sys_sigsuspend(int history0, int history1, old_sigset_t mask)
481{
482 mask &= _BLOCKABLE;
483 spin_lock_irq(&current->sighand->siglock);
484 current->saved_sigmask = current->blocked;
485 siginitset(&current->blocked, mask);
486 recalc_sigpending();
487 spin_unlock_irq(&current->sighand->siglock);
488
489 current->state = TASK_INTERRUPTIBLE;
490 schedule();
491 set_restore_sigmask();
492
493 return -ERESTARTNOHAND;
494}
495
496asmlinkage int
497sys_sigaction(int sig, const struct old_sigaction __user *act,
498 struct old_sigaction __user *oact)
499{
500 struct k_sigaction new_ka, old_ka;
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800501 int ret = 0;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800502
503 if (act) {
504 old_sigset_t mask;
505
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800506 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800507 return -EFAULT;
508
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800509 get_user_try {
510 get_user_ex(new_ka.sa.sa_handler, &act->sa_handler);
511 get_user_ex(new_ka.sa.sa_flags, &act->sa_flags);
512 get_user_ex(mask, &act->sa_mask);
513 get_user_ex(new_ka.sa.sa_restorer, &act->sa_restorer);
514 } get_user_catch(ret);
515
516 if (ret)
517 return -EFAULT;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800518 siginitset(&new_ka.sa.sa_mask, mask);
519 }
520
521 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
522
523 if (!ret && oact) {
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800524 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800525 return -EFAULT;
526
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800527 put_user_try {
528 put_user_ex(old_ka.sa.sa_handler, &oact->sa_handler);
529 put_user_ex(old_ka.sa.sa_flags, &oact->sa_flags);
530 put_user_ex(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
531 put_user_ex(old_ka.sa.sa_restorer, &oact->sa_restorer);
532 } put_user_catch(ret);
533
534 if (ret)
535 return -EFAULT;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800536 }
537
538 return ret;
539}
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800540#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800541
542#ifdef CONFIG_X86_32
Brian Gerstb12bdaf2009-02-11 16:43:58 -0500543int sys_sigaltstack(struct pt_regs *regs)
544{
545 const stack_t __user *uss = (const stack_t __user *)regs->bx;
546 stack_t __user *uoss = (stack_t __user *)regs->cx;
547
548 return do_sigaltstack(uss, uoss, regs->sp);
549}
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800550#else /* !CONFIG_X86_32 */
551asmlinkage long
552sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
553 struct pt_regs *regs)
554{
555 return do_sigaltstack(uss, uoss, regs->sp);
556}
Brian Gerstb12bdaf2009-02-11 16:43:58 -0500557#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800558
559/*
560 * Do a signal return; undo the signal stack.
561 */
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800562#ifdef CONFIG_X86_32
Brian Gerstb12bdaf2009-02-11 16:43:58 -0500563unsigned long sys_sigreturn(struct pt_regs *regs)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800564{
565 struct sigframe __user *frame;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800566 unsigned long ax;
567 sigset_t set;
568
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800569 frame = (struct sigframe __user *)(regs->sp - 8);
570
571 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
572 goto badframe;
573 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
574 && __copy_from_user(&set.sig[1], &frame->extramask,
575 sizeof(frame->extramask))))
576 goto badframe;
577
578 sigdelsetmask(&set, ~_BLOCKABLE);
579 spin_lock_irq(&current->sighand->siglock);
580 current->blocked = set;
581 recalc_sigpending();
582 spin_unlock_irq(&current->sighand->siglock);
583
584 if (restore_sigcontext(regs, &frame->sc, &ax))
585 goto badframe;
586 return ax;
587
588badframe:
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800589 signal_fault(regs, frame, "sigreturn");
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800590
591 return 0;
592}
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800593#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800594
H. Peter Anvin74452502009-02-11 16:31:40 -0800595long sys_rt_sigreturn(struct pt_regs *regs)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800596{
597 struct rt_sigframe __user *frame;
598 unsigned long ax;
599 sigset_t set;
600
601 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
602 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
603 goto badframe;
604 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
605 goto badframe;
606
607 sigdelsetmask(&set, ~_BLOCKABLE);
608 spin_lock_irq(&current->sighand->siglock);
609 current->blocked = set;
610 recalc_sigpending();
611 spin_unlock_irq(&current->sighand->siglock);
612
613 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
614 goto badframe;
615
616 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
617 goto badframe;
618
619 return ax;
620
621badframe:
622 signal_fault(regs, frame, "rt_sigreturn");
623 return 0;
624}
625
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100627 * OK, we're invoking a handler:
628 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700629static int signr_convert(int sig)
630{
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700631#ifdef CONFIG_X86_32
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700632 struct thread_info *info = current_thread_info();
633
634 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
635 return info->exec_domain->signal_invmap[sig];
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700636#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700637 return sig;
638}
639
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700640#ifdef CONFIG_X86_32
641
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700642#define is_ia32 1
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700643#define ia32_setup_frame __setup_frame
644#define ia32_setup_rt_frame __setup_rt_frame
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700645
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700646#else /* !CONFIG_X86_32 */
647
648#ifdef CONFIG_IA32_EMULATION
649#define is_ia32 test_thread_flag(TIF_IA32)
650#else /* !CONFIG_IA32_EMULATION */
651#define is_ia32 0
652#endif /* CONFIG_IA32_EMULATION */
653
Hiroshi Shimamotof5223762008-12-17 18:47:17 -0800654int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
655 sigset_t *set, struct pt_regs *regs);
656int ia32_setup_frame(int sig, struct k_sigaction *ka,
657 sigset_t *set, struct pt_regs *regs);
658
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700659#endif /* CONFIG_X86_32 */
660
Roland McGrath7c1def12005-06-23 00:08:21 -0700661static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700662setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
663 sigset_t *set, struct pt_regs *regs)
664{
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700665 int usig = signr_convert(sig);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700666 int ret;
667
668 /* Set up the stack frame */
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700669 if (is_ia32) {
670 if (ka->sa.sa_flags & SA_SIGINFO)
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700671 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700672 else
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700673 ret = ia32_setup_frame(usig, ka, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700674 } else
675 ret = __setup_rt_frame(sig, ka, info, set, regs);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700676
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700677 if (ret) {
678 force_sigsegv(sig, current);
679 return -EFAULT;
680 }
681
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700682 return ret;
683}
684
685static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800687 sigset_t *oldset, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688{
Roland McGrath7c1def12005-06-23 00:08:21 -0700689 int ret;
690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700692 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700694 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800695 case -ERESTART_RESTARTBLOCK:
696 case -ERESTARTNOHAND:
697 regs->ax = -EINTR;
698 break;
699
700 case -ERESTARTSYS:
701 if (!(ka->sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100702 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800704 }
705 /* fallthrough */
706 case -ERESTARTNOINTR:
707 regs->ax = regs->orig_ax;
708 regs->ip -= 2;
709 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 }
711 }
712
713 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100714 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
715 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100717 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100718 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100719 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700721 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Ingo Molnar7e907f42008-03-06 10:33:08 +0100723 if (ret)
724 return ret;
Roland McGrath7c1def12005-06-23 00:08:21 -0700725
Hiroshi Shimamoto86d32372008-09-23 17:22:32 -0700726#ifdef CONFIG_X86_64
727 /*
728 * This has nothing to do with segment registers,
729 * despite the name. This magic affects uaccess.h
730 * macros' behavior. Reset it to the normal setting.
731 */
732 set_fs(USER_DS);
733#endif
734
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700735 /*
736 * Clear the direction flag as per the ABI for function entry.
737 */
738 regs->flags &= ~X86_EFLAGS_DF;
739
740 /*
741 * Clear TF when entering the signal handler, but
742 * notify any tracer that was single-stepping it.
743 * The tracer may want to single-step inside the
744 * handler too.
745 */
746 regs->flags &= ~X86_EFLAGS_TF;
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700747
Ingo Molnar7e907f42008-03-06 10:33:08 +0100748 spin_lock_irq(&current->sighand->siglock);
749 sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
750 if (!(ka->sa.sa_flags & SA_NODEFER))
751 sigaddset(&current->blocked, sig);
752 recalc_sigpending();
753 spin_unlock_irq(&current->sighand->siglock);
754
Roland McGrath36a03302008-03-14 17:46:38 -0700755 tracehook_signal_handler(sig, info, ka, regs,
756 test_thread_flag(TIF_SINGLESTEP));
757
Ingo Molnar7e907f42008-03-06 10:33:08 +0100758 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759}
760
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700761#ifdef CONFIG_X86_32
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700762#define NR_restart_syscall __NR_restart_syscall
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700763#else /* !CONFIG_X86_32 */
764#define NR_restart_syscall \
765 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
766#endif /* CONFIG_X86_32 */
767
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768/*
769 * Note that 'init' is a special process: it doesn't get signals it doesn't
770 * want to handle. Thus you cannot kill init even with a SIGKILL even by
771 * mistake.
772 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100773static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774{
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800775 struct k_sigaction ka;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 siginfo_t info;
777 int signr;
David Howells283828f2006-01-18 17:44:00 -0800778 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
780 /*
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800781 * We want the common case to go fast, which is why we may in certain
782 * cases get here from kernel mode. Just return without doing anything
783 * if so.
784 * X86_32: vm86 regs switched out by assembly code before reaching
785 * here, so testing against kernel CS suffices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 */
Vincent Hanquez717b5942005-06-23 00:08:45 -0700787 if (!user_mode(regs))
David Howells283828f2006-01-18 17:44:00 -0800788 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700790 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
David Howells283828f2006-01-18 17:44:00 -0800791 oldset = &current->saved_sigmask;
792 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 oldset = &current->blocked;
794
795 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
796 if (signr > 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100797 /*
798 * Re-enable any watchpoints before delivering the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 * signal to user space. The processor register will
800 * have been cleared if the watchpoint triggered
801 * inside the kernel.
802 */
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800803 if (current->thread.debugreg7)
Roland McGrath0f534092008-01-30 13:30:59 +0100804 set_debugreg(current->thread.debugreg7, 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
Ingo Molnar7e907f42008-03-06 10:33:08 +0100806 /* Whee! Actually deliver the signal. */
David Howells283828f2006-01-18 17:44:00 -0800807 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100808 /*
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700809 * A signal was successfully delivered; the saved
David Howells283828f2006-01-18 17:44:00 -0800810 * sigmask will have been stored in the signal frame,
811 * and will be restored by sigreturn, so we can simply
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700812 * clear the TS_RESTORE_SIGMASK flag.
Ingo Molnar7e907f42008-03-06 10:33:08 +0100813 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700814 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800815 }
David Howells283828f2006-01-18 17:44:00 -0800816 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 }
818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700820 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700822 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800823 case -ERESTARTNOHAND:
824 case -ERESTARTSYS:
825 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100826 regs->ax = regs->orig_ax;
827 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800828 break;
829
830 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700831 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100832 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800833 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 }
835 }
David Howells283828f2006-01-18 17:44:00 -0800836
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800837 /*
838 * If there's no signal to deliver, we just put the saved sigmask
839 * back.
840 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700841 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
842 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
David Howells283828f2006-01-18 17:44:00 -0800843 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
844 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845}
846
847/*
848 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800849 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100851void
852do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853{
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700854#if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
855 /* notify userspace of pending MCEs */
856 if (thread_info_flags & _TIF_MCE_NOTIFY)
857 mce_notify_user();
858#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700861 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800862 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100863
Roland McGrath59e52132008-04-19 19:10:57 -0700864 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
865 clear_thread_flag(TIF_NOTIFY_RESUME);
866 tracehook_notify_resume(regs);
867 }
868
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700869#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 clear_thread_flag(TIF_IRET);
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700871#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700873
874void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
875{
876 struct task_struct *me = current;
877
878 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800879 printk("%s"
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700880 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800881 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700882 me->comm, me->pid, where, frame,
883 regs->ip, regs->sp, regs->orig_ax);
884 print_vma_addr(" in ", regs->ip);
885 printk(KERN_CONT "\n");
886 }
887
888 force_sig(SIGSEGV, me);
889}