blob: 963616d364ec48984013edb1750ce1507df4fb44 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/i386/kernel/signal.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 *
6 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
7 * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes
8 */
9
10#include <linux/sched.h>
11#include <linux/mm.h>
12#include <linux/smp.h>
13#include <linux/smp_lock.h>
14#include <linux/kernel.h>
15#include <linux/signal.h>
16#include <linux/errno.h>
17#include <linux/wait.h>
18#include <linux/unistd.h>
19#include <linux/stddef.h>
20#include <linux/personality.h>
21#include <linux/suspend.h>
22#include <linux/ptrace.h>
23#include <linux/elf.h>
24#include <asm/processor.h>
25#include <asm/ucontext.h>
26#include <asm/uaccess.h>
27#include <asm/i387.h>
28#include "sigframe.h"
29
30#define DEBUG_SIG 0
31
32#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
33
34/*
35 * Atomically swap in the new signal mask, and wait for a signal.
36 */
37asmlinkage int
38sys_sigsuspend(int history0, int history1, old_sigset_t mask)
39{
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 mask &= _BLOCKABLE;
41 spin_lock_irq(&current->sighand->siglock);
David Howells283828f2006-01-18 17:44:00 -080042 current->saved_sigmask = current->blocked;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 siginitset(&current->blocked, mask);
44 recalc_sigpending();
45 spin_unlock_irq(&current->sighand->siglock);
46
David Howells283828f2006-01-18 17:44:00 -080047 current->state = TASK_INTERRUPTIBLE;
48 schedule();
49 set_thread_flag(TIF_RESTORE_SIGMASK);
50 return -ERESTARTNOHAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
53asmlinkage int
54sys_sigaction(int sig, const struct old_sigaction __user *act,
55 struct old_sigaction __user *oact)
56{
57 struct k_sigaction new_ka, old_ka;
58 int ret;
59
60 if (act) {
61 old_sigset_t mask;
62 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
63 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
64 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
65 return -EFAULT;
66 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
67 __get_user(mask, &act->sa_mask);
68 siginitset(&new_ka.sa.sa_mask, mask);
69 }
70
71 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
72
73 if (!ret && oact) {
74 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
75 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
76 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
77 return -EFAULT;
78 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
79 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
80 }
81
82 return ret;
83}
84
85asmlinkage int
86sys_sigaltstack(unsigned long ebx)
87{
88 /* This is needed to make gcc realize it doesn't own the "struct pt_regs" */
89 struct pt_regs *regs = (struct pt_regs *)&ebx;
90 const stack_t __user *uss = (const stack_t __user *)ebx;
91 stack_t __user *uoss = (stack_t __user *)regs->ecx;
92
93 return do_sigaltstack(uss, uoss, regs->esp);
94}
95
96
97/*
98 * Do a signal return; undo the signal stack.
99 */
100
101static int
102restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *peax)
103{
104 unsigned int err = 0;
105
106 /* Always make any pending restarted system calls return -EINTR */
107 current_thread_info()->restart_block.fn = do_no_restart_syscall;
108
109#define COPY(x) err |= __get_user(regs->x, &sc->x)
110
111#define COPY_SEG(seg) \
112 { unsigned short tmp; \
113 err |= __get_user(tmp, &sc->seg); \
114 regs->x##seg = tmp; }
115
116#define COPY_SEG_STRICT(seg) \
117 { unsigned short tmp; \
118 err |= __get_user(tmp, &sc->seg); \
119 regs->x##seg = tmp|3; }
120
121#define GET_SEG(seg) \
122 { unsigned short tmp; \
123 err |= __get_user(tmp, &sc->seg); \
124 loadsegment(seg,tmp); }
125
126#define FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | X86_EFLAGS_DF | \
127 X86_EFLAGS_TF | X86_EFLAGS_SF | X86_EFLAGS_ZF | \
128 X86_EFLAGS_AF | X86_EFLAGS_PF | X86_EFLAGS_CF)
129
130 GET_SEG(gs);
131 GET_SEG(fs);
132 COPY_SEG(es);
133 COPY_SEG(ds);
134 COPY(edi);
135 COPY(esi);
136 COPY(ebp);
137 COPY(esp);
138 COPY(ebx);
139 COPY(edx);
140 COPY(ecx);
141 COPY(eip);
142 COPY_SEG_STRICT(cs);
143 COPY_SEG_STRICT(ss);
144
145 {
146 unsigned int tmpflags;
147 err |= __get_user(tmpflags, &sc->eflags);
148 regs->eflags = (regs->eflags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
149 regs->orig_eax = -1; /* disable syscall checks */
150 }
151
152 {
153 struct _fpstate __user * buf;
154 err |= __get_user(buf, &sc->fpstate);
155 if (buf) {
156 if (!access_ok(VERIFY_READ, buf, sizeof(*buf)))
157 goto badframe;
158 err |= restore_i387(buf);
159 } else {
160 struct task_struct *me = current;
161 if (used_math()) {
162 clear_fpu(me);
163 clear_used_math();
164 }
165 }
166 }
167
168 err |= __get_user(*peax, &sc->eax);
169 return err;
170
171badframe:
172 return 1;
173}
174
175asmlinkage int sys_sigreturn(unsigned long __unused)
176{
177 struct pt_regs *regs = (struct pt_regs *) &__unused;
178 struct sigframe __user *frame = (struct sigframe __user *)(regs->esp - 8);
179 sigset_t set;
180 int eax;
181
182 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
183 goto badframe;
184 if (__get_user(set.sig[0], &frame->sc.oldmask)
185 || (_NSIG_WORDS > 1
186 && __copy_from_user(&set.sig[1], &frame->extramask,
187 sizeof(frame->extramask))))
188 goto badframe;
189
190 sigdelsetmask(&set, ~_BLOCKABLE);
191 spin_lock_irq(&current->sighand->siglock);
192 current->blocked = set;
193 recalc_sigpending();
194 spin_unlock_irq(&current->sighand->siglock);
195
196 if (restore_sigcontext(regs, &frame->sc, &eax))
197 goto badframe;
198 return eax;
199
200badframe:
201 force_sig(SIGSEGV, current);
202 return 0;
203}
204
205asmlinkage int sys_rt_sigreturn(unsigned long __unused)
206{
207 struct pt_regs *regs = (struct pt_regs *) &__unused;
208 struct rt_sigframe __user *frame = (struct rt_sigframe __user *)(regs->esp - 4);
209 sigset_t set;
210 int eax;
211
212 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
213 goto badframe;
214 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
215 goto badframe;
216
217 sigdelsetmask(&set, ~_BLOCKABLE);
218 spin_lock_irq(&current->sighand->siglock);
219 current->blocked = set;
220 recalc_sigpending();
221 spin_unlock_irq(&current->sighand->siglock);
222
223 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &eax))
224 goto badframe;
225
226 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->esp) == -EFAULT)
227 goto badframe;
228
229 return eax;
230
231badframe:
232 force_sig(SIGSEGV, current);
233 return 0;
234}
235
236/*
237 * Set up a signal frame.
238 */
239
240static int
241setup_sigcontext(struct sigcontext __user *sc, struct _fpstate __user *fpstate,
242 struct pt_regs *regs, unsigned long mask)
243{
244 int tmp, err = 0;
245
246 tmp = 0;
Zachary Amsden4d37e7e2005-09-03 15:56:38 -0700247 savesegment(gs, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
Zachary Amsden4d37e7e2005-09-03 15:56:38 -0700249 savesegment(fs, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 err |= __put_user(tmp, (unsigned int __user *)&sc->fs);
251
252 err |= __put_user(regs->xes, (unsigned int __user *)&sc->es);
253 err |= __put_user(regs->xds, (unsigned int __user *)&sc->ds);
254 err |= __put_user(regs->edi, &sc->edi);
255 err |= __put_user(regs->esi, &sc->esi);
256 err |= __put_user(regs->ebp, &sc->ebp);
257 err |= __put_user(regs->esp, &sc->esp);
258 err |= __put_user(regs->ebx, &sc->ebx);
259 err |= __put_user(regs->edx, &sc->edx);
260 err |= __put_user(regs->ecx, &sc->ecx);
261 err |= __put_user(regs->eax, &sc->eax);
262 err |= __put_user(current->thread.trap_no, &sc->trapno);
263 err |= __put_user(current->thread.error_code, &sc->err);
264 err |= __put_user(regs->eip, &sc->eip);
265 err |= __put_user(regs->xcs, (unsigned int __user *)&sc->cs);
266 err |= __put_user(regs->eflags, &sc->eflags);
267 err |= __put_user(regs->esp, &sc->esp_at_signal);
268 err |= __put_user(regs->xss, (unsigned int __user *)&sc->ss);
269
270 tmp = save_i387(fpstate);
271 if (tmp < 0)
272 err = 1;
273 else
274 err |= __put_user(tmp ? fpstate : NULL, &sc->fpstate);
275
276 /* non-iBCS2 extensions.. */
277 err |= __put_user(mask, &sc->oldmask);
278 err |= __put_user(current->thread.cr2, &sc->cr2);
279
280 return err;
281}
282
283/*
284 * Determine which stack to use..
285 */
286static inline void __user *
287get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
288{
289 unsigned long esp;
290
291 /* Default to using normal stack */
292 esp = regs->esp;
293
294 /* This is the X/Open sanctioned signal stack switching. */
295 if (ka->sa.sa_flags & SA_ONSTACK) {
296 if (sas_ss_flags(esp) == 0)
297 esp = current->sas_ss_sp + current->sas_ss_size;
298 }
299
300 /* This is the legacy signal stack switching. */
301 else if ((regs->xss & 0xffff) != __USER_DS &&
302 !(ka->sa.sa_flags & SA_RESTORER) &&
303 ka->sa.sa_restorer) {
304 esp = (unsigned long) ka->sa.sa_restorer;
305 }
306
Markus F.X.J. Oberhumerd347f372005-10-09 18:54:23 +0200307 esp -= frame_size;
308 /* Align the stack pointer according to the i386 ABI,
309 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
310 esp = ((esp + 4) & -16ul) - 4;
311 return (void __user *) esp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312}
313
314/* These symbols are defined with the addresses in the vsyscall page.
315 See vsyscall-sigreturn.S. */
316extern void __user __kernel_sigreturn;
317extern void __user __kernel_rt_sigreturn;
318
Roland McGrath7c1def12005-06-23 00:08:21 -0700319static int setup_frame(int sig, struct k_sigaction *ka,
320 sigset_t *set, struct pt_regs * regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
322 void __user *restorer;
323 struct sigframe __user *frame;
324 int err = 0;
325 int usig;
326
327 frame = get_sigframe(ka, regs, sizeof(*frame));
328
329 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
330 goto give_sigsegv;
331
332 usig = current_thread_info()->exec_domain
333 && current_thread_info()->exec_domain->signal_invmap
334 && sig < 32
335 ? current_thread_info()->exec_domain->signal_invmap[sig]
336 : sig;
337
338 err = __put_user(usig, &frame->sig);
339 if (err)
340 goto give_sigsegv;
341
342 err = setup_sigcontext(&frame->sc, &frame->fpstate, regs, set->sig[0]);
343 if (err)
344 goto give_sigsegv;
345
346 if (_NSIG_WORDS > 1) {
347 err = __copy_to_user(&frame->extramask, &set->sig[1],
348 sizeof(frame->extramask));
349 if (err)
350 goto give_sigsegv;
351 }
352
353 restorer = &__kernel_sigreturn;
354 if (ka->sa.sa_flags & SA_RESTORER)
355 restorer = ka->sa.sa_restorer;
356
357 /* Set up to return from userspace. */
358 err |= __put_user(restorer, &frame->pretcode);
359
360 /*
361 * This is popl %eax ; movl $,%eax ; int $0x80
362 *
363 * WE DO NOT USE IT ANY MORE! It's only left here for historical
364 * reasons and because gdb uses it as a signature to notice
365 * signal handler stack frames.
366 */
367 err |= __put_user(0xb858, (short __user *)(frame->retcode+0));
368 err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2));
369 err |= __put_user(0x80cd, (short __user *)(frame->retcode+6));
370
371 if (err)
372 goto give_sigsegv;
373
374 /* Set up registers for signal handler */
375 regs->esp = (unsigned long) frame;
376 regs->eip = (unsigned long) ka->sa.sa_handler;
377 regs->eax = (unsigned long) sig;
378 regs->edx = (unsigned long) 0;
379 regs->ecx = (unsigned long) 0;
380
381 set_fs(USER_DS);
382 regs->xds = __USER_DS;
383 regs->xes = __USER_DS;
384 regs->xss = __USER_DS;
385 regs->xcs = __USER_CS;
386
387 /*
388 * Clear TF when entering the signal handler, but
389 * notify any tracer that was single-stepping it.
390 * The tracer may want to single-step inside the
391 * handler too.
392 */
393 regs->eflags &= ~TF_MASK;
394 if (test_thread_flag(TIF_SINGLESTEP))
395 ptrace_notify(SIGTRAP);
396
397#if DEBUG_SIG
398 printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n",
399 current->comm, current->pid, frame, regs->eip, frame->pretcode);
400#endif
401
David Howells283828f2006-01-18 17:44:00 -0800402 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404give_sigsegv:
405 force_sigsegv(sig, current);
David Howells283828f2006-01-18 17:44:00 -0800406 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407}
408
Roland McGrath7c1def12005-06-23 00:08:21 -0700409static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 sigset_t *set, struct pt_regs * regs)
411{
412 void __user *restorer;
413 struct rt_sigframe __user *frame;
414 int err = 0;
415 int usig;
416
417 frame = get_sigframe(ka, regs, sizeof(*frame));
418
419 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
420 goto give_sigsegv;
421
422 usig = current_thread_info()->exec_domain
423 && current_thread_info()->exec_domain->signal_invmap
424 && sig < 32
425 ? current_thread_info()->exec_domain->signal_invmap[sig]
426 : sig;
427
428 err |= __put_user(usig, &frame->sig);
429 err |= __put_user(&frame->info, &frame->pinfo);
430 err |= __put_user(&frame->uc, &frame->puc);
431 err |= copy_siginfo_to_user(&frame->info, info);
432 if (err)
433 goto give_sigsegv;
434
435 /* Create the ucontext. */
436 err |= __put_user(0, &frame->uc.uc_flags);
437 err |= __put_user(0, &frame->uc.uc_link);
438 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
439 err |= __put_user(sas_ss_flags(regs->esp),
440 &frame->uc.uc_stack.ss_flags);
441 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
442 err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->fpstate,
443 regs, set->sig[0]);
444 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
445 if (err)
446 goto give_sigsegv;
447
448 /* Set up to return from userspace. */
449 restorer = &__kernel_rt_sigreturn;
450 if (ka->sa.sa_flags & SA_RESTORER)
451 restorer = ka->sa.sa_restorer;
452 err |= __put_user(restorer, &frame->pretcode);
453
454 /*
455 * This is movl $,%eax ; int $0x80
456 *
457 * WE DO NOT USE IT ANY MORE! It's only left here for historical
458 * reasons and because gdb uses it as a signature to notice
459 * signal handler stack frames.
460 */
461 err |= __put_user(0xb8, (char __user *)(frame->retcode+0));
462 err |= __put_user(__NR_rt_sigreturn, (int __user *)(frame->retcode+1));
463 err |= __put_user(0x80cd, (short __user *)(frame->retcode+5));
464
465 if (err)
466 goto give_sigsegv;
467
468 /* Set up registers for signal handler */
469 regs->esp = (unsigned long) frame;
470 regs->eip = (unsigned long) ka->sa.sa_handler;
471 regs->eax = (unsigned long) usig;
472 regs->edx = (unsigned long) &frame->info;
473 regs->ecx = (unsigned long) &frame->uc;
474
475 set_fs(USER_DS);
476 regs->xds = __USER_DS;
477 regs->xes = __USER_DS;
478 regs->xss = __USER_DS;
479 regs->xcs = __USER_CS;
480
481 /*
482 * Clear TF when entering the signal handler, but
483 * notify any tracer that was single-stepping it.
484 * The tracer may want to single-step inside the
485 * handler too.
486 */
487 regs->eflags &= ~TF_MASK;
488 if (test_thread_flag(TIF_SINGLESTEP))
489 ptrace_notify(SIGTRAP);
490
491#if DEBUG_SIG
492 printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n",
493 current->comm, current->pid, frame, regs->eip, frame->pretcode);
494#endif
495
David Howells283828f2006-01-18 17:44:00 -0800496 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498give_sigsegv:
499 force_sigsegv(sig, current);
David Howells283828f2006-01-18 17:44:00 -0800500 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
502
503/*
504 * OK, we're invoking a handler
505 */
506
Roland McGrath7c1def12005-06-23 00:08:21 -0700507static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
509 sigset_t *oldset, struct pt_regs * regs)
510{
Roland McGrath7c1def12005-06-23 00:08:21 -0700511 int ret;
512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 /* Are we from a system call? */
514 if (regs->orig_eax >= 0) {
515 /* If so, check system call restarting.. */
516 switch (regs->eax) {
517 case -ERESTART_RESTARTBLOCK:
518 case -ERESTARTNOHAND:
519 regs->eax = -EINTR;
520 break;
521
522 case -ERESTARTSYS:
523 if (!(ka->sa.sa_flags & SA_RESTART)) {
524 regs->eax = -EINTR;
525 break;
526 }
527 /* fallthrough */
528 case -ERESTARTNOINTR:
529 regs->eax = regs->orig_eax;
530 regs->eip -= 2;
531 }
532 }
533
534 /*
535 * If TF is set due to a debugger (PT_DTRACE), clear the TF flag so
536 * that register information in the sigcontext is correct.
537 */
538 if (unlikely(regs->eflags & TF_MASK)
539 && likely(current->ptrace & PT_DTRACE)) {
540 current->ptrace &= ~PT_DTRACE;
541 regs->eflags &= ~TF_MASK;
542 }
543
544 /* Set up the stack frame */
545 if (ka->sa.sa_flags & SA_SIGINFO)
Roland McGrath7c1def12005-06-23 00:08:21 -0700546 ret = setup_rt_frame(sig, ka, info, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 else
Roland McGrath7c1def12005-06-23 00:08:21 -0700548 ret = setup_frame(sig, ka, oldset, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
David Howells283828f2006-01-18 17:44:00 -0800550 if (ret == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 spin_lock_irq(&current->sighand->siglock);
552 sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
Steven Rostedt69be8f12005-08-29 11:44:09 -0400553 if (!(ka->sa.sa_flags & SA_NODEFER))
554 sigaddset(&current->blocked,sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 recalc_sigpending();
556 spin_unlock_irq(&current->sighand->siglock);
557 }
Roland McGrath7c1def12005-06-23 00:08:21 -0700558
559 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560}
561
562/*
563 * Note that 'init' is a special process: it doesn't get signals it doesn't
564 * want to handle. Thus you cannot kill init even with a SIGKILL even by
565 * mistake.
566 */
David Howells283828f2006-01-18 17:44:00 -0800567static void fastcall do_signal(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568{
569 siginfo_t info;
570 int signr;
571 struct k_sigaction ka;
David Howells283828f2006-01-18 17:44:00 -0800572 sigset_t *oldset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574 /*
575 * We want the common case to go fast, which
576 * is why we may in certain cases get here from
577 * kernel mode. Just return without doing anything
Zachary Amsden0998e422005-09-03 15:56:43 -0700578 * if so. vm86 regs switched out by assembly code
579 * before reaching here, so testing against kernel
580 * CS suffices.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 */
Vincent Hanquez717b5942005-06-23 00:08:45 -0700582 if (!user_mode(regs))
David Howells283828f2006-01-18 17:44:00 -0800583 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Linus Torvalds6f0dcb72005-06-25 20:09:12 -0700585 if (try_to_freeze())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 goto no_signal;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
David Howells283828f2006-01-18 17:44:00 -0800588 if (test_thread_flag(TIF_RESTORE_SIGMASK))
589 oldset = &current->saved_sigmask;
590 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 oldset = &current->blocked;
592
593 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
594 if (signr > 0) {
595 /* Reenable any watchpoints before delivering the
596 * signal to user space. The processor register will
597 * have been cleared if the watchpoint triggered
598 * inside the kernel.
599 */
David Howells283828f2006-01-18 17:44:00 -0800600 if (unlikely(current->thread.debugreg[7]))
Vincent Hanquez1cc6f122005-06-23 00:08:43 -0700601 set_debugreg(current->thread.debugreg[7], 7);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
603 /* Whee! Actually deliver the signal. */
David Howells283828f2006-01-18 17:44:00 -0800604 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
605 /* a signal was successfully delivered; the saved
606 * sigmask will have been stored in the signal frame,
607 * and will be restored by sigreturn, so we can simply
608 * clear the TIF_RESTORE_SIGMASK flag */
609 if (test_thread_flag(TIF_RESTORE_SIGMASK))
610 clear_thread_flag(TIF_RESTORE_SIGMASK);
611 }
612
613 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 }
615
David Howells283828f2006-01-18 17:44:00 -0800616no_signal:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 /* Did we come from a system call? */
618 if (regs->orig_eax >= 0) {
619 /* Restart the system call - no handlers present */
David Howells283828f2006-01-18 17:44:00 -0800620 switch (regs->eax) {
621 case -ERESTARTNOHAND:
622 case -ERESTARTSYS:
623 case -ERESTARTNOINTR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 regs->eax = regs->orig_eax;
625 regs->eip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800626 break;
627
628 case -ERESTART_RESTARTBLOCK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 regs->eax = __NR_restart_syscall;
630 regs->eip -= 2;
David Howells283828f2006-01-18 17:44:00 -0800631 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 }
633 }
David Howells283828f2006-01-18 17:44:00 -0800634
635 /* if there's no signal to deliver, we just put the saved sigmask
636 * back */
637 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
638 clear_thread_flag(TIF_RESTORE_SIGMASK);
639 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641}
642
643/*
644 * notification of userspace execution resumption
David Howells283828f2006-01-18 17:44:00 -0800645 * - triggered by the TIF_WORK_MASK flags
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 */
647__attribute__((regparm(3)))
David Howells283828f2006-01-18 17:44:00 -0800648void do_notify_resume(struct pt_regs *regs, void *_unused,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 __u32 thread_info_flags)
650{
651 /* Pending single-step? */
652 if (thread_info_flags & _TIF_SINGLESTEP) {
653 regs->eflags |= TF_MASK;
654 clear_thread_flag(TIF_SINGLESTEP);
655 }
David Howells283828f2006-01-18 17:44:00 -0800656
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 /* deal with pending signal delivery */
David Howells283828f2006-01-18 17:44:00 -0800658 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
659 do_signal(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
661 clear_thread_flag(TIF_IRET);
662}