Use dentry_path() to create full path to inode object
[pohmelfs.git] / arch / x86 / kernel / signal.c
blob46a01bdc27e2846582d88fca80356506349e1074
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 */
9 #include <linux/sched.h>
10 #include <linux/mm.h>
11 #include <linux/smp.h>
12 #include <linux/kernel.h>
13 #include <linux/signal.h>
14 #include <linux/errno.h>
15 #include <linux/wait.h>
16 #include <linux/ptrace.h>
17 #include <linux/tracehook.h>
18 #include <linux/unistd.h>
19 #include <linux/stddef.h>
20 #include <linux/personality.h>
21 #include <linux/uaccess.h>
22 #include <linux/user-return-notifier.h>
24 #include <asm/processor.h>
25 #include <asm/ucontext.h>
26 #include <asm/i387.h>
27 #include <asm/vdso.h>
28 #include <asm/mce.h>
30 #ifdef CONFIG_X86_64
31 #include <asm/proto.h>
32 #include <asm/ia32_unistd.h>
33 #endif /* CONFIG_X86_64 */
35 #include <asm/syscall.h>
36 #include <asm/syscalls.h>
38 #include <asm/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) do { \
54 get_user_ex(regs->x, &sc->x); \
55 } while (0)
57 #define GET_SEG(seg) ({ \
58 unsigned short tmp; \
59 get_user_ex(tmp, &sc->seg); \
60 tmp; \
63 #define COPY_SEG(seg) do { \
64 regs->seg = GET_SEG(seg); \
65 } while (0)
67 #define COPY_SEG_CPL3(seg) do { \
68 regs->seg = GET_SEG(seg) | 3; \
69 } while (0)
71 static int
72 restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
73 unsigned long *pax)
75 void __user *buf;
76 unsigned int tmpflags;
77 unsigned int err = 0;
79 /* Always make any pending restarted system calls return -EINTR */
80 current_thread_info()->restart_block.fn = do_no_restart_syscall;
82 get_user_try {
84 #ifdef CONFIG_X86_32
85 set_user_gs(regs, GET_SEG(gs));
86 COPY_SEG(fs);
87 COPY_SEG(es);
88 COPY_SEG(ds);
89 #endif /* CONFIG_X86_32 */
91 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
92 COPY(dx); COPY(cx); COPY(ip);
94 #ifdef CONFIG_X86_64
95 COPY(r8);
96 COPY(r9);
97 COPY(r10);
98 COPY(r11);
99 COPY(r12);
100 COPY(r13);
101 COPY(r14);
102 COPY(r15);
103 #endif /* CONFIG_X86_64 */
105 #ifdef CONFIG_X86_32
106 COPY_SEG_CPL3(cs);
107 COPY_SEG_CPL3(ss);
108 #else /* !CONFIG_X86_32 */
109 /* Kernel saves and restores only the CS segment register on signals,
110 * which is the bare minimum needed to allow mixed 32/64-bit code.
111 * App's signal handler can save/restore other segments if needed. */
112 COPY_SEG_CPL3(cs);
113 #endif /* CONFIG_X86_32 */
115 get_user_ex(tmpflags, &sc->flags);
116 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
117 regs->orig_ax = -1; /* disable syscall checks */
119 get_user_ex(buf, &sc->fpstate);
120 err |= restore_i387_xstate(buf);
122 get_user_ex(*pax, &sc->ax);
123 } get_user_catch(err);
125 return err;
128 static int
129 setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
130 struct pt_regs *regs, unsigned long mask)
132 int err = 0;
134 put_user_try {
136 #ifdef CONFIG_X86_32
137 put_user_ex(get_user_gs(regs), (unsigned int __user *)&sc->gs);
138 put_user_ex(regs->fs, (unsigned int __user *)&sc->fs);
139 put_user_ex(regs->es, (unsigned int __user *)&sc->es);
140 put_user_ex(regs->ds, (unsigned int __user *)&sc->ds);
141 #endif /* CONFIG_X86_32 */
143 put_user_ex(regs->di, &sc->di);
144 put_user_ex(regs->si, &sc->si);
145 put_user_ex(regs->bp, &sc->bp);
146 put_user_ex(regs->sp, &sc->sp);
147 put_user_ex(regs->bx, &sc->bx);
148 put_user_ex(regs->dx, &sc->dx);
149 put_user_ex(regs->cx, &sc->cx);
150 put_user_ex(regs->ax, &sc->ax);
151 #ifdef CONFIG_X86_64
152 put_user_ex(regs->r8, &sc->r8);
153 put_user_ex(regs->r9, &sc->r9);
154 put_user_ex(regs->r10, &sc->r10);
155 put_user_ex(regs->r11, &sc->r11);
156 put_user_ex(regs->r12, &sc->r12);
157 put_user_ex(regs->r13, &sc->r13);
158 put_user_ex(regs->r14, &sc->r14);
159 put_user_ex(regs->r15, &sc->r15);
160 #endif /* CONFIG_X86_64 */
162 put_user_ex(current->thread.trap_no, &sc->trapno);
163 put_user_ex(current->thread.error_code, &sc->err);
164 put_user_ex(regs->ip, &sc->ip);
165 #ifdef CONFIG_X86_32
166 put_user_ex(regs->cs, (unsigned int __user *)&sc->cs);
167 put_user_ex(regs->flags, &sc->flags);
168 put_user_ex(regs->sp, &sc->sp_at_signal);
169 put_user_ex(regs->ss, (unsigned int __user *)&sc->ss);
170 #else /* !CONFIG_X86_32 */
171 put_user_ex(regs->flags, &sc->flags);
172 put_user_ex(regs->cs, &sc->cs);
173 put_user_ex(0, &sc->gs);
174 put_user_ex(0, &sc->fs);
175 #endif /* CONFIG_X86_32 */
177 put_user_ex(fpstate, &sc->fpstate);
179 /* non-iBCS2 extensions.. */
180 put_user_ex(mask, &sc->oldmask);
181 put_user_ex(current->thread.cr2, &sc->cr2);
182 } put_user_catch(err);
184 return err;
188 * Set up a signal frame.
192 * Determine which stack to use..
194 static unsigned long align_sigframe(unsigned long sp)
196 #ifdef CONFIG_X86_32
198 * Align the stack pointer according to the i386 ABI,
199 * i.e. so that on function entry ((sp + 4) & 15) == 0.
201 sp = ((sp + 4) & -16ul) - 4;
202 #else /* !CONFIG_X86_32 */
203 sp = round_down(sp, 16) - 8;
204 #endif
205 return sp;
208 static inline void __user *
209 get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
210 void __user **fpstate)
212 /* Default to using normal stack */
213 unsigned long sp = regs->sp;
214 int onsigstack = on_sig_stack(sp);
216 #ifdef CONFIG_X86_64
217 /* redzone */
218 sp -= 128;
219 #endif /* CONFIG_X86_64 */
221 if (!onsigstack) {
222 /* This is the X/Open sanctioned signal stack switching. */
223 if (ka->sa.sa_flags & SA_ONSTACK) {
224 if (current->sas_ss_size)
225 sp = current->sas_ss_sp + current->sas_ss_size;
226 } else {
227 #ifdef CONFIG_X86_32
228 /* This is the legacy signal stack switching. */
229 if ((regs->ss & 0xffff) != __USER_DS &&
230 !(ka->sa.sa_flags & SA_RESTORER) &&
231 ka->sa.sa_restorer)
232 sp = (unsigned long) ka->sa.sa_restorer;
233 #endif /* CONFIG_X86_32 */
237 if (used_math()) {
238 sp -= sig_xstate_size;
239 #ifdef CONFIG_X86_64
240 sp = round_down(sp, 64);
241 #endif /* CONFIG_X86_64 */
242 *fpstate = (void __user *)sp;
245 sp = align_sigframe(sp - frame_size);
248 * If we are on the alternate signal stack and would overflow it, don't.
249 * Return an always-bogus address instead so we will die with SIGSEGV.
251 if (onsigstack && !likely(on_sig_stack(sp)))
252 return (void __user *)-1L;
254 /* save i387 state */
255 if (used_math() && save_i387_xstate(*fpstate) < 0)
256 return (void __user *)-1L;
258 return (void __user *)sp;
261 #ifdef CONFIG_X86_32
262 static const struct {
263 u16 poplmovl;
264 u32 val;
265 u16 int80;
266 } __attribute__((packed)) retcode = {
267 0xb858, /* popl %eax; movl $..., %eax */
268 __NR_sigreturn,
269 0x80cd, /* int $0x80 */
272 static const struct {
273 u8 movl;
274 u32 val;
275 u16 int80;
276 u8 pad;
277 } __attribute__((packed)) rt_retcode = {
278 0xb8, /* movl $..., %eax */
279 __NR_rt_sigreturn,
280 0x80cd, /* int $0x80 */
284 static int
285 __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
286 struct pt_regs *regs)
288 struct sigframe __user *frame;
289 void __user *restorer;
290 int err = 0;
291 void __user *fpstate = NULL;
293 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
295 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
296 return -EFAULT;
298 if (__put_user(sig, &frame->sig))
299 return -EFAULT;
301 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
302 return -EFAULT;
304 if (_NSIG_WORDS > 1) {
305 if (__copy_to_user(&frame->extramask, &set->sig[1],
306 sizeof(frame->extramask)))
307 return -EFAULT;
310 if (current->mm->context.vdso)
311 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
312 else
313 restorer = &frame->retcode;
314 if (ka->sa.sa_flags & SA_RESTORER)
315 restorer = ka->sa.sa_restorer;
317 /* Set up to return from userspace. */
318 err |= __put_user(restorer, &frame->pretcode);
321 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
323 * WE DO NOT USE IT ANY MORE! It's only left here for historical
324 * reasons and because gdb uses it as a signature to notice
325 * signal handler stack frames.
327 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
329 if (err)
330 return -EFAULT;
332 /* Set up registers for signal handler */
333 regs->sp = (unsigned long)frame;
334 regs->ip = (unsigned long)ka->sa.sa_handler;
335 regs->ax = (unsigned long)sig;
336 regs->dx = 0;
337 regs->cx = 0;
339 regs->ds = __USER_DS;
340 regs->es = __USER_DS;
341 regs->ss = __USER_DS;
342 regs->cs = __USER_CS;
344 return 0;
347 static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
348 sigset_t *set, struct pt_regs *regs)
350 struct rt_sigframe __user *frame;
351 void __user *restorer;
352 int err = 0;
353 void __user *fpstate = NULL;
355 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
357 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
358 return -EFAULT;
360 put_user_try {
361 put_user_ex(sig, &frame->sig);
362 put_user_ex(&frame->info, &frame->pinfo);
363 put_user_ex(&frame->uc, &frame->puc);
364 err |= copy_siginfo_to_user(&frame->info, info);
366 /* Create the ucontext. */
367 if (cpu_has_xsave)
368 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
369 else
370 put_user_ex(0, &frame->uc.uc_flags);
371 put_user_ex(0, &frame->uc.uc_link);
372 put_user_ex(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
373 put_user_ex(sas_ss_flags(regs->sp),
374 &frame->uc.uc_stack.ss_flags);
375 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
376 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
377 regs, set->sig[0]);
378 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
380 /* Set up to return from userspace. */
381 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
382 if (ka->sa.sa_flags & SA_RESTORER)
383 restorer = ka->sa.sa_restorer;
384 put_user_ex(restorer, &frame->pretcode);
387 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
389 * WE DO NOT USE IT ANY MORE! It's only left here for historical
390 * reasons and because gdb uses it as a signature to notice
391 * signal handler stack frames.
393 put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
394 } put_user_catch(err);
396 if (err)
397 return -EFAULT;
399 /* Set up registers for signal handler */
400 regs->sp = (unsigned long)frame;
401 regs->ip = (unsigned long)ka->sa.sa_handler;
402 regs->ax = (unsigned long)sig;
403 regs->dx = (unsigned long)&frame->info;
404 regs->cx = (unsigned long)&frame->uc;
406 regs->ds = __USER_DS;
407 regs->es = __USER_DS;
408 regs->ss = __USER_DS;
409 regs->cs = __USER_CS;
411 return 0;
413 #else /* !CONFIG_X86_32 */
414 static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
415 sigset_t *set, struct pt_regs *regs)
417 struct rt_sigframe __user *frame;
418 void __user *fp = NULL;
419 int err = 0;
420 struct task_struct *me = current;
422 frame = get_sigframe(ka, regs, sizeof(struct rt_sigframe), &fp);
424 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
425 return -EFAULT;
427 if (ka->sa.sa_flags & SA_SIGINFO) {
428 if (copy_siginfo_to_user(&frame->info, info))
429 return -EFAULT;
432 put_user_try {
433 /* Create the ucontext. */
434 if (cpu_has_xsave)
435 put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
436 else
437 put_user_ex(0, &frame->uc.uc_flags);
438 put_user_ex(0, &frame->uc.uc_link);
439 put_user_ex(me->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
440 put_user_ex(sas_ss_flags(regs->sp),
441 &frame->uc.uc_stack.ss_flags);
442 put_user_ex(me->sas_ss_size, &frame->uc.uc_stack.ss_size);
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 /* Set up to return from userspace. If provided, use a stub
447 already in userspace. */
448 /* x86-64 should always use SA_RESTORER. */
449 if (ka->sa.sa_flags & SA_RESTORER) {
450 put_user_ex(ka->sa.sa_restorer, &frame->pretcode);
451 } else {
452 /* could use a vstub here */
453 err |= -EFAULT;
455 } put_user_catch(err);
457 if (err)
458 return -EFAULT;
460 /* Set up registers for signal handler */
461 regs->di = sig;
462 /* In case the signal handler was declared without prototypes */
463 regs->ax = 0;
465 /* This also works for non SA_SIGINFO handlers because they expect the
466 next argument after the signal number on the stack. */
467 regs->si = (unsigned long)&frame->info;
468 regs->dx = (unsigned long)&frame->uc;
469 regs->ip = (unsigned long) ka->sa.sa_handler;
471 regs->sp = (unsigned long)frame;
473 /* Set up the CS register to run signal handlers in 64-bit mode,
474 even if the handler happens to be interrupting 32-bit code. */
475 regs->cs = __USER_CS;
477 return 0;
479 #endif /* CONFIG_X86_32 */
481 #ifdef CONFIG_X86_32
483 * Atomically swap in the new signal mask, and wait for a signal.
485 asmlinkage int
486 sys_sigsuspend(int history0, int history1, old_sigset_t mask)
488 sigset_t blocked;
490 current->saved_sigmask = current->blocked;
492 mask &= _BLOCKABLE;
493 siginitset(&blocked, mask);
494 set_current_blocked(&blocked);
496 current->state = TASK_INTERRUPTIBLE;
497 schedule();
499 set_restore_sigmask();
500 return -ERESTARTNOHAND;
503 asmlinkage int
504 sys_sigaction(int sig, const struct old_sigaction __user *act,
505 struct old_sigaction __user *oact)
507 struct k_sigaction new_ka, old_ka;
508 int ret = 0;
510 if (act) {
511 old_sigset_t mask;
513 if (!access_ok(VERIFY_READ, act, sizeof(*act)))
514 return -EFAULT;
516 get_user_try {
517 get_user_ex(new_ka.sa.sa_handler, &act->sa_handler);
518 get_user_ex(new_ka.sa.sa_flags, &act->sa_flags);
519 get_user_ex(mask, &act->sa_mask);
520 get_user_ex(new_ka.sa.sa_restorer, &act->sa_restorer);
521 } get_user_catch(ret);
523 if (ret)
524 return -EFAULT;
525 siginitset(&new_ka.sa.sa_mask, mask);
528 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
530 if (!ret && oact) {
531 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
532 return -EFAULT;
534 put_user_try {
535 put_user_ex(old_ka.sa.sa_handler, &oact->sa_handler);
536 put_user_ex(old_ka.sa.sa_flags, &oact->sa_flags);
537 put_user_ex(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
538 put_user_ex(old_ka.sa.sa_restorer, &oact->sa_restorer);
539 } put_user_catch(ret);
541 if (ret)
542 return -EFAULT;
545 return ret;
547 #endif /* CONFIG_X86_32 */
549 long
550 sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
551 struct pt_regs *regs)
553 return do_sigaltstack(uss, uoss, regs->sp);
557 * Do a signal return; undo the signal stack.
559 #ifdef CONFIG_X86_32
560 unsigned long sys_sigreturn(struct pt_regs *regs)
562 struct sigframe __user *frame;
563 unsigned long ax;
564 sigset_t set;
566 frame = (struct sigframe __user *)(regs->sp - 8);
568 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
569 goto badframe;
570 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
571 && __copy_from_user(&set.sig[1], &frame->extramask,
572 sizeof(frame->extramask))))
573 goto badframe;
575 sigdelsetmask(&set, ~_BLOCKABLE);
576 set_current_blocked(&set);
578 if (restore_sigcontext(regs, &frame->sc, &ax))
579 goto badframe;
580 return ax;
582 badframe:
583 signal_fault(regs, frame, "sigreturn");
585 return 0;
587 #endif /* CONFIG_X86_32 */
589 long sys_rt_sigreturn(struct pt_regs *regs)
591 struct rt_sigframe __user *frame;
592 unsigned long ax;
593 sigset_t set;
595 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
596 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
597 goto badframe;
598 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
599 goto badframe;
601 sigdelsetmask(&set, ~_BLOCKABLE);
602 set_current_blocked(&set);
604 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
605 goto badframe;
607 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
608 goto badframe;
610 return ax;
612 badframe:
613 signal_fault(regs, frame, "rt_sigreturn");
614 return 0;
618 * OK, we're invoking a handler:
620 static int signr_convert(int sig)
622 #ifdef CONFIG_X86_32
623 struct thread_info *info = current_thread_info();
625 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
626 return info->exec_domain->signal_invmap[sig];
627 #endif /* CONFIG_X86_32 */
628 return sig;
631 #ifdef CONFIG_X86_32
633 #define is_ia32 1
634 #define ia32_setup_frame __setup_frame
635 #define ia32_setup_rt_frame __setup_rt_frame
637 #else /* !CONFIG_X86_32 */
639 #ifdef CONFIG_IA32_EMULATION
640 #define is_ia32 test_thread_flag(TIF_IA32)
641 #else /* !CONFIG_IA32_EMULATION */
642 #define is_ia32 0
643 #endif /* CONFIG_IA32_EMULATION */
645 int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
646 sigset_t *set, struct pt_regs *regs);
647 int ia32_setup_frame(int sig, struct k_sigaction *ka,
648 sigset_t *set, struct pt_regs *regs);
650 #endif /* CONFIG_X86_32 */
652 static int
653 setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
654 struct pt_regs *regs)
656 int usig = signr_convert(sig);
657 sigset_t *set = &current->blocked;
658 int ret;
660 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
661 set = &current->saved_sigmask;
663 /* Set up the stack frame */
664 if (is_ia32) {
665 if (ka->sa.sa_flags & SA_SIGINFO)
666 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
667 else
668 ret = ia32_setup_frame(usig, ka, set, regs);
669 } else
670 ret = __setup_rt_frame(sig, ka, info, set, regs);
672 if (ret) {
673 force_sigsegv(sig, current);
674 return -EFAULT;
677 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
678 return ret;
681 static int
682 handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
683 struct pt_regs *regs)
685 int ret;
687 /* Are we from a system call? */
688 if (syscall_get_nr(current, regs) >= 0) {
689 /* If so, check system call restarting.. */
690 switch (syscall_get_error(current, regs)) {
691 case -ERESTART_RESTARTBLOCK:
692 case -ERESTARTNOHAND:
693 regs->ax = -EINTR;
694 break;
696 case -ERESTARTSYS:
697 if (!(ka->sa.sa_flags & SA_RESTART)) {
698 regs->ax = -EINTR;
699 break;
701 /* fallthrough */
702 case -ERESTARTNOINTR:
703 regs->ax = regs->orig_ax;
704 regs->ip -= 2;
705 break;
710 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
711 * flag so that register information in the sigcontext is correct.
713 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
714 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
715 regs->flags &= ~X86_EFLAGS_TF;
717 ret = setup_rt_frame(sig, ka, info, regs);
719 if (ret)
720 return ret;
723 * Clear the direction flag as per the ABI for function entry.
725 regs->flags &= ~X86_EFLAGS_DF;
728 * Clear TF when entering the signal handler, but
729 * notify any tracer that was single-stepping it.
730 * The tracer may want to single-step inside the
731 * handler too.
733 regs->flags &= ~X86_EFLAGS_TF;
735 block_sigmask(ka, sig);
737 tracehook_signal_handler(sig, info, ka, regs,
738 test_thread_flag(TIF_SINGLESTEP));
740 return 0;
743 #ifdef CONFIG_X86_32
744 #define NR_restart_syscall __NR_restart_syscall
745 #else /* !CONFIG_X86_32 */
746 #define NR_restart_syscall \
747 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
748 #endif /* CONFIG_X86_32 */
751 * Note that 'init' is a special process: it doesn't get signals it doesn't
752 * want to handle. Thus you cannot kill init even with a SIGKILL even by
753 * mistake.
755 static void do_signal(struct pt_regs *regs)
757 struct k_sigaction ka;
758 siginfo_t info;
759 int signr;
762 * We want the common case to go fast, which is why we may in certain
763 * cases get here from kernel mode. Just return without doing anything
764 * if so.
765 * X86_32: vm86 regs switched out by assembly code before reaching
766 * here, so testing against kernel CS suffices.
768 if (!user_mode(regs))
769 return;
771 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
772 if (signr > 0) {
773 /* Whee! Actually deliver the signal. */
774 handle_signal(signr, &info, &ka, regs);
775 return;
778 /* Did we come from a system call? */
779 if (syscall_get_nr(current, regs) >= 0) {
780 /* Restart the system call - no handlers present */
781 switch (syscall_get_error(current, regs)) {
782 case -ERESTARTNOHAND:
783 case -ERESTARTSYS:
784 case -ERESTARTNOINTR:
785 regs->ax = regs->orig_ax;
786 regs->ip -= 2;
787 break;
789 case -ERESTART_RESTARTBLOCK:
790 regs->ax = NR_restart_syscall;
791 regs->ip -= 2;
792 break;
797 * If there's no signal to deliver, we just put the saved sigmask
798 * back.
800 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
801 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
802 set_current_blocked(&current->saved_sigmask);
807 * notification of userspace execution resumption
808 * - triggered by the TIF_WORK_MASK flags
810 void
811 do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
813 #ifdef CONFIG_X86_MCE
814 /* notify userspace of pending MCEs */
815 if (thread_info_flags & _TIF_MCE_NOTIFY)
816 mce_notify_process();
817 #endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
819 /* deal with pending signal delivery */
820 if (thread_info_flags & _TIF_SIGPENDING)
821 do_signal(regs);
823 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
824 clear_thread_flag(TIF_NOTIFY_RESUME);
825 tracehook_notify_resume(regs);
826 if (current->replacement_session_keyring)
827 key_replace_session_keyring();
829 if (thread_info_flags & _TIF_USER_RETURN_NOTIFY)
830 fire_user_return_notifiers();
832 #ifdef CONFIG_X86_32
833 clear_thread_flag(TIF_IRET);
834 #endif /* CONFIG_X86_32 */
837 void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
839 struct task_struct *me = current;
841 if (show_unhandled_signals && printk_ratelimit()) {
842 printk("%s"
843 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
844 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
845 me->comm, me->pid, where, frame,
846 regs->ip, regs->sp, regs->orig_ax);
847 print_vma_addr(" in ", regs->ip);
848 printk(KERN_CONT "\n");
851 force_sig(SIGSEGV, me);