blob: eaa2c5e3f2cd5c81616a27b61a0e2b69dad39ee6 [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 */
Andy Lutomirskif56141e2015-02-12 15:01:14 -080072 current->restart_block.fn = do_no_restart_syscall;
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080073
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
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -080097 COPY_SEG_CPL3(cs);
98 COPY_SEG_CPL3(ss);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -080099
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800100 get_user_ex(tmpflags, &sc->flags);
101 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
102 regs->orig_ax = -1; /* disable syscall checks */
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800103
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800104 get_user_ex(buf, &sc->fpstate);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800105
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800106 get_user_ex(*pax, &sc->ax);
107 } get_user_catch(err);
108
H. Peter Anvin49b8c6952012-09-21 17:18:44 -0700109 err |= restore_xstate_sig(buf, config_enabled(CONFIG_X86_32));
H. Peter Anvin5e883532012-09-21 12:43:15 -0700110
Brian Gerst1daeaa32015-03-21 18:54:21 -0400111 force_iret();
112
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800113 return err;
114}
115
H. Peter Anvin85139422012-02-19 07:43:09 -0800116int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
117 struct pt_regs *regs, unsigned long mask)
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800118{
119 int err = 0;
120
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800121 put_user_try {
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800122
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800123#ifdef CONFIG_X86_32
Tejun Heod9a89a22009-02-09 22:17:40 +0900124 put_user_ex(get_user_gs(regs), (unsigned int __user *)&sc->gs);
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800125 put_user_ex(regs->fs, (unsigned int __user *)&sc->fs);
126 put_user_ex(regs->es, (unsigned int __user *)&sc->es);
127 put_user_ex(regs->ds, (unsigned int __user *)&sc->ds);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800128#endif /* CONFIG_X86_32 */
129
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800130 put_user_ex(regs->di, &sc->di);
131 put_user_ex(regs->si, &sc->si);
132 put_user_ex(regs->bp, &sc->bp);
133 put_user_ex(regs->sp, &sc->sp);
134 put_user_ex(regs->bx, &sc->bx);
135 put_user_ex(regs->dx, &sc->dx);
136 put_user_ex(regs->cx, &sc->cx);
137 put_user_ex(regs->ax, &sc->ax);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800138#ifdef CONFIG_X86_64
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800139 put_user_ex(regs->r8, &sc->r8);
140 put_user_ex(regs->r9, &sc->r9);
141 put_user_ex(regs->r10, &sc->r10);
142 put_user_ex(regs->r11, &sc->r11);
143 put_user_ex(regs->r12, &sc->r12);
144 put_user_ex(regs->r13, &sc->r13);
145 put_user_ex(regs->r14, &sc->r14);
146 put_user_ex(regs->r15, &sc->r15);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800147#endif /* CONFIG_X86_64 */
148
Srikar Dronamraju51e7dc72012-03-12 14:55:55 +0530149 put_user_ex(current->thread.trap_nr, &sc->trapno);
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800150 put_user_ex(current->thread.error_code, &sc->err);
151 put_user_ex(regs->ip, &sc->ip);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800152#ifdef CONFIG_X86_32
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800153 put_user_ex(regs->cs, (unsigned int __user *)&sc->cs);
154 put_user_ex(regs->flags, &sc->flags);
155 put_user_ex(regs->sp, &sc->sp_at_signal);
156 put_user_ex(regs->ss, (unsigned int __user *)&sc->ss);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800157#else /* !CONFIG_X86_32 */
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800158 put_user_ex(regs->flags, &sc->flags);
159 put_user_ex(regs->cs, &sc->cs);
Andy Lutomirski9a036b932015-03-12 13:57:52 -0700160 put_user_ex(0, &sc->__pad2);
161 put_user_ex(0, &sc->__pad1);
Andy Lutomirskic6f20622015-03-12 13:57:51 -0700162 put_user_ex(regs->ss, &sc->ss);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800163#endif /* CONFIG_X86_32 */
164
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800165 put_user_ex(fpstate, &sc->fpstate);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800166
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800167 /* non-iBCS2 extensions.. */
168 put_user_ex(mask, &sc->oldmask);
169 put_user_ex(current->thread.cr2, &sc->cr2);
170 } put_user_catch(err);
Hiroshi Shimamoto26016572008-11-24 18:21:37 -0800171
172 return err;
173}
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 * Set up a signal frame.
177 */
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800178
179/*
180 * Determine which stack to use..
181 */
Hiroshi Shimamoto1fae0272009-02-27 10:30:32 -0800182static unsigned long align_sigframe(unsigned long sp)
183{
184#ifdef CONFIG_X86_32
185 /*
186 * Align the stack pointer according to the i386 ABI,
187 * i.e. so that on function entry ((sp + 4) & 15) == 0.
188 */
189 sp = ((sp + 4) & -16ul) - 4;
190#else /* !CONFIG_X86_32 */
191 sp = round_down(sp, 16) - 8;
192#endif
193 return sp;
194}
195
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800196static inline void __user *
197get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
198 void __user **fpstate)
199{
200 /* Default to using normal stack */
Suresh Siddha72a671c2012-07-24 16:05:29 -0700201 unsigned long math_size = 0;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800202 unsigned long sp = regs->sp;
Suresh Siddha72a671c2012-07-24 16:05:29 -0700203 unsigned long buf_fx = 0;
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700204 int onsigstack = on_sig_stack(sp);
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800205
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800206 /* redzone */
Suresh Siddha050902c2012-07-24 16:05:27 -0700207 if (config_enabled(CONFIG_X86_64))
208 sp -= 128;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800209
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700210 if (!onsigstack) {
211 /* This is the X/Open sanctioned signal stack switching. */
212 if (ka->sa.sa_flags & SA_ONSTACK) {
Hiroshi Shimamoto0f8f3082009-03-26 10:03:08 -0700213 if (current->sas_ss_size)
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700214 sp = current->sas_ss_sp + current->sas_ss_size;
Suresh Siddha050902c2012-07-24 16:05:27 -0700215 } else if (config_enabled(CONFIG_X86_32) &&
216 (regs->ss & 0xffff) != __USER_DS &&
217 !(ka->sa.sa_flags & SA_RESTORER) &&
218 ka->sa.sa_restorer) {
219 /* This is the legacy signal stack switching. */
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700220 sp = (unsigned long) ka->sa.sa_restorer;
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700221 }
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800222 }
223
224 if (used_math()) {
Suresh Siddha72a671c2012-07-24 16:05:29 -0700225 sp = alloc_mathframe(sp, config_enabled(CONFIG_X86_32),
226 &buf_fx, &math_size);
Hiroshi Shimamoto25051702009-03-02 17:20:01 -0800227 *fpstate = (void __user *)sp;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800228 }
229
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700230 sp = align_sigframe(sp - frame_size);
231
232 /*
233 * If we are on the alternate signal stack and would overflow it, don't.
234 * Return an always-bogus address instead so we will die with SIGSEGV.
235 */
236 if (onsigstack && !likely(on_sig_stack(sp)))
237 return (void __user *)-1L;
238
Suresh Siddha72a671c2012-07-24 16:05:29 -0700239 /* save i387 and extended state */
240 if (used_math() &&
241 save_xstate_sig(*fpstate, (void __user *)buf_fx, math_size) < 0)
Hiroshi Shimamoto14fc9fb2009-03-19 10:56:29 -0700242 return (void __user *)-1L;
243
244 return (void __user *)sp;
Hiroshi Shimamoto75779f02009-02-27 10:29:57 -0800245}
246
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800247#ifdef CONFIG_X86_32
248static const struct {
249 u16 poplmovl;
250 u32 val;
251 u16 int80;
252} __attribute__((packed)) retcode = {
253 0xb858, /* popl %eax; movl $..., %eax */
254 __NR_sigreturn,
255 0x80cd, /* int $0x80 */
256};
257
258static const struct {
259 u8 movl;
260 u32 val;
261 u16 int80;
262 u8 pad;
263} __attribute__((packed)) rt_retcode = {
264 0xb8, /* movl $..., %eax */
265 __NR_rt_sigreturn,
266 0x80cd, /* int $0x80 */
267 0
268};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Ingo Molnar7e907f42008-03-06 10:33:08 +0100270static int
Al Viro235b8022012-11-09 23:51:47 -0500271__setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700272 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 struct sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100275 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700277 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Al Viro235b8022012-11-09 23:51:47 -0500279 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700282 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700284 if (__put_user(sig, &frame->sig))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700285 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700287 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700288 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290 if (_NSIG_WORDS > 1) {
Hiroshi Shimamoto2ba48e12008-09-12 17:02:53 -0700291 if (__copy_to_user(&frame->extramask, &set->sig[1],
292 sizeof(frame->extramask)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700293 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 }
295
Roland McGrath1a3e4ca2008-04-09 01:29:27 -0700296 if (current->mm->context.vdso)
Andy Lutomirski6f121e52014-05-05 12:19:34 -0700297 restorer = current->mm->context.vdso +
298 selected_vdso32->sym___kernel_sigreturn;
Andi Kleen9fbbd4d2007-02-13 13:26:26 +0100299 else
Jan Engelhardtade1af72008-01-30 13:33:23 +0100300 restorer = &frame->retcode;
Al Viro235b8022012-11-09 23:51:47 -0500301 if (ksig->ka.sa.sa_flags & SA_RESTORER)
302 restorer = ksig->ka.sa.sa_restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304 /* Set up to return from userspace. */
305 err |= __put_user(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 /*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100308 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 *
310 * WE DO NOT USE IT ANY MORE! It's only left here for historical
311 * reasons and because gdb uses it as a signature to notice
312 * signal handler stack frames.
313 */
Hiroshi Shimamoto4a612042008-11-11 19:09:29 -0800314 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
316 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700317 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100320 regs->sp = (unsigned long)frame;
Al Viro235b8022012-11-09 23:51:47 -0500321 regs->ip = (unsigned long)ksig->ka.sa.sa_handler;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100322 regs->ax = (unsigned long)sig;
Harvey Harrison92bc2052008-02-08 12:09:56 -0800323 regs->dx = 0;
324 regs->cx = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100326 regs->ds = __USER_DS;
327 regs->es = __USER_DS;
328 regs->ss = __USER_DS;
329 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
David Howells283828f2006-01-18 17:44:00 -0800331 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
Al Viro235b8022012-11-09 23:51:47 -0500334static int __setup_rt_frame(int sig, struct ksignal *ksig,
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700335 sigset_t *set, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 struct rt_sigframe __user *frame;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100338 void __user *restorer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 int err = 0;
Suresh Siddhaab513702008-07-29 10:29:22 -0700340 void __user *fpstate = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Al Viro235b8022012-11-09 23:51:47 -0500342 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700345 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800347 put_user_try {
348 put_user_ex(sig, &frame->sig);
349 put_user_ex(&frame->info, &frame->pinfo);
350 put_user_ex(&frame->uc, &frame->puc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800352 /* Create the ucontext. */
353 if (cpu_has_xsave)
354 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
355 else
356 put_user_ex(0, &frame->uc.uc_flags);
357 put_user_ex(0, &frame->uc.uc_link);
Al Virobd1c149a2013-09-01 20:35:01 +0100358 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800360 /* Set up to return from userspace. */
Andy Lutomirski6f121e52014-05-05 12:19:34 -0700361 restorer = current->mm->context.vdso +
Andy Lutomirski6ba19a62014-06-21 07:31:55 -0700362 selected_vdso32->sym___kernel_rt_sigreturn;
Al Viro235b8022012-11-09 23:51:47 -0500363 if (ksig->ka.sa.sa_flags & SA_RESTORER)
364 restorer = ksig->ka.sa.sa_restorer;
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800365 put_user_ex(restorer, &frame->pretcode);
Ingo Molnar7e907f42008-03-06 10:33:08 +0100366
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800367 /*
368 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
369 *
370 * WE DO NOT USE IT ANY MORE! It's only left here for historical
371 * reasons and because gdb uses it as a signature to notice
372 * signal handler stack frames.
373 */
374 put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
375 } put_user_catch(err);
H. Peter Anvin49b8c6952012-09-21 17:18:44 -0700376
Al Viro235b8022012-11-09 23:51:47 -0500377 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
H. Peter Anvin5e883532012-09-21 12:43:15 -0700378 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
379 regs, set->sig[0]);
380 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382 if (err)
Hiroshi Shimamoto3d0aedd2008-09-12 17:01:09 -0700383 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385 /* Set up registers for signal handler */
Ingo Molnar7e907f42008-03-06 10:33:08 +0100386 regs->sp = (unsigned long)frame;
Al Viro235b8022012-11-09 23:51:47 -0500387 regs->ip = (unsigned long)ksig->ka.sa.sa_handler;
Hiroshi Shimamoto13ad7722008-09-05 16:28:38 -0700388 regs->ax = (unsigned long)sig;
Ingo Molnar7e907f42008-03-06 10:33:08 +0100389 regs->dx = (unsigned long)&frame->info;
390 regs->cx = (unsigned long)&frame->uc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100392 regs->ds = __USER_DS;
393 regs->es = __USER_DS;
394 regs->ss = __USER_DS;
395 regs->cs = __USER_CS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
David Howells283828f2006-01-18 17:44:00 -0800397 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398}
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800399#else /* !CONFIG_X86_32 */
Al Viro235b8022012-11-09 23:51:47 -0500400static int __setup_rt_frame(int sig, struct ksignal *ksig,
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800401 sigset_t *set, struct pt_regs *regs)
402{
403 struct rt_sigframe __user *frame;
404 void __user *fp = NULL;
405 int err = 0;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800406
Al Viro235b8022012-11-09 23:51:47 -0500407 frame = get_sigframe(&ksig->ka, regs, sizeof(struct rt_sigframe), &fp);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800408
409 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
410 return -EFAULT;
411
Al Viro235b8022012-11-09 23:51:47 -0500412 if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
413 if (copy_siginfo_to_user(&frame->info, &ksig->info))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800414 return -EFAULT;
415 }
416
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800417 put_user_try {
418 /* Create the ucontext. */
419 if (cpu_has_xsave)
420 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
421 else
422 put_user_ex(0, &frame->uc.uc_flags);
423 put_user_ex(0, &frame->uc.uc_link);
Al Virobd1c149a2013-09-01 20:35:01 +0100424 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800425
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800426 /* Set up to return from userspace. If provided, use a stub
427 already in userspace. */
428 /* x86-64 should always use SA_RESTORER. */
Al Viro235b8022012-11-09 23:51:47 -0500429 if (ksig->ka.sa.sa_flags & SA_RESTORER) {
430 put_user_ex(ksig->ka.sa.sa_restorer, &frame->pretcode);
Hiroshi Shimamoto98e3d452009-01-23 15:50:10 -0800431 } else {
432 /* could use a vstub here */
433 err |= -EFAULT;
434 }
435 } put_user_catch(err);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800436
H. Peter Anvin5e883532012-09-21 12:43:15 -0700437 err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
438 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
439
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800440 if (err)
441 return -EFAULT;
442
443 /* Set up registers for signal handler */
444 regs->di = sig;
445 /* In case the signal handler was declared without prototypes */
446 regs->ax = 0;
447
448 /* This also works for non SA_SIGINFO handlers because they expect the
449 next argument after the signal number on the stack. */
450 regs->si = (unsigned long)&frame->info;
451 regs->dx = (unsigned long)&frame->uc;
Al Viro235b8022012-11-09 23:51:47 -0500452 regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800453
454 regs->sp = (unsigned long)frame;
455
Andy Lutomirskic6f20622015-03-12 13:57:51 -0700456 /*
457 * Set up the CS and SS registers to run signal handlers in
458 * 64-bit mode, even if the handler happens to be interrupting
459 * 32-bit or 16-bit code.
460 *
461 * SS is subtle. In 64-bit mode, we don't need any particular
462 * SS descriptor, but we do need SS to be valid. It's possible
463 * that the old SS is entirely bogus -- this can happen if the
464 * signal we're trying to deliver is #GP or #SS caused by a bad
465 * SS value.
466 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800467 regs->cs = __USER_CS;
Andy Lutomirskic6f20622015-03-12 13:57:51 -0700468 regs->ss = __USER_DS;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800469
470 return 0;
471}
472#endif /* CONFIG_X86_32 */
473
Al Viro235b8022012-11-09 23:51:47 -0500474static int x32_setup_rt_frame(struct ksignal *ksig,
475 compat_sigset_t *set,
Suresh Siddha050902c2012-07-24 16:05:27 -0700476 struct pt_regs *regs)
477{
478#ifdef CONFIG_X86_X32_ABI
479 struct rt_sigframe_x32 __user *frame;
480 void __user *restorer;
481 int err = 0;
482 void __user *fpstate = NULL;
483
Al Viro235b8022012-11-09 23:51:47 -0500484 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
Suresh Siddha050902c2012-07-24 16:05:27 -0700485
486 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
487 return -EFAULT;
488
Al Viro235b8022012-11-09 23:51:47 -0500489 if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
490 if (copy_siginfo_to_user32(&frame->info, &ksig->info))
Suresh Siddha050902c2012-07-24 16:05:27 -0700491 return -EFAULT;
492 }
493
494 put_user_try {
495 /* Create the ucontext. */
496 if (cpu_has_xsave)
497 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
498 else
499 put_user_ex(0, &frame->uc.uc_flags);
500 put_user_ex(0, &frame->uc.uc_link);
Al Virobd1c149a2013-09-01 20:35:01 +0100501 compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
Suresh Siddha050902c2012-07-24 16:05:27 -0700502 put_user_ex(0, &frame->uc.uc__pad0);
Suresh Siddha050902c2012-07-24 16:05:27 -0700503
Al Viro235b8022012-11-09 23:51:47 -0500504 if (ksig->ka.sa.sa_flags & SA_RESTORER) {
505 restorer = ksig->ka.sa.sa_restorer;
Suresh Siddha050902c2012-07-24 16:05:27 -0700506 } else {
507 /* could use a vstub here */
508 restorer = NULL;
509 err |= -EFAULT;
510 }
511 put_user_ex(restorer, &frame->pretcode);
512 } put_user_catch(err);
513
H. Peter Anvin49b8c6952012-09-21 17:18:44 -0700514 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
515 regs, set->sig[0]);
516 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
517
Suresh Siddha050902c2012-07-24 16:05:27 -0700518 if (err)
519 return -EFAULT;
520
521 /* Set up registers for signal handler */
522 regs->sp = (unsigned long) frame;
Al Viro235b8022012-11-09 23:51:47 -0500523 regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
Suresh Siddha050902c2012-07-24 16:05:27 -0700524
525 /* We use the x32 calling convention here... */
Al Viro235b8022012-11-09 23:51:47 -0500526 regs->di = ksig->sig;
Suresh Siddha050902c2012-07-24 16:05:27 -0700527 regs->si = (unsigned long) &frame->info;
528 regs->dx = (unsigned long) &frame->uc;
529
530 loadsegment(ds, __USER_DS);
531 loadsegment(es, __USER_DS);
532
533 regs->cs = __USER_CS;
534 regs->ss = __USER_DS;
535#endif /* CONFIG_X86_X32_ABI */
536
537 return 0;
538}
539
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800540/*
541 * Do a signal return; undo the signal stack.
542 */
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800543#ifdef CONFIG_X86_32
Andi Kleenff491032013-08-05 15:02:40 -0700544asmlinkage unsigned long sys_sigreturn(void)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800545{
Al Viro3fe26fa2012-11-12 14:32:42 -0500546 struct pt_regs *regs = current_pt_regs();
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800547 struct sigframe __user *frame;
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800548 unsigned long ax;
549 sigset_t set;
550
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800551 frame = (struct sigframe __user *)(regs->sp - 8);
552
553 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
554 goto badframe;
555 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
556 && __copy_from_user(&set.sig[1], &frame->extramask,
557 sizeof(frame->extramask))))
558 goto badframe;
559
Oleg Nesterov39822942011-07-10 21:27:27 +0200560 set_current_blocked(&set);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800561
562 if (restore_sigcontext(regs, &frame->sc, &ax))
563 goto badframe;
564 return ax;
565
566badframe:
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800567 signal_fault(regs, frame, "sigreturn");
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800568
569 return 0;
570}
Hiroshi Shimamotoe5fa2d02008-11-24 18:24:11 -0800571#endif /* CONFIG_X86_32 */
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800572
Andi Kleenff491032013-08-05 15:02:40 -0700573asmlinkage long sys_rt_sigreturn(void)
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800574{
Al Viro3fe26fa2012-11-12 14:32:42 -0500575 struct pt_regs *regs = current_pt_regs();
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800576 struct rt_sigframe __user *frame;
577 unsigned long ax;
578 sigset_t set;
579
580 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
581 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
582 goto badframe;
583 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
584 goto badframe;
585
Oleg Nesterove9bd3f02011-04-27 21:09:39 +0200586 set_current_blocked(&set);
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800587
588 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
589 goto badframe;
590
Al Viroc40702c2012-11-20 14:24:26 -0500591 if (restore_altstack(&frame->uc.uc_stack))
Hiroshi Shimamotobfeb91a2008-11-24 18:23:12 -0800592 goto badframe;
593
594 return ax;
595
596badframe:
597 signal_fault(regs, frame, "rt_sigreturn");
598 return 0;
599}
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601/*
Ingo Molnar7e907f42008-03-06 10:33:08 +0100602 * OK, we're invoking a handler:
603 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700604static int signr_convert(int sig)
605{
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700606#ifdef CONFIG_X86_32
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700607 struct thread_info *info = current_thread_info();
608
609 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
610 return info->exec_domain->signal_invmap[sig];
Hiroshi Shimamoto96bf84b2008-10-29 18:44:08 -0700611#endif /* CONFIG_X86_32 */
Hiroshi Shimamoto8d8c13b2008-09-24 19:10:29 -0700612 return sig;
613}
614
Roland McGrath7c1def12005-06-23 00:08:21 -0700615static int
Al Viro235b8022012-11-09 23:51:47 -0500616setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700617{
Al Viro235b8022012-11-09 23:51:47 -0500618 int usig = signr_convert(ksig->sig);
Al Virob7f9a112012-05-02 09:59:21 -0400619 sigset_t *set = sigmask_to_save();
Suresh Siddha050902c2012-07-24 16:05:27 -0700620 compat_sigset_t *cset = (compat_sigset_t *) set;
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700621
622 /* Set up the stack frame */
Suresh Siddha050902c2012-07-24 16:05:27 -0700623 if (is_ia32_frame()) {
Al Viro235b8022012-11-09 23:51:47 -0500624 if (ksig->ka.sa.sa_flags & SA_SIGINFO)
625 return ia32_setup_rt_frame(usig, ksig, cset, regs);
Hiroshi Shimamoto455edbc2008-09-24 19:13:11 -0700626 else
Al Viro235b8022012-11-09 23:51:47 -0500627 return ia32_setup_frame(usig, ksig, cset, regs);
Suresh Siddha050902c2012-07-24 16:05:27 -0700628 } else if (is_x32_frame()) {
Al Viro235b8022012-11-09 23:51:47 -0500629 return x32_setup_rt_frame(ksig, cset, regs);
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800630 } else {
Al Viro235b8022012-11-09 23:51:47 -0500631 return __setup_rt_frame(ksig->sig, ksig, set, regs);
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800632 }
Hiroshi Shimamoto1d130242008-09-05 16:28:06 -0700633}
634
Al Viroa610d6e2012-05-21 23:42:15 -0400635static void
Al Viro235b8022012-11-09 23:51:47 -0500636handle_signal(struct ksignal *ksig, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
Al Viro235b8022012-11-09 23:51:47 -0500638 bool failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 /* Are we from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700640 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 /* If so, check system call restarting.. */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700642 switch (syscall_get_error(current, regs)) {
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800643 case -ERESTART_RESTARTBLOCK:
644 case -ERESTARTNOHAND:
645 regs->ax = -EINTR;
646 break;
647
648 case -ERESTARTSYS:
Al Viro235b8022012-11-09 23:51:47 -0500649 if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100650 regs->ax = -EINTR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 break;
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800652 }
653 /* fallthrough */
654 case -ERESTARTNOINTR:
655 regs->ax = regs->orig_ax;
656 regs->ip -= 2;
657 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 }
659 }
660
661 /*
Roland McGrathe1f28772008-01-30 13:30:50 +0100662 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
663 * flag so that register information in the sigcontext is correct.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 */
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100665 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
Roland McGrathe1f28772008-01-30 13:30:50 +0100666 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100667 regs->flags &= ~X86_EFLAGS_TF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Al Viro235b8022012-11-09 23:51:47 -0500669 failed = (setup_rt_frame(ksig, regs) < 0);
670 if (!failed) {
671 /*
672 * Clear the direction flag as per the ABI for function entry.
Jiri Olsaddd40da2013-05-01 17:25:43 +0200673 *
Jiri Olsa24cda102013-05-01 17:25:42 +0200674 * Clear RF when entering the signal handler, because
675 * it might disable possible debug exception from the
676 * signal handler.
Jiri Olsaddd40da2013-05-01 17:25:43 +0200677 *
Al Viro235b8022012-11-09 23:51:47 -0500678 * Clear TF when entering the signal handler, but
679 * notify any tracer that was single-stepping it.
680 * The tracer may want to single-step inside the
681 * handler too.
682 */
Jiri Olsaddd40da2013-05-01 17:25:43 +0200683 regs->flags &= ~(X86_EFLAGS_DF|X86_EFLAGS_RF|X86_EFLAGS_TF);
Oleg Nesterov66463db2014-09-02 19:57:13 +0200684 /*
685 * Ensure the signal handler starts with the new fpu state.
686 */
687 if (used_math())
688 drop_init_fpu(current);
Al Viroa610d6e2012-05-21 23:42:15 -0400689 }
Al Viro235b8022012-11-09 23:51:47 -0500690 signal_setup_done(failed, ksig, test_thread_flag(TIF_SINGLESTEP));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691}
692
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700693#ifdef CONFIG_X86_32
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700694#define NR_restart_syscall __NR_restart_syscall
Hiroshi Shimamoto57917752008-10-29 18:46:40 -0700695#else /* !CONFIG_X86_32 */
696#define NR_restart_syscall \
697 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
698#endif /* CONFIG_X86_32 */
699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700/*
701 * Note that 'init' is a special process: it doesn't get signals it doesn't
702 * want to handle. Thus you cannot kill init even with a SIGKILL even by
703 * mistake.
704 */
Harvey Harrison75604d72008-01-30 13:31:17 +0100705static void do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706{
Al Viro235b8022012-11-09 23:51:47 -0500707 struct ksignal ksig;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
Al Viro235b8022012-11-09 23:51:47 -0500709 if (get_signal(&ksig)) {
Ingo Molnar7e907f42008-03-06 10:33:08 +0100710 /* Whee! Actually deliver the signal. */
Al Viro235b8022012-11-09 23:51:47 -0500711 handle_signal(&ksig, regs);
David Howells283828f2006-01-18 17:44:00 -0800712 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 }
714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 /* Did we come from a system call? */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700716 if (syscall_get_nr(current, regs) >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 /* Restart the system call - no handlers present */
Hiroshi Shimamotobb579252008-09-05 16:26:55 -0700718 switch (syscall_get_error(current, regs)) {
David Howells283828f2006-01-18 17:44:00 -0800719 case -ERESTARTNOHAND:
720 case -ERESTARTSYS:
721 case -ERESTARTNOINTR:
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100722 regs->ax = regs->orig_ax;
723 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800724 break;
725
726 case -ERESTART_RESTARTBLOCK:
Hiroshi Shimamoto8fcd8e22008-09-05 16:27:39 -0700727 regs->ax = NR_restart_syscall;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +0100728 regs->ip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800729 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 }
731 }
David Howells283828f2006-01-18 17:44:00 -0800732
Harvey Harrisonac66f3f2008-02-08 12:09:58 -0800733 /*
734 * If there's no signal to deliver, we just put the saved sigmask
735 * back.
736 */
Al Viro51a7b442012-05-21 23:33:55 -0400737 restore_saved_sigmask();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738}
739
740/*
741 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800742 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 */
Andi Kleen277d5b42013-08-05 15:02:43 -0700744__visible void
Ingo Molnar7e907f42008-03-06 10:33:08 +0100745do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746{
Frederic Weisbecker91d1aa432012-11-27 19:33:25 +0100747 user_exit();
Frederic Weisbeckeredf55fd2012-07-11 20:26:39 +0200748
Oleg Nesterovdb023ea2012-09-14 19:05:46 +0200749 if (thread_info_flags & _TIF_UPROBE)
Srikar Dronamraju0326f5a2012-03-13 23:30:11 +0530750 uprobe_notify_resume(regs);
Srikar Dronamraju0326f5a2012-03-13 23:30:11 +0530751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 /* deal with pending signal delivery */
Roland McGrath5a8da0e2008-04-30 00:53:10 -0700753 if (thread_info_flags & _TIF_SIGPENDING)
David Howells283828f2006-01-18 17:44:00 -0800754 do_signal(regs);
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100755
Roland McGrath59e52132008-04-19 19:10:57 -0700756 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
757 clear_thread_flag(TIF_NOTIFY_RESUME);
758 tracehook_notify_resume(regs);
759 }
Avi Kivity7c68af62009-09-19 09:40:22 +0300760 if (thread_info_flags & _TIF_USER_RETURN_NOTIFY)
761 fire_user_return_notifiers();
Roland McGrath59e52132008-04-19 19:10:57 -0700762
Frederic Weisbecker91d1aa432012-11-27 19:33:25 +0100763 user_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764}
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700765
766void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
767{
768 struct task_struct *me = current;
769
770 if (show_unhandled_signals && printk_ratelimit()) {
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800771 printk("%s"
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700772 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
Hiroshi Shimamotoae417bb2008-12-16 14:02:16 -0800773 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700774 me->comm, me->pid, where, frame,
775 regs->ip, regs->sp, regs->orig_ax);
776 print_vma_addr(" in ", regs->ip);
Joe Perchesc767a542012-05-21 19:50:07 -0700777 pr_cont("\n");
Hiroshi Shimamoto72fa50f2008-09-05 16:27:11 -0700778 }
779
780 force_sig(SIGSEGV, me);
781}
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800782
783#ifdef CONFIG_X86_X32_ABI
Al Viro3fe26fa2012-11-12 14:32:42 -0500784asmlinkage long sys32_x32_rt_sigreturn(void)
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800785{
Al Viro3fe26fa2012-11-12 14:32:42 -0500786 struct pt_regs *regs = current_pt_regs();
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800787 struct rt_sigframe_x32 __user *frame;
788 sigset_t set;
789 unsigned long ax;
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800790
791 frame = (struct rt_sigframe_x32 __user *)(regs->sp - 8);
792
793 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
794 goto badframe;
795 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
796 goto badframe;
797
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800798 set_current_blocked(&set);
799
800 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
801 goto badframe;
802
Al Viro90268432012-12-14 14:47:53 -0500803 if (compat_restore_altstack(&frame->uc.uc_stack))
H. Peter Anvinc5a37392012-02-19 09:41:09 -0800804 goto badframe;
805
806 return ax;
807
808badframe:
809 signal_fault(regs, frame, "x32 rt_sigreturn");
810 return 0;
811}
812#endif