b3f30d2a21781da5d2697861dabf38d52d4417f6
[deliverable/linux.git] / arch / x86 / kernel / signal_32.c
1 /*
2 * Copyright (C) 1991, 1992 Linus Torvalds
3 *
4 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
5 * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes
6 */
7
8 #include <linux/sched.h>
9 #include <linux/mm.h>
10 #include <linux/smp.h>
11 #include <linux/kernel.h>
12 #include <linux/signal.h>
13 #include <linux/errno.h>
14 #include <linux/wait.h>
15 #include <linux/ptrace.h>
16 #include <linux/tracehook.h>
17 #include <linux/unistd.h>
18 #include <linux/stddef.h>
19 #include <linux/personality.h>
20 #include <linux/uaccess.h>
21
22 #include <asm/processor.h>
23 #include <asm/ucontext.h>
24 #include <asm/i387.h>
25 #include <asm/vdso.h>
26
27 #ifdef CONFIG_X86_64
28 #include <asm/proto.h>
29 #include <asm/ia32_unistd.h>
30 #include <asm/mce.h>
31 #endif /* CONFIG_X86_64 */
32
33 #include <asm/syscall.h>
34 #include <asm/syscalls.h>
35
36 #include "sigframe.h"
37
38 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
39
40 #define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \
41 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
42 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
43 X86_EFLAGS_CF)
44
45 #ifdef CONFIG_X86_32
46 # define FIX_EFLAGS (__FIX_EFLAGS | X86_EFLAGS_RF)
47 #else
48 # define FIX_EFLAGS __FIX_EFLAGS
49 #endif
50
51 static const struct {
52 u16 poplmovl;
53 u32 val;
54 u16 int80;
55 } __attribute__((packed)) retcode = {
56 0xb858, /* popl %eax; movl $..., %eax */
57 __NR_sigreturn,
58 0x80cd, /* int $0x80 */
59 };
60
61 static const struct {
62 u8 movl;
63 u32 val;
64 u16 int80;
65 u8 pad;
66 } __attribute__((packed)) rt_retcode = {
67 0xb8, /* movl $..., %eax */
68 __NR_rt_sigreturn,
69 0x80cd, /* int $0x80 */
70 0
71 };
72
73 #define COPY(x) { \
74 err |= __get_user(regs->x, &sc->x); \
75 }
76
77 #define COPY_SEG(seg) { \
78 unsigned short tmp; \
79 err |= __get_user(tmp, &sc->seg); \
80 regs->seg = tmp; \
81 }
82
83 #define COPY_SEG_CPL3(seg) { \
84 unsigned short tmp; \
85 err |= __get_user(tmp, &sc->seg); \
86 regs->seg = tmp | 3; \
87 }
88
89 #define GET_SEG(seg) { \
90 unsigned short tmp; \
91 err |= __get_user(tmp, &sc->seg); \
92 loadsegment(seg, tmp); \
93 }
94
95 static int
96 restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
97 unsigned long *pax)
98 {
99 void __user *buf;
100 unsigned int tmpflags;
101 unsigned int err = 0;
102
103 /* Always make any pending restarted system calls return -EINTR */
104 current_thread_info()->restart_block.fn = do_no_restart_syscall;
105
106 #ifdef CONFIG_X86_32
107 GET_SEG(gs);
108 COPY_SEG(fs);
109 COPY_SEG(es);
110 COPY_SEG(ds);
111 #endif /* CONFIG_X86_32 */
112
113 COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
114 COPY(dx); COPY(cx); COPY(ip);
115
116 #ifdef CONFIG_X86_64
117 COPY(r8);
118 COPY(r9);
119 COPY(r10);
120 COPY(r11);
121 COPY(r12);
122 COPY(r13);
123 COPY(r14);
124 COPY(r15);
125 #endif /* CONFIG_X86_64 */
126
127 #ifdef CONFIG_X86_32
128 COPY_SEG_CPL3(cs);
129 COPY_SEG_CPL3(ss);
130 #else /* !CONFIG_X86_32 */
131 /* Kernel saves and restores only the CS segment register on signals,
132 * which is the bare minimum needed to allow mixed 32/64-bit code.
133 * App's signal handler can save/restore other segments if needed. */
134 COPY_SEG_CPL3(cs);
135 #endif /* CONFIG_X86_32 */
136
137 err |= __get_user(tmpflags, &sc->flags);
138 regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
139 regs->orig_ax = -1; /* disable syscall checks */
140
141 err |= __get_user(buf, &sc->fpstate);
142 err |= restore_i387_xstate(buf);
143
144 err |= __get_user(*pax, &sc->ax);
145 return err;
146 }
147
148 static int
149 setup_sigcontext(struct sigcontext __user *sc, void __user *fpstate,
150 struct pt_regs *regs, unsigned long mask)
151 {
152 int err = 0;
153
154 #ifdef CONFIG_X86_32
155 {
156 unsigned int tmp;
157
158 savesegment(gs, tmp);
159 err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
160 }
161 err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs);
162 err |= __put_user(regs->es, (unsigned int __user *)&sc->es);
163 err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds);
164 #endif /* CONFIG_X86_32 */
165
166 err |= __put_user(regs->di, &sc->di);
167 err |= __put_user(regs->si, &sc->si);
168 err |= __put_user(regs->bp, &sc->bp);
169 err |= __put_user(regs->sp, &sc->sp);
170 err |= __put_user(regs->bx, &sc->bx);
171 err |= __put_user(regs->dx, &sc->dx);
172 err |= __put_user(regs->cx, &sc->cx);
173 err |= __put_user(regs->ax, &sc->ax);
174 #ifdef CONFIG_X86_64
175 err |= __put_user(regs->r8, &sc->r8);
176 err |= __put_user(regs->r9, &sc->r9);
177 err |= __put_user(regs->r10, &sc->r10);
178 err |= __put_user(regs->r11, &sc->r11);
179 err |= __put_user(regs->r12, &sc->r12);
180 err |= __put_user(regs->r13, &sc->r13);
181 err |= __put_user(regs->r14, &sc->r14);
182 err |= __put_user(regs->r15, &sc->r15);
183 #endif /* CONFIG_X86_64 */
184
185 err |= __put_user(current->thread.trap_no, &sc->trapno);
186 err |= __put_user(current->thread.error_code, &sc->err);
187 err |= __put_user(regs->ip, &sc->ip);
188 #ifdef CONFIG_X86_32
189 err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs);
190 err |= __put_user(regs->flags, &sc->flags);
191 err |= __put_user(regs->sp, &sc->sp_at_signal);
192 err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss);
193 #else /* !CONFIG_X86_32 */
194 err |= __put_user(regs->flags, &sc->flags);
195 err |= __put_user(regs->cs, &sc->cs);
196 err |= __put_user(0, &sc->gs);
197 err |= __put_user(0, &sc->fs);
198 #endif /* CONFIG_X86_32 */
199
200 err |= __put_user(fpstate, &sc->fpstate);
201
202 /* non-iBCS2 extensions.. */
203 err |= __put_user(mask, &sc->oldmask);
204 err |= __put_user(current->thread.cr2, &sc->cr2);
205
206 return err;
207 }
208
209 /*
210 * Atomically swap in the new signal mask, and wait for a signal.
211 */
212 asmlinkage int
213 sys_sigsuspend(int history0, int history1, old_sigset_t mask)
214 {
215 mask &= _BLOCKABLE;
216 spin_lock_irq(&current->sighand->siglock);
217 current->saved_sigmask = current->blocked;
218 siginitset(&current->blocked, mask);
219 recalc_sigpending();
220 spin_unlock_irq(&current->sighand->siglock);
221
222 current->state = TASK_INTERRUPTIBLE;
223 schedule();
224 set_restore_sigmask();
225
226 return -ERESTARTNOHAND;
227 }
228
229 asmlinkage int
230 sys_sigaction(int sig, const struct old_sigaction __user *act,
231 struct old_sigaction __user *oact)
232 {
233 struct k_sigaction new_ka, old_ka;
234 int ret;
235
236 if (act) {
237 old_sigset_t mask;
238
239 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
240 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
241 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
242 return -EFAULT;
243
244 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
245 __get_user(mask, &act->sa_mask);
246 siginitset(&new_ka.sa.sa_mask, mask);
247 }
248
249 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
250
251 if (!ret && oact) {
252 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
253 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
254 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
255 return -EFAULT;
256
257 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
258 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
259 }
260
261 return ret;
262 }
263
264 #ifdef CONFIG_X86_32
265 asmlinkage int sys_sigaltstack(unsigned long bx)
266 {
267 /*
268 * This is needed to make gcc realize it doesn't own the
269 * "struct pt_regs"
270 */
271 struct pt_regs *regs = (struct pt_regs *)&bx;
272 const stack_t __user *uss = (const stack_t __user *)bx;
273 stack_t __user *uoss = (stack_t __user *)regs->cx;
274
275 return do_sigaltstack(uss, uoss, regs->sp);
276 }
277 #else /* !CONFIG_X86_32 */
278 asmlinkage long
279 sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
280 struct pt_regs *regs)
281 {
282 return do_sigaltstack(uss, uoss, regs->sp);
283 }
284 #endif /* CONFIG_X86_32 */
285
286 /*
287 * Do a signal return; undo the signal stack.
288 */
289 asmlinkage unsigned long sys_sigreturn(unsigned long __unused)
290 {
291 struct sigframe __user *frame;
292 struct pt_regs *regs;
293 unsigned long ax;
294 sigset_t set;
295
296 regs = (struct pt_regs *) &__unused;
297 frame = (struct sigframe __user *)(regs->sp - 8);
298
299 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
300 goto badframe;
301 if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1
302 && __copy_from_user(&set.sig[1], &frame->extramask,
303 sizeof(frame->extramask))))
304 goto badframe;
305
306 sigdelsetmask(&set, ~_BLOCKABLE);
307 spin_lock_irq(&current->sighand->siglock);
308 current->blocked = set;
309 recalc_sigpending();
310 spin_unlock_irq(&current->sighand->siglock);
311
312 if (restore_sigcontext(regs, &frame->sc, &ax))
313 goto badframe;
314 return ax;
315
316 badframe:
317 if (show_unhandled_signals && printk_ratelimit()) {
318 printk("%s%s[%d] bad frame in sigreturn frame:"
319 "%p ip:%lx sp:%lx oeax:%lx",
320 task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
321 current->comm, task_pid_nr(current), frame, regs->ip,
322 regs->sp, regs->orig_ax);
323 print_vma_addr(" in ", regs->ip);
324 printk(KERN_CONT "\n");
325 }
326
327 force_sig(SIGSEGV, current);
328
329 return 0;
330 }
331
332 static long do_rt_sigreturn(struct pt_regs *regs)
333 {
334 struct rt_sigframe __user *frame;
335 unsigned long ax;
336 sigset_t set;
337
338 frame = (struct rt_sigframe __user *)(regs->sp - sizeof(long));
339 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
340 goto badframe;
341 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
342 goto badframe;
343
344 sigdelsetmask(&set, ~_BLOCKABLE);
345 spin_lock_irq(&current->sighand->siglock);
346 current->blocked = set;
347 recalc_sigpending();
348 spin_unlock_irq(&current->sighand->siglock);
349
350 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
351 goto badframe;
352
353 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
354 goto badframe;
355
356 return ax;
357
358 badframe:
359 signal_fault(regs, frame, "rt_sigreturn");
360 return 0;
361 }
362
363 #ifdef CONFIG_X86_32
364 asmlinkage int sys_rt_sigreturn(unsigned long __unused)
365 {
366 struct pt_regs *regs = (struct pt_regs *)&__unused;
367
368 return do_rt_sigreturn(regs);
369 }
370 #else /* !CONFIG_X86_32 */
371 asmlinkage long sys_rt_sigreturn(struct pt_regs *regs)
372 {
373 return do_rt_sigreturn(regs);
374 }
375 #endif /* CONFIG_X86_32 */
376
377 /*
378 * Set up a signal frame.
379 */
380
381 /*
382 * Determine which stack to use..
383 */
384 static inline void __user *
385 get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
386 void **fpstate)
387 {
388 unsigned long sp;
389
390 /* Default to using normal stack */
391 sp = regs->sp;
392
393 /*
394 * If we are on the alternate signal stack and would overflow it, don't.
395 * Return an always-bogus address instead so we will die with SIGSEGV.
396 */
397 if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
398 return (void __user *) -1L;
399
400 /* This is the X/Open sanctioned signal stack switching. */
401 if (ka->sa.sa_flags & SA_ONSTACK) {
402 if (sas_ss_flags(sp) == 0)
403 sp = current->sas_ss_sp + current->sas_ss_size;
404 } else {
405 /* This is the legacy signal stack switching. */
406 if ((regs->ss & 0xffff) != __USER_DS &&
407 !(ka->sa.sa_flags & SA_RESTORER) &&
408 ka->sa.sa_restorer)
409 sp = (unsigned long) ka->sa.sa_restorer;
410 }
411
412 if (used_math()) {
413 sp = sp - sig_xstate_size;
414 *fpstate = (struct _fpstate *) sp;
415 if (save_i387_xstate(*fpstate) < 0)
416 return (void __user *)-1L;
417 }
418
419 sp -= frame_size;
420 /*
421 * Align the stack pointer according to the i386 ABI,
422 * i.e. so that on function entry ((sp + 4) & 15) == 0.
423 */
424 sp = ((sp + 4) & -16ul) - 4;
425
426 return (void __user *) sp;
427 }
428
429 static int
430 __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
431 struct pt_regs *regs)
432 {
433 struct sigframe __user *frame;
434 void __user *restorer;
435 int err = 0;
436 void __user *fpstate = NULL;
437
438 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
439
440 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
441 return -EFAULT;
442
443 if (__put_user(sig, &frame->sig))
444 return -EFAULT;
445
446 if (setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
447 return -EFAULT;
448
449 if (_NSIG_WORDS > 1) {
450 if (__copy_to_user(&frame->extramask, &set->sig[1],
451 sizeof(frame->extramask)))
452 return -EFAULT;
453 }
454
455 if (current->mm->context.vdso)
456 restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
457 else
458 restorer = &frame->retcode;
459 if (ka->sa.sa_flags & SA_RESTORER)
460 restorer = ka->sa.sa_restorer;
461
462 /* Set up to return from userspace. */
463 err |= __put_user(restorer, &frame->pretcode);
464
465 /*
466 * This is popl %eax ; movl $__NR_sigreturn, %eax ; int $0x80
467 *
468 * WE DO NOT USE IT ANY MORE! It's only left here for historical
469 * reasons and because gdb uses it as a signature to notice
470 * signal handler stack frames.
471 */
472 err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
473
474 if (err)
475 return -EFAULT;
476
477 /* Set up registers for signal handler */
478 regs->sp = (unsigned long)frame;
479 regs->ip = (unsigned long)ka->sa.sa_handler;
480 regs->ax = (unsigned long)sig;
481 regs->dx = 0;
482 regs->cx = 0;
483
484 regs->ds = __USER_DS;
485 regs->es = __USER_DS;
486 regs->ss = __USER_DS;
487 regs->cs = __USER_CS;
488
489 return 0;
490 }
491
492 static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
493 sigset_t *set, struct pt_regs *regs)
494 {
495 struct rt_sigframe __user *frame;
496 void __user *restorer;
497 int err = 0;
498 void __user *fpstate = NULL;
499
500 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
501
502 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
503 return -EFAULT;
504
505 err |= __put_user(sig, &frame->sig);
506 err |= __put_user(&frame->info, &frame->pinfo);
507 err |= __put_user(&frame->uc, &frame->puc);
508 err |= copy_siginfo_to_user(&frame->info, info);
509 if (err)
510 return -EFAULT;
511
512 /* Create the ucontext. */
513 if (cpu_has_xsave)
514 err |= __put_user(UC_FP_XSTATE, &frame->uc.uc_flags);
515 else
516 err |= __put_user(0, &frame->uc.uc_flags);
517 err |= __put_user(0, &frame->uc.uc_link);
518 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
519 err |= __put_user(sas_ss_flags(regs->sp),
520 &frame->uc.uc_stack.ss_flags);
521 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
522 err |= setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
523 regs, set->sig[0]);
524 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
525 if (err)
526 return -EFAULT;
527
528 /* Set up to return from userspace. */
529 restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
530 if (ka->sa.sa_flags & SA_RESTORER)
531 restorer = ka->sa.sa_restorer;
532 err |= __put_user(restorer, &frame->pretcode);
533
534 /*
535 * This is movl $__NR_rt_sigreturn, %ax ; int $0x80
536 *
537 * WE DO NOT USE IT ANY MORE! It's only left here for historical
538 * reasons and because gdb uses it as a signature to notice
539 * signal handler stack frames.
540 */
541 err |= __put_user(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
542
543 if (err)
544 return -EFAULT;
545
546 /* Set up registers for signal handler */
547 regs->sp = (unsigned long)frame;
548 regs->ip = (unsigned long)ka->sa.sa_handler;
549 regs->ax = (unsigned long)sig;
550 regs->dx = (unsigned long)&frame->info;
551 regs->cx = (unsigned long)&frame->uc;
552
553 regs->ds = __USER_DS;
554 regs->es = __USER_DS;
555 regs->ss = __USER_DS;
556 regs->cs = __USER_CS;
557
558 return 0;
559 }
560
561 /*
562 * OK, we're invoking a handler:
563 */
564 static int signr_convert(int sig)
565 {
566 #ifdef CONFIG_X86_32
567 struct thread_info *info = current_thread_info();
568
569 if (info->exec_domain && info->exec_domain->signal_invmap && sig < 32)
570 return info->exec_domain->signal_invmap[sig];
571 #endif /* CONFIG_X86_32 */
572 return sig;
573 }
574
575 #ifdef CONFIG_X86_32
576
577 #define is_ia32 1
578 #define ia32_setup_frame __setup_frame
579 #define ia32_setup_rt_frame __setup_rt_frame
580
581 #else /* !CONFIG_X86_32 */
582
583 #ifdef CONFIG_IA32_EMULATION
584 #define is_ia32 test_thread_flag(TIF_IA32)
585 #else /* !CONFIG_IA32_EMULATION */
586 #define is_ia32 0
587 #endif /* CONFIG_IA32_EMULATION */
588
589 #endif /* CONFIG_X86_32 */
590
591 static int
592 setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
593 sigset_t *set, struct pt_regs *regs)
594 {
595 int usig = signr_convert(sig);
596 int ret;
597
598 /* Set up the stack frame */
599 if (is_ia32) {
600 if (ka->sa.sa_flags & SA_SIGINFO)
601 ret = ia32_setup_rt_frame(usig, ka, info, set, regs);
602 else
603 ret = ia32_setup_frame(usig, ka, set, regs);
604 } else
605 ret = __setup_rt_frame(sig, ka, info, set, regs);
606
607 if (ret) {
608 force_sigsegv(sig, current);
609 return -EFAULT;
610 }
611
612 return ret;
613 }
614
615 static int
616 handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
617 sigset_t *oldset, struct pt_regs *regs)
618 {
619 int ret;
620
621 /* Are we from a system call? */
622 if (syscall_get_nr(current, regs) >= 0) {
623 /* If so, check system call restarting.. */
624 switch (syscall_get_error(current, regs)) {
625 case -ERESTART_RESTARTBLOCK:
626 case -ERESTARTNOHAND:
627 regs->ax = -EINTR;
628 break;
629
630 case -ERESTARTSYS:
631 if (!(ka->sa.sa_flags & SA_RESTART)) {
632 regs->ax = -EINTR;
633 break;
634 }
635 /* fallthrough */
636 case -ERESTARTNOINTR:
637 regs->ax = regs->orig_ax;
638 regs->ip -= 2;
639 break;
640 }
641 }
642
643 /*
644 * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
645 * flag so that register information in the sigcontext is correct.
646 */
647 if (unlikely(regs->flags & X86_EFLAGS_TF) &&
648 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
649 regs->flags &= ~X86_EFLAGS_TF;
650
651 ret = setup_rt_frame(sig, ka, info, oldset, regs);
652
653 if (ret)
654 return ret;
655
656 #ifdef CONFIG_X86_64
657 /*
658 * This has nothing to do with segment registers,
659 * despite the name. This magic affects uaccess.h
660 * macros' behavior. Reset it to the normal setting.
661 */
662 set_fs(USER_DS);
663 #endif
664
665 /*
666 * Clear the direction flag as per the ABI for function entry.
667 */
668 regs->flags &= ~X86_EFLAGS_DF;
669
670 /*
671 * Clear TF when entering the signal handler, but
672 * notify any tracer that was single-stepping it.
673 * The tracer may want to single-step inside the
674 * handler too.
675 */
676 regs->flags &= ~X86_EFLAGS_TF;
677
678 spin_lock_irq(&current->sighand->siglock);
679 sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
680 if (!(ka->sa.sa_flags & SA_NODEFER))
681 sigaddset(&current->blocked, sig);
682 recalc_sigpending();
683 spin_unlock_irq(&current->sighand->siglock);
684
685 tracehook_signal_handler(sig, info, ka, regs,
686 test_thread_flag(TIF_SINGLESTEP));
687
688 return 0;
689 }
690
691 #ifdef CONFIG_X86_32
692 #define NR_restart_syscall __NR_restart_syscall
693 #else /* !CONFIG_X86_32 */
694 #define NR_restart_syscall \
695 test_thread_flag(TIF_IA32) ? __NR_ia32_restart_syscall : __NR_restart_syscall
696 #endif /* CONFIG_X86_32 */
697
698 /*
699 * Note that 'init' is a special process: it doesn't get signals it doesn't
700 * want to handle. Thus you cannot kill init even with a SIGKILL even by
701 * mistake.
702 */
703 static void do_signal(struct pt_regs *regs)
704 {
705 struct k_sigaction ka;
706 siginfo_t info;
707 int signr;
708 sigset_t *oldset;
709
710 /*
711 * We want the common case to go fast, which is why we may in certain
712 * cases get here from kernel mode. Just return without doing anything
713 * if so.
714 * X86_32: vm86 regs switched out by assembly code before reaching
715 * here, so testing against kernel CS suffices.
716 */
717 if (!user_mode(regs))
718 return;
719
720 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
721 oldset = &current->saved_sigmask;
722 else
723 oldset = &current->blocked;
724
725 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
726 if (signr > 0) {
727 /*
728 * Re-enable any watchpoints before delivering the
729 * signal to user space. The processor register will
730 * have been cleared if the watchpoint triggered
731 * inside the kernel.
732 */
733 if (current->thread.debugreg7)
734 set_debugreg(current->thread.debugreg7, 7);
735
736 /* Whee! Actually deliver the signal. */
737 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
738 /*
739 * A signal was successfully delivered; the saved
740 * sigmask will have been stored in the signal frame,
741 * and will be restored by sigreturn, so we can simply
742 * clear the TS_RESTORE_SIGMASK flag.
743 */
744 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
745 }
746 return;
747 }
748
749 /* Did we come from a system call? */
750 if (syscall_get_nr(current, regs) >= 0) {
751 /* Restart the system call - no handlers present */
752 switch (syscall_get_error(current, regs)) {
753 case -ERESTARTNOHAND:
754 case -ERESTARTSYS:
755 case -ERESTARTNOINTR:
756 regs->ax = regs->orig_ax;
757 regs->ip -= 2;
758 break;
759
760 case -ERESTART_RESTARTBLOCK:
761 regs->ax = NR_restart_syscall;
762 regs->ip -= 2;
763 break;
764 }
765 }
766
767 /*
768 * If there's no signal to deliver, we just put the saved sigmask
769 * back.
770 */
771 if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
772 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
773 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
774 }
775 }
776
777 /*
778 * notification of userspace execution resumption
779 * - triggered by the TIF_WORK_MASK flags
780 */
781 void
782 do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
783 {
784 #if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
785 /* notify userspace of pending MCEs */
786 if (thread_info_flags & _TIF_MCE_NOTIFY)
787 mce_notify_user();
788 #endif /* CONFIG_X86_64 && CONFIG_X86_MCE */
789
790 /* deal with pending signal delivery */
791 if (thread_info_flags & _TIF_SIGPENDING)
792 do_signal(regs);
793
794 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
795 clear_thread_flag(TIF_NOTIFY_RESUME);
796 tracehook_notify_resume(regs);
797 }
798
799 #ifdef CONFIG_X86_32
800 clear_thread_flag(TIF_IRET);
801 #endif /* CONFIG_X86_32 */
802 }
803
804 void signal_fault(struct pt_regs *regs, void __user *frame, char *where)
805 {
806 struct task_struct *me = current;
807
808 if (show_unhandled_signals && printk_ratelimit()) {
809 printk(KERN_INFO
810 "%s[%d] bad frame in %s frame:%p ip:%lx sp:%lx orax:%lx",
811 me->comm, me->pid, where, frame,
812 regs->ip, regs->sp, regs->orig_ax);
813 print_vma_addr(" in ", regs->ip);
814 printk(KERN_CONT "\n");
815 }
816
817 force_sig(SIGSEGV, me);
818 }
This page took 0.060561 seconds and 4 git commands to generate.