File: /usr/src/linux/arch/parisc/kernel/signal.c

1     /*
2      *  linux/arch/parisc/kernel/signal.c: Architecture-specific signal
3      *  handling support.
4      *
5      *  Copyright (C) 2000 David Huggins-Daines <dhd@debian.org>
6      *  Copyright (C) 2000 Linuxcare, Inc.
7      *
8      *  Based on the ia64, i386, and alpha versions.
9      *
10      *  Like the IA-64, we are a recent enough port (we are *starting*
11      *  with glibc2.2) that we do not need to support the old non-realtime
12      *  Linux signals.  Therefore we don't.  HP/UX signals will go in
13      *  arch/parisc/hpux/signal.c when we figure out how to do them.
14      */
15     
16     #include <linux/version.h>
17     #include <linux/sched.h>
18     #include <linux/mm.h>
19     #include <linux/smp.h>
20     #include <linux/smp_lock.h>
21     #include <linux/kernel.h>
22     #include <linux/signal.h>
23     #include <linux/errno.h>
24     #include <linux/wait.h>
25     #include <linux/ptrace.h>
26     #include <linux/unistd.h>
27     #include <linux/stddef.h>
28     #include <asm/ucontext.h>
29     #include <asm/uaccess.h>
30     #include <asm/pgalloc.h>
31     
32     #define DEBUG_SIG 0
33     
34     #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
35     
36     extern long sys_wait4 (int, int *, int, struct rusage *);
37     int do_signal(sigset_t *oldset, struct pt_regs *regs, int in_syscall);
38     
39     int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
40     {
41     	if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
42     		return -EFAULT;
43     	if (from->si_code < 0)
44     		return __copy_to_user(to, from, sizeof(siginfo_t));
45     	else {
46     		int err;
47     
48     		/*
49     		 * If you change siginfo_t structure, please be sure
50     		 * this code is fixed accordingly.  It should never
51     		 * copy any pad contained in the structure to avoid
52     		 * security leaks, but must copy the generic 3 ints
53     		 * plus the relevant union member.
54     		 */
55     		err = __put_user(from->si_signo, &to->si_signo);
56     		err |= __put_user(from->si_errno, &to->si_errno);
57     		err |= __put_user((short)from->si_code, &to->si_code);
58     		switch (from->si_code >> 16) {
59     		      case __SI_FAULT >> 16:
60     			/* FIXME: should we put the interruption code here? */
61     		      case __SI_POLL >> 16:
62     			err |= __put_user(from->si_addr, &to->si_addr);
63     			break;
64     		      case __SI_CHLD >> 16:
65     			err |= __put_user(from->si_utime, &to->si_utime);
66     			err |= __put_user(from->si_stime, &to->si_stime);
67     			err |= __put_user(from->si_status, &to->si_status);
68     		      default:
69     			err |= __put_user(from->si_uid, &to->si_uid);
70     			err |= __put_user(from->si_pid, &to->si_pid);
71     			break;
72     		      /* case __SI_RT: This is not generated by the kernel as of now.  */
73     		}
74     		return err;
75     	}
76     }
77     
78     /*
79      * Atomically swap in the new signal mask, and wait for a signal.
80      */
81     #ifdef __LP64__
82     #include "sys32.h"
83     #endif
84     
85     asmlinkage int
86     sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize, struct pt_regs *regs)
87     {
88     	sigset_t saveset, newset;
89     #ifdef __LP64__
90     	/* XXX FIXME -- assumes 32-bit user app! */
91     	sigset_t32 newset32;
92     
93     	/* XXX: Don't preclude handling different sized sigset_t's.  */
94     	if (sigsetsize != sizeof(sigset_t32))
95     		return -EINVAL;
96     
97     	if (copy_from_user(&newset32, (sigset_t32 *)unewset, sizeof(newset32)))
98     		return -EFAULT;
99     
100     	newset.sig[0] = newset32.sig[0] | ((unsigned long)newset32.sig[1] << 32);
101     #else
102     
103     	/* XXX: Don't preclude handling different sized sigset_t's.  */
104     	if (sigsetsize != sizeof(sigset_t))
105     		return -EINVAL;
106     
107     	if (copy_from_user(&newset, unewset, sizeof(newset)))
108     		return -EFAULT;
109     #endif
110     	sigdelsetmask(&newset, ~_BLOCKABLE);
111     
112     	spin_lock_irq(&current->sigmask_lock);
113     	saveset = current->blocked;
114     	current->blocked = newset;
115     	recalc_sigpending(current);
116     	spin_unlock_irq(&current->sigmask_lock);
117     
118     	regs->gr[28] = -EINTR;
119     	while (1) {
120     		current->state = TASK_INTERRUPTIBLE;
121     		schedule();
122     		if (do_signal(&saveset, regs, 1))
123     			return -EINTR;
124     	}
125     }
126     
127     /*
128      * Do a signal return - restore sigcontext.
129      */
130     
131     struct rt_sigframe {
132     	unsigned int tramp[4];
133     	struct siginfo info;
134     	struct ucontext uc;
135     };
136     
137     /* Trampoline for calling rt_sigreturn() */
138     #define INSN_LDI_R25_0	 0x34190000 /* ldi  0,%r25 (in_syscall=0) */
139     #define INSN_LDI_R25_1	 0x34190002 /* ldi  1,%r25 (in_syscall=1) */
140     #define INSN_LDI_R20	 0x3414015a /* ldi  __NR_rt_sigreturn,%r20 */
141     #define INSN_BLE_SR2_R0  0xe4008200 /* be,l 0x100(%sr2,%r0),%sr0,%r31 */
142     #define INSN_NOP	 0x80000240 /* nop */
143     /* For debugging */
144     #define INSN_DIE_HORRIBLY 0x68000ccc /* stw %r0,0x666(%sr0,%r0) */
145     
146     /*
147      * The 32-bit ABI wants at least 48 bytes for a function call frame:
148      * 16 bytes for arg0-arg3, and 32 bytes for magic (the only part of
149      * which Linux/parisc uses is sp-20 for the saved return pointer...)
150      * Then, the stack pointer must be rounded to a cache line (64 bytes).
151      */
152     #define PARISC_RT_SIGFRAME_SIZE					\
153     	(((sizeof(struct rt_sigframe) + 48) + 63) & -64)
154     
155     static long
156     restore_sigcontext(struct sigcontext *sc, struct pt_regs *regs)
157     {
158     	long err = 0;
159     
160     	err |= __copy_from_user(regs->gr, sc->sc_gr, sizeof(regs->gr));
161     	err |= __copy_from_user(regs->fr, sc->sc_fr, sizeof(regs->fr));
162     	err |= __copy_from_user(regs->iaoq, sc->sc_iaoq, sizeof(regs->iaoq));
163     	err |= __copy_from_user(regs->iasq, sc->sc_iasq, sizeof(regs->iasq));
164     	err |= __get_user(regs->sar, &sc->sc_sar);
165     
166     #if DEBUG_SIG
167     	printk("restore_sigcontext: r28 is %ld\n", regs->gr[28]);
168     #endif
169     	return err;
170     }
171     
172     void
173     sys_rt_sigreturn(struct pt_regs *regs, int in_syscall)
174     {
175     	struct rt_sigframe *frame;
176     	struct siginfo si;
177     	sigset_t set;
178     	unsigned long usp = regs->gr[30];
179     
180     	/* Unwind the user stack to get the rt_sigframe structure. */
181     	frame = (struct rt_sigframe *)
182     		(usp - PARISC_RT_SIGFRAME_SIZE);
183     #if DEBUG_SIG
184     	printk("in sys_rt_sigreturn, frame is %p\n", frame);
185     #endif
186     
187     	/* Verify that it's a good sigcontext before using it */
188     	if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
189     		goto give_sigsegv;
190     	if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
191     		goto give_sigsegv;
192     
193     	sigdelsetmask(&set, ~_BLOCKABLE);
194     	spin_lock_irq(&current->sigmask_lock);
195     	current->blocked = set;
196     	recalc_sigpending(current);
197     	spin_unlock_irq(&current->sigmask_lock);
198     
199     	/* Good thing we saved the old gr[30], eh? */
200     	if (restore_sigcontext(&frame->uc.uc_mcontext, regs))
201     		goto give_sigsegv;
202     
203     #if DEBUG_SIG
204     	printk("usp: %#08lx stack %p",
205     	       usp, &frame->uc.uc_stack);
206     #endif
207     
208     	/* I don't know why everyone else assumes they can call this
209                with a pointer to a stack_t on the kernel stack.  That
210                makes no sense.  Anyway we'll do it like m68k, since we
211                also are using segmentation in the same way as them. */
212     	if (do_sigaltstack(&frame->uc.uc_stack, NULL, usp) == -EFAULT)
213     		goto give_sigsegv;
214     
215     	/* If we are on the syscall path IAOQ will not be restored, and
216     	 * if we are on the interrupt path we must not corrupt gr31.
217     	 */
218     	if (in_syscall)
219     		regs->gr[31] = regs->iaoq[0];
220     #if DEBUG_SIG
221     	printk("returning to %#lx\n", regs->iaoq[0]);
222     	printk("in sys_rt_sigreturn:\n");
223     	show_regs(regs);
224     #endif
225     	return;
226     
227     give_sigsegv:
228     #if DEBUG_SIG
229     	printk("fuckup in sys_rt_sigreturn, sending SIGSEGV\n");
230     #endif
231     	si.si_signo = SIGSEGV;
232     	si.si_errno = 0;
233     	si.si_code = SI_KERNEL;
234     	si.si_pid = current->pid;
235     	si.si_uid = current->uid;
236     	si.si_addr = &frame->uc;
237     	force_sig_info(SIGSEGV, &si, current);
238     	return;
239     }
240     
241     /*
242      * Set up a signal frame.
243      */
244     
245     static inline void *
246     get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
247     {
248     	if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! on_sig_stack(sp))
249     		sp = current->sas_ss_sp + current->sas_ss_size;
250     
251     	return (void *) sp; /* Stacks grow up.  Fun. */
252     }
253     
254     static long
255     setup_sigcontext(struct sigcontext *sc, struct pt_regs *regs, int in_syscall)
256     		 
257     {
258     	unsigned long flags = 0;
259     	long err = 0;
260     
261     	if (on_sig_stack((unsigned long) sc))
262     		flags |= PARISC_SC_FLAG_ONSTACK;
263     	if (in_syscall) {
264     		flags |= PARISC_SC_FLAG_IN_SYSCALL;
265     		/* regs->iaoq is undefined in the syscall return path */
266     		err |= __put_user(regs->gr[31], &sc->sc_iaoq[0]);
267     		err |= __put_user(regs->gr[31]+4, &sc->sc_iaoq[1]);
268     #if DEBUG_SIG
269     		printk("setup_sigcontext: iaoq %#lx/%#lx\n", regs->gr[31], regs->gr[31]);
270     #endif
271     	} else {
272     		err |= __copy_to_user(sc->sc_iaoq, regs->iaoq, sizeof(regs->iaoq));
273     		err |= __copy_to_user(sc->sc_iasq, regs->iasq, sizeof(regs->iasq));
274     #if DEBUG_SIG
275     		printk("setup_sigcontext: iaoq %#lx/%#lx\n", regs->iaoq[0], regs->iaoq[1]);
276     #endif
277     	}
278     
279     	err |= __put_user(flags, &sc->sc_flags);
280     	err |= __copy_to_user(sc->sc_gr, regs->gr, sizeof(regs->gr));
281     	err |= __copy_to_user(sc->sc_fr, regs->fr, sizeof(regs->fr));
282     	err |= __put_user(regs->sar, &sc->sc_sar);
283     #if DEBUG_SIG
284     	printk("setup_sigcontext: r28 is %ld\n", regs->gr[28]);
285     #endif
286     
287     	return err;
288     }
289     
290     static long
291     setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
292     	       sigset_t *set, struct pt_regs *regs, int in_syscall)
293     {
294     	struct rt_sigframe *frame;
295     	unsigned long rp, usp, haddr;
296     	struct siginfo si;
297     	int err = 0;
298     
299     	usp = regs->gr[30];
300     	/* access_ok is broken, so do a simplistic "are we stomping on
301                kernel space" assertion. */
302     	if (usp > PAGE_OFFSET) {
303     		printk("setup_rt_frame: called on kernel space (usp=%#lx),  NOW YOU MUST DIE!!!\n",
304     		       usp);
305     		show_regs(regs);
306     		while(1);
307     	}
308     		
309     	frame = get_sigframe(ka, usp, sizeof(*frame));
310     	if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
311     		goto give_sigsegv;
312     
313     #if DEBUG_SIG
314     	printk("setup_rt_frame 1: frame %p info %p\n", frame, info);
315     #endif
316     
317     	err |= __copy_to_user(&frame->info, info, sizeof(siginfo_t));
318     	err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
319     	err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
320     	err |= __put_user(sas_ss_flags(regs->gr[30]),
321     			  &frame->uc.uc_stack.ss_flags);
322     	err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, in_syscall);
323     	err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
324     	if (err)
325     		goto give_sigsegv;
326     
327     	/* Set up to return from userspace.  If provided, use a stub
328     	   already in userspace.  */
329     	err |= __put_user(in_syscall ? INSN_LDI_R25_1 : INSN_LDI_R25_0,
330     			&frame->tramp[0]);
331     	err |= __put_user(INSN_LDI_R20, &frame->tramp[1]);
332     	err |= __put_user(INSN_BLE_SR2_R0, &frame->tramp[2]);
333     	err |= __put_user(INSN_NOP, &frame->tramp[3]);
334     
335     #if DEBUG_SIG
336     	/* Assert that we're flushing in the correct space... */
337     	{
338     		int sid;
339     		asm ("mfsp %%sr3,%0" : "=r" (sid));
340     		printk("flushing 64 bytes at space %#x offset %p\n",
341     		       sid, frame->tramp);
342     	}
343     #endif
344     
345     #if CACHE_FLUSHING_IS_NOT_BROKEN
346     	flush_icache_range((unsigned long) &frame->tramp[0],
347     			   (unsigned long) &frame->tramp[4]);
348     #else
349     	/* It should *always* be cache line-aligned, but the compiler
350                sometimes screws up. */
351     	asm volatile("fdc 0(%%sr3,%0)\n\t"
352     		     "fdc %1(%%sr3,%0)\n\t"
353     		     "sync\n\t"
354     		     "fic 0(%%sr3,%0)\n\t"
355     		     "fic %1(%%sr3,%0)\n\t"
356     		     "sync\n\t"
357     		     : : "r" (frame->tramp), "r" (L1_CACHE_BYTES));
358     #endif
359     	rp = (unsigned long) frame->tramp;
360     
361     	if (err)
362     		goto give_sigsegv;
363     
364     #ifdef __LP64__
365     /* Much more has to happen with signals than this -- but it'll at least */
366     /* provide a pointer to some places which definitely need a look. */
367     #define HACK unsigned int
368     #else
369     #define HACK unsigned long
370     #endif
371     	haddr = (HACK) ka->sa.sa_handler;
372     	/* ARGH!  Fucking brain damage.  You don't want to know. */
373     	if (haddr & 2) {
374     		HACK *plabel;
375     		HACK ltp;
376     
377     		plabel = (HACK *) (haddr & ~3);
378     		err |= __get_user(haddr, plabel);
379     		err |= __get_user(ltp, plabel + 1);
380     		if (err)
381     			goto give_sigsegv;
382     		regs->gr[19] = ltp;
383     	}
384     
385     	/* The syscall return path will create IAOQ values from r31.
386     	 */
387     	if (in_syscall)
388     		regs->gr[31] = (HACK) haddr;
389     	else {
390     		regs->iaoq[0] = (HACK) haddr | 3;
391     		regs->iaoq[1] = regs->iaoq[0] + 4;
392     	}
393     
394     	regs->gr[2]  = rp;                /* userland return pointer */
395     	regs->gr[26] = sig;               /* signal number */
396     	regs->gr[25] = (HACK) &frame->info; /* siginfo pointer */
397     	regs->gr[24] = (HACK) &frame->uc;   /* ucontext pointer */
398     #if DEBUG_SIG
399     	printk("making sigreturn frame: %#lx + %#lx = %#lx\n",
400     	       regs->gr[30], PARISC_RT_SIGFRAME_SIZE,
401     	       regs->gr[30] + PARISC_RT_SIGFRAME_SIZE);
402     #endif
403     	/* Raise the user stack pointer to make a proper call frame. */
404     	regs->gr[30] = ((HACK) frame + PARISC_RT_SIGFRAME_SIZE);
405     
406     #if DEBUG_SIG
407     	printk("SIG deliver (%s:%d): frame=0x%p sp=%#lx iaoq=%#lx/%#lx rp=%#lx\n",
408     	       current->comm, current->pid, frame, regs->gr[30],
409     	       regs->iaoq[0], regs->iaoq[1], rp);
410     #endif
411     
412     	return 1;
413     
414     give_sigsegv:
415     #if DEBUG_SIG
416     	printk("fuckup in setup_rt_frame, sending SIGSEGV\n");
417     #endif
418     	if (sig == SIGSEGV)
419     		ka->sa.sa_handler = SIG_DFL;
420     	si.si_signo = SIGSEGV;
421     	si.si_errno = 0;
422     	si.si_code = SI_KERNEL;
423     	si.si_pid = current->pid;
424     	si.si_uid = current->uid;
425     	si.si_addr = frame;
426     	force_sig_info(SIGSEGV, &si, current);
427     	return 0;
428     }
429     
430     /*
431      * OK, we're invoking a handler.
432      */	
433     
434     static long
435     handle_signal(unsigned long sig, struct k_sigaction *ka,
436     	      siginfo_t *info, sigset_t *oldset,
437     	      struct pt_regs *regs, int in_syscall)
438     {
439     #if DEBUG_SIG
440     	printk("handle_signal(sig=%ld, ka=%p, info=%p, oldset=%p, regs=%p)\n",
441     	       sig, ka, info, oldset, regs);
442     #endif
443     	/* Set up the stack frame */
444     	if (!setup_rt_frame(sig, ka, info, oldset, regs, in_syscall))
445     		return 0;
446     
447     	if (ka->sa.sa_flags & SA_ONESHOT)
448     		ka->sa.sa_handler = SIG_DFL;
449     
450     	if (!(ka->sa.sa_flags & SA_NODEFER)) {
451     		spin_lock_irq(&current->sigmask_lock);
452     		sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
453     		sigaddset(&current->blocked,sig);
454     		recalc_sigpending(current);
455     		spin_unlock_irq(&current->sigmask_lock);
456     	}
457     	return 1;
458     }
459     
460     /*
461      * Note that 'init' is a special process: it doesn't get signals it doesn't
462      * want to handle. Thus you cannot kill init even with a SIGKILL even by
463      * mistake.
464      *
465      * We need to be able to restore the syscall arguments (r21-r26) to
466      * restart syscalls.  Thus, the syscall path should save them in the
467      * pt_regs structure (it's okay to do so since they are caller-save
468      * registers).  As noted below, the syscall number gets restored for
469      * us due to the magic of delayed branching.
470      */
471     asmlinkage int
472     do_signal(sigset_t *oldset, struct pt_regs *regs, int in_syscall)
473     {
474     	siginfo_t info;
475     	struct k_sigaction *ka;
476     
477     #if DEBUG_SIG
478     	printk("do_signal(oldset=0x%p, regs=0x%p, sr7 %#lx, pending %d, in_syscall=%d\n",
479     	       oldset, regs, regs->sr[7], current->sigpending, in_syscall);
480     #endif
481     	/* Everyone else checks to see if they are in kernel mode at
482     	   this point and exits if that's the case.  I'm not sure why
483     	   we would be called in that case, but for some reason we
484     	   are. */
485     
486     	if (!oldset)
487     		oldset = &current->blocked;
488     
489     #if DEBUG_SIG
490     	printk("do_signal: oldset %08lx:%08lx\n", oldset->sig[0], oldset->sig[1]);
491     #endif
492     
493     	for (;;) {
494     		unsigned long signr;
495     
496     		spin_lock_irq(&current->sigmask_lock);
497     		signr = dequeue_signal(&current->blocked, &info);
498     		spin_unlock_irq(&current->sigmask_lock);
499     #if DEBUG_SIG
500     		printk("do_signal: signr=%ld, pid=%d\n", signr, current->pid);
501     #endif
502     
503     		if (!signr)
504     			break;
505     
506     		if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) {
507     			/* Let the debugger run.  */
508     			current->exit_code = signr;
509     			set_current_state(TASK_STOPPED);
510     			notify_parent(current, SIGCHLD);
511     			schedule();
512     
513     			/* We're back.  Did the debugger cancel the sig?  */
514     			if (!(signr = current->exit_code))
515     				continue;
516     			current->exit_code = 0;
517     
518     			/* The debugger continued.  Ignore SIGSTOP.  */
519     			if (signr == SIGSTOP)
520     				continue;
521     
522     			/* Update the siginfo structure.  Is this good?  */
523     			if (signr != info.si_signo) {
524     				info.si_signo = signr;
525     				info.si_errno = 0;
526     				info.si_code = SI_USER;
527     				info.si_pid = current->p_pptr->pid;
528     				info.si_uid = current->p_pptr->uid;
529     			}
530     
531     			/* If the (new) signal is now blocked, requeue it.  */
532     			if (sigismember(&current->blocked, signr)) {
533     				send_sig_info(signr, &info, current);
534     				continue;
535     			}
536     		}
537     
538     		ka = &current->sig->action[signr-1];
539     #if DEBUG_SIG
540     		printk("sa_handler is %lx\n", ka->sa.sa_handler);
541     #endif
542     		if ((unsigned long) ka->sa.sa_handler == (unsigned long) SIG_IGN) {
543     			if (signr != SIGCHLD)
544     				continue;
545     			while (sys_wait4(-1, NULL, WNOHANG, NULL) > 0)
546     				/* nothing */;
547     			continue;
548     		}
549     
550     		if ((unsigned long) ka->sa.sa_handler == (unsigned long) SIG_DFL) {
551     			int exit_code = signr;
552     
553     			/* Init gets no signals it doesn't want.  */
554     			if (current->pid == 1)
555     				continue;
556     
557     			switch (signr) {
558     			case SIGCONT: case SIGCHLD: case SIGWINCH:
559     				continue;
560     
561     			case SIGTSTP: case SIGTTIN: case SIGTTOU:
562     				if (is_orphaned_pgrp(current->pgrp))
563     					continue;
564     				/* FALLTHRU */
565     
566     			case SIGSTOP:
567     				set_current_state(TASK_STOPPED);
568     				current->exit_code = signr;
569     				if (!(current->p_pptr->sig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP))
570     					notify_parent(current, SIGCHLD);
571     				schedule();
572     				continue;
573     
574     			case SIGQUIT: case SIGILL: case SIGTRAP:
575     			case SIGABRT: case SIGFPE: case SIGSEGV:
576     			case SIGBUS: case SIGSYS: case SIGXCPU: case SIGXFSZ:
577     				if (signr == SIGQUIT) /* Userspace debugging */
578     					show_regs(regs);
579     				if (do_coredump(signr, regs))
580     					exit_code |= 0x80;
581     				/* FALLTHRU */
582     
583     			default:
584     				lock_kernel();
585     				sigaddset(&current->pending.signal, signr);
586     				recalc_sigpending(current);
587     				current->flags |= PF_SIGNALED;
588     				do_exit(exit_code);
589     				/* NOTREACHED */
590     			}
591     		}
592     
593     		/* Restart a system call if necessary. */
594     		if (in_syscall) {
595     			/* Check the return code */
596     			switch (regs->gr[28]) {
597     			case -ERESTARTNOHAND:
598     #if DEBUG_SIG
599     				printk("ERESTARTNOHAND: returning -EINTR\n");
600     #endif
601     				regs->gr[28] = -EINTR;
602     				break;
603     
604     			case -ERESTARTSYS:
605     				if (!(ka->sa.sa_flags & SA_RESTART)) {
606     #if DEBUG_SIG
607     					printk("ERESTARTSYS: putting -EINTR\n");
608     #endif
609     					regs->gr[28] = -EINTR;
610     					break;
611     				}
612     			/* fallthrough */
613     			case -ERESTARTNOINTR:
614     				/* A syscall is just a branch, so all
615                                        we have to do is fiddle the return
616                                        pointer. */
617     				regs->gr[31] -= 8; /* delayed branching */
618     				/* Preserve original r28. */
619     				regs->gr[28] = regs->orig_r28;
620     				break;
621     			}
622     		}
623     		/* Whee!  Actually deliver the signal.  If the
624     		   delivery failed, we need to continue to iterate in
625     		   this loop so we can deliver the SIGSEGV... */
626     		if (handle_signal(signr, ka, &info, oldset, regs, in_syscall)) {
627     #if DEBUG_SIG
628     			printk("Exiting do_signal (success), regs->gr[28] = %ld\n", regs->gr[28]);
629     #endif
630     			return 1;
631     		}
632     	}
633     
634     	/* Did we come from a system call? */
635     	if (in_syscall) {
636     		/* Restart the system call - no handlers present */
637     		if (regs->gr[28] == -ERESTARTNOHAND ||
638     		    regs->gr[28] == -ERESTARTSYS ||
639     		    regs->gr[28] == -ERESTARTNOINTR) {
640     			/* Hooray for delayed branching.  We don't
641                                have to restore %r20 (the system call
642                                number) because it gets loaded in the delay
643                                slot of the branch external instruction. */
644     			regs->gr[31] -= 8;
645     			/* Preserve original r28. */
646     			regs->gr[28] = regs->orig_r28;
647     		}
648     	}
649     #if DEBUG_SIG
650     	printk("Exiting do_signal (not delivered), regs->gr[28] = %ld\n", regs->gr[28]);
651     #endif
652     	return 0;
653     }
654