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