blob: a0da58db43a86ea9f2ec85154cd46bc2828c822e [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)
Andy Lutomirski6f121e52014-05-05 12:19:34 -0700301 restorer = current->mm->context.vdso +
302 selected_vdso32->sym___kernel_sigreturn;
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100303 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100304 restorer = &frame->retcode;
Al Viro235b8022012-11-09 23:51:47 -0500305 if (ksig->ka.sa.sa_flags & SA_RESTORER)
306 restorer = ksig->ka.sa.sa_restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 /* Set up to return from userspace. */
309 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100312 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 *
314 * WE DO NOT USE IT ANY MORE! It's only left here for historical
315 * reasons and because gdb uses it as a signature to notice
316 * signal handler stack frames.
317 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800318 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700321 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100324 regs->sp = (unsigned long)frame;
Al Viro235b8022012-11-09 23:51:47 -0500325 regs->ip = (unsigned long)ksig->ka.sa.sa_handler;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100326 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800327 regs->dx = 0;
328 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100330 regs->ds = __USER_DS;
331 regs->es = __USER_DS;
332 regs->ss = __USER_DS;
333 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
David Howells283828f2006-01-18 17:44:00 -0800335 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
Al Viro235b8022012-11-09 23:51:47 -0500338static int __setup_rt_frame(int sig, struct ksignal *ksig,
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700339 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100342 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700344 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Al Viro235b8022012-11-09 23:51:47 -0500346 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700349 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800351 put_user_try {
352 put_user_ex(sig, &frame->sig);
353 put_user_ex(&frame->info, &frame->pinfo);
354 put_user_ex(&frame->uc, &frame->puc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800356 /* Create the ucontext. */
357 if (cpu_has_xsave)
358 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
359 else
360 put_user_ex(0, &frame->uc.uc_flags);
361 put_user_ex(0, &frame->uc.uc_link);
Al Virobd1c149a2013-09-01 20:35:01 +0100362 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800364 /* Set up to return from userspace. */
Andy Lutomirski6f121e52014-05-05 12:19:34 -0700365 restorer = current->mm->context.vdso +
366 selected_vdso32->sym___kernel_sigreturn;
Al Viro235b8022012-11-09 23:51:47 -0500367 if (ksig->ka.sa.sa_flags & SA_RESTORER)
368 restorer = ksig->ka.sa.sa_restorer;
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800369 put_user_ex(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100370
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800371 /*
372 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
373 *
374 * WE DO NOT USE IT ANY MORE! It's only left here for historical
375 * reasons and because gdb uses it as a signature to notice
376 * signal handler stack frames.
377 */
378 put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
379 } put_user_catch(err);
H. Peter Anvin49b8c6952012-09-21 17:18:44 -0700380
Al Viro235b8022012-11-09 23:51:47 -0500381 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
H. Peter Anvin5e883532012-09-21 12:43:15 -0700382 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
383 regs, set->sig[0]);
384 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
386 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700387 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
389 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100390 regs->sp = (unsigned long)frame;
Al Viro235b8022012-11-09 23:51:47 -0500391 regs->ip = (unsigned long)ksig->ka.sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700392 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100393 regs->dx = (unsigned long)&frame->info;
394 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100396 regs->ds = __USER_DS;
397 regs->es = __USER_DS;
398 regs->ss = __USER_DS;
399 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
David Howells283828f2006-01-18 17:44:00 -0800401 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402}
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800403#else /* !CONFIG_X86_32 */
Al Viro235b8022012-11-09 23:51:47 -0500404static int __setup_rt_frame(int sig, struct ksignal *ksig,
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800405 sigset_t *set, struct pt_regs *regs)
406{
407 struct rt_sigframe __user *frame;
408 void __user *fp = NULL;
409 int err = 0;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800410
Al Viro235b8022012-11-09 23:51:47 -0500411 frame = get_sigframe(&ksig->ka, regs, sizeof(struct rt_sigframe), &fp);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800412
413 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
414 return -EFAULT;
415
Al Viro235b8022012-11-09 23:51:47 -0500416 if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
417 if (copy_siginfo_to_user(&frame->info, &ksig->info))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800418 return -EFAULT;
419 }
420
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800421 put_user_try {
422 /* Create the ucontext. */
423 if (cpu_has_xsave)
424 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
425 else
426 put_user_ex(0, &frame->uc.uc_flags);
427 put_user_ex(0, &frame->uc.uc_link);
Al Virobd1c149a2013-09-01 20:35:01 +0100428 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800429
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800430 /* Set up to return from userspace. If provided, use a stub
431 already in userspace. */
432 /* x86-64 should always use SA_RESTORER. */
Al Viro235b8022012-11-09 23:51:47 -0500433 if (ksig->ka.sa.sa_flags & SA_RESTORER) {
434 put_user_ex(ksig->ka.sa.sa_restorer, &frame->pretcode);
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800435 } else {
436 /* could use a vstub here */
437 err |= -EFAULT;
438 }
439 } put_user_catch(err);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800440
H. Peter Anvin5e883532012-09-21 12:43:15 -0700441 err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
442 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
443
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800444 if (err)
445 return -EFAULT;
446
447 /* Set up registers for signal handler */
448 regs->di = sig;
449 /* In case the signal handler was declared without prototypes */
450 regs->ax = 0;
451
452 /* This also works for non SA_SIGINFO handlers because they expect the
453 next argument after the signal number on the stack. */
454 regs->si = (unsigned long)&frame->info;
455 regs->dx = (unsigned long)&frame->uc;
Al Viro235b8022012-11-09 23:51:47 -0500456 regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800457
458 regs->sp = (unsigned long)frame;
459
460 /* Set up the CS register to run signal handlers in 64-bit mode,
461 even if the handler happens to be interrupting 32-bit code. */
462 regs->cs = __USER_CS;
463
464 return 0;
465}
466#endif /* CONFIG_X86_32 */
467
Al Viro235b8022012-11-09 23:51:47 -0500468static int x32_setup_rt_frame(struct ksignal *ksig,
469 compat_sigset_t *set,
Suresh Siddha050902c2012-07-24 16:05:27 -0700470 struct pt_regs *regs)
471{
472#ifdef CONFIG_X86_X32_ABI
473 struct rt_sigframe_x32 __user *frame;
474 void __user *restorer;
475 int err = 0;
476 void __user *fpstate = NULL;
477
Al Viro235b8022012-11-09 23:51:47 -0500478 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
Suresh Siddha050902c2012-07-24 16:05:27 -0700479
480 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
481 return -EFAULT;
482
Al Viro235b8022012-11-09 23:51:47 -0500483 if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
484 if (copy_siginfo_to_user32(&frame->info, &ksig->info))
Suresh Siddha050902c2012-07-24 16:05:27 -0700485 return -EFAULT;
486 }
487
488 put_user_try {
489 /* Create the ucontext. */
490 if (cpu_has_xsave)
491 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
492 else
493 put_user_ex(0, &frame->uc.uc_flags);
494 put_user_ex(0, &frame->uc.uc_link);
Al Virobd1c149a2013-09-01 20:35:01 +0100495 compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
Suresh Siddha050902c2012-07-24 16:05:27 -0700496 put_user_ex(0, &frame->uc.uc__pad0);
Suresh Siddha050902c2012-07-24 16:05:27 -0700497
Al Viro235b8022012-11-09 23:51:47 -0500498 if (ksig->ka.sa.sa_flags & SA_RESTORER) {
499 restorer = ksig->ka.sa.sa_restorer;
Suresh Siddha050902c2012-07-24 16:05:27 -0700500 } else {
501 /* could use a vstub here */
502 restorer = NULL;
503 err |= -EFAULT;
504 }
505 put_user_ex(restorer, &frame->pretcode);
506 } put_user_catch(err);
507
H. Peter Anvin49b8c6952012-09-21 17:18:44 -0700508 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
509 regs, set->sig[0]);
510 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
511
Suresh Siddha050902c2012-07-24 16:05:27 -0700512 if (err)
513 return -EFAULT;
514
515 /* Set up registers for signal handler */
516 regs->sp = (unsigned long) frame;
Al Viro235b8022012-11-09 23:51:47 -0500517 regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
Suresh Siddha050902c2012-07-24 16:05:27 -0700518
519 /* We use the x32 calling convention here... */
Al Viro235b8022012-11-09 23:51:47 -0500520 regs->di = ksig->sig;
Suresh Siddha050902c2012-07-24 16:05:27 -0700521 regs->si = (unsigned long) &frame->info;
522 regs->dx = (unsigned long) &frame->uc;
523
524 loadsegment(ds, __USER_DS);
525 loadsegment(es, __USER_DS);
526
527 regs->cs = __USER_CS;
528 regs->ss = __USER_DS;
529#endif /* CONFIG_X86_X32_ABI */
530
531 return 0;
532}
533
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800534/*
535 * Do a signal return; undo the signal stack.
536 */
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800537#ifdef CONFIG_X86_32
Andi Kleenff491032013-08-05 15:02:40 -0700538asmlinkage unsigned long sys_sigreturn(void)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800539{
Al Viro3fe26fa2012-11-12 14:32:42 -0500540 struct pt_regs *regs = current_pt_regs();
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800541 struct sigframe __user *frame;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800542 unsigned long ax;
543 sigset_t set;
544
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800545 frame = (struct sigframe __user *)(regs->sp - 8);
546
547 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
548 goto badframe;
549 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
550 && __copy_from_user(&set.sig[1], &frame->extramask,
551 sizeof(frame->extramask))))
552 goto badframe;
553
Oleg Nesterov39822942011-07-10 21:27:27 +0200554 set_current_blocked(&set);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800555
556 if (restore_sigcontext(regs, &frame->sc, &ax))
557 goto badframe;
558 return ax;
559
560badframe:
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800561 signal_fault(regs, frame, "sigreturn");
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800562
563 return 0;
564}
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800565#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800566
Andi Kleenff491032013-08-05 15:02:40 -0700567asmlinkage long sys_rt_sigreturn(void)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800568{
Al Viro3fe26fa2012-11-12 14:32:42 -0500569 struct pt_regs *regs = current_pt_regs();
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800570 struct rt_sigframe __user *frame;
571 unsigned long ax;
572 sigset_t set;
573
574 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
575 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
576 goto badframe;
577 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
578 goto badframe;
579
Oleg Nesterove9bd3f02011-04-27 21:09:39 +0200580 set_current_blocked(&set);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800581
582 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
583 goto badframe;
584
Al Viroc40702c2012-11-20 14:24:26 -0500585 if (restore_altstack(&frame->uc.uc_stack))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800586 goto badframe;
587
588 return ax;
589
590badframe:
591 signal_fault(regs, frame, "rt_sigreturn");
592 return 0;
593}
594
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100596 * OK, we're invoking a handler:
597 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700598static int signr_convert(int sig)
599{
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700600#ifdef CONFIG_X86_32
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700601 struct thread_info *info = current_thread_info();
602
603 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
604 return info->exec_domain->signal_invmap[sig];
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700605#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700606 return sig;
607}
608
Roland McGrath7c1def12005-06-23 00:08:21 -0700609static int
Al Viro235b8022012-11-09 23:51:47 -0500610setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700611{
Al Viro235b8022012-11-09 23:51:47 -0500612 int usig = signr_convert(ksig->sig);
Al Virob7f9a112012-05-02 09:59:21 -0400613 sigset_t *set = sigmask_to_save();
Suresh Siddha050902c2012-07-24 16:05:27 -0700614 compat_sigset_t *cset = (compat_sigset_t *) set;
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700615
616 /* Set up the stack frame */
Suresh Siddha050902c2012-07-24 16:05:27 -0700617 if (is_ia32_frame()) {
Al Viro235b8022012-11-09 23:51:47 -0500618 if (ksig->ka.sa.sa_flags & SA_SIGINFO)
619 return ia32_setup_rt_frame(usig, ksig, cset, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700620 else
Al Viro235b8022012-11-09 23:51:47 -0500621 return ia32_setup_frame(usig, ksig, cset, regs);
Suresh Siddha050902c2012-07-24 16:05:27 -0700622 } else if (is_x32_frame()) {
Al Viro235b8022012-11-09 23:51:47 -0500623 return x32_setup_rt_frame(ksig, cset, regs);
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800624 } else {
Al Viro235b8022012-11-09 23:51:47 -0500625 return __setup_rt_frame(ksig->sig, ksig, set, regs);
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800626 }
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700627}
628
Al Viroa610d6e2012-05-21 23:42:15 -0400629static void
Al Viro235b8022012-11-09 23:51:47 -0500630handle_signal(struct ksignal *ksig, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631{
Al Viro235b8022012-11-09 23:51:47 -0500632 bool failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700634 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700636 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800637 case -ERESTART_RESTARTBLOCK:
638 case -ERESTARTNOHAND:
639 regs->ax = -EINTR;
640 break;
641
642 case -ERESTARTSYS:
Al Viro235b8022012-11-09 23:51:47 -0500643 if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100644 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800646 }
647 /* fallthrough */
648 case -ERESTARTNOINTR:
649 regs->ax = regs->orig_ax;
650 regs->ip -= 2;
651 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653 }
654
655 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100656 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
657 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100659 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100660 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100661 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Al Viro235b8022012-11-09 23:51:47 -0500663 failed = (setup_rt_frame(ksig, regs) < 0);
664 if (!failed) {
665 /*
666 * Clear the direction flag as per the ABI for function entry.
Jiri Olsaddd40da2013-05-01 17:25:43 +0200667 *
Jiri Olsa24cda102013-05-01 17:25:42 +0200668 * Clear RF when entering the signal handler, because
669 * it might disable possible debug exception from the
670 * signal handler.
Jiri Olsaddd40da2013-05-01 17:25:43 +0200671 *
Al Viro235b8022012-11-09 23:51:47 -0500672 * Clear TF when entering the signal handler, but
673 * notify any tracer that was single-stepping it.
674 * The tracer may want to single-step inside the
675 * handler too.
676 */
Jiri Olsaddd40da2013-05-01 17:25:43 +0200677 regs->flags &= ~(X86_EFLAGS_DF|X86_EFLAGS_RF|X86_EFLAGS_TF);
Al Viroa610d6e2012-05-21 23:42:15 -0400678 }
Al Viro235b8022012-11-09 23:51:47 -0500679 signal_setup_done(failed, ksig, test_thread_flag(TIF_SINGLESTEP));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680}
681
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700682#ifdef CONFIG_X86_32
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700683#define NR_restart_syscall __NR_restart_syscall
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700684#else /* !CONFIG_X86_32 */
685#define NR_restart_syscall \
686 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
687#endif /* CONFIG_X86_32 */
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689/*
690 * Note that 'init' is a special process: it doesn't get signals it doesn't
691 * want to handle. Thus you cannot kill init even with a SIGKILL even by
692 * mistake.
693 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100694static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
Al Viro235b8022012-11-09 23:51:47 -0500696 struct ksignal ksig;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
Al Viro235b8022012-11-09 23:51:47 -0500698 if (get_signal(&ksig)) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100699 /* Whee! Actually deliver the signal. */
Al Viro235b8022012-11-09 23:51:47 -0500700 handle_signal(&ksig, regs);
David Howells283828f2006-01-18 17:44:00 -0800701 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 }
703
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700705 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700707 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800708 case -ERESTARTNOHAND:
709 case -ERESTARTSYS:
710 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100711 regs->ax = regs->orig_ax;
712 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800713 break;
714
715 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700716 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100717 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800718 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 }
720 }
David Howells283828f2006-01-18 17:44:00 -0800721
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800722 /*
723 * If there's no signal to deliver, we just put the saved sigmask
724 * back.
725 */
Al Viro51a7b442012-05-21 23:33:55 -0400726 restore_saved_sigmask();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727}
728
729/*
730 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800731 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 */
Andi Kleen277d5b42013-08-05 15:02:43 -0700733__visible void
Ingo Molnar7e907f42008-03-06 10:33:08 +0100734do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735{
Frederic Weisbecker91d1aa432012-11-27 19:33:25 +0100736 user_exit();
Frederic Weisbeckeredf55fd2012-07-11 20:26:39 +0200737
Andi Kleenc1ebf832009-07-09 00:31:41 +0200738#ifdef CONFIG_X86_MCE
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700739 /* notify userspace of pending MCEs */
740 if (thread_info_flags & _TIF_MCE_NOTIFY)
Andi Kleen9b1beaf2009-05-27 21:56:59 +0200741 mce_notify_process();
Hiroshi Shimamotoee847c52008-09-23 17:21:45 -0700742#endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
743
Oleg Nesterovdb023ea2012-09-14 19:05:46 +0200744 if (thread_info_flags & _TIF_UPROBE)
Srikar Dronamraju0326f5a2012-03-13 23:30:11 +0530745 uprobe_notify_resume(regs);
Srikar Dronamraju0326f5a2012-03-13 23:30:11 +0530746
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700748 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800749 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100750
Roland McGrath59e52132008-04-19 19:10:57 -0700751 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
752 clear_thread_flag(TIF_NOTIFY_RESUME);
753 tracehook_notify_resume(regs);
754 }
Avi Kivity7c68af62009-09-19 09:40:22 +0300755 if (thread_info_flags & _TIF_USER_RETURN_NOTIFY)
756 fire_user_return_notifiers();
Roland McGrath59e52132008-04-19 19:10:57 -0700757
Frederic Weisbecker91d1aa432012-11-27 19:33:25 +0100758 user_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700760
761void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
762{
763 struct task_struct *me = current;
764
765 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800766 printk("%s"
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700767 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800768 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700769 me->comm, me->pid, where, frame,
770 regs->ip, regs->sp, regs->orig_ax);
771 print_vma_addr(" in ", regs->ip);
Joe Perchesc767a542012-05-21 19:50:07 -0700772 pr_cont("\n");
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700773 }
774
775 force_sig(SIGSEGV, me);
776}
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800777
778#ifdef CONFIG_X86_X32_ABI
Al Viro3fe26fa2012-11-12 14:32:42 -0500779asmlinkage long sys32_x32_rt_sigreturn(void)
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800780{
Al Viro3fe26fa2012-11-12 14:32:42 -0500781 struct pt_regs *regs = current_pt_regs();
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800782 struct rt_sigframe_x32 __user *frame;
783 sigset_t set;
784 unsigned long ax;
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800785
786 frame = (struct rt_sigframe_x32 __user *)(regs->sp - 8);
787
788 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
789 goto badframe;
790 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
791 goto badframe;
792
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800793 set_current_blocked(&set);
794
795 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
796 goto badframe;
797
Al Viro90268432012-12-14 14:47:53 -0500798 if (compat_restore_altstack(&frame->uc.uc_stack))
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800799 goto badframe;
800
801 return ax;
802
803badframe:
804 signal_fault(regs, frame, "x32 rt_sigreturn");
805 return 0;
806}
807#endif