ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / ia64 / kernel / signal.c
1 /*
2  * Architecture-specific signal handling support.
3  *
4  * Copyright (C) 1999-2003 Hewlett-Packard Co
5  *      David Mosberger-Tang <davidm@hpl.hp.com>
6  *
7  * Derived from i386 and Alpha versions.
8  */
9
10 #include <linux/config.h>
11 #include <linux/errno.h>
12 #include <linux/kernel.h>
13 #include <linux/mm.h>
14 #include <linux/ptrace.h>
15 #include <linux/sched.h>
16 #include <linux/signal.h>
17 #include <linux/smp.h>
18 #include <linux/smp_lock.h>
19 #include <linux/stddef.h>
20 #include <linux/tty.h>
21 #include <linux/binfmts.h>
22 #include <linux/unistd.h>
23 #include <linux/wait.h>
24
25 #include <asm/ia32.h>
26 #include <asm/intrinsics.h>
27 #include <asm/uaccess.h>
28 #include <asm/rse.h>
29 #include <asm/sigcontext.h>
30
31 #include "sigframe.h"
32
33 #define DEBUG_SIG       0
34 #define STACK_ALIGN     16              /* minimal alignment for stack pointer */
35 #define _BLOCKABLE      (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
36
37 #if _NSIG_WORDS > 1
38 # define PUT_SIGSET(k,u)        __copy_to_user((u)->sig, (k)->sig, sizeof(sigset_t))
39 # define GET_SIGSET(k,u)        __copy_from_user((k)->sig, (u)->sig, sizeof(sigset_t))
40 #else
41 # define PUT_SIGSET(k,u)        __put_user((k)->sig[0], &(u)->sig[0])
42 # define GET_SIGSET(k,u)        __get_user((k)->sig[0], &(u)->sig[0])
43 #endif
44
45 #ifdef ASM_SUPPORTED
46 /*
47  * Don't let GCC uses f16-f31 so that when we setup/restore the registers in the signal
48  * context in __kernel_sigtramp(), we can be sure that registers f16-f31 contain user-level
49  * values.
50  */
51 register double f16 asm ("f16"); register double f17 asm ("f17");
52 register double f18 asm ("f18"); register double f19 asm ("f19");
53 register double f20 asm ("f20"); register double f21 asm ("f21");
54 register double f22 asm ("f22"); register double f23 asm ("f23");
55
56 register double f24 asm ("f24"); register double f25 asm ("f25");
57 register double f26 asm ("f26"); register double f27 asm ("f27");
58 register double f28 asm ("f28"); register double f29 asm ("f29");
59 register double f30 asm ("f30"); register double f31 asm ("f31");
60 #endif
61
62 long
63 ia64_rt_sigsuspend (sigset_t *uset, size_t sigsetsize, struct sigscratch *scr)
64 {
65         sigset_t oldset, set;
66
67         /* XXX: Don't preclude handling different sized sigset_t's.  */
68         if (sigsetsize != sizeof(sigset_t))
69                 return -EINVAL;
70
71         if (!access_ok(VERIFY_READ, uset, sigsetsize))
72                 return -EFAULT;
73
74         if (GET_SIGSET(&set, uset))
75                 return -EFAULT;
76
77         sigdelsetmask(&set, ~_BLOCKABLE);
78
79         spin_lock_irq(&current->sighand->siglock);
80         {
81                 oldset = current->blocked;
82                 current->blocked = set;
83                 recalc_sigpending();
84         }
85         spin_unlock_irq(&current->sighand->siglock);
86
87         /*
88          * The return below usually returns to the signal handler.  We need to
89          * pre-set the correct error code here to ensure that the right values
90          * get saved in sigcontext by ia64_do_signal.
91          */
92         scr->pt.r8 = EINTR;
93         scr->pt.r10 = -1;
94
95         while (1) {
96                 current->state = TASK_INTERRUPTIBLE;
97                 schedule();
98                 if (ia64_do_signal(&oldset, scr, 1))
99                         return -EINTR;
100         }
101 }
102
103 asmlinkage long
104 sys_sigaltstack (const stack_t *uss, stack_t *uoss, long arg2, long arg3, long arg4,
105                  long arg5, long arg6, long arg7, long stack)
106 {
107         struct pt_regs *pt = (struct pt_regs *) &stack;
108
109         return do_sigaltstack(uss, uoss, pt->r12);
110 }
111
112 static long
113 restore_sigcontext (struct sigcontext *sc, struct sigscratch *scr)
114 {
115         unsigned long ip, flags, nat, um, cfm;
116         long err;
117
118         /* Always make any pending restarted system calls return -EINTR */
119         current_thread_info()->restart_block.fn = do_no_restart_syscall;
120
121         /* restore scratch that always needs gets updated during signal delivery: */
122         err  = __get_user(flags, &sc->sc_flags);
123         err |= __get_user(nat, &sc->sc_nat);
124         err |= __get_user(ip, &sc->sc_ip);                      /* instruction pointer */
125         err |= __get_user(cfm, &sc->sc_cfm);
126         err |= __get_user(um, &sc->sc_um);                      /* user mask */
127         err |= __get_user(scr->pt.ar_rsc, &sc->sc_ar_rsc);
128         err |= __get_user(scr->pt.ar_unat, &sc->sc_ar_unat);
129         err |= __get_user(scr->pt.ar_fpsr, &sc->sc_ar_fpsr);
130         err |= __get_user(scr->pt.ar_pfs, &sc->sc_ar_pfs);
131         err |= __get_user(scr->pt.pr, &sc->sc_pr);              /* predicates */
132         err |= __get_user(scr->pt.b0, &sc->sc_br[0]);           /* b0 (rp) */
133         err |= __get_user(scr->pt.b6, &sc->sc_br[6]);           /* b6 */
134         err |= __copy_from_user(&scr->pt.r1, &sc->sc_gr[1], 8); /* r1 */
135         err |= __copy_from_user(&scr->pt.r8, &sc->sc_gr[8], 4*8);       /* r8-r11 */
136         err |= __copy_from_user(&scr->pt.r12, &sc->sc_gr[12], 2*8);     /* r12-r13 */
137         err |= __copy_from_user(&scr->pt.r15, &sc->sc_gr[15], 8);       /* r15 */
138
139         scr->pt.cr_ifs = cfm | (1UL << 63);
140
141         /* establish new instruction pointer: */
142         scr->pt.cr_iip = ip & ~0x3UL;
143         ia64_psr(&scr->pt)->ri = ip & 0x3;
144         scr->pt.cr_ipsr = (scr->pt.cr_ipsr & ~IA64_PSR_UM) | (um & IA64_PSR_UM);
145
146         scr->scratch_unat = ia64_put_scratch_nat_bits(&scr->pt, nat);
147
148         if (!(flags & IA64_SC_FLAG_IN_SYSCALL)) {
149                 /* Restore most scratch-state only when not in syscall. */
150                 err |= __get_user(scr->pt.ar_ccv, &sc->sc_ar_ccv);              /* ar.ccv */
151                 err |= __get_user(scr->pt.b7, &sc->sc_br[7]);                   /* b7 */
152                 err |= __get_user(scr->pt.r14, &sc->sc_gr[14]);                 /* r14 */
153                 err |= __copy_from_user(&scr->pt.ar_csd, &sc->sc_ar25, 2*8); /* ar.csd & ar.ssd */
154                 err |= __copy_from_user(&scr->pt.r2, &sc->sc_gr[2], 2*8);       /* r2-r3 */
155                 err |= __copy_from_user(&scr->pt.r16, &sc->sc_gr[16], 16*8);    /* r16-r31 */
156         }
157
158         if ((flags & IA64_SC_FLAG_FPH_VALID) != 0) {
159                 struct ia64_psr *psr = ia64_psr(&scr->pt);
160
161                 __copy_from_user(current->thread.fph, &sc->sc_fr[32], 96*16);
162                 psr->mfh = 0;   /* drop signal handler's fph contents... */
163                 if (psr->dfh)
164                         ia64_drop_fpu(current);
165                 else {
166                         /* We already own the local fph, otherwise psr->dfh wouldn't be 0.  */
167                         __ia64_load_fpu(current->thread.fph);
168                         ia64_set_local_fpu_owner(current);
169                 }
170         }
171         return err;
172 }
173
174 int
175 copy_siginfo_to_user (siginfo_t *to, siginfo_t *from)
176 {
177         if (!access_ok(VERIFY_WRITE, to, sizeof(siginfo_t)))
178                 return -EFAULT;
179         if (from->si_code < 0) {
180                 if (__copy_to_user(to, from, sizeof(siginfo_t)))
181                         return -EFAULT;
182                 return 0;
183         } else {
184                 int err;
185
186                 /*
187                  * If you change siginfo_t structure, please be sure this code is fixed
188                  * accordingly.  It should never copy any pad contained in the structure
189                  * to avoid security leaks, but must copy the generic 3 ints plus the
190                  * relevant union member.
191                  */
192                 err = __put_user(from->si_signo, &to->si_signo);
193                 err |= __put_user(from->si_errno, &to->si_errno);
194                 err |= __put_user((short)from->si_code, &to->si_code);
195                 switch (from->si_code >> 16) {
196                       case __SI_FAULT >> 16:
197                         err |= __put_user(from->si_flags, &to->si_flags);
198                         err |= __put_user(from->si_isr, &to->si_isr);
199                       case __SI_POLL >> 16:
200                         err |= __put_user(from->si_addr, &to->si_addr);
201                         err |= __put_user(from->si_imm, &to->si_imm);
202                         break;
203                       case __SI_TIMER >> 16:
204                         err |= __put_user(from->si_tid, &to->si_tid);
205                         err |= __put_user(from->si_overrun, &to->si_overrun);
206                         err |= __put_user(from->si_ptr, &to->si_ptr);
207                         break;
208                       case __SI_RT >> 16:       /* Not generated by the kernel as of now.  */
209                       case __SI_MESGQ >> 16:
210                         err |= __put_user(from->si_uid, &to->si_uid);
211                         err |= __put_user(from->si_pid, &to->si_pid);
212                         err |= __put_user(from->si_ptr, &to->si_ptr);
213                         break;
214                       case __SI_CHLD >> 16:
215                         err |= __put_user(from->si_utime, &to->si_utime);
216                         err |= __put_user(from->si_stime, &to->si_stime);
217                         err |= __put_user(from->si_status, &to->si_status);
218                       default:
219                         err |= __put_user(from->si_uid, &to->si_uid);
220                         err |= __put_user(from->si_pid, &to->si_pid);
221                         break;
222                 }
223                 return err;
224         }
225 }
226
227 long
228 ia64_rt_sigreturn (struct sigscratch *scr)
229 {
230         extern char ia64_strace_leave_kernel, ia64_leave_kernel;
231         struct sigcontext *sc;
232         struct siginfo si;
233         sigset_t set;
234         long retval;
235
236         sc = &((struct sigframe *) (scr->pt.r12 + 16))->sc;
237
238         /*
239          * When we return to the previously executing context, r8 and r10 have already
240          * been setup the way we want them.  Indeed, if the signal wasn't delivered while
241          * in a system call, we must not touch r8 or r10 as otherwise user-level state
242          * could be corrupted.
243          */
244         retval = (long) &ia64_leave_kernel;
245         if (test_thread_flag(TIF_SYSCALL_TRACE))
246                 /*
247                  * strace expects to be notified after sigreturn returns even though the
248                  * context to which we return may not be in the middle of a syscall.
249                  * Thus, the return-value that strace displays for sigreturn is
250                  * meaningless.
251                  */
252                 retval = (long) &ia64_strace_leave_kernel;
253
254         if (!access_ok(VERIFY_READ, sc, sizeof(*sc)))
255                 goto give_sigsegv;
256
257         if (GET_SIGSET(&set, &sc->sc_mask))
258                 goto give_sigsegv;
259
260         sigdelsetmask(&set, ~_BLOCKABLE);
261
262         spin_lock_irq(&current->sighand->siglock);
263         {
264                 current->blocked = set;
265                 recalc_sigpending();
266         }
267         spin_unlock_irq(&current->sighand->siglock);
268
269         if (restore_sigcontext(sc, scr))
270                 goto give_sigsegv;
271
272 #if DEBUG_SIG
273         printk("SIG return (%s:%d): sp=%lx ip=%lx\n",
274                current->comm, current->pid, scr->pt.r12, scr->pt.cr_iip);
275 #endif
276         /*
277          * It is more difficult to avoid calling this function than to
278          * call it and ignore errors.
279          */
280         do_sigaltstack(&sc->sc_stack, 0, scr->pt.r12);
281         return retval;
282
283   give_sigsegv:
284         si.si_signo = SIGSEGV;
285         si.si_errno = 0;
286         si.si_code = SI_KERNEL;
287         si.si_pid = current->pid;
288         si.si_uid = current->uid;
289         si.si_addr = sc;
290         force_sig_info(SIGSEGV, &si, current);
291         return retval;
292 }
293
294 /*
295  * This does just the minimum required setup of sigcontext.
296  * Specifically, it only installs data that is either not knowable at
297  * the user-level or that gets modified before execution in the
298  * trampoline starts.  Everything else is done at the user-level.
299  */
300 static long
301 setup_sigcontext (struct sigcontext *sc, sigset_t *mask, struct sigscratch *scr)
302 {
303         unsigned long flags = 0, ifs, cfm, nat;
304         long err;
305
306         ifs = scr->pt.cr_ifs;
307
308         if (on_sig_stack((unsigned long) sc))
309                 flags |= IA64_SC_FLAG_ONSTACK;
310         if ((ifs & (1UL << 63)) == 0) {
311                 /* if cr_ifs isn't valid, we got here through a syscall */
312                 flags |= IA64_SC_FLAG_IN_SYSCALL;
313                 cfm = scr->ar_pfs & ((1UL << 38) - 1);
314         } else
315                 cfm = ifs & ((1UL << 38) - 1);
316         ia64_flush_fph(current);
317         if ((current->thread.flags & IA64_THREAD_FPH_VALID)) {
318                 flags |= IA64_SC_FLAG_FPH_VALID;
319                 __copy_to_user(&sc->sc_fr[32], current->thread.fph, 96*16);
320         }
321
322         nat = ia64_get_scratch_nat_bits(&scr->pt, scr->scratch_unat);
323
324         err  = __put_user(flags, &sc->sc_flags);
325         err |= __put_user(nat, &sc->sc_nat);
326         err |= PUT_SIGSET(mask, &sc->sc_mask);
327         err |= __put_user(cfm, &sc->sc_cfm);
328         err |= __put_user(scr->pt.cr_ipsr & IA64_PSR_UM, &sc->sc_um);
329         err |= __put_user(scr->pt.ar_rsc, &sc->sc_ar_rsc);
330         err |= __put_user(scr->pt.ar_unat, &sc->sc_ar_unat);            /* ar.unat */
331         err |= __put_user(scr->pt.ar_fpsr, &sc->sc_ar_fpsr);            /* ar.fpsr */
332         err |= __put_user(scr->pt.ar_pfs, &sc->sc_ar_pfs);
333         err |= __put_user(scr->pt.pr, &sc->sc_pr);                      /* predicates */
334         err |= __put_user(scr->pt.b0, &sc->sc_br[0]);                   /* b0 (rp) */
335         err |= __put_user(scr->pt.b6, &sc->sc_br[6]);                   /* b6 */
336         err |= __copy_to_user(&sc->sc_gr[1], &scr->pt.r1, 8);           /* r1 */
337         err |= __copy_to_user(&sc->sc_gr[8], &scr->pt.r8, 4*8);         /* r8-r11 */
338         err |= __copy_to_user(&sc->sc_gr[12], &scr->pt.r12, 2*8);       /* r12-r13 */
339         err |= __copy_to_user(&sc->sc_gr[15], &scr->pt.r15, 8);         /* r15 */
340         err |= __put_user(scr->pt.cr_iip + ia64_psr(&scr->pt)->ri, &sc->sc_ip);
341
342         if (flags & IA64_SC_FLAG_IN_SYSCALL) {
343                 /* Clear scratch registers if the signal interrupted a system call. */
344                 err |= __put_user(0, &sc->sc_ar_ccv);                           /* ar.ccv */
345                 err |= __put_user(0, &sc->sc_br[7]);                            /* b7 */
346                 err |= __put_user(0, &sc->sc_gr[14]);                           /* r14 */
347                 err |= __clear_user(&sc->sc_ar25, 2*8);                 /* ar.csd & ar.ssd */
348                 err |= __clear_user(&sc->sc_gr[2], 2*8);                        /* r2-r3 */
349                 err |= __clear_user(&sc->sc_gr[16], 16*8);                      /* r16-r31 */
350         } else {
351                 /* Copy scratch regs to sigcontext if the signal didn't interrupt a syscall. */
352                 err |= __put_user(scr->pt.ar_ccv, &sc->sc_ar_ccv);              /* ar.ccv */
353                 err |= __put_user(scr->pt.b7, &sc->sc_br[7]);                   /* b7 */
354                 err |= __put_user(scr->pt.r14, &sc->sc_gr[14]);                 /* r14 */
355                 err |= __copy_to_user(&scr->pt.ar_csd, &sc->sc_ar25, 2*8); /* ar.csd & ar.ssd */
356                 err |= __copy_to_user(&sc->sc_gr[2], &scr->pt.r2, 2*8);         /* r2-r3 */
357                 err |= __copy_to_user(&sc->sc_gr[16], &scr->pt.r16, 16*8);      /* r16-r31 */
358         }
359         return err;
360 }
361
362 /*
363  * Check whether the register-backing store is already on the signal stack.
364  */
365 static inline int
366 rbs_on_sig_stack (unsigned long bsp)
367 {
368         return (bsp - current->sas_ss_sp < current->sas_ss_size);
369 }
370
371 static long
372 setup_frame (int sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *set,
373              struct sigscratch *scr)
374 {
375         extern char __kernel_sigtramp[];
376         unsigned long tramp_addr, new_rbs = 0;
377         struct sigframe *frame;
378         struct siginfo si;
379         long err;
380
381         frame = (void *) scr->pt.r12;
382         tramp_addr = (unsigned long) __kernel_sigtramp;
383         if ((ka->sa.sa_flags & SA_ONSTACK) && sas_ss_flags((unsigned long) frame) == 0) {
384                 frame = (void *) ((current->sas_ss_sp + current->sas_ss_size)
385                                   & ~(STACK_ALIGN - 1));
386                 /*
387                  * We need to check for the register stack being on the signal stack
388                  * separately, because it's switched separately (memory stack is switched
389                  * in the kernel, register stack is switched in the signal trampoline).
390                  */
391                 if (!rbs_on_sig_stack(scr->pt.ar_bspstore))
392                         new_rbs = (current->sas_ss_sp + sizeof(long) - 1) & ~(sizeof(long) - 1);
393         }
394         frame = (void *) frame - ((sizeof(*frame) + STACK_ALIGN - 1) & ~(STACK_ALIGN - 1));
395
396         if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
397                 goto give_sigsegv;
398
399         err  = __put_user(sig, &frame->arg0);
400         err |= __put_user(&frame->info, &frame->arg1);
401         err |= __put_user(&frame->sc, &frame->arg2);
402         err |= __put_user(new_rbs, &frame->sc.sc_rbs_base);
403         err |= __put_user(0, &frame->sc.sc_loadrs);     /* initialize to zero */
404         err |= __put_user(ka->sa.sa_handler, &frame->handler);
405
406         err |= copy_siginfo_to_user(&frame->info, info);
407
408         err |= __put_user(current->sas_ss_sp, &frame->sc.sc_stack.ss_sp);
409         err |= __put_user(current->sas_ss_size, &frame->sc.sc_stack.ss_size);
410         err |= __put_user(sas_ss_flags(scr->pt.r12), &frame->sc.sc_stack.ss_flags);
411         err |= setup_sigcontext(&frame->sc, set, scr);
412
413         if (err)
414                 goto give_sigsegv;
415
416         scr->pt.r12 = (unsigned long) frame - 16;       /* new stack pointer */
417         scr->pt.ar_fpsr = FPSR_DEFAULT;                 /* reset fpsr for signal handler */
418         scr->pt.cr_iip = tramp_addr;
419         ia64_psr(&scr->pt)->ri = 0;                     /* start executing in first slot */
420         ia64_psr(&scr->pt)->be = 0;                     /* force little-endian byte-order */
421         /*
422          * Force the interruption function mask to zero.  This has no effect when a
423          * system-call got interrupted by a signal (since, in that case, scr->pt_cr_ifs is
424          * ignored), but it has the desirable effect of making it possible to deliver a
425          * signal with an incomplete register frame (which happens when a mandatory RSE
426          * load faults).  Furthermore, it has no negative effect on the getting the user's
427          * dirty partition preserved, because that's governed by scr->pt.loadrs.
428          */
429         scr->pt.cr_ifs = (1UL << 63);
430
431         /*
432          * Note: this affects only the NaT bits of the scratch regs (the ones saved in
433          * pt_regs), which is exactly what we want.
434          */
435         scr->scratch_unat = 0; /* ensure NaT bits of r12 is clear */
436
437 #if DEBUG_SIG
438         printk("SIG deliver (%s:%d): sig=%d sp=%lx ip=%lx handler=%p\n",
439                current->comm, current->pid, sig, scr->pt.r12, frame->sc.sc_ip, frame->handler);
440 #endif
441         return 1;
442
443   give_sigsegv:
444         if (sig == SIGSEGV)
445                 ka->sa.sa_handler = SIG_DFL;
446         si.si_signo = SIGSEGV;
447         si.si_errno = 0;
448         si.si_code = SI_KERNEL;
449         si.si_pid = current->pid;
450         si.si_uid = current->uid;
451         si.si_addr = frame;
452         force_sig_info(SIGSEGV, &si, current);
453         return 0;
454 }
455
456 static long
457 handle_signal (unsigned long sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *oldset,
458                struct sigscratch *scr)
459 {
460         if (IS_IA32_PROCESS(&scr->pt)) {
461                 /* send signal to IA-32 process */
462                 if (!ia32_setup_frame1(sig, ka, info, oldset, &scr->pt))
463                         return 0;
464         } else
465                 /* send signal to IA-64 process */
466                 if (!setup_frame(sig, ka, info, oldset, scr))
467                         return 0;
468
469         if (ka->sa.sa_flags & SA_ONESHOT)
470                 ka->sa.sa_handler = SIG_DFL;
471
472         if (!(ka->sa.sa_flags & SA_NODEFER)) {
473                 spin_lock_irq(&current->sighand->siglock);
474                 {
475                         sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
476                         sigaddset(&current->blocked, sig);
477                         recalc_sigpending();
478                 }
479                 spin_unlock_irq(&current->sighand->siglock);
480         }
481         return 1;
482 }
483
484 /*
485  * Note that `init' is a special process: it doesn't get signals it doesn't want to
486  * handle.  Thus you cannot kill init even with a SIGKILL even by mistake.
487  */
488 long
489 ia64_do_signal (sigset_t *oldset, struct sigscratch *scr, long in_syscall)
490 {
491         struct k_sigaction *ka;
492         siginfo_t info;
493         long restart = in_syscall;
494         long errno = scr->pt.r8;
495 #       define ERR_CODE(c)      (IS_IA32_PROCESS(&scr->pt) ? -(c) : (c))
496
497         /*
498          * In the ia64_leave_kernel code path, we want the common case to go fast, which
499          * is why we may in certain cases get here from kernel mode. Just return without
500          * doing anything if so.
501          */
502         if (!user_mode(&scr->pt))
503                 return 0;
504
505         if (!oldset)
506                 oldset = &current->blocked;
507
508         /*
509          * This only loops in the rare cases of handle_signal() failing, in which case we
510          * need to push through a forced SIGSEGV.
511          */
512         while (1) {
513                 int signr = get_signal_to_deliver(&info, &scr->pt, NULL);
514
515                 /*
516                  * get_signal_to_deliver() may have run a debugger (via notify_parent())
517                  * and the debugger may have modified the state (e.g., to arrange for an
518                  * inferior call), thus it's important to check for restarting _after_
519                  * get_signal_to_deliver().
520                  */
521                 if (IS_IA32_PROCESS(&scr->pt)) {
522                         if (in_syscall) {
523                                 if (errno >= 0)
524                                         restart = 0;
525                                 else
526                                         errno = -errno;
527                         }
528                 } else if ((long) scr->pt.r10 != -1)
529                         /*
530                          * A system calls has to be restarted only if one of the error codes
531                          * ERESTARTNOHAND, ERESTARTSYS, or ERESTARTNOINTR is returned.  If r10
532                          * isn't -1 then r8 doesn't hold an error code and we don't need to
533                          * restart the syscall, so we can clear the "restart" flag here.
534                          */
535                         restart = 0;
536
537                 if (signr <= 0)
538                         break;
539
540                 ka = &current->sighand->action[signr - 1];
541
542                 if (unlikely(restart)) {
543                         switch (errno) {
544                               case ERESTART_RESTARTBLOCK:
545                               case ERESTARTNOHAND:
546                                 scr->pt.r8 = ERR_CODE(EINTR);
547                                 /* note: scr->pt.r10 is already -1 */
548                                 break;
549
550                               case ERESTARTSYS:
551                                 if ((ka->sa.sa_flags & SA_RESTART) == 0) {
552                                         scr->pt.r8 = ERR_CODE(EINTR);
553                                         /* note: scr->pt.r10 is already -1 */
554                                         break;
555                                 }
556                               case ERESTARTNOINTR:
557                                 if (IS_IA32_PROCESS(&scr->pt)) {
558                                         scr->pt.r8 = scr->pt.r1;
559                                         scr->pt.cr_iip -= 2;
560                                 } else
561                                         ia64_decrement_ip(&scr->pt);
562                                 restart = 0; /* don't restart twice if handle_signal() fails... */
563                         }
564                 }
565
566                 /*
567                  * Whee!  Actually deliver the signal.  If the delivery failed, we need to
568                  * continue to iterate in this loop so we can deliver the SIGSEGV...
569                  */
570                 if (handle_signal(signr, ka, &info, oldset, scr))
571                         return 1;
572         }
573
574         /* Did we come from a system call? */
575         if (restart) {
576                 /* Restart the system call - no handlers present */
577                 if (errno == ERESTARTNOHAND || errno == ERESTARTSYS || errno == ERESTARTNOINTR
578                     || errno == ERESTART_RESTARTBLOCK)
579                 {
580                         if (IS_IA32_PROCESS(&scr->pt)) {
581                                 scr->pt.r8 = scr->pt.r1;
582                                 scr->pt.cr_iip -= 2;
583                                 if (errno == ERESTART_RESTARTBLOCK)
584                                         scr->pt.r8 = 0; /* x86 version of __NR_restart_syscall */
585                         } else {
586                                 /*
587                                  * Note: the syscall number is in r15 which is saved in
588                                  * pt_regs so all we need to do here is adjust ip so that
589                                  * the "break" instruction gets re-executed.
590                                  */
591                                 ia64_decrement_ip(&scr->pt);
592                                 if (errno == ERESTART_RESTARTBLOCK)
593                                         scr->pt.r15 = __NR_restart_syscall;
594                         }
595                 }
596         }
597         return 0;
598 }