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

1     /*
2      * BK Id: SCCS/s.signal.c 1.7 05/17/01 18:14:22 cort
3      */
4     /*
5      *  linux/arch/ppc/kernel/signal.c
6      *
7      *  PowerPC version 
8      *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
9      *
10      *  Derived from "arch/i386/kernel/signal.c"
11      *    Copyright (C) 1991, 1992 Linus Torvalds
12      *    1997-11-28  Modified for POSIX.1b signals by Richard Henderson
13      *
14      *  This program is free software; you can redistribute it and/or
15      *  modify it under the terms of the GNU General Public License
16      *  as published by the Free Software Foundation; either version
17      *  2 of the License, or (at your option) any later version.
18      */
19     
20     #include <linux/sched.h>
21     #include <linux/mm.h>
22     #include <linux/smp.h>
23     #include <linux/smp_lock.h>
24     #include <linux/kernel.h>
25     #include <linux/signal.h>
26     #include <linux/errno.h>
27     #include <linux/wait.h>
28     #include <linux/ptrace.h>
29     #include <linux/unistd.h>
30     #include <linux/stddef.h>
31     #include <linux/elf.h>
32     #include <asm/ucontext.h>
33     #include <asm/uaccess.h>
34     #include <asm/pgtable.h>
35     
36     #define DEBUG_SIG 0
37     
38     #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
39     
40     #ifndef MIN
41     #define MIN(a,b) (((a) < (b)) ? (a) : (b))
42     #endif
43     
44     #define GP_REGS_SIZE	MIN(sizeof(elf_gregset_t), sizeof(struct pt_regs))
45     
46     /* 
47      * These are the flags in the MSR that the user is allowed to change
48      * by modifying the saved value of the MSR on the stack.  SE and BE
49      * should not be in this list since gdb may want to change these.  I.e,
50      * you should be able to step out of a signal handler to see what
51      * instruction executes next after the signal handler completes.
52      * Alternately, if you stepped into a signal handler, you should be
53      * able to continue 'til the next breakpoint from within the signal
54      * handler, even if the handler returns.
55      */
56     #define MSR_USERCHANGE	(MSR_FE0 | MSR_FE1)
57     
58     int do_signal(sigset_t *oldset, struct pt_regs *regs);
59     
60     int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
61     {
62     	if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
63     		return -EFAULT;
64     	if (from->si_code < 0)
65     		return __copy_to_user(to, from, sizeof(siginfo_t));
66     	else {
67     		int err;
68     
69     		/* If you change siginfo_t structure, please be sure
70     		   this code is fixed accordingly.
71     		   It should never copy any pad contained in the structure
72     		   to avoid security leaks, but must copy the generic
73     		   3 ints plus the relevant union member.  */
74     		err = __put_user(from->si_signo, &to->si_signo);
75     		err |= __put_user(from->si_errno, &to->si_errno);
76     		err |= __put_user((short)from->si_code, &to->si_code);
77     		/* First 32bits of unions are always present.  */
78     		err |= __put_user(from->si_pid, &to->si_pid);
79     		switch (from->si_code >> 16) {
80     		case __SI_FAULT >> 16:
81     			break;
82     		case __SI_CHLD >> 16:
83     			err |= __put_user(from->si_utime, &to->si_utime);
84     			err |= __put_user(from->si_stime, &to->si_stime);
85     			err |= __put_user(from->si_status, &to->si_status);
86     		default:
87     			err |= __put_user(from->si_uid, &to->si_uid);
88     			break;
89     		/* case __SI_RT: This is not generated by the kernel as of now.  */
90     		}
91     		return err;
92     	}
93     }
94     
95     /*
96      * Atomically swap in the new signal mask, and wait for a signal.
97      */
98     int
99     sys_sigsuspend(old_sigset_t mask, int p2, int p3, int p4, int p6, int p7,
100     	       struct pt_regs *regs)
101     {
102     	sigset_t saveset;
103     
104     	mask &= _BLOCKABLE;
105     	spin_lock_irq(&current->sigmask_lock);
106     	saveset = current->blocked;
107     	siginitset(&current->blocked, mask);
108     	recalc_sigpending(current);
109     	spin_unlock_irq(&current->sigmask_lock);
110     
111     	regs->gpr[3] = -EINTR;
112     	while (1) {
113     		current->state = TASK_INTERRUPTIBLE;
114     		schedule();
115     		if (do_signal(&saveset, regs))
116     			/*
117     			 * If a signal handler needs to be called,
118     			 * do_signal() has set R3 to the signal number (the
119     			 * first argument of the signal handler), so don't
120     			 * overwrite that with EINTR !
121     			 * In the other cases, do_signal() doesn't touch 
122     			 * R3, so it's still set to -EINTR (see above).
123     			 */
124     			return regs->gpr[3];
125     	}
126     }
127     
128     int
129     sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize, int p3, int p4, int p6,
130     		  int p7, struct pt_regs *regs)
131     {
132     	sigset_t saveset, newset;
133     
134     	/* XXX: Don't preclude handling different sized sigset_t's.  */
135     	if (sigsetsize != sizeof(sigset_t))
136     		return -EINVAL;
137     
138     	if (copy_from_user(&newset, unewset, sizeof(newset)))
139     		return -EFAULT;
140     	sigdelsetmask(&newset, ~_BLOCKABLE);
141     
142     	spin_lock_irq(&current->sigmask_lock);
143     	saveset = current->blocked;
144     	current->blocked = newset;
145     	recalc_sigpending(current);
146     	spin_unlock_irq(&current->sigmask_lock);
147     
148     	regs->gpr[3] = -EINTR;
149     	while (1) {
150     		current->state = TASK_INTERRUPTIBLE;
151     		schedule();
152     		if (do_signal(&saveset, regs))
153     			return regs->gpr[3];
154     	}
155     }
156     
157     
158     int
159     sys_sigaltstack(const stack_t *uss, stack_t *uoss)
160     {
161     	struct pt_regs *regs = (struct pt_regs *) &uss;
162     	return do_sigaltstack(uss, uoss, regs->gpr[1]);
163     }
164     
165     int 
166     sys_sigaction(int sig, const struct old_sigaction *act,
167     	      struct old_sigaction *oact)
168     {
169     	struct k_sigaction new_ka, old_ka;
170     	int ret;
171     
172     	if (act) {
173     		old_sigset_t mask;
174     		if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
175     		    __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
176     		    __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
177     			return -EFAULT;
178     		__get_user(new_ka.sa.sa_flags, &act->sa_flags);
179     		__get_user(mask, &act->sa_mask);
180     		siginitset(&new_ka.sa.sa_mask, mask);
181     	}
182     
183     	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
184     
185     	if (!ret && oact) {
186     		if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
187     		    __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
188     		    __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
189     			return -EFAULT;
190     		__put_user(old_ka.sa.sa_flags, &oact->sa_flags);
191     		__put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
192     	}
193     
194     	return ret;
195     }
196     
197     /*
198      * When we have signals to deliver, we set up on the
199      * user stack, going down from the original stack pointer:
200      *	a sigregs struct
201      *	one or more sigcontext structs with
202      *	a gap of __SIGNAL_FRAMESIZE bytes
203      *
204      * Each of these things must be a multiple of 16 bytes in size.
205      *
206      */
207     struct sigregs {
208     	elf_gregset_t	gp_regs;
209     	double		fp_regs[ELF_NFPREG];
210     	unsigned long	tramp[2];
211     	/* Programs using the rs6000/xcoff abi can save up to 19 gp regs
212     	   and 18 fp regs below sp before decrementing it. */
213     	int		abigap[56];
214     };
215     
216     struct rt_sigframe
217     {
218     	unsigned long	_unused[2];
219     	struct siginfo *pinfo;
220     	void *puc;
221     	struct siginfo info;
222     	struct ucontext uc;
223     };
224     
225     
226     /*
227      *  When we have rt signals to deliver, we set up on the
228      *  user stack, going down from the original stack pointer:
229      *	   a sigregs struct
230      *	   one rt_sigframe struct (siginfo + ucontext)
231      *	   a gap of __SIGNAL_FRAMESIZE bytes
232      *
233      *  Each of these things must be a multiple of 16 bytes in size.
234      *
235      */
236     int sys_rt_sigreturn(struct pt_regs *regs)
237     {
238     	struct rt_sigframe *rt_sf;
239     	struct sigcontext_struct sigctx;
240     	struct sigregs *sr;
241     	int ret;
242     	elf_gregset_t saved_regs;  /* an array of ELF_NGREG unsigned longs */
243     	sigset_t set;
244     	stack_t st;
245     	unsigned long prevsp;
246     
247     	rt_sf = (struct rt_sigframe *)(regs->gpr[1] + __SIGNAL_FRAMESIZE);
248     	if (copy_from_user(&sigctx, &rt_sf->uc.uc_mcontext, sizeof(sigctx))
249     	    || copy_from_user(&set, &rt_sf->uc.uc_sigmask, sizeof(set))
250     	    || copy_from_user(&st, &rt_sf->uc.uc_stack, sizeof(st)))
251     		goto badframe;
252     	sigdelsetmask(&set, ~_BLOCKABLE);
253     	spin_lock_irq(&current->sigmask_lock);
254     	current->blocked = set;
255     	recalc_sigpending(current);
256     	spin_unlock_irq(&current->sigmask_lock);
257     
258     	rt_sf++;			/* Look at next rt_sigframe */
259     	if (rt_sf == (struct rt_sigframe *)(sigctx.regs)) {
260     		/* Last stacked signal - restore registers -
261     		 * sigctx is initialized to point to the 
262     		 * preamble frame (where registers are stored) 
263     		 * see handle_signal()
264     		 */
265     		sr = (struct sigregs *) sigctx.regs;
266     		if (regs->msr & MSR_FP )
267     			giveup_fpu(current);
268     		if (copy_from_user(saved_regs, &sr->gp_regs,
269     				   sizeof(sr->gp_regs)))
270     			goto badframe;
271     		saved_regs[PT_MSR] = (regs->msr & ~MSR_USERCHANGE)
272     			| (saved_regs[PT_MSR] & MSR_USERCHANGE);
273     		memcpy(regs, saved_regs, GP_REGS_SIZE);
274     		if (copy_from_user(current->thread.fpr, &sr->fp_regs,
275     				   sizeof(sr->fp_regs)))
276     			goto badframe;
277     		/* This function sets back the stack flags into
278     		   the current task structure.  */
279     		sys_sigaltstack(&st, NULL);
280     
281     		ret = regs->result;
282     	} else {
283     		/* More signals to go */
284     		/* Set up registers for next signal handler */
285     		regs->gpr[1] = (unsigned long)rt_sf - __SIGNAL_FRAMESIZE;
286     		if (copy_from_user(&sigctx, &rt_sf->uc.uc_mcontext, sizeof(sigctx)))
287     			goto badframe;
288     		sr = (struct sigregs *) sigctx.regs;
289     		regs->gpr[3] = ret = sigctx.signal;
290     		/* Get the siginfo   */
291     		get_user(regs->gpr[4], (unsigned long *)&rt_sf->pinfo);
292     		/* Get the ucontext */
293     		get_user(regs->gpr[5], (unsigned long *)&rt_sf->puc);
294     		regs->gpr[6] = (unsigned long) rt_sf;
295     
296     		regs->link = (unsigned long) &sr->tramp;
297     		regs->nip = sigctx.handler;
298     		if (get_user(prevsp, &sr->gp_regs[PT_R1])
299     		    || put_user(prevsp, (unsigned long *) regs->gpr[1]))
300     			goto badframe;
301     	}
302     	return ret;
303     
304     badframe:
305     	do_exit(SIGSEGV);
306     }
307     
308     static void
309     setup_rt_frame(struct pt_regs *regs, struct sigregs *frame,
310     	       signed long newsp)
311     {
312     	struct rt_sigframe *rt_sf = (struct rt_sigframe *) newsp;
313     
314     	/* Set up preamble frame */
315     	if (verify_area(VERIFY_WRITE, frame, sizeof(*frame)))
316     		goto badframe;
317     	if (regs->msr & MSR_FP)
318     		giveup_fpu(current);
319     	if (__copy_to_user(&frame->gp_regs, regs, GP_REGS_SIZE)
320     	    || __copy_to_user(&frame->fp_regs, current->thread.fpr,
321     			      ELF_NFPREG * sizeof(double))
322     	/* Set up to return from user space.
323     	   It calls the sc exception at offset 0x9999 
324     	   for sys_rt_sigreturn().
325     	*/
326     	    || __put_user(0x38006666UL, &frame->tramp[0])	/* li r0,0x6666 */
327     	    || __put_user(0x44000002UL, &frame->tramp[1]))	/* sc */
328     		goto badframe;
329     	flush_icache_range((unsigned long) &frame->tramp[0],
330     			   (unsigned long) &frame->tramp[2]);
331     
332     	/* Retrieve rt_sigframe from stack and
333     	   set up registers for signal handler
334     	*/
335     	newsp -= __SIGNAL_FRAMESIZE;
336     	if (put_user(regs->gpr[1], (unsigned long *)newsp)
337     	    || get_user(regs->nip, &rt_sf->uc.uc_mcontext.handler)
338     	    || get_user(regs->gpr[3], &rt_sf->uc.uc_mcontext.signal)
339     	    || get_user(regs->gpr[4], (unsigned long *)&rt_sf->pinfo)
340     	    || get_user(regs->gpr[5], (unsigned long *)&rt_sf->puc))
341     		goto badframe;
342     
343     	regs->gpr[1] = newsp;
344     	regs->gpr[6] = (unsigned long) rt_sf;
345     	regs->link = (unsigned long) frame->tramp;
346     
347     	return;
348     
349     badframe:
350     #if DEBUG_SIG
351     	printk("badframe in setup_rt_frame, regs=%p frame=%p newsp=%lx\n",
352     	       regs, frame, newsp);
353     #endif
354     	do_exit(SIGSEGV);
355     }
356     
357     /*
358      * Do a signal return; undo the signal stack.
359      */
360     int sys_sigreturn(struct pt_regs *regs)
361     {
362     	struct sigcontext_struct *sc, sigctx;
363     	struct sigregs *sr;
364     	int ret;
365     	elf_gregset_t saved_regs;  /* an array of ELF_NGREG unsigned longs */
366     	sigset_t set;
367     	unsigned long prevsp;
368     
369     	sc = (struct sigcontext_struct *)(regs->gpr[1] + __SIGNAL_FRAMESIZE);
370     	if (copy_from_user(&sigctx, sc, sizeof(sigctx)))
371     		goto badframe;
372     
373     	set.sig[0] = sigctx.oldmask;
374     #if _NSIG_WORDS > 1
375     	set.sig[1] = sigctx._unused[3];
376     #endif
377     	sigdelsetmask(&set, ~_BLOCKABLE);
378     	spin_lock_irq(&current->sigmask_lock);
379     	current->blocked = set;
380     	recalc_sigpending(current);
381     	spin_unlock_irq(&current->sigmask_lock);
382     
383     	sc++;			/* Look at next sigcontext */
384     	if (sc == (struct sigcontext_struct *)(sigctx.regs)) {
385     		/* Last stacked signal - restore registers */
386     		sr = (struct sigregs *) sigctx.regs;
387     		if (regs->msr & MSR_FP )
388     			giveup_fpu(current);
389     		if (copy_from_user(saved_regs, &sr->gp_regs,
390     				   sizeof(sr->gp_regs)))
391     			goto badframe;
392     		saved_regs[PT_MSR] = (regs->msr & ~MSR_USERCHANGE)
393     			| (saved_regs[PT_MSR] & MSR_USERCHANGE);
394     		memcpy(regs, saved_regs, GP_REGS_SIZE);
395     
396     		if (copy_from_user(current->thread.fpr, &sr->fp_regs,
397     				   sizeof(sr->fp_regs)))
398     			goto badframe;
399     
400     		ret = regs->result;
401     
402     	} else {
403     		/* More signals to go */
404     		regs->gpr[1] = (unsigned long)sc - __SIGNAL_FRAMESIZE;
405     		if (copy_from_user(&sigctx, sc, sizeof(sigctx)))
406     			goto badframe;
407     		sr = (struct sigregs *) sigctx.regs;
408     		regs->gpr[3] = ret = sigctx.signal;
409     		regs->gpr[4] = (unsigned long) sc;
410     		regs->link = (unsigned long) &sr->tramp;
411     		regs->nip = sigctx.handler;
412     
413     		if (get_user(prevsp, &sr->gp_regs[PT_R1])
414     		    || put_user(prevsp, (unsigned long *) regs->gpr[1]))
415     			goto badframe;
416     	}
417     	return ret;
418     
419     badframe:
420     	do_exit(SIGSEGV);
421     }	
422     
423     /*
424      * Set up a signal frame.
425      */
426     static void
427     setup_frame(struct pt_regs *regs, struct sigregs *frame,
428     	    unsigned long newsp)
429     {
430     	struct sigcontext_struct *sc = (struct sigcontext_struct *) newsp;
431     
432     	if (verify_area(VERIFY_WRITE, frame, sizeof(*frame)))
433     		goto badframe;
434     		if (regs->msr & MSR_FP)
435     			giveup_fpu(current);
436     	if (__copy_to_user(&frame->gp_regs, regs, GP_REGS_SIZE)
437     	    || __copy_to_user(&frame->fp_regs, current->thread.fpr,
438     			      ELF_NFPREG * sizeof(double))
439     	    || __put_user(0x38007777UL, &frame->tramp[0])    /* li r0,0x7777 */
440     	    || __put_user(0x44000002UL, &frame->tramp[1]))   /* sc */
441     		goto badframe;
442     	flush_icache_range((unsigned long) &frame->tramp[0],
443     			   (unsigned long) &frame->tramp[2]);
444     
445     	newsp -= __SIGNAL_FRAMESIZE;
446     	if (put_user(regs->gpr[1], (unsigned long *)newsp)
447     	    || get_user(regs->nip, &sc->handler)
448     	    || get_user(regs->gpr[3], &sc->signal))
449     		goto badframe;
450     	regs->gpr[1] = newsp;
451     	regs->gpr[4] = (unsigned long) sc;
452     	regs->link = (unsigned long) frame->tramp;
453     
454     	return;
455     
456     badframe:
457     #if DEBUG_SIG
458     	printk("badframe in setup_frame, regs=%p frame=%p newsp=%lx\n",
459     	       regs, frame, newsp);
460     #endif
461     	do_exit(SIGSEGV);
462     }
463     
464     /*
465      * OK, we're invoking a handler
466      */
467     static void
468     handle_signal(unsigned long sig, struct k_sigaction *ka,
469     	      siginfo_t *info, sigset_t *oldset, struct pt_regs * regs,
470     	      unsigned long *newspp, unsigned long frame)
471     {
472     	struct sigcontext_struct *sc;
473     	struct rt_sigframe *rt_sf;
474     
475     	if (regs->trap == 0x0C00 /* System Call! */
476     	    && ((int)regs->result == -ERESTARTNOHAND ||
477     		((int)regs->result == -ERESTARTSYS &&
478     		 !(ka->sa.sa_flags & SA_RESTART))))
479     		regs->result = -EINTR;
480     
481     	/* Set up Signal Frame */
482     	if (ka->sa.sa_flags & SA_SIGINFO) {
483     		/* Put a Real Time Context onto stack */
484     		*newspp -= sizeof(*rt_sf);
485     		rt_sf = (struct rt_sigframe *) *newspp;
486     		if (verify_area(VERIFY_WRITE, rt_sf, sizeof(*rt_sf)))
487     			goto badframe;
488     
489     		if (__put_user((unsigned long) ka->sa.sa_handler, &rt_sf->uc.uc_mcontext.handler)
490     		    || __put_user(&rt_sf->info, &rt_sf->pinfo)
491     		    || __put_user(&rt_sf->uc, &rt_sf->puc)
492     		    /* Put the siginfo */
493     		    || __copy_to_user(&rt_sf->info, info, sizeof(*info))
494     		    /* Create the ucontext */
495     		    || __put_user(0, &rt_sf->uc.uc_flags)
496     		    || __put_user(0, &rt_sf->uc.uc_link)
497     		    || __put_user(current->sas_ss_sp, &rt_sf->uc.uc_stack.ss_sp)
498     		    || __put_user(sas_ss_flags(regs->gpr[1]), 
499     				  &rt_sf->uc.uc_stack.ss_flags)
500     		    || __put_user(current->sas_ss_size, &rt_sf->uc.uc_stack.ss_size)
501     		    || __copy_to_user(&rt_sf->uc.uc_sigmask, oldset, sizeof(*oldset))
502     		    /* mcontext.regs points to preamble register frame */
503     		    || __put_user((struct pt_regs *)frame, &rt_sf->uc.uc_mcontext.regs)
504     		    || __put_user(sig, &rt_sf->uc.uc_mcontext.signal))
505     			goto badframe;
506     	} else {
507     		/* Put another sigcontext on the stack */
508     		*newspp -= sizeof(*sc);
509     		sc = (struct sigcontext_struct *) *newspp;
510     		if (verify_area(VERIFY_WRITE, sc, sizeof(*sc)))
511     			goto badframe;
512     		
513     		if (__put_user((unsigned long) ka->sa.sa_handler, &sc->handler)
514     		    || __put_user(oldset->sig[0], &sc->oldmask)
515     #if _NSIG_WORDS > 1
516     		    || __put_user(oldset->sig[1], &sc->_unused[3])
517     #endif
518     		    || __put_user((struct pt_regs *)frame, &sc->regs)
519     		    || __put_user(sig, &sc->signal))
520     			goto badframe;
521     	}
522     
523     	if (ka->sa.sa_flags & SA_ONESHOT)
524     		ka->sa.sa_handler = SIG_DFL;
525     
526     	if (!(ka->sa.sa_flags & SA_NODEFER)) {
527     		spin_lock_irq(&current->sigmask_lock);
528     		sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
529     		sigaddset(&current->blocked,sig);
530     		recalc_sigpending(current);
531     		spin_unlock_irq(&current->sigmask_lock);
532     	}
533     	return;
534     
535     badframe:
536     #if DEBUG_SIG
537     	printk("badframe in handle_signal, regs=%p frame=%lx newsp=%lx\n",
538     	       regs, frame, *newspp);
539     	printk("sc=%p sig=%d ka=%p info=%p oldset=%p\n", sc, sig, ka, info, oldset);
540     #endif
541     	do_exit(SIGSEGV);
542     }
543     
544     /*
545      * Note that 'init' is a special process: it doesn't get signals it doesn't
546      * want to handle. Thus you cannot kill init even with a SIGKILL even by
547      * mistake.
548      */
549     int do_signal(sigset_t *oldset, struct pt_regs *regs)
550     {
551     	siginfo_t info;
552     	struct k_sigaction *ka;
553     	unsigned long frame, newsp;
554     
555     	if (!oldset)
556     		oldset = &current->blocked;
557     
558     	newsp = frame = 0;
559     
560     	for (;;) {
561     		unsigned long signr;
562     
563     		spin_lock_irq(&current->sigmask_lock);
564     		signr = dequeue_signal(&current->blocked, &info);
565     		spin_unlock_irq(&current->sigmask_lock);
566     
567     		if (!signr)
568     			break;
569     
570     		if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) {
571     			/* Let the debugger run.  */
572     			current->exit_code = signr;
573     			current->state = TASK_STOPPED;
574     			notify_parent(current, SIGCHLD);
575     			schedule();
576     
577     			/* We're back.  Did the debugger cancel the sig?  */
578     			if (!(signr = current->exit_code))
579     				continue;
580     			current->exit_code = 0;
581     
582     			/* The debugger continued.  Ignore SIGSTOP.  */
583     			if (signr == SIGSTOP)
584     				continue;
585     
586     			/* Update the siginfo structure.  Is this good?  */
587     			if (signr != info.si_signo) {
588     				info.si_signo = signr;
589     				info.si_errno = 0;
590     				info.si_code = SI_USER;
591     				info.si_pid = current->p_pptr->pid;
592     				info.si_uid = current->p_pptr->uid;
593     			}
594     
595     			/* If the (new) signal is now blocked, requeue it.  */
596     			if (sigismember(&current->blocked, signr)) {
597     				send_sig_info(signr, &info, current);
598     				continue;
599     			}
600     		}
601     
602     		ka = &current->sig->action[signr-1];
603     		if (ka->sa.sa_handler == SIG_IGN) {
604     			if (signr != SIGCHLD)
605     				continue;
606     			/* Check for SIGCHLD: it's special.  */
607     			while (sys_wait4(-1, NULL, WNOHANG, NULL) > 0)
608     				/* nothing */;
609     			continue;
610     		}
611     
612     		if (ka->sa.sa_handler == SIG_DFL) {
613     			int exit_code = signr;
614     
615     			/* Init gets no signals it doesn't want.  */
616     			if (current->pid == 1)
617     				continue;
618     
619     			switch (signr) {
620     			case SIGCONT: case SIGCHLD: case SIGWINCH:
621     				continue;
622     
623     			case SIGTSTP: case SIGTTIN: case SIGTTOU:
624     				if (is_orphaned_pgrp(current->pgrp))
625     					continue;
626     				/* FALLTHRU */
627     
628     			case SIGSTOP:
629     				current->state = TASK_STOPPED;
630     				current->exit_code = signr;
631     				if (!(current->p_pptr->sig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP))
632     					notify_parent(current, SIGCHLD);
633     				schedule();
634     				continue;
635     
636     			case SIGQUIT: case SIGILL: case SIGTRAP:
637     			case SIGABRT: case SIGFPE: case SIGSEGV:
638     			case SIGBUS: case SIGSYS: case SIGXCPU: case SIGXFSZ:
639     				if (do_coredump(signr, regs))
640     					exit_code |= 0x80;
641     				/* FALLTHRU */
642     
643     			default:
644     				sigaddset(&current->pending.signal, signr);
645     				recalc_sigpending(current);
646     				current->flags |= PF_SIGNALED;
647     				do_exit(exit_code);
648     				/* NOTREACHED */
649     			}
650     		}
651     
652     		if ( (ka->sa.sa_flags & SA_ONSTACK)
653     		     && (! on_sig_stack(regs->gpr[1])))
654     			newsp = (current->sas_ss_sp + current->sas_ss_size);
655     		else
656     			newsp = regs->gpr[1];
657     		newsp = frame = newsp - sizeof(struct sigregs);
658     
659     		/* Whee!  Actually deliver the signal.  */
660     		handle_signal(signr, ka, &info, oldset, regs, &newsp, frame);
661     		break;
662     	}
663     
664     	if (regs->trap == 0x0C00 /* System Call! */ &&
665     	    ((int)regs->result == -ERESTARTNOHAND ||
666     	     (int)regs->result == -ERESTARTSYS ||
667     	     (int)regs->result == -ERESTARTNOINTR)) {
668     		regs->gpr[3] = regs->orig_gpr3;
669     		regs->nip -= 4;		/* Back up & retry system call */
670     		regs->result = 0;
671     	}
672     
673     	if (newsp == frame)
674     		return 0;		/* no signals delivered */
675     
676     	if (ka->sa.sa_flags & SA_SIGINFO)
677     		setup_rt_frame(regs, (struct sigregs *) frame, newsp);
678     	else
679     		setup_frame(regs, (struct sigregs *) frame, newsp);
680     	return 1;
681     }
682     
683