vfs: remove unused wrapper block_page_mkwrite()
[linux/fpc-iii.git] / arch / x86 / kernel / signal.c
blobb7ffb7c00075787532ceec10b6aed0028ea01b5c
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/fpu/internal.h>
30 #include <asm/fpu/signal.h>
31 #include <asm/vdso.h>
32 #include <asm/mce.h>
33 #include <asm/sighandling.h>
34 #include <asm/vm86.h>
36 #ifdef CONFIG_X86_64
37 #include <asm/proto.h>
38 #include <asm/ia32_unistd.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)
66 unsigned long buf_val;
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->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); COPY(ax);
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_val, &sc->fpstate);
112 buf = (void __user *)buf_val;
113 } get_user_catch(err);
115 err |= fpu__restore_sig(buf, config_enabled(CONFIG_X86_32));
117 force_iret();
119 return err;
122 int setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
123 struct pt_regs *regs, unsigned long mask)
125 int err = 0;
127 put_user_try {
129 #ifdef CONFIG_X86_32
130 put_user_ex(get_user_gs(regs), (unsigned int __user *)&sc->gs);
131 put_user_ex(regs->fs, (unsigned int __user *)&sc->fs);
132 put_user_ex(regs->es, (unsigned int __user *)&sc->es);
133 put_user_ex(regs->ds, (unsigned int __user *)&sc->ds);
134 #endif /* CONFIG_X86_32 */
136 put_user_ex(regs->di, &sc->di);
137 put_user_ex(regs->si, &sc->si);
138 put_user_ex(regs->bp, &sc->bp);
139 put_user_ex(regs->sp, &sc->sp);
140 put_user_ex(regs->bx, &sc->bx);
141 put_user_ex(regs->dx, &sc->dx);
142 put_user_ex(regs->cx, &sc->cx);
143 put_user_ex(regs->ax, &sc->ax);
144 #ifdef CONFIG_X86_64
145 put_user_ex(regs->r8, &sc->r8);
146 put_user_ex(regs->r9, &sc->r9);
147 put_user_ex(regs->r10, &sc->r10);
148 put_user_ex(regs->r11, &sc->r11);
149 put_user_ex(regs->r12, &sc->r12);
150 put_user_ex(regs->r13, &sc->r13);
151 put_user_ex(regs->r14, &sc->r14);
152 put_user_ex(regs->r15, &sc->r15);
153 #endif /* CONFIG_X86_64 */
155 put_user_ex(current->thread.trap_nr, &sc->trapno);
156 put_user_ex(current->thread.error_code, &sc->err);
157 put_user_ex(regs->ip, &sc->ip);
158 #ifdef CONFIG_X86_32
159 put_user_ex(regs->cs, (unsigned int __user *)&sc->cs);
160 put_user_ex(regs->flags, &sc->flags);
161 put_user_ex(regs->sp, &sc->sp_at_signal);
162 put_user_ex(regs->ss, (unsigned int __user *)&sc->ss);
163 #else /* !CONFIG_X86_32 */
164 put_user_ex(regs->flags, &sc->flags);
165 put_user_ex(regs->cs, &sc->cs);
166 put_user_ex(0, &sc->gs);
167 put_user_ex(0, &sc->fs);
168 #endif /* CONFIG_X86_32 */
170 put_user_ex(fpstate, &sc->fpstate);
172 /* non-iBCS2 extensions.. */
173 put_user_ex(mask, &sc->oldmask);
174 put_user_ex(current->thread.cr2, &sc->cr2);
175 } put_user_catch(err);
177 return err;
181 * Set up a signal frame.
185 * Determine which stack to use..
187 static unsigned long align_sigframe(unsigned long sp)
189 #ifdef CONFIG_X86_32
191 * Align the stack pointer according to the i386 ABI,
192 * i.e. so that on function entry ((sp + 4) & 15) == 0.
194 sp = ((sp + 4) & -16ul) - 4;
195 #else /* !CONFIG_X86_32 */
196 sp = round_down(sp, 16) - 8;
197 #endif
198 return sp;
201 static void __user *
202 get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
203 void __user **fpstate)
205 /* Default to using normal stack */
206 unsigned long math_size = 0;
207 unsigned long sp = regs->sp;
208 unsigned long buf_fx = 0;
209 int onsigstack = on_sig_stack(sp);
210 struct fpu *fpu = &current->thread.fpu;
212 /* redzone */
213 if (config_enabled(CONFIG_X86_64))
214 sp -= 128;
216 if (!onsigstack) {
217 /* This is the X/Open sanctioned signal stack switching. */
218 if (ka->sa.sa_flags & SA_ONSTACK) {
219 if (current->sas_ss_size)
220 sp = current->sas_ss_sp + current->sas_ss_size;
221 } else if (config_enabled(CONFIG_X86_32) &&
222 (regs->ss & 0xffff) != __USER_DS &&
223 !(ka->sa.sa_flags & SA_RESTORER) &&
224 ka->sa.sa_restorer) {
225 /* This is the legacy signal stack switching. */
226 sp = (unsigned long) ka->sa.sa_restorer;
230 if (fpu->fpstate_active) {
231 sp = fpu__alloc_mathframe(sp, config_enabled(CONFIG_X86_32),
232 &buf_fx, &math_size);
233 *fpstate = (void __user *)sp;
236 sp = align_sigframe(sp - frame_size);
239 * If we are on the alternate signal stack and would overflow it, don't.
240 * Return an always-bogus address instead so we will die with SIGSEGV.
242 if (onsigstack && !likely(on_sig_stack(sp)))
243 return (void __user *)-1L;
245 /* save i387 and extended state */
246 if (fpu->fpstate_active &&
247 copy_fpstate_to_sigframe(*fpstate, (void __user *)buf_fx, math_size) < 0)
248 return (void __user *)-1L;
250 return (void __user *)sp;
253 #ifdef CONFIG_X86_32
254 static const struct {
255 u16 poplmovl;
256 u32 val;
257 u16 int80;
258 } __attribute__((packed)) retcode = {
259 0xb858, /* popl %eax; movl $..., %eax */
260 __NR_sigreturn,
261 0x80cd, /* int $0x80 */
264 static const struct {
265 u8 movl;
266 u32 val;
267 u16 int80;
268 u8 pad;
269 } __attribute__((packed)) rt_retcode = {
270 0xb8, /* movl $..., %eax */
271 __NR_rt_sigreturn,
272 0x80cd, /* int $0x80 */
276 static int
277 __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
278 struct pt_regs *regs)
280 struct sigframe __user *frame;
281 void __user *restorer;
282 int err = 0;
283 void __user *fpstate = NULL;
285 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
287 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
288 return -EFAULT;
290 if (__put_user(sig, &frame->sig))
291 return -EFAULT;
293 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
294 return -EFAULT;
296 if (_NSIG_WORDS > 1) {
297 if (__copy_to_user(&frame->extramask, &set->sig[1],
298 sizeof(frame->extramask)))
299 return -EFAULT;
302 if (current->mm->context.vdso)
303 restorer = current->mm->context.vdso +
304 vdso_image_32.sym___kernel_sigreturn;
305 else
306 restorer = &frame->retcode;
307 if (ksig->ka.sa.sa_flags & SA_RESTORER)
308 restorer = ksig->ka.sa.sa_restorer;
310 /* Set up to return from userspace. */
311 err |= __put_user(restorer, &frame->pretcode);
314 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
316 * WE DO NOT USE IT ANY MORE! It's only left here for historical
317 * reasons and because gdb uses it as a signature to notice
318 * signal handler stack frames.
320 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
322 if (err)
323 return -EFAULT;
325 /* Set up registers for signal handler */
326 regs->sp = (unsigned long)frame;
327 regs->ip = (unsigned long)ksig->ka.sa.sa_handler;
328 regs->ax = (unsigned long)sig;
329 regs->dx = 0;
330 regs->cx = 0;
332 regs->ds = __USER_DS;
333 regs->es = __USER_DS;
334 regs->ss = __USER_DS;
335 regs->cs = __USER_CS;
337 return 0;
340 static int __setup_rt_frame(int sig, struct ksignal *ksig,
341 sigset_t *set, struct pt_regs *regs)
343 struct rt_sigframe __user *frame;
344 void __user *restorer;
345 int err = 0;
346 void __user *fpstate = NULL;
348 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
350 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
351 return -EFAULT;
353 put_user_try {
354 put_user_ex(sig, &frame->sig);
355 put_user_ex(&frame->info, &frame->pinfo);
356 put_user_ex(&frame->uc, &frame->puc);
358 /* Create the ucontext. */
359 if (cpu_has_xsave)
360 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
361 else
362 put_user_ex(0, &frame->uc.uc_flags);
363 put_user_ex(0, &frame->uc.uc_link);
364 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
366 /* Set up to return from userspace. */
367 restorer = current->mm->context.vdso +
368 vdso_image_32.sym___kernel_rt_sigreturn;
369 if (ksig->ka.sa.sa_flags & SA_RESTORER)
370 restorer = ksig->ka.sa.sa_restorer;
371 put_user_ex(restorer, &frame->pretcode);
374 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
376 * WE DO NOT USE IT ANY MORE! It's only left here for historical
377 * reasons and because gdb uses it as a signature to notice
378 * signal handler stack frames.
380 put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
381 } put_user_catch(err);
383 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
384 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
385 regs, set->sig[0]);
386 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
388 if (err)
389 return -EFAULT;
391 /* Set up registers for signal handler */
392 regs->sp = (unsigned long)frame;
393 regs->ip = (unsigned long)ksig->ka.sa.sa_handler;
394 regs->ax = (unsigned long)sig;
395 regs->dx = (unsigned long)&frame->info;
396 regs->cx = (unsigned long)&frame->uc;
398 regs->ds = __USER_DS;
399 regs->es = __USER_DS;
400 regs->ss = __USER_DS;
401 regs->cs = __USER_CS;
403 return 0;
405 #else /* !CONFIG_X86_32 */
406 static int __setup_rt_frame(int sig, struct ksignal *ksig,
407 sigset_t *set, struct pt_regs *regs)
409 struct rt_sigframe __user *frame;
410 void __user *fp = NULL;
411 int err = 0;
413 frame = get_sigframe(&ksig->ka, regs, sizeof(struct rt_sigframe), &fp);
415 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
416 return -EFAULT;
418 if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
419 if (copy_siginfo_to_user(&frame->info, &ksig->info))
420 return -EFAULT;
423 put_user_try {
424 /* Create the ucontext. */
425 if (cpu_has_xsave)
426 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
427 else
428 put_user_ex(0, &frame->uc.uc_flags);
429 put_user_ex(0, &frame->uc.uc_link);
430 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
432 /* Set up to return from userspace. If provided, use a stub
433 already in userspace. */
434 /* x86-64 should always use SA_RESTORER. */
435 if (ksig->ka.sa.sa_flags & SA_RESTORER) {
436 put_user_ex(ksig->ka.sa.sa_restorer, &frame->pretcode);
437 } else {
438 /* could use a vstub here */
439 err |= -EFAULT;
441 } put_user_catch(err);
443 err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
444 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
446 if (err)
447 return -EFAULT;
449 /* Set up registers for signal handler */
450 regs->di = sig;
451 /* In case the signal handler was declared without prototypes */
452 regs->ax = 0;
454 /* This also works for non SA_SIGINFO handlers because they expect the
455 next argument after the signal number on the stack. */
456 regs->si = (unsigned long)&frame->info;
457 regs->dx = (unsigned long)&frame->uc;
458 regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
460 regs->sp = (unsigned long)frame;
462 /* Set up the CS register to run signal handlers in 64-bit mode,
463 even if the handler happens to be interrupting 32-bit code. */
464 regs->cs = __USER_CS;
466 return 0;
468 #endif /* CONFIG_X86_32 */
470 static int x32_setup_rt_frame(struct ksignal *ksig,
471 compat_sigset_t *set,
472 struct pt_regs *regs)
474 #ifdef CONFIG_X86_X32_ABI
475 struct rt_sigframe_x32 __user *frame;
476 void __user *restorer;
477 int err = 0;
478 void __user *fpstate = NULL;
480 frame = get_sigframe(&ksig->ka, regs, sizeof(*frame), &fpstate);
482 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
483 return -EFAULT;
485 if (ksig->ka.sa.sa_flags & SA_SIGINFO) {
486 if (copy_siginfo_to_user32(&frame->info, &ksig->info))
487 return -EFAULT;
490 put_user_try {
491 /* Create the ucontext. */
492 if (cpu_has_xsave)
493 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
494 else
495 put_user_ex(0, &frame->uc.uc_flags);
496 put_user_ex(0, &frame->uc.uc_link);
497 compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
498 put_user_ex(0, &frame->uc.uc__pad0);
500 if (ksig->ka.sa.sa_flags & SA_RESTORER) {
501 restorer = ksig->ka.sa.sa_restorer;
502 } else {
503 /* could use a vstub here */
504 restorer = NULL;
505 err |= -EFAULT;
507 put_user_ex(restorer, &frame->pretcode);
508 } put_user_catch(err);
510 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
511 regs, set->sig[0]);
512 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
514 if (err)
515 return -EFAULT;
517 /* Set up registers for signal handler */
518 regs->sp = (unsigned long) frame;
519 regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
521 /* We use the x32 calling convention here... */
522 regs->di = ksig->sig;
523 regs->si = (unsigned long) &frame->info;
524 regs->dx = (unsigned long) &frame->uc;
526 loadsegment(ds, __USER_DS);
527 loadsegment(es, __USER_DS);
529 regs->cs = __USER_CS;
530 regs->ss = __USER_DS;
531 #endif /* CONFIG_X86_X32_ABI */
533 return 0;
537 * Do a signal return; undo the signal stack.
539 #ifdef CONFIG_X86_32
540 asmlinkage unsigned long sys_sigreturn(void)
542 struct pt_regs *regs = current_pt_regs();
543 struct sigframe __user *frame;
544 sigset_t set;
546 frame = (struct sigframe __user *)(regs->sp - 8);
548 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
549 goto badframe;
550 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
551 && __copy_from_user(&set.sig[1], &frame->extramask,
552 sizeof(frame->extramask))))
553 goto badframe;
555 set_current_blocked(&set);
557 if (restore_sigcontext(regs, &frame->sc))
558 goto badframe;
559 return regs->ax;
561 badframe:
562 signal_fault(regs, frame, "sigreturn");
564 return 0;
566 #endif /* CONFIG_X86_32 */
568 asmlinkage long sys_rt_sigreturn(void)
570 struct pt_regs *regs = current_pt_regs();
571 struct rt_sigframe __user *frame;
572 sigset_t set;
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;
580 set_current_blocked(&set);
582 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
583 goto badframe;
585 if (restore_altstack(&frame->uc.uc_stack))
586 goto badframe;
588 return regs->ax;
590 badframe:
591 signal_fault(regs, frame, "rt_sigreturn");
592 return 0;
595 static inline int is_ia32_compat_frame(void)
597 return config_enabled(CONFIG_IA32_EMULATION) &&
598 test_thread_flag(TIF_IA32);
601 static inline int is_ia32_frame(void)
603 return config_enabled(CONFIG_X86_32) || is_ia32_compat_frame();
606 static inline int is_x32_frame(void)
608 return config_enabled(CONFIG_X86_X32_ABI) && test_thread_flag(TIF_X32);
611 static int
612 setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
614 int usig = ksig->sig;
615 sigset_t *set = sigmask_to_save();
616 compat_sigset_t *cset = (compat_sigset_t *) set;
618 /* Set up the stack frame */
619 if (is_ia32_frame()) {
620 if (ksig->ka.sa.sa_flags & SA_SIGINFO)
621 return ia32_setup_rt_frame(usig, ksig, cset, regs);
622 else
623 return ia32_setup_frame(usig, ksig, cset, regs);
624 } else if (is_x32_frame()) {
625 return x32_setup_rt_frame(ksig, cset, regs);
626 } else {
627 return __setup_rt_frame(ksig->sig, ksig, set, regs);
631 static void
632 handle_signal(struct ksignal *ksig, struct pt_regs *regs)
634 bool stepping, failed;
635 struct fpu *fpu = &current->thread.fpu;
637 if (v8086_mode(regs))
638 save_v86_state((struct kernel_vm86_regs *) regs, VM86_SIGNAL);
640 /* Are we from a system call? */
641 if (syscall_get_nr(current, regs) >= 0) {
642 /* If so, check system call restarting.. */
643 switch (syscall_get_error(current, regs)) {
644 case -ERESTART_RESTARTBLOCK:
645 case -ERESTARTNOHAND:
646 regs->ax = -EINTR;
647 break;
649 case -ERESTARTSYS:
650 if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
651 regs->ax = -EINTR;
652 break;
654 /* fallthrough */
655 case -ERESTARTNOINTR:
656 regs->ax = regs->orig_ax;
657 regs->ip -= 2;
658 break;
663 * If TF is set due to a debugger (TIF_FORCED_TF), clear TF now
664 * so that register information in the sigcontext is correct and
665 * then notify the tracer before entering the signal handler.
667 stepping = test_thread_flag(TIF_SINGLESTEP);
668 if (stepping)
669 user_disable_single_step(current);
671 failed = (setup_rt_frame(ksig, regs) < 0);
672 if (!failed) {
674 * Clear the direction flag as per the ABI for function entry.
676 * Clear RF when entering the signal handler, because
677 * it might disable possible debug exception from the
678 * signal handler.
680 * Clear TF for the case when it wasn't set by debugger to
681 * avoid the recursive send_sigtrap() in SIGTRAP handler.
683 regs->flags &= ~(X86_EFLAGS_DF|X86_EFLAGS_RF|X86_EFLAGS_TF);
685 * Ensure the signal handler starts with the new fpu state.
687 if (fpu->fpstate_active)
688 fpu__clear(fpu);
690 signal_setup_done(failed, ksig, stepping);
693 #ifdef CONFIG_X86_32
694 #define NR_restart_syscall __NR_restart_syscall
695 #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 */
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.
705 void do_signal(struct pt_regs *regs)
707 struct ksignal ksig;
709 if (get_signal(&ksig)) {
710 /* Whee! Actually deliver the signal. */
711 handle_signal(&ksig, regs);
712 return;
715 /* Did we come from a system call? */
716 if (syscall_get_nr(current, regs) >= 0) {
717 /* Restart the system call - no handlers present */
718 switch (syscall_get_error(current, regs)) {
719 case -ERESTARTNOHAND:
720 case -ERESTARTSYS:
721 case -ERESTARTNOINTR:
722 regs->ax = regs->orig_ax;
723 regs->ip -= 2;
724 break;
726 case -ERESTART_RESTARTBLOCK:
727 regs->ax = NR_restart_syscall;
728 regs->ip -= 2;
729 break;
734 * If there's no signal to deliver, we just put the saved sigmask
735 * back.
737 restore_saved_sigmask();
740 void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
742 struct task_struct *me = current;
744 if (show_unhandled_signals && printk_ratelimit()) {
745 printk("%s"
746 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
747 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
748 me->comm, me->pid, where, frame,
749 regs->ip, regs->sp, regs->orig_ax);
750 print_vma_addr(" in ", regs->ip);
751 pr_cont("\n");
754 force_sig(SIGSEGV, me);
757 #ifdef CONFIG_X86_X32_ABI
758 asmlinkage long sys32_x32_rt_sigreturn(void)
760 struct pt_regs *regs = current_pt_regs();
761 struct rt_sigframe_x32 __user *frame;
762 sigset_t set;
764 frame = (struct rt_sigframe_x32 __user *)(regs->sp - 8);
766 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
767 goto badframe;
768 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
769 goto badframe;
771 set_current_blocked(&set);
773 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
774 goto badframe;
776 if (compat_restore_altstack(&frame->uc.uc_stack))
777 goto badframe;
779 return regs->ax;
781 badframe:
782 signal_fault(regs, frame, "x32 rt_sigreturn");
783 return 0;
785 #endif