x86/efi: Enforce CONFIG_RELOCATABLE for EFI boot stub
[linux/fpc-iii.git] / arch / x86 / kernel / signal.c
blob9e5de6813e1fa7dfa11eab1beff350fa188afb97
1 /*
2 * Copyright (C) 1991, 1992 Linus Torvalds
3 * Copyright (C) 2000, 2001, 2002 Andi Kleen SuSE Labs
5 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
6 * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes
7 * 2000-2002 x86-64 support by Andi Kleen
8 */
10 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/sched.h>
13 #include <linux/mm.h>
14 #include <linux/smp.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/wait.h>
18 #include <linux/tracehook.h>
19 #include <linux/unistd.h>
20 #include <linux/stddef.h>
21 #include <linux/personality.h>
22 #include <linux/uaccess.h>
23 #include <linux/user-return-notifier.h>
24 #include <linux/uprobes.h>
25 #include <linux/context_tracking.h>
27 #include <asm/processor.h>
28 #include <asm/ucontext.h>
29 #include <asm/i387.h>
30 #include <asm/fpu-internal.h>
31 #include <asm/vdso.h>
32 #include <asm/mce.h>
33 #include <asm/sighandling.h>
35 #ifdef CONFIG_X86_64
36 #include <asm/proto.h>
37 #include <asm/ia32_unistd.h>
38 #include <asm/sys_ia32.h>
39 #endif /* CONFIG_X86_64 */
41 #include <asm/syscall.h>
42 #include <asm/syscalls.h>
44 #include <asm/sigframe.h>
46 #define COPY(x) do { \
47 get_user_ex(regs->x, &sc->x); \
48 } while (0)
50 #define GET_SEG(seg) ({ \
51 unsigned short tmp; \
52 get_user_ex(tmp, &sc->seg); \
53 tmp; \
56 #define COPY_SEG(seg) do { \
57 regs->seg = GET_SEG(seg); \
58 } while (0)
60 #define COPY_SEG_CPL3(seg) do { \
61 regs->seg = GET_SEG(seg) | 3; \
62 } while (0)
64 int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
65 unsigned long *pax)
67 void __user *buf;
68 unsigned int tmpflags;
69 unsigned int err = 0;
71 /* Always make any pending restarted system calls return -EINTR */
72 current_thread_info()->restart_block.fn = do_no_restart_syscall;
74 get_user_try {
76 #ifdef CONFIG_X86_32
77 set_user_gs(regs, GET_SEG(gs));
78 COPY_SEG(fs);
79 COPY_SEG(es);
80 COPY_SEG(ds);
81 #endif /* CONFIG_X86_32 */
83 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
84 COPY(dx); COPY(cx); COPY(ip);
86 #ifdef CONFIG_X86_64
87 COPY(r8);
88 COPY(r9);
89 COPY(r10);
90 COPY(r11);
91 COPY(r12);
92 COPY(r13);
93 COPY(r14);
94 COPY(r15);
95 #endif /* CONFIG_X86_64 */
97 #ifdef CONFIG_X86_32
98 COPY_SEG_CPL3(cs);
99 COPY_SEG_CPL3(ss);
100 #else /* !CONFIG_X86_32 */
101 /* 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);
105 #endif /* CONFIG_X86_32 */
107 get_user_ex(tmpflags, &sc->flags);
108 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
109 regs->orig_ax = -1; /* disable syscall checks */
111 get_user_ex(buf, &sc->fpstate);
113 get_user_ex(*pax, &sc->ax);
114 } get_user_catch(err);
116 err |= restore_xstate_sig(buf, config_enabled(CONFIG_X86_32));
118 return err;
121 int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
122 struct pt_regs *regs, unsigned long mask)
124 int err = 0;
126 put_user_try {
128 #ifdef CONFIG_X86_32
129 put_user_ex(get_user_gs(regs), (unsigned int __user *)&sc->gs);
130 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);
133 #endif /* CONFIG_X86_32 */
135 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);
143 #ifdef CONFIG_X86_64
144 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);
152 #endif /* CONFIG_X86_64 */
154 put_user_ex(current->thread.trap_nr, &sc->trapno);
155 put_user_ex(current->thread.error_code, &sc->err);
156 put_user_ex(regs->ip, &sc->ip);
157 #ifdef CONFIG_X86_32
158 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);
162 #else /* !CONFIG_X86_32 */
163 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);
167 #endif /* CONFIG_X86_32 */
169 put_user_ex(fpstate, &sc->fpstate);
171 /* non-iBCS2 extensions.. */
172 put_user_ex(mask, &sc->oldmask);
173 put_user_ex(current->thread.cr2, &sc->cr2);
174 } put_user_catch(err);
176 return err;
180 * Set up a signal frame.
184 * Determine which stack to use..
186 static unsigned long align_sigframe(unsigned long sp)
188 #ifdef CONFIG_X86_32
190 * Align the stack pointer according to the i386 ABI,
191 * i.e. so that on function entry ((sp + 4) & 15) == 0.
193 sp = ((sp + 4) & -16ul) - 4;
194 #else /* !CONFIG_X86_32 */
195 sp = round_down(sp, 16) - 8;
196 #endif
197 return sp;
200 static inline void __user *
201 get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
202 void __user **fpstate)
204 /* Default to using normal stack */
205 unsigned long math_size = 0;
206 unsigned long sp = regs->sp;
207 unsigned long buf_fx = 0;
208 int onsigstack = on_sig_stack(sp);
210 /* redzone */
211 if (config_enabled(CONFIG_X86_64))
212 sp -= 128;
214 if (!onsigstack) {
215 /* This is the X/Open sanctioned signal stack switching. */
216 if (ka->sa.sa_flags & SA_ONSTACK) {
217 if (current->sas_ss_size)
218 sp = current->sas_ss_sp + current->sas_ss_size;
219 } 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. */
224 sp = (unsigned long) ka->sa.sa_restorer;
228 if (used_math()) {
229 sp = alloc_mathframe(sp, config_enabled(CONFIG_X86_32),
230 &buf_fx, &math_size);
231 *fpstate = (void __user *)sp;
234 sp = align_sigframe(sp - frame_size);
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.
240 if (onsigstack && !likely(on_sig_stack(sp)))
241 return (void __user *)-1L;
243 /* save i387 and extended state */
244 if (used_math() &&
245 save_xstate_sig(*fpstate, (void __user *)buf_fx, math_size) < 0)
246 return (void __user *)-1L;
248 return (void __user *)sp;
251 #ifdef CONFIG_X86_32
252 static 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 */
262 static 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 */
274 static int
275 __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
276 struct pt_regs *regs)
278 struct sigframe __user *frame;
279 void __user *restorer;
280 int err = 0;
281 void __user *fpstate = NULL;
283 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
285 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
286 return -EFAULT;
288 if (__put_user(sig, &frame->sig))
289 return -EFAULT;
291 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
292 return -EFAULT;
294 if (_NSIG_WORDS > 1) {
295 if (__copy_to_user(&frame->extramask, &set->sig[1],
296 sizeof(frame->extramask)))
297 return -EFAULT;
300 if (current->mm->context.vdso)
301 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
302 else
303 restorer = &frame->retcode;
304 if (ksig->ka.sa.sa_flags & SA_RESTORER)
305 restorer = ksig->ka.sa.sa_restorer;
307 /* Set up to return from userspace. */
308 err |= __put_user(restorer, &frame->pretcode);
311 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
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.
317 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
319 if (err)
320 return -EFAULT;
322 /* Set up registers for signal handler */
323 regs->sp = (unsigned long)frame;
324 regs->ip = (unsigned long)ksig->ka.sa.sa_handler;
325 regs->ax = (unsigned long)sig;
326 regs->dx = 0;
327 regs->cx = 0;
329 regs->ds = __USER_DS;
330 regs->es = __USER_DS;
331 regs->ss = __USER_DS;
332 regs->cs = __USER_CS;
334 return 0;
337 static int __setup_rt_frame(int sig, struct ksignal *ksig,
338 sigset_t *set, struct pt_regs *regs)
340 struct rt_sigframe __user *frame;
341 void __user *restorer;
342 int err = 0;
343 void __user *fpstate = NULL;
345 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
347 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
348 return -EFAULT;
350 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);
355 /* 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);
361 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
363 /* Set up to return from userspace. */
364 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
365 if (ksig->ka.sa.sa_flags & SA_RESTORER)
366 restorer = ksig->ka.sa.sa_restorer;
367 put_user_ex(restorer, &frame->pretcode);
370 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
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.
376 put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
377 } put_user_catch(err);
379 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
380 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));
384 if (err)
385 return -EFAULT;
387 /* Set up registers for signal handler */
388 regs->sp = (unsigned long)frame;
389 regs->ip = (unsigned long)ksig->ka.sa.sa_handler;
390 regs->ax = (unsigned long)sig;
391 regs->dx = (unsigned long)&frame->info;
392 regs->cx = (unsigned long)&frame->uc;
394 regs->ds = __USER_DS;
395 regs->es = __USER_DS;
396 regs->ss = __USER_DS;
397 regs->cs = __USER_CS;
399 return 0;
401 #else /* !CONFIG_X86_32 */
402 static int __setup_rt_frame(int sig, struct ksignal *ksig,
403 sigset_t *set, struct pt_regs *regs)
405 struct rt_sigframe __user *frame;
406 void __user *fp = NULL;
407 int err = 0;
409 frame = get_sigframe(&ksig->ka, regs, sizeof(struct rt_sigframe), &fp);
411 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
412 return -EFAULT;
414 if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
415 if (copy_siginfo_to_user(&frame->info, &ksig->info))
416 return -EFAULT;
419 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);
426 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
428 /* Set up to return from userspace. If provided, use a stub
429 already in userspace. */
430 /* x86-64 should always use SA_RESTORER. */
431 if (ksig->ka.sa.sa_flags & SA_RESTORER) {
432 put_user_ex(ksig->ka.sa.sa_restorer, &frame->pretcode);
433 } else {
434 /* could use a vstub here */
435 err |= -EFAULT;
437 } put_user_catch(err);
439 err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
440 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
442 if (err)
443 return -EFAULT;
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;
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;
454 regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
456 regs->sp = (unsigned long)frame;
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;
462 return 0;
464 #endif /* CONFIG_X86_32 */
466 static int x32_setup_rt_frame(struct ksignal *ksig,
467 compat_sigset_t *set,
468 struct pt_regs *regs)
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;
476 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
478 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
479 return -EFAULT;
481 if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
482 if (copy_siginfo_to_user32(&frame->info, &ksig->info))
483 return -EFAULT;
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);
493 compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
494 put_user_ex(0, &frame->uc.uc__pad0);
496 if (ksig->ka.sa.sa_flags & SA_RESTORER) {
497 restorer = ksig->ka.sa.sa_restorer;
498 } else {
499 /* could use a vstub here */
500 restorer = NULL;
501 err |= -EFAULT;
503 put_user_ex(restorer, &frame->pretcode);
504 } put_user_catch(err);
506 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));
510 if (err)
511 return -EFAULT;
513 /* Set up registers for signal handler */
514 regs->sp = (unsigned long) frame;
515 regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
517 /* We use the x32 calling convention here... */
518 regs->di = ksig->sig;
519 regs->si = (unsigned long) &frame->info;
520 regs->dx = (unsigned long) &frame->uc;
522 loadsegment(ds, __USER_DS);
523 loadsegment(es, __USER_DS);
525 regs->cs = __USER_CS;
526 regs->ss = __USER_DS;
527 #endif /* CONFIG_X86_X32_ABI */
529 return 0;
533 * Do a signal return; undo the signal stack.
535 #ifdef CONFIG_X86_32
536 asmlinkage unsigned long sys_sigreturn(void)
538 struct pt_regs *regs = current_pt_regs();
539 struct sigframe __user *frame;
540 unsigned long ax;
541 sigset_t set;
543 frame = (struct sigframe __user *)(regs->sp - 8);
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;
552 set_current_blocked(&set);
554 if (restore_sigcontext(regs, &frame->sc, &ax))
555 goto badframe;
556 return ax;
558 badframe:
559 signal_fault(regs, frame, "sigreturn");
561 return 0;
563 #endif /* CONFIG_X86_32 */
565 asmlinkage long sys_rt_sigreturn(void)
567 struct pt_regs *regs = current_pt_regs();
568 struct rt_sigframe __user *frame;
569 unsigned long ax;
570 sigset_t set;
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;
578 set_current_blocked(&set);
580 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
581 goto badframe;
583 if (restore_altstack(&frame->uc.uc_stack))
584 goto badframe;
586 return ax;
588 badframe:
589 signal_fault(regs, frame, "rt_sigreturn");
590 return 0;
594 * OK, we're invoking a handler:
596 static int signr_convert(int sig)
598 #ifdef CONFIG_X86_32
599 struct thread_info *info = current_thread_info();
601 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
602 return info->exec_domain->signal_invmap[sig];
603 #endif /* CONFIG_X86_32 */
604 return sig;
607 static int
608 setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
610 int usig = signr_convert(ksig->sig);
611 sigset_t *set = sigmask_to_save();
612 compat_sigset_t *cset = (compat_sigset_t *) set;
614 /* Set up the stack frame */
615 if (is_ia32_frame()) {
616 if (ksig->ka.sa.sa_flags & SA_SIGINFO)
617 return ia32_setup_rt_frame(usig, ksig, cset, regs);
618 else
619 return ia32_setup_frame(usig, ksig, cset, regs);
620 } else if (is_x32_frame()) {
621 return x32_setup_rt_frame(ksig, cset, regs);
622 } else {
623 return __setup_rt_frame(ksig->sig, ksig, set, regs);
627 static void
628 handle_signal(struct ksignal *ksig, struct pt_regs *regs)
630 bool failed;
631 /* Are we from a system call? */
632 if (syscall_get_nr(current, regs) >= 0) {
633 /* If so, check system call restarting.. */
634 switch (syscall_get_error(current, regs)) {
635 case -ERESTART_RESTARTBLOCK:
636 case -ERESTARTNOHAND:
637 regs->ax = -EINTR;
638 break;
640 case -ERESTARTSYS:
641 if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
642 regs->ax = -EINTR;
643 break;
645 /* fallthrough */
646 case -ERESTARTNOINTR:
647 regs->ax = regs->orig_ax;
648 regs->ip -= 2;
649 break;
654 * 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.
657 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
658 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
659 regs->flags &= ~X86_EFLAGS_TF;
661 failed = (setup_rt_frame(ksig, regs) < 0);
662 if (!failed) {
664 * Clear the direction flag as per the ABI for function entry.
666 * Clear RF when entering the signal handler, because
667 * it might disable possible debug exception from the
668 * signal handler.
670 * 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.
675 regs->flags &= ~(X86_EFLAGS_DF|X86_EFLAGS_RF|X86_EFLAGS_TF);
677 signal_setup_done(failed, ksig, test_thread_flag(TIF_SINGLESTEP));
680 #ifdef CONFIG_X86_32
681 #define NR_restart_syscall __NR_restart_syscall
682 #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 */
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.
692 static void do_signal(struct pt_regs *regs)
694 struct ksignal ksig;
696 if (get_signal(&ksig)) {
697 /* Whee! Actually deliver the signal. */
698 handle_signal(&ksig, regs);
699 return;
702 /* Did we come from a system call? */
703 if (syscall_get_nr(current, regs) >= 0) {
704 /* Restart the system call - no handlers present */
705 switch (syscall_get_error(current, regs)) {
706 case -ERESTARTNOHAND:
707 case -ERESTARTSYS:
708 case -ERESTARTNOINTR:
709 regs->ax = regs->orig_ax;
710 regs->ip -= 2;
711 break;
713 case -ERESTART_RESTARTBLOCK:
714 regs->ax = NR_restart_syscall;
715 regs->ip -= 2;
716 break;
721 * If there's no signal to deliver, we just put the saved sigmask
722 * back.
724 restore_saved_sigmask();
728 * notification of userspace execution resumption
729 * - triggered by the TIF_WORK_MASK flags
731 __visible void
732 do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
734 user_exit();
736 #ifdef CONFIG_X86_MCE
737 /* notify userspace of pending MCEs */
738 if (thread_info_flags & _TIF_MCE_NOTIFY)
739 mce_notify_process();
740 #endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
742 if (thread_info_flags & _TIF_UPROBE)
743 uprobe_notify_resume(regs);
745 /* deal with pending signal delivery */
746 if (thread_info_flags & _TIF_SIGPENDING)
747 do_signal(regs);
749 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
750 clear_thread_flag(TIF_NOTIFY_RESUME);
751 tracehook_notify_resume(regs);
753 if (thread_info_flags & _TIF_USER_RETURN_NOTIFY)
754 fire_user_return_notifiers();
756 user_enter();
759 void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
761 struct task_struct *me = current;
763 if (show_unhandled_signals && printk_ratelimit()) {
764 printk("%s"
765 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
766 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
767 me->comm, me->pid, where, frame,
768 regs->ip, regs->sp, regs->orig_ax);
769 print_vma_addr(" in ", regs->ip);
770 pr_cont("\n");
773 force_sig(SIGSEGV, me);
776 #ifdef CONFIG_X86_X32_ABI
777 asmlinkage long sys32_x32_rt_sigreturn(void)
779 struct pt_regs *regs = current_pt_regs();
780 struct rt_sigframe_x32 __user *frame;
781 sigset_t set;
782 unsigned long ax;
784 frame = (struct rt_sigframe_x32 __user *)(regs->sp - 8);
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;
791 set_current_blocked(&set);
793 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
794 goto badframe;
796 if (compat_restore_altstack(&frame->uc.uc_stack))
797 goto badframe;
799 return ax;
801 badframe:
802 signal_fault(regs, frame, "x32 rt_sigreturn");
803 return 0;
805 #endif