blob: d859eea07db7df7c302ea3a56133584d356aa3e0 [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 */
Joe Perchesc767a542012-05-21 19:50:07 -07009
10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11
Ingo Molnar7e907f42008-03-06 10:33:08 +010012#include <linux/sched.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010013#include <linux/mm.h>
Hiroshi Shimamoto5c9b3a02008-11-21 17:36:41 -080014#include <linux/smp.h>
15#include <linux/kernel.h>
Hiroshi Shimamoto5c9b3a02008-11-21 17:36:41 -080016#include <linux/errno.h>
17#include <linux/wait.h>
Hiroshi Shimamoto5c9b3a02008-11-21 17:36:41 -080018#include <linux/tracehook.h>
19#include <linux/unistd.h>
20#include <linux/stddef.h>
21#include <linux/personality.h>
22#include <linux/uaccess.h>
Avi Kivity7c68af62009-09-19 09:40:22 +030023#include <linux/user-return-notifier.h>
Srikar Dronamraju0326f5a2012-03-13 23:30:11 +053024#include <linux/uprobes.h>
Frederic Weisbecker91d1aa432012-11-27 19:33:25 +010025#include <linux/context_tracking.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/processor.h>
28#include <asm/ucontext.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <asm/i387.h>
Linus Torvalds1361b832012-02-21 13:19:22 -080030#include <asm/fpu-internal.h>
Roland McGrath6c3652e2008-01-30 13:30:42 +010031#include <asm/vdso.h>
Andi Kleen4efc0672009-04-28 19:07:31 +020032#include <asm/mce.h>
H. Peter Anvinf28f0c22012-02-19 07:38:43 -080033#include <asm/sighandling.h>
Hiroshi Shimamoto5c9b3a02008-11-21 17:36:41 -080034
35#ifdef CONFIG_X86_64
36#include <asm/proto.h>
37#include <asm/ia32_unistd.h>
H. Peter Anvinc5a37392012-02-19 09:41:09 -080038#include <asm/sys_ia32.h>
Hiroshi Shimamoto5c9b3a02008-11-21 17:36:41 -080039#endif /* CONFIG_X86_64 */
40
Hiroshi Shimamotobb579252008-09-05 16:26:55 -070041#include <asm/syscall.h>
Jaswinder Singhbbc1f692008-07-21 21:34:13 +053042#include <asm/syscalls.h>
Ingo Molnar7e907f42008-03-06 10:33:08 +010043
Hiroshi Shimamoto41af86f2008-12-17 18:50:32 -080044#include <asm/sigframe.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Tejun Heod9a89a22009-02-09 22:17:40 +090046#define COPY(x) do { \
47 get_user_ex(regs->x, &sc->x); \
48} while (0)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080049
Tejun Heod9a89a22009-02-09 22:17:40 +090050#define GET_SEG(seg) ({ \
51 unsigned short tmp; \
52 get_user_ex(tmp, &sc->seg); \
53 tmp; \
54})
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080055
Tejun Heod9a89a22009-02-09 22:17:40 +090056#define COPY_SEG(seg) do { \
57 regs->seg = GET_SEG(seg); \
58} while (0)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080059
Tejun Heod9a89a22009-02-09 22:17:40 +090060#define COPY_SEG_CPL3(seg) do { \
61 regs->seg = GET_SEG(seg) | 3; \
62} while (0)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080063
H. Peter Anvin85139422012-02-19 07:43:09 -080064int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
65 unsigned long *pax)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080066{
67 void __user *buf;
68 unsigned int tmpflags;
69 unsigned int err = 0;
70
71 /* Always make any pending restarted system calls return -EINTR */
72 current_thread_info()->restart_block.fn = do_no_restart_syscall;
73
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080074 get_user_try {
75
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080076#ifdef CONFIG_X86_32
Tejun Heod9a89a22009-02-09 22:17:40 +090077 set_user_gs(regs, GET_SEG(gs));
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080078 COPY_SEG(fs);
79 COPY_SEG(es);
80 COPY_SEG(ds);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080081#endif /* CONFIG_X86_32 */
82
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080083 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
84 COPY(dx); COPY(cx); COPY(ip);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080085
86#ifdef CONFIG_X86_64
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080087 COPY(r8);
88 COPY(r9);
89 COPY(r10);
90 COPY(r11);
91 COPY(r12);
92 COPY(r13);
93 COPY(r14);
94 COPY(r15);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080095#endif /* CONFIG_X86_64 */
96
97#ifdef CONFIG_X86_32
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080098 COPY_SEG_CPL3(cs);
99 COPY_SEG_CPL3(ss);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800100#else /* !CONFIG_X86_32 */
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800101 /* Kernel saves and restores only the CS segment register on signals,
102 * which is the bare minimum needed to allow mixed 32/64-bit code.
103 * App's signal handler can save/restore other segments if needed. */
104 COPY_SEG_CPL3(cs);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800105#endif /* CONFIG_X86_32 */
106
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800107 get_user_ex(tmpflags, &sc->flags);
108 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
109 regs->orig_ax = -1; /* disable syscall checks */
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800110
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800111 get_user_ex(buf, &sc->fpstate);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800112
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800113 get_user_ex(*pax, &sc->ax);
114 } get_user_catch(err);
115
H. Peter Anvin49b8c6952012-09-21 17:18:44 -0700116 err |= restore_xstate_sig(buf, config_enabled(CONFIG_X86_32));
H. Peter Anvin5e883532012-09-21 12:43:15 -0700117
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800118 return err;
119}
120
H. Peter Anvin85139422012-02-19 07:43:09 -0800121int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
122 struct pt_regs *regs, unsigned long mask)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800123{
124 int err = 0;
125
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800126 put_user_try {
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800127
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800128#ifdef CONFIG_X86_32
Tejun Heod9a89a22009-02-09 22:17:40 +0900129 put_user_ex(get_user_gs(regs), (unsigned int __user *)&sc->gs);
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800130 put_user_ex(regs->fs, (unsigned int __user *)&sc->fs);
131 put_user_ex(regs->es, (unsigned int __user *)&sc->es);
132 put_user_ex(regs->ds, (unsigned int __user *)&sc->ds);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800133#endif /* CONFIG_X86_32 */
134
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800135 put_user_ex(regs->di, &sc->di);
136 put_user_ex(regs->si, &sc->si);
137 put_user_ex(regs->bp, &sc->bp);
138 put_user_ex(regs->sp, &sc->sp);
139 put_user_ex(regs->bx, &sc->bx);
140 put_user_ex(regs->dx, &sc->dx);
141 put_user_ex(regs->cx, &sc->cx);
142 put_user_ex(regs->ax, &sc->ax);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800143#ifdef CONFIG_X86_64
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800144 put_user_ex(regs->r8, &sc->r8);
145 put_user_ex(regs->r9, &sc->r9);
146 put_user_ex(regs->r10, &sc->r10);
147 put_user_ex(regs->r11, &sc->r11);
148 put_user_ex(regs->r12, &sc->r12);
149 put_user_ex(regs->r13, &sc->r13);
150 put_user_ex(regs->r14, &sc->r14);
151 put_user_ex(regs->r15, &sc->r15);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800152#endif /* CONFIG_X86_64 */
153
Srikar Dronamraju51e7dc72012-03-12 14:55:55 +0530154 put_user_ex(current->thread.trap_nr, &sc->trapno);
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800155 put_user_ex(current->thread.error_code, &sc->err);
156 put_user_ex(regs->ip, &sc->ip);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800157#ifdef CONFIG_X86_32
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800158 put_user_ex(regs->cs, (unsigned int __user *)&sc->cs);
159 put_user_ex(regs->flags, &sc->flags);
160 put_user_ex(regs->sp, &sc->sp_at_signal);
161 put_user_ex(regs->ss, (unsigned int __user *)&sc->ss);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800162#else /* !CONFIG_X86_32 */
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800163 put_user_ex(regs->flags, &sc->flags);
164 put_user_ex(regs->cs, &sc->cs);
165 put_user_ex(0, &sc->gs);
166 put_user_ex(0, &sc->fs);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800167#endif /* CONFIG_X86_32 */
168
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800169 put_user_ex(fpstate, &sc->fpstate);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800170
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800171 /* non-iBCS2 extensions.. */
172 put_user_ex(mask, &sc->oldmask);
173 put_user_ex(current->thread.cr2, &sc->cr2);
174 } put_user_catch(err);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800175
176 return err;
177}
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 * Set up a signal frame.
181 */
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800182
183/*
184 * Determine which stack to use..
185 */
Hiroshi Shimamoto1fae0272009-02-27 10:30:32 -0800186static unsigned long align_sigframe(unsigned long sp)
187{
188#ifdef CONFIG_X86_32
189 /*
190 * Align the stack pointer according to the i386 ABI,
191 * i.e. so that on function entry ((sp + 4) & 15) == 0.
192 */
193 sp = ((sp + 4) & -16ul) - 4;
194#else /* !CONFIG_X86_32 */
195 sp = round_down(sp, 16) - 8;
196#endif
197 return sp;
198}
199
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800200static inline void __user *
201get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
202 void __user **fpstate)
203{
204 /* Default to using normal stack */
Suresh Siddha72a671c2012-07-24 16:05:29 -0700205 unsigned long math_size = 0;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800206 unsigned long sp = regs->sp;
Suresh Siddha72a671c2012-07-24 16:05:29 -0700207 unsigned long buf_fx = 0;
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700208 int onsigstack = on_sig_stack(sp);
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800209
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800210 /* redzone */
Suresh Siddha050902c2012-07-24 16:05:27 -0700211 if (config_enabled(CONFIG_X86_64))
212 sp -= 128;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800213
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700214 if (!onsigstack) {
215 /* This is the X/Open sanctioned signal stack switching. */
216 if (ka->sa.sa_flags & SA_ONSTACK) {
Hiroshi Shimamoto0f8f3082009-03-26 10:03:08 -0700217 if (current->sas_ss_size)
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700218 sp = current->sas_ss_sp + current->sas_ss_size;
Suresh Siddha050902c2012-07-24 16:05:27 -0700219 } else if (config_enabled(CONFIG_X86_32) &&
220 (regs->ss & 0xffff) != __USER_DS &&
221 !(ka->sa.sa_flags & SA_RESTORER) &&
222 ka->sa.sa_restorer) {
223 /* This is the legacy signal stack switching. */
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700224 sp = (unsigned long) ka->sa.sa_restorer;
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700225 }
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800226 }
227
228 if (used_math()) {
Suresh Siddha72a671c2012-07-24 16:05:29 -0700229 sp = alloc_mathframe(sp, config_enabled(CONFIG_X86_32),
230 &buf_fx, &math_size);
Hiroshi Shimamoto25051702009-03-02 17:20:01 -0800231 *fpstate = (void __user *)sp;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800232 }
233
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700234 sp = align_sigframe(sp - frame_size);
235
236 /*
237 * If we are on the alternate signal stack and would overflow it, don't.
238 * Return an always-bogus address instead so we will die with SIGSEGV.
239 */
240 if (onsigstack && !likely(on_sig_stack(sp)))
241 return (void __user *)-1L;
242
Suresh Siddha72a671c2012-07-24 16:05:29 -0700243 /* save i387 and extended state */
244 if (used_math() &&
245 save_xstate_sig(*fpstate, (void __user *)buf_fx, math_size) < 0)
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700246 return (void __user *)-1L;
247
248 return (void __user *)sp;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800249}
250
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800251#ifdef CONFIG_X86_32
252static const struct {
253 u16 poplmovl;
254 u32 val;
255 u16 int80;
256} __attribute__((packed)) retcode = {
257 0xb858, /* popl %eax; movl $..., %eax */
258 __NR_sigreturn,
259 0x80cd, /* int $0x80 */
260};
261
262static const struct {
263 u8 movl;
264 u32 val;
265 u16 int80;
266 u8 pad;
267} __attribute__((packed)) rt_retcode = {
268 0xb8, /* movl $..., %eax */
269 __NR_rt_sigreturn,
270 0x80cd, /* int $0x80 */
271 0
272};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Ingo Molnar7e907f42008-03-06 10:33:08 +0100274static int
Al Viro235b8022012-11-09 23:51:47 -0500275__setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700276 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 struct sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100279 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700281 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Al Viro235b8022012-11-09 23:51:47 -0500283 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700286 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700288 if (__put_user(sig, &frame->sig))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700289 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700291 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700292 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294 if (_NSIG_WORDS > 1) {
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700295 if (__copy_to_user(&frame->extramask, &set->sig[1],
296 sizeof(frame->extramask)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700297 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
299
Roland McGrath1a3e4ca2008-04-09 01:29:27 -0700300 if (current->mm->context.vdso)
Roland McGrath6c3652e2008-01-30 13:30:42 +0100301 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100302 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100303 restorer = &frame->retcode;
Al Viro235b8022012-11-09 23:51:47 -0500304 if (ksig->ka.sa.sa_flags & SA_RESTORER)
305 restorer = ksig->ka.sa.sa_restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
307 /* Set up to return from userspace. */
308 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100311 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 *
313 * WE DO NOT USE IT ANY MORE! It's only left here for historical
314 * reasons and because gdb uses it as a signature to notice
315 * signal handler stack frames.
316 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800317 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700320 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100323 regs->sp = (unsigned long)frame;
Al Viro235b8022012-11-09 23:51:47 -0500324 regs->ip = (unsigned long)ksig->ka.sa.sa_handler;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100325 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800326 regs->dx = 0;
327 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100329 regs->ds = __USER_DS;
330 regs->es = __USER_DS;
331 regs->ss = __USER_DS;
332 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
David Howells283828f2006-01-18 17:44:00 -0800334 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
336
Al Viro235b8022012-11-09 23:51:47 -0500337static int __setup_rt_frame(int sig, struct ksignal *ksig,
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700338 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100341 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700343 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
Al Viro235b8022012-11-09 23:51:47 -0500345 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700348 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800350 put_user_try {
351 put_user_ex(sig, &frame->sig);
352 put_user_ex(&frame->info, &frame->pinfo);
353 put_user_ex(&frame->uc, &frame->puc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800355 /* Create the ucontext. */
356 if (cpu_has_xsave)
357 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
358 else
359 put_user_ex(0, &frame->uc.uc_flags);
360 put_user_ex(0, &frame->uc.uc_link);
Al Virobd1c149a2013-09-01 20:35:01 +0100361 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800363 /* Set up to return from userspace. */
364 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
Al Viro235b8022012-11-09 23:51:47 -0500365 if (ksig->ka.sa.sa_flags & SA_RESTORER)
366 restorer = ksig->ka.sa.sa_restorer;
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800367 put_user_ex(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100368
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800369 /*
370 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
371 *
372 * WE DO NOT USE IT ANY MORE! It's only left here for historical
373 * reasons and because gdb uses it as a signature to notice
374 * signal handler stack frames.
375 */
376 put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
377 } put_user_catch(err);
H. Peter Anvin49b8c6952012-09-21 17:18:44 -0700378
Al Viro235b8022012-11-09 23:51:47 -0500379 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
H. Peter Anvin5e883532012-09-21 12:43:15 -0700380 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
381 regs, set->sig[0]);
382 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700385 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100388 regs->sp = (unsigned long)frame;
Al Viro235b8022012-11-09 23:51:47 -0500389 regs->ip = (unsigned long)ksig->ka.sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700390 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100391 regs->dx = (unsigned long)&frame->info;
392 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100394 regs->ds = __USER_DS;
395 regs->es = __USER_DS;
396 regs->ss = __USER_DS;
397 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
David Howells283828f2006-01-18 17:44:00 -0800399 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800401#else /* !CONFIG_X86_32 */
Al Viro235b8022012-11-09 23:51:47 -0500402static int __setup_rt_frame(int sig, struct ksignal *ksig,
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800403 sigset_t *set, struct pt_regs *regs)
404{
405 struct rt_sigframe __user *frame;
406 void __user *fp = NULL;
407 int err = 0;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800408
Al Viro235b8022012-11-09 23:51:47 -0500409 frame = get_sigframe(&ksig->ka, regs, sizeof(struct rt_sigframe), &fp);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800410
411 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
412 return -EFAULT;
413
Al Viro235b8022012-11-09 23:51:47 -0500414 if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
415 if (copy_siginfo_to_user(&frame->info, &ksig->info))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800416 return -EFAULT;
417 }
418
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800419 put_user_try {
420 /* Create the ucontext. */
421 if (cpu_has_xsave)
422 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
423 else
424 put_user_ex(0, &frame->uc.uc_flags);
425 put_user_ex(0, &frame->uc.uc_link);
Al Virobd1c149a2013-09-01 20:35:01 +0100426 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800427
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800428 /* Set up to return from userspace. If provided, use a stub
429 already in userspace. */
430 /* x86-64 should always use SA_RESTORER. */
Al Viro235b8022012-11-09 23:51:47 -0500431 if (ksig->ka.sa.sa_flags & SA_RESTORER) {
432 put_user_ex(ksig->ka.sa.sa_restorer, &frame->pretcode);
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800433 } else {
434 /* could use a vstub here */
435 err |= -EFAULT;
436 }
437 } put_user_catch(err);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800438
H. Peter Anvin5e883532012-09-21 12:43:15 -0700439 err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
440 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
441
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800442 if (err)
443 return -EFAULT;
444
445 /* Set up registers for signal handler */
446 regs->di = sig;
447 /* In case the signal handler was declared without prototypes */
448 regs->ax = 0;
449
450 /* This also works for non SA_SIGINFO handlers because they expect the
451 next argument after the signal number on the stack. */
452 regs->si = (unsigned long)&frame->info;
453 regs->dx = (unsigned long)&frame->uc;
Al Viro235b8022012-11-09 23:51:47 -0500454 regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800455
456 regs->sp = (unsigned long)frame;
457
458 /* Set up the CS register to run signal handlers in 64-bit mode,
459 even if the handler happens to be interrupting 32-bit code. */
460 regs->cs = __USER_CS;
461
462 return 0;
463}
464#endif /* CONFIG_X86_32 */
465
Al Viro235b8022012-11-09 23:51:47 -0500466static int x32_setup_rt_frame(struct ksignal *ksig,
467 compat_sigset_t *set,
Suresh Siddha050902c2012-07-24 16:05:27 -0700468 struct pt_regs *regs)
469{
470#ifdef CONFIG_X86_X32_ABI
471 struct rt_sigframe_x32 __user *frame;
472 void __user *restorer;
473 int err = 0;
474 void __user *fpstate = NULL;
475
Al Viro235b8022012-11-09 23:51:47 -0500476 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
Suresh Siddha050902c2012-07-24 16:05:27 -0700477
478 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
479 return -EFAULT;
480
Al Viro235b8022012-11-09 23:51:47 -0500481 if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
482 if (copy_siginfo_to_user32(&frame->info, &ksig->info))
Suresh Siddha050902c2012-07-24 16:05:27 -0700483 return -EFAULT;
484 }
485
486 put_user_try {
487 /* Create the ucontext. */
488 if (cpu_has_xsave)
489 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
490 else
491 put_user_ex(0, &frame->uc.uc_flags);
492 put_user_ex(0, &frame->uc.uc_link);
Al Virobd1c149a2013-09-01 20:35:01 +0100493 compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
Suresh Siddha050902c2012-07-24 16:05:27 -0700494 put_user_ex(0, &frame->uc.uc__pad0);
Suresh Siddha050902c2012-07-24 16:05:27 -0700495
Al Viro235b8022012-11-09 23:51:47 -0500496 if (ksig->ka.sa.sa_flags & SA_RESTORER) {
497 restorer = ksig->ka.sa.sa_restorer;
Suresh Siddha050902c2012-07-24 16:05:27 -0700498 } else {
499 /* could use a vstub here */
500 restorer = NULL;
501 err |= -EFAULT;
502 }
503 put_user_ex(restorer, &frame->pretcode);
504 } put_user_catch(err);
505
H. Peter Anvin49b8c6952012-09-21 17:18:44 -0700506 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
507 regs, set->sig[0]);
508 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
509
Suresh Siddha050902c2012-07-24 16:05:27 -0700510 if (err)
511 return -EFAULT;
512
513 /* Set up registers for signal handler */
514 regs->sp = (unsigned long) frame;
Al Viro235b8022012-11-09 23:51:47 -0500515 regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
Suresh Siddha050902c2012-07-24 16:05:27 -0700516
517 /* We use the x32 calling convention here... */
Al Viro235b8022012-11-09 23:51:47 -0500518 regs->di = ksig->sig;
Suresh Siddha050902c2012-07-24 16:05:27 -0700519 regs->si = (unsigned long) &frame->info;
520 regs->dx = (unsigned long) &frame->uc;
521
522 loadsegment(ds, __USER_DS);
523 loadsegment(es, __USER_DS);
524
525 regs->cs = __USER_CS;
526 regs->ss = __USER_DS;
527#endif /* CONFIG_X86_X32_ABI */
528
529 return 0;
530}
531
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800532/*
533 * Do a signal return; undo the signal stack.
534 */
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800535#ifdef CONFIG_X86_32
Al Viro3fe26fa2012-11-12 14:32:42 -0500536unsigned long sys_sigreturn(void)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800537{
Al Viro3fe26fa2012-11-12 14:32:42 -0500538 struct pt_regs *regs = current_pt_regs();
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800539 struct sigframe __user *frame;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800540 unsigned long ax;
541 sigset_t set;
542
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800543 frame = (struct sigframe __user *)(regs->sp - 8);
544
545 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
546 goto badframe;
547 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
548 && __copy_from_user(&set.sig[1], &frame->extramask,
549 sizeof(frame->extramask))))
550 goto badframe;
551
Oleg Nesterov39822942011-07-10 21:27:27 +0200552 set_current_blocked(&set);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800553
554 if (restore_sigcontext(regs, &frame->sc, &ax))
555 goto badframe;
556 return ax;
557
558badframe:
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800559 signal_fault(regs, frame, "sigreturn");
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800560
561 return 0;
562}
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800563#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800564
Al Viro3fe26fa2012-11-12 14:32:42 -0500565long sys_rt_sigreturn(void)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800566{
Al Viro3fe26fa2012-11-12 14:32:42 -0500567 struct pt_regs *regs = current_pt_regs();
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800568 struct rt_sigframe __user *frame;
569 unsigned long ax;
570 sigset_t set;
571
572 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
573 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
574 goto badframe;
575 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
576 goto badframe;
577
Oleg Nesterove9bd3f02011-04-27 21:09:39 +0200578 set_current_blocked(&set);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800579
580 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
581 goto badframe;
582
Al Viroc40702c2012-11-20 14:24:26 -0500583 if (restore_altstack(&frame->uc.uc_stack))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800584 goto badframe;
585
586 return ax;
587
588badframe:
589 signal_fault(regs, frame, "rt_sigreturn");
590 return 0;
591}
592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100594 * OK, we're invoking a handler:
595 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700596static int signr_convert(int sig)
597{
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700598#ifdef CONFIG_X86_32
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700599 struct thread_info *info = current_thread_info();
600
601 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
602 return info->exec_domain->signal_invmap[sig];
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700603#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700604 return sig;
605}
606
Roland McGrath7c1def12005-06-23 00:08:21 -0700607static int
Al Viro235b8022012-11-09 23:51:47 -0500608setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700609{
Al Viro235b8022012-11-09 23:51:47 -0500610 int usig = signr_convert(ksig->sig);
Al Virob7f9a112012-05-02 09:59:21 -0400611 sigset_t *set = sigmask_to_save();
Suresh Siddha050902c2012-07-24 16:05:27 -0700612 compat_sigset_t *cset = (compat_sigset_t *) set;
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700613
614 /* Set up the stack frame */
Suresh Siddha050902c2012-07-24 16:05:27 -0700615 if (is_ia32_frame()) {
Al Viro235b8022012-11-09 23:51:47 -0500616 if (ksig->ka.sa.sa_flags & SA_SIGINFO)
617 return ia32_setup_rt_frame(usig, ksig, cset, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700618 else
Al Viro235b8022012-11-09 23:51:47 -0500619 return ia32_setup_frame(usig, ksig, cset, regs);
Suresh Siddha050902c2012-07-24 16:05:27 -0700620 } else if (is_x32_frame()) {
Al Viro235b8022012-11-09 23:51:47 -0500621 return x32_setup_rt_frame(ksig, cset, regs);
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800622 } else {
Al Viro235b8022012-11-09 23:51:47 -0500623 return __setup_rt_frame(ksig->sig, ksig, set, regs);
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800624 }
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700625}
626
Al Viroa610d6e2012-05-21 23:42:15 -0400627static void
Al Viro235b8022012-11-09 23:51:47 -0500628handle_signal(struct ksignal *ksig, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629{
Al Viro235b8022012-11-09 23:51:47 -0500630 bool failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700632 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700634 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800635 case -ERESTART_RESTARTBLOCK:
636 case -ERESTARTNOHAND:
637 regs->ax = -EINTR;
638 break;
639
640 case -ERESTARTSYS:
Al Viro235b8022012-11-09 23:51:47 -0500641 if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100642 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800644 }
645 /* fallthrough */
646 case -ERESTARTNOINTR:
647 regs->ax = regs->orig_ax;
648 regs->ip -= 2;
649 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 }
651 }
652
653 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100654 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
655 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100657 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100658 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100659 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Al Viro235b8022012-11-09 23:51:47 -0500661 failed = (setup_rt_frame(ksig, regs) < 0);
662 if (!failed) {
663 /*
664 * Clear the direction flag as per the ABI for function entry.
Jiri Olsaddd40da2013-05-01 17:25:43 +0200665 *
Jiri Olsa24cda102013-05-01 17:25:42 +0200666 * Clear RF when entering the signal handler, because
667 * it might disable possible debug exception from the
668 * signal handler.
Jiri Olsaddd40da2013-05-01 17:25:43 +0200669 *
Al Viro235b8022012-11-09 23:51:47 -0500670 * Clear TF when entering the signal handler, but
671 * notify any tracer that was single-stepping it.
672 * The tracer may want to single-step inside the
673 * handler too.
674 */
Jiri Olsaddd40da2013-05-01 17:25:43 +0200675 regs->flags &= ~(X86_EFLAGS_DF|X86_EFLAGS_RF|X86_EFLAGS_TF);
Al Viroa610d6e2012-05-21 23:42:15 -0400676 }
Al Viro235b8022012-11-09 23:51:47 -0500677 signal_setup_done(failed, ksig, test_thread_flag(TIF_SINGLESTEP));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700680#ifdef CONFIG_X86_32
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700681#define NR_restart_syscall __NR_restart_syscall
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700682#else /* !CONFIG_X86_32 */
683#define NR_restart_syscall \
684 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
685#endif /* CONFIG_X86_32 */
686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687/*
688 * Note that 'init' is a special process: it doesn't get signals it doesn't
689 * want to handle. Thus you cannot kill init even with a SIGKILL even by
690 * mistake.
691 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100692static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
Al Viro235b8022012-11-09 23:51:47 -0500694 struct ksignal ksig;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Al Viro235b8022012-11-09 23:51:47 -0500696 if (get_signal(&ksig)) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100697 /* Whee! Actually deliver the signal. */
Al Viro235b8022012-11-09 23:51:47 -0500698 handle_signal(&ksig, regs);
David Howells283828f2006-01-18 17:44:00 -0800699 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700703 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700705 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800706 case -ERESTARTNOHAND:
707 case -ERESTARTSYS:
708 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100709 regs->ax = regs->orig_ax;
710 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800711 break;
712
713 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700714 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100715 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800716 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 }
718 }
David Howells283828f2006-01-18 17:44:00 -0800719
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800720 /*
721 * If there's no signal to deliver, we just put the saved sigmask
722 * back.
723 */
Al Viro51a7b442012-05-21 23:33:55 -0400724 restore_saved_sigmask();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725}
726
727/*
728 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800729 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100731void
732do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
Frederic Weisbecker91d1aa432012-11-27 19:33:25 +0100734 user_exit();
Frederic Weisbeckeredf55fd2012-07-11 20:26:39 +0200735
Andi Kleenc1ebf832009-07-09 00:31:41 +0200736#ifdef CONFIG_X86_MCE
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700737 /* notify userspace of pending MCEs */
738 if (thread_info_flags & _TIF_MCE_NOTIFY)
Andi Kleen9b1beaf2009-05-27 21:56:59 +0200739 mce_notify_process();
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700740#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
741
Oleg Nesterovdb023ea2012-09-14 19:05:46 +0200742 if (thread_info_flags & _TIF_UPROBE)
Srikar Dronamraju0326f5a2012-03-13 23:30:11 +0530743 uprobe_notify_resume(regs);
Srikar Dronamraju0326f5a2012-03-13 23:30:11 +0530744
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700746 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800747 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100748
Roland McGrath59e52132008-04-19 19:10:57 -0700749 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
750 clear_thread_flag(TIF_NOTIFY_RESUME);
751 tracehook_notify_resume(regs);
752 }
Avi Kivity7c68af62009-09-19 09:40:22 +0300753 if (thread_info_flags & _TIF_USER_RETURN_NOTIFY)
754 fire_user_return_notifiers();
Roland McGrath59e52132008-04-19 19:10:57 -0700755
Frederic Weisbecker91d1aa432012-11-27 19:33:25 +0100756 user_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700758
759void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
760{
761 struct task_struct *me = current;
762
763 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800764 printk("%s"
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700765 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800766 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700767 me->comm, me->pid, where, frame,
768 regs->ip, regs->sp, regs->orig_ax);
769 print_vma_addr(" in ", regs->ip);
Joe Perchesc767a542012-05-21 19:50:07 -0700770 pr_cont("\n");
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700771 }
772
773 force_sig(SIGSEGV, me);
774}
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800775
776#ifdef CONFIG_X86_X32_ABI
Al Viro3fe26fa2012-11-12 14:32:42 -0500777asmlinkage long sys32_x32_rt_sigreturn(void)
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800778{
Al Viro3fe26fa2012-11-12 14:32:42 -0500779 struct pt_regs *regs = current_pt_regs();
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800780 struct rt_sigframe_x32 __user *frame;
781 sigset_t set;
782 unsigned long ax;
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800783
784 frame = (struct rt_sigframe_x32 __user *)(regs->sp - 8);
785
786 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
787 goto badframe;
788 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
789 goto badframe;
790
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800791 set_current_blocked(&set);
792
793 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
794 goto badframe;
795
Al Viro90268432012-12-14 14:47:53 -0500796 if (compat_restore_altstack(&frame->uc.uc_stack))
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800797 goto badframe;
798
799 return ax;
800
801badframe:
802 signal_fault(regs, frame, "x32 rt_sigreturn");
803 return 0;
804}
805#endif