1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1991, 1992  Linus Torvalds
7  * Copyright (C) 1994 - 1999  Ralf Baechle
8  * Copyright (C) 1999 Silicon Graphics, Inc.
9  */
10 #include <linux/config.h>
11 #include <linux/sched.h>
12 #include <linux/mm.h>
13 #include <linux/smp.h>
14 #include <linux/smp_lock.h>
15 #include <linux/kernel.h>
16 #include <linux/personality.h>
17 #include <linux/signal.h>
18 #include <linux/errno.h>
19 #include <linux/wait.h>
20 #include <linux/unistd.h>
21 
22 #include <asm/asm.h>
23 #include <asm/bitops.h>
24 #include <asm/cpu.h>
25 #include <asm/fpu.h>
26 #include <asm/offset.h>
27 #include <asm/pgalloc.h>
28 #include <asm/ptrace.h>
29 #include <asm/uaccess.h>
30 #include <asm/ucontext.h>
31 
32 #define DEBUG_SIG 0
33 
34 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
35 
36 extern asmlinkage int do_signal(sigset_t *oldset, struct pt_regs *regs);
37 
38 extern asmlinkage void syscall_trace(void);
39 
copy_siginfo_to_user(siginfo_t * to,siginfo_t * from)40 int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
41 {
42 	if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
43 		return -EFAULT;
44 	if (from->si_code < 0)
45 		return __copy_to_user(to, from, sizeof(siginfo_t));
46 	else {
47 		int err;
48 
49 		/* If you change siginfo_t structure, please be sure
50 		   this code is fixed accordingly.
51 		   It should never copy any pad contained in the structure
52 		   to avoid security leaks, but must copy the generic
53 		   3 ints plus the relevant union member.  */
54 		err = __put_user(from->si_signo, &to->si_signo);
55 		err |= __put_user(from->si_errno, &to->si_errno);
56 		err |= __put_user((short)from->si_code, &to->si_code);
57 		/* First 32bits of unions are always present.  */
58 		err |= __put_user(from->si_pid, &to->si_pid);
59 		switch (from->si_code >> 16) {
60 		case __SI_FAULT >> 16:
61 			break;
62 		case __SI_CHLD >> 16:
63 			err |= __put_user(from->si_utime, &to->si_utime);
64 			err |= __put_user(from->si_stime, &to->si_stime);
65 			err |= __put_user(from->si_status, &to->si_status);
66 		default:
67 			err |= __put_user(from->si_uid, &to->si_uid);
68 			break;
69 		/* case __SI_RT: This is not generated by the kernel as of now.  */
70 		}
71 		return err;
72 	}
73 }
74 
75 /*
76  * Atomically swap in the new signal mask, and wait for a signal.
77  */
78 save_static_function(sys_sigsuspend);
_sys_sigsuspend(struct pt_regs regs)79 static_unused int _sys_sigsuspend(struct pt_regs regs)
80 {
81 	sigset_t *uset, saveset, newset;
82 
83 	uset = (sigset_t *) regs.regs[4];
84 	if (copy_from_user(&newset, uset, sizeof(sigset_t)))
85 		return -EFAULT;
86 	sigdelsetmask(&newset, ~_BLOCKABLE);
87 
88 	spin_lock_irq(&current->sigmask_lock);
89 	saveset = current->blocked;
90 	current->blocked = newset;
91 	recalc_sigpending(current);
92 	spin_unlock_irq(&current->sigmask_lock);
93 
94 	regs.regs[2] = EINTR;
95 	regs.regs[7] = 1;
96 	while (1) {
97 		current->state = TASK_INTERRUPTIBLE;
98 		schedule();
99 		if (do_signal(&saveset, &regs))
100 			return -EINTR;
101 	}
102 }
103 
104 save_static_function(sys_rt_sigsuspend);
_sys_rt_sigsuspend(struct pt_regs regs)105 static_unused int _sys_rt_sigsuspend(struct pt_regs regs)
106 {
107 	sigset_t *unewset, saveset, newset;
108         size_t sigsetsize;
109 
110 	/* XXX Don't preclude handling different sized sigset_t's.  */
111 	sigsetsize = regs.regs[5];
112 	if (sigsetsize != sizeof(sigset_t))
113 		return -EINVAL;
114 
115 	unewset = (sigset_t *) regs.regs[4];
116 	if (copy_from_user(&newset, unewset, sizeof(newset)))
117 		return -EFAULT;
118 	sigdelsetmask(&newset, ~_BLOCKABLE);
119 
120 	spin_lock_irq(&current->sigmask_lock);
121 	saveset = current->blocked;
122 	current->blocked = newset;
123         recalc_sigpending(current);
124 	spin_unlock_irq(&current->sigmask_lock);
125 
126 	regs.regs[2] = EINTR;
127 	regs.regs[7] = 1;
128 	while (1) {
129 		current->state = TASK_INTERRUPTIBLE;
130 		schedule();
131 		if (do_signal(&saveset, &regs))
132 			return -EINTR;
133 	}
134 }
135 
sys_sigaction(int sig,const struct sigaction * act,struct sigaction * oact)136 asmlinkage int sys_sigaction(int sig, const struct sigaction *act,
137 	struct sigaction *oact)
138 {
139 	struct k_sigaction new_ka, old_ka;
140 	int ret;
141 	int err = 0;
142 
143 	if (act) {
144 		old_sigset_t mask;
145 
146 		if (!access_ok(VERIFY_READ, act, sizeof(*act)))
147 			return -EFAULT;
148 		err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler);
149 		err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
150 		err |= __get_user(mask, &act->sa_mask.sig[0]);
151 		if (err)
152 			return -EFAULT;
153 
154 		siginitset(&new_ka.sa.sa_mask, mask);
155 	}
156 
157 	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
158 
159 	if (!ret && oact) {
160 		if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
161                         return -EFAULT;
162 		err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
163 		err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler);
164 		err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
165                 err |= __put_user(0, &oact->sa_mask.sig[1]);
166                 err |= __put_user(0, &oact->sa_mask.sig[2]);
167                 err |= __put_user(0, &oact->sa_mask.sig[3]);
168                 if (err)
169 			return -EFAULT;
170 	}
171 
172 	return ret;
173 }
174 
sys_sigaltstack(struct pt_regs regs)175 asmlinkage int sys_sigaltstack(struct pt_regs regs)
176 {
177 	const stack_t *uss = (const stack_t *) regs.regs[4];
178 	stack_t *uoss = (stack_t *) regs.regs[5];
179 	unsigned long usp = regs.regs[29];
180 
181 	return do_sigaltstack(uss, uoss, usp);
182 }
183 
restore_sigcontext(struct pt_regs * regs,struct sigcontext * sc)184 static int restore_sigcontext(struct pt_regs *regs, struct sigcontext *sc)
185 {
186 	int err = 0;
187 	u64 reg;
188 
189 	err |= __get_user(regs->cp0_epc, &sc->sc_pc);
190 
191 	err |= __get_user(reg, &sc->sc_mdhi);
192 	regs->hi = (int) reg;
193 	err |= __get_user(reg, &sc->sc_mdlo);
194 	regs->lo = (int) reg;
195 
196 #define restore_gp_reg(i) do {						\
197 	err |= __get_user(reg, &sc->sc_regs[i]);			\
198 	regs->regs[i] = reg;						\
199 } while(0)
200 	restore_gp_reg( 1); restore_gp_reg( 2); restore_gp_reg( 3);
201 	restore_gp_reg( 4); restore_gp_reg( 5); restore_gp_reg( 6);
202 	restore_gp_reg( 7); restore_gp_reg( 8); restore_gp_reg( 9);
203 	restore_gp_reg(10); restore_gp_reg(11); restore_gp_reg(12);
204 	restore_gp_reg(13); restore_gp_reg(14); restore_gp_reg(15);
205 	restore_gp_reg(16); restore_gp_reg(17); restore_gp_reg(18);
206 	restore_gp_reg(19); restore_gp_reg(20); restore_gp_reg(21);
207 	restore_gp_reg(22); restore_gp_reg(23); restore_gp_reg(24);
208 	restore_gp_reg(25); restore_gp_reg(26); restore_gp_reg(27);
209 	restore_gp_reg(28); restore_gp_reg(29); restore_gp_reg(30);
210 	restore_gp_reg(31);
211 #undef restore_gp_reg
212 
213 	err |= __get_user(current->used_math, &sc->sc_used_math);
214 
215 	if (current->used_math) {
216 		/* restore fpu context if we have used it before */
217 		own_fpu();
218 		err |= restore_fp_context(sc);
219 	} else {
220 		/* signal handler may have used FPU.  Give it up. */
221 		lose_fpu();
222 	}
223 
224 	return err;
225 }
226 
227 struct sigframe {
228 	u32 sf_ass[4];			/* argument save space for o32 */
229 	u32 sf_code[2];			/* signal trampoline */
230 	struct sigcontext sf_sc;
231 	sigset_t sf_mask;
232 };
233 
234 struct rt_sigframe {
235 	u32 rs_ass[4];			/* argument save space for o32 */
236 	u32 rs_code[2];			/* signal trampoline */
237 	struct siginfo rs_info;
238 	struct ucontext rs_uc;
239 };
240 
sys_sigreturn(struct pt_regs regs)241 asmlinkage void sys_sigreturn(struct pt_regs regs)
242 {
243 	struct sigframe *frame;
244 	sigset_t blocked;
245 
246 	frame = (struct sigframe *) regs.regs[29];
247 	if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
248 		goto badframe;
249 	if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
250 		goto badframe;
251 
252 	sigdelsetmask(&blocked, ~_BLOCKABLE);
253 	spin_lock_irq(&current->sigmask_lock);
254 	current->blocked = blocked;
255 	recalc_sigpending(current);
256 	spin_unlock_irq(&current->sigmask_lock);
257 
258 	if (restore_sigcontext(&regs, &frame->sf_sc))
259 		goto badframe;
260 
261 	/*
262 	 * Don't let your children do this ...
263 	 */
264 	if (current->ptrace & PT_TRACESYS)
265 		syscall_trace();
266 	__asm__ __volatile__(
267 		"move\t$29, %0\n\t"
268 		"j\tret_from_sys_call"
269 		:/* no outputs */
270 		:"r" (&regs));
271 	/* Unreached */
272 
273 badframe:
274 	force_sig(SIGSEGV, current);
275 }
276 
sys_rt_sigreturn(struct pt_regs regs)277 asmlinkage void sys_rt_sigreturn(struct pt_regs regs)
278 {
279 	struct rt_sigframe *frame;
280 	sigset_t set;
281 	stack_t st;
282 
283 	frame = (struct rt_sigframe *) regs.regs[29];
284 	if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
285 		goto badframe;
286 	if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
287 		goto badframe;
288 
289 	sigdelsetmask(&set, ~_BLOCKABLE);
290 	spin_lock_irq(&current->sigmask_lock);
291 	current->blocked = set;
292 	recalc_sigpending(current);
293 	spin_unlock_irq(&current->sigmask_lock);
294 
295 	if (restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext))
296 		goto badframe;
297 
298 	if (__copy_from_user(&st, &frame->rs_uc.uc_stack, sizeof(st)))
299 		goto badframe;
300 	/* It is more difficult to avoid calling this function than to
301 	   call it and ignore errors.  */
302 	do_sigaltstack(&st, NULL, regs.regs[29]);
303 
304 	/*
305 	 * Don't let your children do this ...
306 	 */
307 	__asm__ __volatile__(
308 		"move\t$29, %0\n\t"
309 		"j\tret_from_sys_call"
310 		:/* no outputs */
311 		:"r" (&regs));
312 	/* Unreached */
313 
314 badframe:
315 	force_sig(SIGSEGV, current);
316 }
317 
setup_sigcontext(struct pt_regs * regs,struct sigcontext * sc)318 static int inline setup_sigcontext(struct pt_regs *regs, struct sigcontext *sc)
319 {
320 	int err = 0;
321 	u64 reg;
322 
323 	reg = regs->cp0_epc; err |= __put_user(reg, &sc->sc_pc);
324 	err |= __put_user(regs->cp0_status, &sc->sc_status);
325 
326 #define save_gp_reg(i) {						\
327 	reg = regs->regs[i];						\
328 	err |= __put_user(reg, &sc->sc_regs[i]);			\
329 } while(0)
330 	reg = 0; err |= __put_user(reg, &sc->sc_regs[0]);
331 	save_gp_reg(1); save_gp_reg(2);
332 	save_gp_reg(3); save_gp_reg(4); save_gp_reg(5); save_gp_reg(6);
333 	save_gp_reg(7); save_gp_reg(8); save_gp_reg(9); save_gp_reg(10);
334 	save_gp_reg(11); save_gp_reg(12); save_gp_reg(13); save_gp_reg(14);
335 	save_gp_reg(15); save_gp_reg(16); save_gp_reg(17); save_gp_reg(18);
336 	save_gp_reg(19); save_gp_reg(20); save_gp_reg(21); save_gp_reg(22);
337 	save_gp_reg(23); save_gp_reg(24); save_gp_reg(25); save_gp_reg(26);
338 	save_gp_reg(27); save_gp_reg(28); save_gp_reg(29); save_gp_reg(30);
339 	save_gp_reg(31);
340 #undef save_gp_reg
341 
342 	reg = regs->hi; err |= __put_user(reg, &sc->sc_mdhi);
343 	reg = regs->lo; err |= __put_user(reg, &sc->sc_mdlo);
344 	err |= __put_user(regs->cp0_cause, &sc->sc_cause);
345 	err |= __put_user(regs->cp0_badvaddr, &sc->sc_badvaddr);
346 
347 	err |= __put_user(current->used_math, &sc->sc_used_math);
348 
349 	if (!current->used_math)
350 		goto out;
351 
352 	/*
353 	 * Save FPU state to signal context.  Signal handler will "inherit"
354 	 * current FPU state.
355 	 */
356 	if (!is_fpu_owner()) {
357 		own_fpu();
358 		restore_fp(current);
359 	}
360 	err |= save_fp_context(sc);
361 
362 out:
363 	return err;
364 }
365 
366 /*
367  * Determine which stack to use..
368  */
get_sigframe(struct k_sigaction * ka,struct pt_regs * regs,size_t frame_size)369 static inline void * get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
370 	size_t frame_size)
371 {
372 	unsigned long sp;
373 
374 	/* Default to using normal stack */
375 	sp = regs->regs[29];
376 
377 	/*
378  	 * FPU emulator may have it's own trampoline active just
379  	 * above the user stack, 16-bytes before the next lowest
380  	 * 16 byte boundary.  Try to avoid trashing it.
381  	 */
382  	sp -= 32;
383 
384 	/* This is the X/Open sanctioned signal stack switching.  */
385 	if ((ka->sa.sa_flags & SA_ONSTACK) && (sas_ss_flags (sp) == 0))
386                 sp = current->sas_ss_sp + current->sas_ss_size;
387 
388 	return (void *)((sp - frame_size) & ALMASK);
389 }
390 
setup_frame(struct k_sigaction * ka,struct pt_regs * regs,int signr,sigset_t * set)391 static void inline setup_frame(struct k_sigaction * ka, struct pt_regs *regs,
392 	int signr, sigset_t *set)
393 {
394 	struct sigframe *frame;
395 	int err = 0;
396 
397 	frame = get_sigframe(ka, regs, sizeof(*frame));
398 	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
399 		goto give_sigsegv;
400 
401 	/*
402 	 * Set up the return code ...
403 	 *
404 	 *         li      v0, __NR_sigreturn
405 	 *         syscall
406 	 */
407 	err |= __put_user(0x24020000 + __NR_sigreturn, frame->sf_code + 0);
408 	err |= __put_user(0x0000000c                 , frame->sf_code + 1);
409 	flush_cache_sigtramp((unsigned long) frame->sf_code);
410 
411 	err |= setup_sigcontext(regs, &frame->sf_sc);
412 	err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
413 	if (err)
414 		goto give_sigsegv;
415 
416 	/*
417 	 * Arguments to signal handler:
418 	 *
419 	 *   a0 = signal number
420 	 *   a1 = 0 (should be cause)
421 	 *   a2 = pointer to struct sigcontext
422 	 *
423 	 * $25 and c0_epc point to the signal handler, $29 points to the
424 	 * struct sigframe.
425 	 */
426 	regs->regs[ 4] = signr;
427 	regs->regs[ 5] = 0;
428 	regs->regs[ 6] = (unsigned long) &frame->sf_sc;
429 	regs->regs[29] = (unsigned long) frame;
430 	regs->regs[31] = (unsigned long) frame->sf_code;
431 	regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
432 
433 #if DEBUG_SIG
434 	printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
435 	       current->comm, current->pid,
436 	       frame, regs->cp0_epc, frame->sf_code);
437 #endif
438         return;
439 
440 give_sigsegv:
441 	if (signr == SIGSEGV)
442 		ka->sa.sa_handler = SIG_DFL;
443 	force_sig(SIGSEGV, current);
444 }
445 
setup_rt_frame(struct k_sigaction * ka,struct pt_regs * regs,int signr,sigset_t * set,siginfo_t * info)446 static void inline setup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,
447 	int signr, sigset_t *set, siginfo_t *info)
448 {
449 	struct rt_sigframe *frame;
450 	int err = 0;
451 
452 	frame = get_sigframe(ka, regs, sizeof(*frame));
453 	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
454 		goto give_sigsegv;
455 
456 	/*
457 	 * Set up the return code ...
458 	 *
459 	 *         li      v0, __NR_rt_sigreturn
460 	 *         syscall
461 	 */
462 	err |= __put_user(0x24020000 + __NR_rt_sigreturn, frame->rs_code + 0);
463 	err |= __put_user(0x0000000c                    , frame->rs_code + 1);
464 	flush_cache_sigtramp((unsigned long) frame->rs_code);
465 
466 	/* Create siginfo.  */
467 	err |= copy_siginfo_to_user(&frame->rs_info, info);
468 
469 	/* Create the ucontext.  */
470 	err |= __put_user(0, &frame->rs_uc.uc_flags);
471 	err |= __put_user(0, &frame->rs_uc.uc_link);
472 	err |= __put_user((void *)current->sas_ss_sp,
473 	                  &frame->rs_uc.uc_stack.ss_sp);
474 	err |= __put_user(sas_ss_flags(regs->regs[29]),
475 	                  &frame->rs_uc.uc_stack.ss_flags);
476 	err |= __put_user(current->sas_ss_size,
477 	                  &frame->rs_uc.uc_stack.ss_size);
478 	err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
479 	err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
480 
481 	if (err)
482 		goto give_sigsegv;
483 
484 	/*
485 	 * Arguments to signal handler:
486 	 *
487 	 *   a0 = signal number
488 	 *   a1 = 0 (should be cause)
489 	 *   a2 = pointer to ucontext
490 	 *
491 	 * $25 and c0_epc point to the signal handler, $29 points to
492 	 * the struct rt_sigframe.
493 	 */
494 	regs->regs[ 4] = signr;
495 	regs->regs[ 5] = (unsigned long) &frame->rs_info;
496 	regs->regs[ 6] = (unsigned long) &frame->rs_uc;
497 	regs->regs[29] = (unsigned long) frame;
498 	regs->regs[31] = (unsigned long) frame->rs_code;
499 	regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;
500 
501 #if DEBUG_SIG
502 	printk("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n",
503 	       current->comm, current->pid,
504 	       frame, regs->cp0_epc, frame->rs_code);
505 #endif
506 	return;
507 
508 give_sigsegv:
509 	if (signr == SIGSEGV)
510 		ka->sa.sa_handler = SIG_DFL;
511 	force_sig(SIGSEGV, current);
512 }
513 
handle_signal(unsigned long sig,struct k_sigaction * ka,siginfo_t * info,sigset_t * oldset,struct pt_regs * regs)514 static inline void handle_signal(unsigned long sig, struct k_sigaction *ka,
515 	siginfo_t *info, sigset_t *oldset, struct pt_regs * regs)
516 {
517 	if (ka->sa.sa_flags & SA_SIGINFO)
518 		setup_rt_frame(ka, regs, sig, oldset, info);
519 	else
520 		setup_frame(ka, regs, sig, oldset);
521 
522 	if (ka->sa.sa_flags & SA_ONESHOT)
523 		ka->sa.sa_handler = SIG_DFL;
524 	if (!(ka->sa.sa_flags & SA_NODEFER)) {
525 		spin_lock_irq(&current->sigmask_lock);
526 		sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
527 		sigaddset(&current->blocked,sig);
528 		recalc_sigpending(current);
529 		spin_unlock_irq(&current->sigmask_lock);
530 	}
531 }
532 
syscall_restart(struct pt_regs * regs,struct k_sigaction * ka)533 static inline void syscall_restart(struct pt_regs *regs, struct k_sigaction *ka)
534 {
535 	switch(regs->regs[0]) {
536 	case ERESTARTNOHAND:
537 		regs->regs[2] = EINTR;
538 		break;
539 	case ERESTARTSYS:
540 		if(!(ka->sa.sa_flags & SA_RESTART)) {
541 			regs->regs[2] = EINTR;
542 			break;
543 		}
544 	/* fallthrough */
545 	case ERESTARTNOINTR:		/* Userland will reload $v0.  */
546 		regs->regs[7] = regs->regs[26];
547 		regs->cp0_epc -= 8;
548 	}
549 
550 	regs->regs[0] = 0;		/* Don't deal with this again.  */
551 }
552 
553 extern int do_irix_signal(sigset_t *oldset, struct pt_regs *regs);
554 
do_signal(sigset_t * oldset,struct pt_regs * regs)555 asmlinkage int do_signal(sigset_t *oldset, struct pt_regs *regs)
556 {
557 	struct k_sigaction *ka;
558 	siginfo_t info;
559 
560 #ifdef CONFIG_BINFMT_IRIX
561 	if (current->personality != PER_LINUX)
562 		return do_irix_signal(oldset, regs);
563 #endif
564 
565 	if (!oldset)
566 		oldset = &current->blocked;
567 
568 	for (;;) {
569 		unsigned long signr;
570 
571 		spin_lock_irq(&current->sigmask_lock);
572 		signr = dequeue_signal(&current->blocked, &info);
573 		spin_unlock_irq(&current->sigmask_lock);
574 
575 		if (!signr)
576 			break;
577 
578 		if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) {
579 			/* Let the debugger run.  */
580 			current->exit_code = signr;
581 			current->state = TASK_STOPPED;
582 			notify_parent(current, SIGCHLD);
583 			schedule();
584 
585 			/* We're back.  Did the debugger cancel the sig?  */
586 			if (!(signr = current->exit_code))
587 				continue;
588 			current->exit_code = 0;
589 
590 			/* The debugger continued.  Ignore SIGSTOP.  */
591 			if (signr == SIGSTOP)
592 				continue;
593 
594 			/* Update the siginfo structure.  Is this good?  */
595 			if (signr != info.si_signo) {
596 				info.si_signo = signr;
597 				info.si_errno = 0;
598 				info.si_code = SI_USER;
599 				info.si_pid = current->p_pptr->pid;
600 				info.si_uid = current->p_pptr->uid;
601 			}
602 
603 			/* If the (new) signal is now blocked, requeue it.  */
604 			if (sigismember(&current->blocked, signr)) {
605 				send_sig_info(signr, &info, current);
606 				continue;
607 			}
608 		}
609 
610 		ka = &current->sig->action[signr-1];
611 		if (ka->sa.sa_handler == SIG_IGN) {
612 			if (signr != SIGCHLD)
613 				continue;
614 			/* Check for SIGCHLD: it's special.  */
615 			while (sys_wait4(-1, NULL, WNOHANG, NULL) > 0)
616 				/* nothing */;
617 			continue;
618 		}
619 
620 		if (ka->sa.sa_handler == SIG_DFL) {
621 			int exit_code = signr;
622 
623 			/* Init gets no signals it doesn't want.  */
624 			if (current->pid == 1)
625 				continue;
626 
627 			switch (signr) {
628 			case SIGCONT: case SIGCHLD: case SIGWINCH: case SIGURG:
629 				continue;
630 
631 			case SIGTSTP: case SIGTTIN: case SIGTTOU:
632 				if (is_orphaned_pgrp(current->pgrp))
633 					continue;
634 				/* FALLTHRU */
635 
636 			case SIGSTOP:
637 				current->state = TASK_STOPPED;
638 				current->exit_code = signr;
639 				if (!(current->p_pptr->sig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP))
640 					notify_parent(current, SIGCHLD);
641 				schedule();
642 				continue;
643 
644 			case SIGQUIT: case SIGILL: case SIGTRAP:
645 			case SIGABRT: case SIGFPE: case SIGSEGV:
646 			case SIGBUS: case SIGSYS: case SIGXCPU: case SIGXFSZ:
647 				if (do_coredump(signr, regs))
648 					exit_code |= 0x80;
649 				/* FALLTHRU */
650 
651 			default:
652 				sig_exit(signr, exit_code, &info);
653 				/* NOTREACHED */
654 			}
655 		}
656 
657 		if (regs->regs[0])
658 			syscall_restart(regs, ka);
659 		/* Whee!  Actually deliver the signal.  */
660 		handle_signal(signr, ka, &info, oldset, regs);
661 		return 1;
662 	}
663 
664 	/*
665 	 * Who's code doesn't conform to the restartable syscall convention
666 	 * dies here!!!  The li instruction, a single machine instruction,
667 	 * must directly be followed by the syscall instruction.
668 	 */
669 	if (regs->regs[0]) {
670 		if (regs->regs[2] == ERESTARTNOHAND ||
671 		    regs->regs[2] == ERESTARTSYS ||
672 		    regs->regs[2] == ERESTARTNOINTR) {
673 			regs->regs[7] = regs->regs[26];
674 			regs->cp0_epc -= 8;
675 		}
676 	}
677 	return 0;
678 }
679