x86: signal: cosmetic unification of __setup_sigframe() and __setup_rt_sigframe()
[linux-2.6/mini2440.git] / arch / x86 / kernel / signal_64.c
blob2da7e6e6080768a049aceffd7d59d5a876509213
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 #include <linux/sched.h>
11 #include <linux/mm.h>
12 #include <linux/smp.h>
13 #include <linux/kernel.h>
14 #include <linux/signal.h>
15 #include <linux/errno.h>
16 #include <linux/wait.h>
17 #include <linux/ptrace.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>
24 #include <asm/processor.h>
25 #include <asm/ucontext.h>
26 #include <asm/i387.h>
27 #include <asm/vdso.h>
29 #ifdef CONFIG_X86_64
30 #include <asm/proto.h>
31 #include <asm/ia32_unistd.h>
32 #include <asm/mce.h>
33 #endif /* CONFIG_X86_64 */
35 #include <asm/syscall.h>
36 #include <asm/syscalls.h>
38 #include "sigframe.h"
40 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
42 #define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \
43 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
44 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
45 X86_EFLAGS_CF)
47 #ifdef CONFIG_X86_32
48 # define FIX_EFLAGS (__FIX_EFLAGS | X86_EFLAGS_RF)
49 #else
50 # define FIX_EFLAGS __FIX_EFLAGS
51 #endif
53 #define COPY(x) { \
54 err |= __get_user(regs->x, &sc->x); \
57 #define COPY_SEG_CPL3(seg) { \
58 unsigned short tmp; \
59 err |= __get_user(tmp, &sc->seg); \
60 regs->seg = tmp | 3; \
63 static int
64 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 #ifdef CONFIG_X86_32
75 GET_SEG(gs);
76 COPY_SEG(fs);
77 COPY_SEG(es);
78 COPY_SEG(ds);
79 #endif /* CONFIG_X86_32 */
81 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
82 COPY(dx); COPY(cx); COPY(ip);
84 #ifdef CONFIG_X86_64
85 COPY(r8);
86 COPY(r9);
87 COPY(r10);
88 COPY(r11);
89 COPY(r12);
90 COPY(r13);
91 COPY(r14);
92 COPY(r15);
93 #endif /* CONFIG_X86_64 */
95 #ifdef CONFIG_X86_32
96 COPY_SEG_CPL3(cs);
97 COPY_SEG_CPL3(ss);
98 #else /* !CONFIG_X86_32 */
99 /* Kernel saves and restores only the CS segment register on signals,
100 * which is the bare minimum needed to allow mixed 32/64-bit code.
101 * App's signal handler can save/restore other segments if needed. */
102 COPY_SEG_CPL3(cs);
103 #endif /* CONFIG_X86_32 */
105 err |= __get_user(tmpflags, &sc->flags);
106 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
107 regs->orig_ax = -1; /* disable syscall checks */
109 err |= __get_user(buf, &sc->fpstate);
110 err |= restore_i387_xstate(buf);
112 err |= __get_user(*pax, &sc->ax);
113 return err;
116 static int
117 setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
118 struct pt_regs *regs, unsigned long mask)
120 int err = 0;
122 #ifdef CONFIG_X86_32
124 unsigned int tmp;
126 savesegment(gs, tmp);
127 err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
129 err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs);
130 err |= __put_user(regs->es, (unsigned int __user *)&sc->es);
131 err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds);
132 #endif /* CONFIG_X86_32 */
134 err |= __put_user(regs->di, &sc->di);
135 err |= __put_user(regs->si, &sc->si);
136 err |= __put_user(regs->bp, &sc->bp);
137 err |= __put_user(regs->sp, &sc->sp);
138 err |= __put_user(regs->bx, &sc->bx);
139 err |= __put_user(regs->dx, &sc->dx);
140 err |= __put_user(regs->cx, &sc->cx);
141 err |= __put_user(regs->ax, &sc->ax);
142 #ifdef CONFIG_X86_64
143 err |= __put_user(regs->r8, &sc->r8);
144 err |= __put_user(regs->r9, &sc->r9);
145 err |= __put_user(regs->r10, &sc->r10);
146 err |= __put_user(regs->r11, &sc->r11);
147 err |= __put_user(regs->r12, &sc->r12);
148 err |= __put_user(regs->r13, &sc->r13);
149 err |= __put_user(regs->r14, &sc->r14);
150 err |= __put_user(regs->r15, &sc->r15);
151 #endif /* CONFIG_X86_64 */
153 err |= __put_user(current->thread.trap_no, &sc->trapno);
154 err |= __put_user(current->thread.error_code, &sc->err);
155 err |= __put_user(regs->ip, &sc->ip);
156 #ifdef CONFIG_X86_32
157 err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs);
158 err |= __put_user(regs->flags, &sc->flags);
159 err |= __put_user(regs->sp, &sc->sp_at_signal);
160 err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss);
161 #else /* !CONFIG_X86_32 */
162 err |= __put_user(regs->flags, &sc->flags);
163 err |= __put_user(regs->cs, &sc->cs);
164 err |= __put_user(0, &sc->gs);
165 err |= __put_user(0, &sc->fs);
166 #endif /* CONFIG_X86_32 */
168 err |= __put_user(fpstate, &sc->fpstate);
170 /* non-iBCS2 extensions.. */
171 err |= __put_user(mask, &sc->oldmask);
172 err |= __put_user(current->thread.cr2, &sc->cr2);
174 return err;
178 * Set up a signal frame.
180 #ifdef CONFIG_X86_32
181 static const struct {
182 u16 poplmovl;
183 u32 val;
184 u16 int80;
185 } __attribute__((packed)) retcode = {
186 0xb858, /* popl %eax; movl $..., %eax */
187 __NR_sigreturn,
188 0x80cd, /* int $0x80 */
191 static const struct {
192 u8 movl;
193 u32 val;
194 u16 int80;
195 u8 pad;
196 } __attribute__((packed)) rt_retcode = {
197 0xb8, /* movl $..., %eax */
198 __NR_rt_sigreturn,
199 0x80cd, /* int $0x80 */
204 * Determine which stack to use..
206 static inline void __user *
207 get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
208 void **fpstate)
210 unsigned long sp;
212 /* Default to using normal stack */
213 sp = regs->sp;
216 * If we are on the alternate signal stack and would overflow it, don't.
217 * Return an always-bogus address instead so we will die with SIGSEGV.
219 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
220 return (void __user *) -1L;
222 /* This is the X/Open sanctioned signal stack switching. */
223 if (ka->sa.sa_flags & SA_ONSTACK) {
224 if (sas_ss_flags(sp) == 0)
225 sp = current->sas_ss_sp + current->sas_ss_size;
226 } else {
227 /* This is the legacy signal stack switching. */
228 if ((regs->ss & 0xffff) != __USER_DS &&
229 !(ka->sa.sa_flags & SA_RESTORER) &&
230 ka->sa.sa_restorer)
231 sp = (unsigned long) ka->sa.sa_restorer;
234 if (used_math()) {
235 sp = sp - sig_xstate_size;
236 *fpstate = (struct _fpstate *) sp;
237 if (save_i387_xstate(*fpstate) < 0)
238 return (void __user *)-1L;
241 sp -= frame_size;
243 * Align the stack pointer according to the i386 ABI,
244 * i.e. so that on function entry ((sp + 4) & 15) == 0.
246 sp = ((sp + 4) & -16ul) - 4;
248 return (void __user *) sp;
251 static int
252 __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
253 struct pt_regs *regs)
255 struct sigframe __user *frame;
256 void __user *restorer;
257 int err = 0;
258 void __user *fpstate = NULL;
260 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
262 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
263 return -EFAULT;
265 if (__put_user(sig, &frame->sig))
266 return -EFAULT;
268 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
269 return -EFAULT;
271 if (_NSIG_WORDS > 1) {
272 if (__copy_to_user(&frame->extramask, &set->sig[1],
273 sizeof(frame->extramask)))
274 return -EFAULT;
277 if (current->mm->context.vdso)
278 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
279 else
280 restorer = &frame->retcode;
281 if (ka->sa.sa_flags & SA_RESTORER)
282 restorer = ka->sa.sa_restorer;
284 /* Set up to return from userspace. */
285 err |= __put_user(restorer, &frame->pretcode);
288 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
290 * WE DO NOT USE IT ANY MORE! It's only left here for historical
291 * reasons and because gdb uses it as a signature to notice
292 * signal handler stack frames.
294 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
296 if (err)
297 return -EFAULT;
299 /* Set up registers for signal handler */
300 regs->sp = (unsigned long)frame;
301 regs->ip = (unsigned long)ka->sa.sa_handler;
302 regs->ax = (unsigned long)sig;
303 regs->dx = 0;
304 regs->cx = 0;
306 regs->ds = __USER_DS;
307 regs->es = __USER_DS;
308 regs->ss = __USER_DS;
309 regs->cs = __USER_CS;
311 return 0;
314 static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
315 sigset_t *set, struct pt_regs *regs)
317 struct rt_sigframe __user *frame;
318 void __user *restorer;
319 int err = 0;
320 void __user *fpstate = NULL;
322 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
324 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
325 return -EFAULT;
327 err |= __put_user(sig, &frame->sig);
328 err |= __put_user(&frame->info, &frame->pinfo);
329 err |= __put_user(&frame->uc, &frame->puc);
330 err |= copy_siginfo_to_user(&frame->info, info);
331 if (err)
332 return -EFAULT;
334 /* Create the ucontext. */
335 if (cpu_has_xsave)
336 err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags);
337 else
338 err |= __put_user(0, &frame->uc.uc_flags);
339 err |= __put_user(0, &frame->uc.uc_link);
340 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
341 err |= __put_user(sas_ss_flags(regs->sp),
342 &frame->uc.uc_stack.ss_flags);
343 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
344 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
345 regs, set->sig[0]);
346 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
347 if (err)
348 return -EFAULT;
350 /* Set up to return from userspace. */
351 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
352 if (ka->sa.sa_flags & SA_RESTORER)
353 restorer = ka->sa.sa_restorer;
354 err |= __put_user(restorer, &frame->pretcode);
357 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
359 * WE DO NOT USE IT ANY MORE! It's only left here for historical
360 * reasons and because gdb uses it as a signature to notice
361 * signal handler stack frames.
363 err |= __put_user(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
365 if (err)
366 return -EFAULT;
368 /* Set up registers for signal handler */
369 regs->sp = (unsigned long)frame;
370 regs->ip = (unsigned long)ka->sa.sa_handler;
371 regs->ax = (unsigned long)sig;
372 regs->dx = (unsigned long)&frame->info;
373 regs->cx = (unsigned long)&frame->uc;
375 regs->ds = __USER_DS;
376 regs->es = __USER_DS;
377 regs->ss = __USER_DS;
378 regs->cs = __USER_CS;
380 return 0;
382 #else /* !CONFIG_X86_32 */
384 * Determine which stack to use..
386 static void __user *
387 get_stack(struct k_sigaction *ka, unsigned long sp, unsigned long size)
389 /* Default to using normal stack - redzone*/
390 sp -= 128;
392 /* This is the X/Open sanctioned signal stack switching. */
393 if (ka->sa.sa_flags & SA_ONSTACK) {
394 if (sas_ss_flags(sp) == 0)
395 sp = current->sas_ss_sp + current->sas_ss_size;
398 return (void __user *)round_down(sp - size, 64);
401 static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
402 sigset_t *set, struct pt_regs *regs)
404 struct rt_sigframe __user *frame;
405 void __user *fp = NULL;
406 int err = 0;
407 struct task_struct *me = current;
409 if (used_math()) {
410 fp = get_stack(ka, regs->sp, sig_xstate_size);
411 frame = (void __user *)round_down(
412 (unsigned long)fp - sizeof(struct rt_sigframe), 16) - 8;
414 if (save_i387_xstate(fp) < 0)
415 return -EFAULT;
416 } else
417 frame = get_stack(ka, regs->sp, sizeof(struct rt_sigframe)) - 8;
419 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
420 return -EFAULT;
422 if (ka->sa.sa_flags & SA_SIGINFO) {
423 if (copy_siginfo_to_user(&frame->info, info))
424 return -EFAULT;
427 /* Create the ucontext. */
428 if (cpu_has_xsave)
429 err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags);
430 else
431 err |= __put_user(0, &frame->uc.uc_flags);
432 err |= __put_user(0, &frame->uc.uc_link);
433 err |= __put_user(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
434 err |= __put_user(sas_ss_flags(regs->sp),
435 &frame->uc.uc_stack.ss_flags);
436 err |= __put_user(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
437 err |= setup_sigcontext(&frame->uc.uc_mcontext, fp, regs, set->sig[0]);
438 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
440 /* Set up to return from userspace. If provided, use a stub
441 already in userspace. */
442 /* x86-64 should always use SA_RESTORER. */
443 if (ka->sa.sa_flags & SA_RESTORER) {
444 err |= __put_user(ka->sa.sa_restorer, &frame->pretcode);
445 } else {
446 /* could use a vstub here */
447 return -EFAULT;
450 if (err)
451 return -EFAULT;
453 /* Set up registers for signal handler */
454 regs->di = sig;
455 /* In case the signal handler was declared without prototypes */
456 regs->ax = 0;
458 /* This also works for non SA_SIGINFO handlers because they expect the
459 next argument after the signal number on the stack. */
460 regs->si = (unsigned long)&frame->info;
461 regs->dx = (unsigned long)&frame->uc;
462 regs->ip = (unsigned long) ka->sa.sa_handler;
464 regs->sp = (unsigned long)frame;
466 /* Set up the CS register to run signal handlers in 64-bit mode,
467 even if the handler happens to be interrupting 32-bit code. */
468 regs->cs = __USER_CS;
470 return 0;
472 #endif /* CONFIG_X86_32 */
474 #ifdef CONFIG_X86_32
475 asmlinkage int sys_sigaltstack(unsigned long bx)
478 * This is needed to make gcc realize it doesn't own the
479 * "struct pt_regs"
481 struct pt_regs *regs = (struct pt_regs *)&bx;
482 const stack_t __user *uss = (const stack_t __user *)bx;
483 stack_t __user *uoss = (stack_t __user *)regs->cx;
485 return do_sigaltstack(uss, uoss, regs->sp);
487 #else /* !CONFIG_X86_32 */
488 asmlinkage long
489 sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
490 struct pt_regs *regs)
492 return do_sigaltstack(uss, uoss, regs->sp);
494 #endif /* CONFIG_X86_32 */
497 * Do a signal return; undo the signal stack.
499 static long do_rt_sigreturn(struct pt_regs *regs)
501 struct rt_sigframe __user *frame;
502 unsigned long ax;
503 sigset_t set;
505 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
506 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
507 goto badframe;
508 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
509 goto badframe;
511 sigdelsetmask(&set, ~_BLOCKABLE);
512 spin_lock_irq(&current->sighand->siglock);
513 current->blocked = set;
514 recalc_sigpending();
515 spin_unlock_irq(&current->sighand->siglock);
517 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
518 goto badframe;
520 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
521 goto badframe;
523 return ax;
525 badframe:
526 signal_fault(regs, frame, "rt_sigreturn");
527 return 0;
530 #ifdef CONFIG_X86_32
531 asmlinkage int sys_rt_sigreturn(unsigned long __unused)
533 struct pt_regs *regs = (struct pt_regs *)&__unused;
535 return do_rt_sigreturn(regs);
537 #else /* !CONFIG_X86_32 */
538 asmlinkage long sys_rt_sigreturn(struct pt_regs *regs)
540 return do_rt_sigreturn(regs);
542 #endif /* CONFIG_X86_32 */
545 * OK, we're invoking a handler
547 static int signr_convert(int sig)
549 #ifdef CONFIG_X86_32
550 struct thread_info *info = current_thread_info();
552 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
553 return info->exec_domain->signal_invmap[sig];
554 #endif /* CONFIG_X86_32 */
555 return sig;
558 #ifdef CONFIG_X86_32
560 #define is_ia32 1
561 #define ia32_setup_frame __setup_frame
562 #define ia32_setup_rt_frame __setup_rt_frame
564 #else /* !CONFIG_X86_32 */
566 #ifdef CONFIG_IA32_EMULATION
567 #define is_ia32 test_thread_flag(TIF_IA32)
568 #else /* !CONFIG_IA32_EMULATION */
569 #define is_ia32 0
570 #endif /* CONFIG_IA32_EMULATION */
572 #endif /* CONFIG_X86_32 */
574 static int
575 setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
576 sigset_t *set, struct pt_regs *regs)
578 int usig = signr_convert(sig);
579 int ret;
581 /* Set up the stack frame */
582 if (is_ia32) {
583 if (ka->sa.sa_flags & SA_SIGINFO)
584 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
585 else
586 ret = ia32_setup_frame(usig, ka, set, regs);
587 } else
588 ret = __setup_rt_frame(sig, ka, info, set, regs);
590 if (ret) {
591 force_sigsegv(sig, current);
592 return -EFAULT;
595 return ret;
598 static int
599 handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
600 sigset_t *oldset, struct pt_regs *regs)
602 int ret;
604 /* Are we from a system call? */
605 if (syscall_get_nr(current, regs) >= 0) {
606 /* If so, check system call restarting.. */
607 switch (syscall_get_error(current, regs)) {
608 case -ERESTART_RESTARTBLOCK:
609 case -ERESTARTNOHAND:
610 regs->ax = -EINTR;
611 break;
613 case -ERESTARTSYS:
614 if (!(ka->sa.sa_flags & SA_RESTART)) {
615 regs->ax = -EINTR;
616 break;
618 /* fallthrough */
619 case -ERESTARTNOINTR:
620 regs->ax = regs->orig_ax;
621 regs->ip -= 2;
622 break;
627 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
628 * flag so that register information in the sigcontext is correct.
630 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
631 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
632 regs->flags &= ~X86_EFLAGS_TF;
634 ret = setup_rt_frame(sig, ka, info, oldset, regs);
636 if (ret)
637 return ret;
639 #ifdef CONFIG_X86_64
641 * This has nothing to do with segment registers,
642 * despite the name. This magic affects uaccess.h
643 * macros' behavior. Reset it to the normal setting.
645 set_fs(USER_DS);
646 #endif
649 * Clear the direction flag as per the ABI for function entry.
651 regs->flags &= ~X86_EFLAGS_DF;
654 * Clear TF when entering the signal handler, but
655 * notify any tracer that was single-stepping it.
656 * The tracer may want to single-step inside the
657 * handler too.
659 regs->flags &= ~X86_EFLAGS_TF;
661 spin_lock_irq(&current->sighand->siglock);
662 sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
663 if (!(ka->sa.sa_flags & SA_NODEFER))
664 sigaddset(&current->blocked, sig);
665 recalc_sigpending();
666 spin_unlock_irq(&current->sighand->siglock);
668 tracehook_signal_handler(sig, info, ka, regs,
669 test_thread_flag(TIF_SINGLESTEP));
671 return 0;
674 #ifdef CONFIG_X86_32
675 #define NR_restart_syscall __NR_restart_syscall
676 #else /* !CONFIG_X86_32 */
677 #define NR_restart_syscall \
678 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
679 #endif /* CONFIG_X86_32 */
682 * Note that 'init' is a special process: it doesn't get signals it doesn't
683 * want to handle. Thus you cannot kill init even with a SIGKILL even by
684 * mistake.
686 static void do_signal(struct pt_regs *regs)
688 struct k_sigaction ka;
689 siginfo_t info;
690 int signr;
691 sigset_t *oldset;
694 * We want the common case to go fast, which is why we may in certain
695 * cases get here from kernel mode. Just return without doing anything
696 * if so.
697 * X86_32: vm86 regs switched out by assembly code before reaching
698 * here, so testing against kernel CS suffices.
700 if (!user_mode(regs))
701 return;
703 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
704 oldset = &current->saved_sigmask;
705 else
706 oldset = &current->blocked;
708 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
709 if (signr > 0) {
711 * Re-enable any watchpoints before delivering the
712 * signal to user space. The processor register will
713 * have been cleared if the watchpoint triggered
714 * inside the kernel.
716 if (current->thread.debugreg7)
717 set_debugreg(current->thread.debugreg7, 7);
719 /* Whee! Actually deliver the signal. */
720 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
722 * A signal was successfully delivered; the saved
723 * sigmask will have been stored in the signal frame,
724 * and will be restored by sigreturn, so we can simply
725 * clear the TS_RESTORE_SIGMASK flag.
727 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
729 return;
732 /* Did we come from a system call? */
733 if (syscall_get_nr(current, regs) >= 0) {
734 /* Restart the system call - no handlers present */
735 switch (syscall_get_error(current, regs)) {
736 case -ERESTARTNOHAND:
737 case -ERESTARTSYS:
738 case -ERESTARTNOINTR:
739 regs->ax = regs->orig_ax;
740 regs->ip -= 2;
741 break;
743 case -ERESTART_RESTARTBLOCK:
744 regs->ax = NR_restart_syscall;
745 regs->ip -= 2;
746 break;
751 * If there's no signal to deliver, we just put the saved sigmask
752 * back.
754 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
755 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
756 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
761 * notification of userspace execution resumption
762 * - triggered by the TIF_WORK_MASK flags
764 void
765 do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
767 #if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
768 /* notify userspace of pending MCEs */
769 if (thread_info_flags & _TIF_MCE_NOTIFY)
770 mce_notify_user();
771 #endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
773 /* deal with pending signal delivery */
774 if (thread_info_flags & _TIF_SIGPENDING)
775 do_signal(regs);
777 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
778 clear_thread_flag(TIF_NOTIFY_RESUME);
779 tracehook_notify_resume(regs);
782 #ifdef CONFIG_X86_32
783 clear_thread_flag(TIF_IRET);
784 #endif /* CONFIG_X86_32 */
787 void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
789 struct task_struct *me = current;
791 if (show_unhandled_signals && printk_ratelimit()) {
792 printk(KERN_INFO
793 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
794 me->comm, me->pid, where, frame,
795 regs->ip, regs->sp, regs->orig_ax);
796 print_vma_addr(" in ", regs->ip);
797 printk(KERN_CONT "\n");
800 force_sig(SIGSEGV, me);