blob: 25edcfc9ba5b8587d06f613481dfa2436f972bdb [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>
Avi Kivity7c68af62009-09-19 09:40:22 +030022#include <linux/user-return-notifier.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>
Linus Torvalds1361b832012-02-21 13:19:22 -080027#include <asm/fpu-internal.h>
Roland McGrath6c3652e2008-01-30 13:30:42 +010028#include <asm/vdso.h>
Andi Kleen4efc0672009-04-28 19:07:31 +020029#include <asm/mce.h>
Hiroshi Shimamoto5c9b3a02008-11-21 17:36:41 -080030
31#ifdef CONFIG_X86_64
32#include <asm/proto.h>
33#include <asm/ia32_unistd.h>
Hiroshi Shimamoto5c9b3a02008-11-21 17:36:41 -080034#endif /* CONFIG_X86_64 */
35
Hiroshi Shimamotobb579252008-09-05 16:26:55 -070036#include <asm/syscall.h>
Jaswinder Singhbbc1f692008-07-21 21:34:13 +053037#include <asm/syscalls.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010038
Hiroshi Shimamoto41af86f2008-12-17 18:50:32 -080039#include <asm/sigframe.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
42
Harvey Harrison1a176802008-02-08 12:09:59 -080043#define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \
44 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
45 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
46 X86_EFLAGS_CF)
47
48#ifdef CONFIG_X86_32
49# define FIX_EFLAGS (__FIX_EFLAGS | X86_EFLAGS_RF)
50#else
51# define FIX_EFLAGS __FIX_EFLAGS
52#endif
53
Tejun Heod9a89a22009-02-09 22:17:40 +090054#define COPY(x) do { \
55 get_user_ex(regs->x, &sc->x); \
56} while (0)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080057
Tejun Heod9a89a22009-02-09 22:17:40 +090058#define GET_SEG(seg) ({ \
59 unsigned short tmp; \
60 get_user_ex(tmp, &sc->seg); \
61 tmp; \
62})
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080063
Tejun Heod9a89a22009-02-09 22:17:40 +090064#define COPY_SEG(seg) do { \
65 regs->seg = GET_SEG(seg); \
66} while (0)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080067
Tejun Heod9a89a22009-02-09 22:17:40 +090068#define COPY_SEG_CPL3(seg) do { \
69 regs->seg = GET_SEG(seg) | 3; \
70} while (0)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080071
72static int
73restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
74 unsigned long *pax)
75{
76 void __user *buf;
77 unsigned int tmpflags;
78 unsigned int err = 0;
79
80 /* Always make any pending restarted system calls return -EINTR */
81 current_thread_info()->restart_block.fn = do_no_restart_syscall;
82
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080083 get_user_try {
84
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080085#ifdef CONFIG_X86_32
Tejun Heod9a89a22009-02-09 22:17:40 +090086 set_user_gs(regs, GET_SEG(gs));
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080087 COPY_SEG(fs);
88 COPY_SEG(es);
89 COPY_SEG(ds);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080090#endif /* CONFIG_X86_32 */
91
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080092 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
93 COPY(dx); COPY(cx); COPY(ip);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080094
95#ifdef CONFIG_X86_64
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080096 COPY(r8);
97 COPY(r9);
98 COPY(r10);
99 COPY(r11);
100 COPY(r12);
101 COPY(r13);
102 COPY(r14);
103 COPY(r15);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800104#endif /* CONFIG_X86_64 */
105
106#ifdef CONFIG_X86_32
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800107 COPY_SEG_CPL3(cs);
108 COPY_SEG_CPL3(ss);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800109#else /* !CONFIG_X86_32 */
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800110 /* Kernel saves and restores only the CS segment register on signals,
111 * which is the bare minimum needed to allow mixed 32/64-bit code.
112 * App's signal handler can save/restore other segments if needed. */
113 COPY_SEG_CPL3(cs);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800114#endif /* CONFIG_X86_32 */
115
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800116 get_user_ex(tmpflags, &sc->flags);
117 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
118 regs->orig_ax = -1; /* disable syscall checks */
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800119
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800120 get_user_ex(buf, &sc->fpstate);
121 err |= restore_i387_xstate(buf);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800122
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800123 get_user_ex(*pax, &sc->ax);
124 } get_user_catch(err);
125
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800126 return err;
127}
128
129static int
130setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
131 struct pt_regs *regs, unsigned long mask)
132{
133 int err = 0;
134
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800135 put_user_try {
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800136
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800137#ifdef CONFIG_X86_32
Tejun Heod9a89a22009-02-09 22:17:40 +0900138 put_user_ex(get_user_gs(regs), (unsigned int __user *)&sc->gs);
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800139 put_user_ex(regs->fs, (unsigned int __user *)&sc->fs);
140 put_user_ex(regs->es, (unsigned int __user *)&sc->es);
141 put_user_ex(regs->ds, (unsigned int __user *)&sc->ds);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800142#endif /* CONFIG_X86_32 */
143
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800144 put_user_ex(regs->di, &sc->di);
145 put_user_ex(regs->si, &sc->si);
146 put_user_ex(regs->bp, &sc->bp);
147 put_user_ex(regs->sp, &sc->sp);
148 put_user_ex(regs->bx, &sc->bx);
149 put_user_ex(regs->dx, &sc->dx);
150 put_user_ex(regs->cx, &sc->cx);
151 put_user_ex(regs->ax, &sc->ax);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800152#ifdef CONFIG_X86_64
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800153 put_user_ex(regs->r8, &sc->r8);
154 put_user_ex(regs->r9, &sc->r9);
155 put_user_ex(regs->r10, &sc->r10);
156 put_user_ex(regs->r11, &sc->r11);
157 put_user_ex(regs->r12, &sc->r12);
158 put_user_ex(regs->r13, &sc->r13);
159 put_user_ex(regs->r14, &sc->r14);
160 put_user_ex(regs->r15, &sc->r15);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800161#endif /* CONFIG_X86_64 */
162
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800163 put_user_ex(current->thread.trap_no, &sc->trapno);
164 put_user_ex(current->thread.error_code, &sc->err);
165 put_user_ex(regs->ip, &sc->ip);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800166#ifdef CONFIG_X86_32
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800167 put_user_ex(regs->cs, (unsigned int __user *)&sc->cs);
168 put_user_ex(regs->flags, &sc->flags);
169 put_user_ex(regs->sp, &sc->sp_at_signal);
170 put_user_ex(regs->ss, (unsigned int __user *)&sc->ss);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800171#else /* !CONFIG_X86_32 */
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800172 put_user_ex(regs->flags, &sc->flags);
173 put_user_ex(regs->cs, &sc->cs);
174 put_user_ex(0, &sc->gs);
175 put_user_ex(0, &sc->fs);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800176#endif /* CONFIG_X86_32 */
177
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800178 put_user_ex(fpstate, &sc->fpstate);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800179
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800180 /* non-iBCS2 extensions.. */
181 put_user_ex(mask, &sc->oldmask);
182 put_user_ex(current->thread.cr2, &sc->cr2);
183 } put_user_catch(err);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800184
185 return err;
186}
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 * Set up a signal frame.
190 */
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800191
192/*
193 * Determine which stack to use..
194 */
Hiroshi Shimamoto1fae0272009-02-27 10:30:32 -0800195static unsigned long align_sigframe(unsigned long sp)
196{
197#ifdef CONFIG_X86_32
198 /*
199 * Align the stack pointer according to the i386 ABI,
200 * i.e. so that on function entry ((sp + 4) & 15) == 0.
201 */
202 sp = ((sp + 4) & -16ul) - 4;
203#else /* !CONFIG_X86_32 */
204 sp = round_down(sp, 16) - 8;
205#endif
206 return sp;
207}
208
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800209static inline void __user *
210get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
211 void __user **fpstate)
212{
213 /* Default to using normal stack */
214 unsigned long sp = regs->sp;
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700215 int onsigstack = on_sig_stack(sp);
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800216
217#ifdef CONFIG_X86_64
218 /* redzone */
219 sp -= 128;
220#endif /* CONFIG_X86_64 */
221
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700222 if (!onsigstack) {
223 /* This is the X/Open sanctioned signal stack switching. */
224 if (ka->sa.sa_flags & SA_ONSTACK) {
Hiroshi Shimamoto0f8f3082009-03-26 10:03:08 -0700225 if (current->sas_ss_size)
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700226 sp = current->sas_ss_sp + current->sas_ss_size;
227 } else {
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800228#ifdef CONFIG_X86_32
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700229 /* This is the legacy signal stack switching. */
230 if ((regs->ss & 0xffff) != __USER_DS &&
231 !(ka->sa.sa_flags & SA_RESTORER) &&
232 ka->sa.sa_restorer)
233 sp = (unsigned long) ka->sa.sa_restorer;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800234#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700235 }
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800236 }
237
238 if (used_math()) {
239 sp -= sig_xstate_size;
Hiroshi Shimamoto25051702009-03-02 17:20:01 -0800240#ifdef CONFIG_X86_64
241 sp = round_down(sp, 64);
242#endif /* CONFIG_X86_64 */
243 *fpstate = (void __user *)sp;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800244 }
245
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700246 sp = align_sigframe(sp - frame_size);
247
248 /*
249 * If we are on the alternate signal stack and would overflow it, don't.
250 * Return an always-bogus address instead so we will die with SIGSEGV.
251 */
252 if (onsigstack && !likely(on_sig_stack(sp)))
253 return (void __user *)-1L;
254
255 /* save i387 state */
256 if (used_math() && save_i387_xstate(*fpstate) < 0)
257 return (void __user *)-1L;
258
259 return (void __user *)sp;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800260}
261
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800262#ifdef CONFIG_X86_32
263static const struct {
264 u16 poplmovl;
265 u32 val;
266 u16 int80;
267} __attribute__((packed)) retcode = {
268 0xb858, /* popl %eax; movl $..., %eax */
269 __NR_sigreturn,
270 0x80cd, /* int $0x80 */
271};
272
273static const struct {
274 u8 movl;
275 u32 val;
276 u16 int80;
277 u8 pad;
278} __attribute__((packed)) rt_retcode = {
279 0xb8, /* movl $..., %eax */
280 __NR_rt_sigreturn,
281 0x80cd, /* int $0x80 */
282 0
283};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
Ingo Molnar7e907f42008-03-06 10:33:08 +0100285static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700286__setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
287 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 struct sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100290 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700292 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700294 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700297 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700299 if (__put_user(sig, &frame->sig))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700300 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700302 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700303 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305 if (_NSIG_WORDS > 1) {
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700306 if (__copy_to_user(&frame->extramask, &set->sig[1],
307 sizeof(frame->extramask)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700308 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
310
Roland McGrath1a3e4ca2008-04-09 01:29:27 -0700311 if (current->mm->context.vdso)
Roland McGrath6c3652e2008-01-30 13:30:42 +0100312 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100313 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100314 restorer = &frame->retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 if (ka->sa.sa_flags & SA_RESTORER)
316 restorer = ka->sa.sa_restorer;
317
318 /* Set up to return from userspace. */
319 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100322 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 *
324 * WE DO NOT USE IT ANY MORE! It's only left here for historical
325 * reasons and because gdb uses it as a signature to notice
326 * signal handler stack frames.
327 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800328 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700331 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100334 regs->sp = (unsigned long)frame;
335 regs->ip = (unsigned long)ka->sa.sa_handler;
336 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800337 regs->dx = 0;
338 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100340 regs->ds = __USER_DS;
341 regs->es = __USER_DS;
342 regs->ss = __USER_DS;
343 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
David Howells283828f2006-01-18 17:44:00 -0800345 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346}
347
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700348static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
349 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100352 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700354 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Suresh Siddha3c1c7f12008-07-29 10:29:21 -0700356 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700359 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800361 put_user_try {
362 put_user_ex(sig, &frame->sig);
363 put_user_ex(&frame->info, &frame->pinfo);
364 put_user_ex(&frame->uc, &frame->puc);
365 err |= copy_siginfo_to_user(&frame->info, info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800367 /* Create the ucontext. */
368 if (cpu_has_xsave)
369 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
370 else
371 put_user_ex(0, &frame->uc.uc_flags);
372 put_user_ex(0, &frame->uc.uc_link);
373 put_user_ex(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
374 put_user_ex(sas_ss_flags(regs->sp),
375 &frame->uc.uc_stack.ss_flags);
376 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
377 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
378 regs, set->sig[0]);
379 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800381 /* Set up to return from userspace. */
382 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
383 if (ka->sa.sa_flags & SA_RESTORER)
384 restorer = ka->sa.sa_restorer;
385 put_user_ex(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100386
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800387 /*
388 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
389 *
390 * WE DO NOT USE IT ANY MORE! It's only left here for historical
391 * reasons and because gdb uses it as a signature to notice
392 * signal handler stack frames.
393 */
394 put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
395 } put_user_catch(err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700398 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100401 regs->sp = (unsigned long)frame;
402 regs->ip = (unsigned long)ka->sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700403 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100404 regs->dx = (unsigned long)&frame->info;
405 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100407 regs->ds = __USER_DS;
408 regs->es = __USER_DS;
409 regs->ss = __USER_DS;
410 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
David Howells283828f2006-01-18 17:44:00 -0800412 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800414#else /* !CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800415static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
416 sigset_t *set, struct pt_regs *regs)
417{
418 struct rt_sigframe __user *frame;
419 void __user *fp = NULL;
420 int err = 0;
421 struct task_struct *me = current;
422
Hiroshi Shimamoto97286a22009-02-27 10:28:48 -0800423 frame = get_sigframe(ka, regs, sizeof(struct rt_sigframe), &fp);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800424
425 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
426 return -EFAULT;
427
428 if (ka->sa.sa_flags & SA_SIGINFO) {
429 if (copy_siginfo_to_user(&frame->info, info))
430 return -EFAULT;
431 }
432
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800433 put_user_try {
434 /* Create the ucontext. */
435 if (cpu_has_xsave)
436 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
437 else
438 put_user_ex(0, &frame->uc.uc_flags);
439 put_user_ex(0, &frame->uc.uc_link);
440 put_user_ex(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
441 put_user_ex(sas_ss_flags(regs->sp),
442 &frame->uc.uc_stack.ss_flags);
443 put_user_ex(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
444 err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
445 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800446
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800447 /* Set up to return from userspace. If provided, use a stub
448 already in userspace. */
449 /* x86-64 should always use SA_RESTORER. */
450 if (ka->sa.sa_flags & SA_RESTORER) {
451 put_user_ex(ka->sa.sa_restorer, &frame->pretcode);
452 } else {
453 /* could use a vstub here */
454 err |= -EFAULT;
455 }
456 } put_user_catch(err);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800457
458 if (err)
459 return -EFAULT;
460
461 /* Set up registers for signal handler */
462 regs->di = sig;
463 /* In case the signal handler was declared without prototypes */
464 regs->ax = 0;
465
466 /* This also works for non SA_SIGINFO handlers because they expect the
467 next argument after the signal number on the stack. */
468 regs->si = (unsigned long)&frame->info;
469 regs->dx = (unsigned long)&frame->uc;
470 regs->ip = (unsigned long) ka->sa.sa_handler;
471
472 regs->sp = (unsigned long)frame;
473
474 /* Set up the CS register to run signal handlers in 64-bit mode,
475 even if the handler happens to be interrupting 32-bit code. */
476 regs->cs = __USER_CS;
477
478 return 0;
479}
480#endif /* CONFIG_X86_32 */
481
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800482#ifdef CONFIG_X86_32
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800483/*
484 * Atomically swap in the new signal mask, and wait for a signal.
485 */
486asmlinkage int
487sys_sigsuspend(int history0, int history1, old_sigset_t mask)
488{
Oleg Nesterov39822942011-07-10 21:27:27 +0200489 sigset_t blocked;
490
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800491 current->saved_sigmask = current->blocked;
Oleg Nesterov39822942011-07-10 21:27:27 +0200492
493 mask &= _BLOCKABLE;
494 siginitset(&blocked, mask);
495 set_current_blocked(&blocked);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800496
497 current->state = TASK_INTERRUPTIBLE;
498 schedule();
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800499
Oleg Nesterov39822942011-07-10 21:27:27 +0200500 set_restore_sigmask();
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800501 return -ERESTARTNOHAND;
502}
503
504asmlinkage int
505sys_sigaction(int sig, const struct old_sigaction __user *act,
506 struct old_sigaction __user *oact)
507{
508 struct k_sigaction new_ka, old_ka;
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800509 int ret = 0;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800510
511 if (act) {
512 old_sigset_t mask;
513
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800514 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800515 return -EFAULT;
516
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800517 get_user_try {
518 get_user_ex(new_ka.sa.sa_handler, &act->sa_handler);
519 get_user_ex(new_ka.sa.sa_flags, &act->sa_flags);
520 get_user_ex(mask, &act->sa_mask);
521 get_user_ex(new_ka.sa.sa_restorer, &act->sa_restorer);
522 } get_user_catch(ret);
523
524 if (ret)
525 return -EFAULT;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800526 siginitset(&new_ka.sa.sa_mask, mask);
527 }
528
529 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
530
531 if (!ret && oact) {
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800532 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800533 return -EFAULT;
534
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800535 put_user_try {
536 put_user_ex(old_ka.sa.sa_handler, &oact->sa_handler);
537 put_user_ex(old_ka.sa.sa_flags, &oact->sa_flags);
538 put_user_ex(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
539 put_user_ex(old_ka.sa.sa_restorer, &oact->sa_restorer);
540 } put_user_catch(ret);
541
542 if (ret)
543 return -EFAULT;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800544 }
545
546 return ret;
547}
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800548#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800549
Brian Gerst052acad2009-12-09 19:01:54 -0500550long
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800551sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
552 struct pt_regs *regs)
553{
554 return do_sigaltstack(uss, uoss, regs->sp);
555}
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);
Oleg Nesterov39822942011-07-10 21:27:27 +0200577 set_current_blocked(&set);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800578
579 if (restore_sigcontext(regs, &frame->sc, &ax))
580 goto badframe;
581 return ax;
582
583badframe:
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800584 signal_fault(regs, frame, "sigreturn");
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800585
586 return 0;
587}
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800588#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800589
H. Peter Anvin74452502009-02-11 16:31:40 -0800590long sys_rt_sigreturn(struct pt_regs *regs)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800591{
592 struct rt_sigframe __user *frame;
593 unsigned long ax;
594 sigset_t set;
595
596 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
597 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
598 goto badframe;
599 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
600 goto badframe;
601
602 sigdelsetmask(&set, ~_BLOCKABLE);
Oleg Nesterove9bd3f02011-04-27 21:09:39 +0200603 set_current_blocked(&set);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800604
605 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
606 goto badframe;
607
608 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
609 goto badframe;
610
611 return ax;
612
613badframe:
614 signal_fault(regs, frame, "rt_sigreturn");
615 return 0;
616}
617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100619 * OK, we're invoking a handler:
620 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700621static int signr_convert(int sig)
622{
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700623#ifdef CONFIG_X86_32
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700624 struct thread_info *info = current_thread_info();
625
626 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
627 return info->exec_domain->signal_invmap[sig];
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700628#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700629 return sig;
630}
631
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700632#ifdef CONFIG_X86_32
633
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700634#define is_ia32 1
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700635#define ia32_setup_frame __setup_frame
636#define ia32_setup_rt_frame __setup_rt_frame
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700637
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700638#else /* !CONFIG_X86_32 */
639
640#ifdef CONFIG_IA32_EMULATION
641#define is_ia32 test_thread_flag(TIF_IA32)
642#else /* !CONFIG_IA32_EMULATION */
643#define is_ia32 0
644#endif /* CONFIG_IA32_EMULATION */
645
Hiroshi Shimamotof5223762008-12-17 18:47:17 -0800646int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
647 sigset_t *set, struct pt_regs *regs);
648int ia32_setup_frame(int sig, struct k_sigaction *ka,
649 sigset_t *set, struct pt_regs *regs);
650
Hiroshi Shimamotocabf5032008-10-29 18:46:07 -0700651#endif /* CONFIG_X86_32 */
652
Roland McGrath7c1def12005-06-23 00:08:21 -0700653static int
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700654setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
Oleg Nesterov9b429622011-07-10 20:22:03 +0200655 struct pt_regs *regs)
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700656{
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700657 int usig = signr_convert(sig);
Oleg Nesterov9b429622011-07-10 20:22:03 +0200658 sigset_t *set = &current->blocked;
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700659 int ret;
660
Oleg Nesterov9b429622011-07-10 20:22:03 +0200661 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
662 set = &current->saved_sigmask;
663
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700664 /* Set up the stack frame */
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700665 if (is_ia32) {
666 if (ka->sa.sa_flags & SA_SIGINFO)
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700667 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700668 else
Hiroshi Shimamoto4694d232008-09-24 19:13:29 -0700669 ret = ia32_setup_frame(usig, ka, set, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700670 } else
671 ret = __setup_rt_frame(sig, ka, info, set, regs);
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700672
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700673 if (ret) {
674 force_sigsegv(sig, current);
675 return -EFAULT;
676 }
677
Oleg Nesterov9b429622011-07-10 20:22:03 +0200678 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700679 return ret;
680}
681
682static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
Oleg Nesterov9b429622011-07-10 20:22:03 +0200684 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685{
Roland McGrath7c1def12005-06-23 00:08:21 -0700686 int ret;
687
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700689 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700691 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800692 case -ERESTART_RESTARTBLOCK:
693 case -ERESTARTNOHAND:
694 regs->ax = -EINTR;
695 break;
696
697 case -ERESTARTSYS:
698 if (!(ka->sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100699 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800701 }
702 /* fallthrough */
703 case -ERESTARTNOINTR:
704 regs->ax = regs->orig_ax;
705 regs->ip -= 2;
706 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 }
708 }
709
710 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100711 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
712 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100714 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100715 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100716 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Oleg Nesterov9b429622011-07-10 20:22:03 +0200718 ret = setup_rt_frame(sig, ka, info, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Ingo Molnar7e907f42008-03-06 10:33:08 +0100720 if (ret)
721 return ret;
Roland McGrath7c1def12005-06-23 00:08:21 -0700722
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700723 /*
724 * Clear the direction flag as per the ABI for function entry.
725 */
726 regs->flags &= ~X86_EFLAGS_DF;
727
728 /*
729 * Clear TF when entering the signal handler, but
730 * notify any tracer that was single-stepping it.
731 * The tracer may want to single-step inside the
732 * handler too.
733 */
734 regs->flags &= ~X86_EFLAGS_TF;
Roland McGrath8b9c5ff2008-04-19 14:26:54 -0700735
Matt Fleming5e6292c2012-01-10 15:11:17 -0800736 block_sigmask(ka, sig);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100737
Roland McGrath36a03302008-03-14 17:46:38 -0700738 tracehook_signal_handler(sig, info, ka, regs,
739 test_thread_flag(TIF_SINGLESTEP));
740
Ingo Molnar7e907f42008-03-06 10:33:08 +0100741 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742}
743
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700744#ifdef CONFIG_X86_32
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700745#define NR_restart_syscall __NR_restart_syscall
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700746#else /* !CONFIG_X86_32 */
747#define NR_restart_syscall \
748 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
749#endif /* CONFIG_X86_32 */
750
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751/*
752 * Note that 'init' is a special process: it doesn't get signals it doesn't
753 * want to handle. Thus you cannot kill init even with a SIGKILL even by
754 * mistake.
755 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100756static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757{
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800758 struct k_sigaction ka;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 siginfo_t info;
760 int signr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 /*
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800763 * We want the common case to go fast, which is why we may in certain
764 * cases get here from kernel mode. Just return without doing anything
765 * if so.
766 * X86_32: vm86 regs switched out by assembly code before reaching
767 * here, so testing against kernel CS suffices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 */
Vincent Hanquez717b5942005-06-23 00:08:45 -0700769 if (!user_mode(regs))
David Howells283828f2006-01-18 17:44:00 -0800770 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
773 if (signr > 0) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100774 /* Whee! Actually deliver the signal. */
Oleg Nesterov9b429622011-07-10 20:22:03 +0200775 handle_signal(signr, &info, &ka, regs);
David Howells283828f2006-01-18 17:44:00 -0800776 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 }
778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700780 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700782 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800783 case -ERESTARTNOHAND:
784 case -ERESTARTSYS:
785 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100786 regs->ax = regs->orig_ax;
787 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800788 break;
789
790 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700791 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100792 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800793 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 }
795 }
David Howells283828f2006-01-18 17:44:00 -0800796
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800797 /*
798 * If there's no signal to deliver, we just put the saved sigmask
799 * back.
800 */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700801 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
802 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
Oleg Nesterov9b429622011-07-10 20:22:03 +0200803 set_current_blocked(&current->saved_sigmask);
David Howells283828f2006-01-18 17:44:00 -0800804 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805}
806
807/*
808 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800809 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100811void
812do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
Andi Kleenc1ebf832009-07-09 00:31:41 +0200814#ifdef CONFIG_X86_MCE
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700815 /* notify userspace of pending MCEs */
816 if (thread_info_flags & _TIF_MCE_NOTIFY)
Andi Kleen9b1beaf2009-05-27 21:56:59 +0200817 mce_notify_process();
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700818#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700821 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800822 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100823
Roland McGrath59e52132008-04-19 19:10:57 -0700824 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
825 clear_thread_flag(TIF_NOTIFY_RESUME);
826 tracehook_notify_resume(regs);
David Howellsee18d642009-09-02 09:14:21 +0100827 if (current->replacement_session_keyring)
828 key_replace_session_keyring();
Roland McGrath59e52132008-04-19 19:10:57 -0700829 }
Avi Kivity7c68af62009-09-19 09:40:22 +0300830 if (thread_info_flags & _TIF_USER_RETURN_NOTIFY)
831 fire_user_return_notifiers();
Roland McGrath59e52132008-04-19 19:10:57 -0700832
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700833#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 clear_thread_flag(TIF_IRET);
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700835#endif /* CONFIG_X86_32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700837
838void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
839{
840 struct task_struct *me = current;
841
842 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800843 printk("%s"
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700844 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800845 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700846 me->comm, me->pid, where, frame,
847 regs->ip, regs->sp, regs->orig_ax);
848 print_vma_addr(" in ", regs->ip);
849 printk(KERN_CONT "\n");
850 }
851
852 force_sig(SIGSEGV, me);
853}