1 /*
2  *  linux/arch/arm/kernel/signal.c
3  *
4  *  Copyright (C) 1995-2001 Russell King
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
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/errno.h>
17 #include <linux/signal.h>
18 #include <linux/wait.h>
19 #include <linux/ptrace.h>
20 #include <linux/stddef.h>
21 #include <linux/unistd.h>
22 #include <linux/personality.h>
23 #include <linux/tty.h>
24 #include <linux/elf.h>
25 
26 #include <asm/pgalloc.h>
27 #include <asm/ucontext.h>
28 #include <asm/uaccess.h>
29 
30 #include "ptrace.h"
31 
32 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
33 
34 /*
35  * For ARM syscalls, we encode the syscall number into the instruction.
36  */
37 #define SWI_SYS_SIGRETURN	(0xef000000|(__NR_sigreturn))
38 #define SWI_SYS_RT_SIGRETURN	(0xef000000|(__NR_rt_sigreturn))
39 
40 /*
41  * For Thumb syscalls, we pass the syscall number via r7.  We therefore
42  * need two 16-bit instructions.
43  */
44 #define SWI_THUMB_SIGRETURN	(0xdf00 << 16 | 0x2700 | (__NR_sigreturn - __NR_SYSCALL_BASE))
45 #define SWI_THUMB_RT_SIGRETURN	(0xdf00 << 16 | 0x2700 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
46 
47 static const unsigned long retcodes[4] = {
48 	SWI_SYS_SIGRETURN,	SWI_THUMB_SIGRETURN,
49 	SWI_SYS_RT_SIGRETURN,	SWI_THUMB_RT_SIGRETURN
50 };
51 
52 asmlinkage int do_signal(sigset_t *oldset, struct pt_regs * regs, int syscall);
53 
copy_siginfo_to_user(siginfo_t * to,siginfo_t * from)54 int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from)
55 {
56 	int err = -EFAULT;;
57 
58 	if (!access_ok (VERIFY_WRITE, to, sizeof(siginfo_t)))
59 		goto out;
60 
61 	if (from->si_code < 0)
62 		return __copy_to_user(to, from, sizeof(siginfo_t));
63 
64 	/* If you change siginfo_t structure, please be sure
65 	   this code is fixed accordingly.
66 	   It should never copy any pad contained in the structure
67 	   to avoid security leaks, but must copy the generic
68 	   3 ints plus the relevant union member.  */
69 	err = __put_user(from->si_signo, &to->si_signo);
70 	err |= __put_user(from->si_errno, &to->si_errno);
71 	err |= __put_user((short)from->si_code, &to->si_code);
72 	/* First 32bits of unions are always present.  */
73 	err |= __put_user(from->si_pid, &to->si_pid);
74 	switch (from->si_code >> 16) {
75 	case __SI_FAULT >> 16:
76 		break;
77 	case __SI_CHLD >> 16:
78 		err |= __put_user(from->si_utime, &to->si_utime);
79 		err |= __put_user(from->si_stime, &to->si_stime);
80 		err |= __put_user(from->si_status, &to->si_status);
81 	default:
82 		err |= __put_user(from->si_uid, &to->si_uid);
83 		break;
84 	/* case __SI_RT: This is not generated by the kernel as of now.  */
85 	}
86 out:
87 	return err;
88 }
89 
90 /*
91  * atomically swap in the new signal mask, and wait for a signal.
92  */
sys_sigsuspend(int restart,unsigned long oldmask,old_sigset_t mask,struct pt_regs * regs)93 asmlinkage int sys_sigsuspend(int restart, unsigned long oldmask, old_sigset_t mask, struct pt_regs *regs)
94 {
95 	sigset_t saveset;
96 
97 	mask &= _BLOCKABLE;
98 	spin_lock_irq(&current->sigmask_lock);
99 	saveset = current->blocked;
100 	siginitset(&current->blocked, mask);
101 	recalc_sigpending(current);
102 	spin_unlock_irq(&current->sigmask_lock);
103 	regs->ARM_r0 = -EINTR;
104 
105 	while (1) {
106 		current->state = TASK_INTERRUPTIBLE;
107 		schedule();
108 		if (do_signal(&saveset, regs, 0))
109 			return regs->ARM_r0;
110 	}
111 }
112 
113 asmlinkage int
sys_rt_sigsuspend(sigset_t * unewset,size_t sigsetsize,struct pt_regs * regs)114 sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize, struct pt_regs *regs)
115 {
116 	sigset_t saveset, newset;
117 
118 	/* XXX: Don't preclude handling different sized sigset_t's. */
119 	if (sigsetsize != sizeof(sigset_t))
120 		return -EINVAL;
121 
122 	if (copy_from_user(&newset, unewset, sizeof(newset)))
123 		return -EFAULT;
124 	sigdelsetmask(&newset, ~_BLOCKABLE);
125 
126 	spin_lock_irq(&current->sigmask_lock);
127 	saveset = current->blocked;
128 	current->blocked = newset;
129 	recalc_sigpending(current);
130 	spin_unlock_irq(&current->sigmask_lock);
131 	regs->ARM_r0 = -EINTR;
132 
133 	while (1) {
134 		current->state = TASK_INTERRUPTIBLE;
135 		schedule();
136 		if (do_signal(&saveset, regs, 0))
137 			return regs->ARM_r0;
138 	}
139 }
140 
141 asmlinkage int
sys_sigaction(int sig,const struct old_sigaction * act,struct old_sigaction * oact)142 sys_sigaction(int sig, const struct old_sigaction *act,
143 	      struct old_sigaction *oact)
144 {
145 	struct k_sigaction new_ka, old_ka;
146 	int ret;
147 
148 	if (act) {
149 		old_sigset_t mask;
150 		if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
151 		    __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
152 		    __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
153 			return -EFAULT;
154 		__get_user(new_ka.sa.sa_flags, &act->sa_flags);
155 		__get_user(mask, &act->sa_mask);
156 		siginitset(&new_ka.sa.sa_mask, mask);
157 	}
158 
159 	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
160 
161 	if (!ret && oact) {
162 		if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
163 		    __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
164 		    __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
165 			return -EFAULT;
166 		__put_user(old_ka.sa.sa_flags, &oact->sa_flags);
167 		__put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
168 	}
169 
170 	return ret;
171 }
172 
173 /*
174  * Do a signal return; undo the signal stack.
175  */
176 struct sigframe
177 {
178 	struct sigcontext sc;
179 	unsigned long extramask[_NSIG_WORDS-1];
180 	unsigned long retcode;
181 };
182 
183 struct rt_sigframe
184 {
185 	struct siginfo *pinfo;
186 	void *puc;
187 	struct siginfo info;
188 	struct ucontext uc;
189 	unsigned long retcode;
190 };
191 
192 static int
restore_sigcontext(struct pt_regs * regs,struct sigcontext * sc)193 restore_sigcontext(struct pt_regs *regs, struct sigcontext *sc)
194 {
195 	int err = 0;
196 
197 	__get_user_error(regs->ARM_r0, &sc->arm_r0, err);
198 	__get_user_error(regs->ARM_r1, &sc->arm_r1, err);
199 	__get_user_error(regs->ARM_r2, &sc->arm_r2, err);
200 	__get_user_error(regs->ARM_r3, &sc->arm_r3, err);
201 	__get_user_error(regs->ARM_r4, &sc->arm_r4, err);
202 	__get_user_error(regs->ARM_r5, &sc->arm_r5, err);
203 	__get_user_error(regs->ARM_r6, &sc->arm_r6, err);
204 	__get_user_error(regs->ARM_r7, &sc->arm_r7, err);
205 	__get_user_error(regs->ARM_r8, &sc->arm_r8, err);
206 	__get_user_error(regs->ARM_r9, &sc->arm_r9, err);
207 	__get_user_error(regs->ARM_r10, &sc->arm_r10, err);
208 	__get_user_error(regs->ARM_fp, &sc->arm_fp, err);
209 	__get_user_error(regs->ARM_ip, &sc->arm_ip, err);
210 	__get_user_error(regs->ARM_sp, &sc->arm_sp, err);
211 	__get_user_error(regs->ARM_lr, &sc->arm_lr, err);
212 	__get_user_error(regs->ARM_pc, &sc->arm_pc, err);
213 #ifdef CONFIG_CPU_32
214 	__get_user_error(regs->ARM_cpsr, &sc->arm_cpsr, err);
215 #endif
216 
217 	err |= !valid_user_regs(regs);
218 
219 	return err;
220 }
221 
sys_sigreturn(struct pt_regs * regs)222 asmlinkage int sys_sigreturn(struct pt_regs *regs)
223 {
224 	struct sigframe *frame;
225 	sigset_t set;
226 
227 	/*
228 	 * Since we stacked the signal on a 64-bit boundary,
229 	 * then 'sp' should be word aligned here.  If it's
230 	 * not, then the user is trying to mess with us.
231 	 */
232 	if (regs->ARM_sp & 7)
233 		goto badframe;
234 
235 	frame = (struct sigframe *)regs->ARM_sp;
236 
237 	if (verify_area(VERIFY_READ, frame, sizeof (*frame)))
238 		goto badframe;
239 	if (__get_user(set.sig[0], &frame->sc.oldmask)
240 	    || (_NSIG_WORDS > 1
241 	        && __copy_from_user(&set.sig[1], &frame->extramask,
242 				    sizeof(frame->extramask))))
243 		goto badframe;
244 
245 	sigdelsetmask(&set, ~_BLOCKABLE);
246 	spin_lock_irq(&current->sigmask_lock);
247 	current->blocked = set;
248 	recalc_sigpending(current);
249 	spin_unlock_irq(&current->sigmask_lock);
250 
251 	if (restore_sigcontext(regs, &frame->sc))
252 		goto badframe;
253 
254 	/* Send SIGTRAP if we're single-stepping */
255 	if (ptrace_cancel_bpt(current))
256 		send_sig(SIGTRAP, current, 1);
257 
258 	return regs->ARM_r0;
259 
260 badframe:
261 	force_sig(SIGSEGV, current);
262 	return 0;
263 }
264 
sys_rt_sigreturn(struct pt_regs * regs)265 asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
266 {
267 	struct rt_sigframe *frame;
268 	sigset_t set;
269 
270 	/*
271 	 * Since we stacked the signal on a 64-bit boundary,
272 	 * then 'sp' should be word aligned here.  If it's
273 	 * not, then the user is trying to mess with us.
274 	 */
275 	if (regs->ARM_sp & 7)
276 		goto badframe;
277 
278 	frame = (struct rt_sigframe *)regs->ARM_sp;
279 
280 	if (verify_area(VERIFY_READ, frame, sizeof (*frame)))
281 		goto badframe;
282 	if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
283 		goto badframe;
284 
285 	sigdelsetmask(&set, ~_BLOCKABLE);
286 	spin_lock_irq(&current->sigmask_lock);
287 	current->blocked = set;
288 	recalc_sigpending(current);
289 	spin_unlock_irq(&current->sigmask_lock);
290 
291 	if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
292 		goto badframe;
293 
294 	/* Send SIGTRAP if we're single-stepping */
295 	if (ptrace_cancel_bpt(current))
296 		send_sig(SIGTRAP, current, 1);
297 
298 	return regs->ARM_r0;
299 
300 badframe:
301 	force_sig(SIGSEGV, current);
302 	return 0;
303 }
304 
305 static int
setup_sigcontext(struct sigcontext * sc,struct pt_regs * regs,unsigned long mask)306 setup_sigcontext(struct sigcontext *sc, /*struct _fpstate *fpstate,*/
307 		 struct pt_regs *regs, unsigned long mask)
308 {
309 	int err = 0;
310 
311 	__put_user_error(regs->ARM_r0, &sc->arm_r0, err);
312 	__put_user_error(regs->ARM_r1, &sc->arm_r1, err);
313 	__put_user_error(regs->ARM_r2, &sc->arm_r2, err);
314 	__put_user_error(regs->ARM_r3, &sc->arm_r3, err);
315 	__put_user_error(regs->ARM_r4, &sc->arm_r4, err);
316 	__put_user_error(regs->ARM_r5, &sc->arm_r5, err);
317 	__put_user_error(regs->ARM_r6, &sc->arm_r6, err);
318 	__put_user_error(regs->ARM_r7, &sc->arm_r7, err);
319 	__put_user_error(regs->ARM_r8, &sc->arm_r8, err);
320 	__put_user_error(regs->ARM_r9, &sc->arm_r9, err);
321 	__put_user_error(regs->ARM_r10, &sc->arm_r10, err);
322 	__put_user_error(regs->ARM_fp, &sc->arm_fp, err);
323 	__put_user_error(regs->ARM_ip, &sc->arm_ip, err);
324 	__put_user_error(regs->ARM_sp, &sc->arm_sp, err);
325 	__put_user_error(regs->ARM_lr, &sc->arm_lr, err);
326 	__put_user_error(regs->ARM_pc, &sc->arm_pc, err);
327 #ifdef CONFIG_CPU_32
328 	__put_user_error(regs->ARM_cpsr, &sc->arm_cpsr, err);
329 #endif
330 
331 	__put_user_error(current->thread.trap_no, &sc->trap_no, err);
332 	__put_user_error(current->thread.error_code, &sc->error_code, err);
333 	__put_user_error(current->thread.address, &sc->fault_address, err);
334 	__put_user_error(mask, &sc->oldmask, err);
335 
336 	return err;
337 }
338 
339 static inline void *
get_sigframe(struct k_sigaction * ka,struct pt_regs * regs,int framesize)340 get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, int framesize)
341 {
342 	unsigned long sp = regs->ARM_sp;
343 
344 	/*
345 	 * This is the X/Open sanctioned signal stack switching.
346 	 */
347 	if ((ka->sa.sa_flags & SA_ONSTACK) && !sas_ss_flags(sp))
348 		sp = current->sas_ss_sp + current->sas_ss_size;
349 
350 	/*
351 	 * ATPCS B01 mandates 8-byte alignment
352 	 */
353 	return (void *)((sp - framesize) & ~7);
354 }
355 
356 static int
setup_return(struct pt_regs * regs,struct k_sigaction * ka,unsigned long * rc,void * frame,int usig)357 setup_return(struct pt_regs *regs, struct k_sigaction *ka,
358 	     unsigned long *rc, void *frame, int usig)
359 {
360 	unsigned long handler = (unsigned long)ka->sa.sa_handler;
361 	unsigned long retcode;
362 	int thumb = 0;
363 #ifdef CONFIG_CPU_32
364 	unsigned long cpsr = regs->ARM_cpsr;
365 
366 	/*
367 	 * Maybe we need to deliver a 32-bit signal to a 26-bit task.
368 	 */
369 	if (ka->sa.sa_flags & SA_THIRTYTWO)
370 		cpsr = (cpsr & ~MODE_MASK) | USR_MODE;
371 
372 #ifdef CONFIG_ARM_THUMB
373 	if (elf_hwcap & HWCAP_THUMB) {
374 		/*
375 		 * The LSB of the handler determines if we're going to
376 		 * be using THUMB or ARM mode for this signal handler.
377 		 */
378 		thumb = handler & 1;
379 
380 		if (thumb)
381 			cpsr |= T_BIT;
382 		else
383 			cpsr &= ~T_BIT;
384 	}
385 #endif
386 #endif
387 
388 	if (ka->sa.sa_flags & SA_RESTORER) {
389 		retcode = (unsigned long)ka->sa.sa_restorer;
390 	} else {
391 		unsigned int idx = thumb;
392 
393 		if (ka->sa.sa_flags & SA_SIGINFO)
394 			idx += 2;
395 
396 		if (__put_user(retcodes[idx], rc))
397 			return 1;
398 
399 		flush_icache_range((unsigned long)rc,
400 				   (unsigned long)(rc + 1));
401 
402 		retcode = ((unsigned long)rc) + thumb;
403 	}
404 
405 	regs->ARM_r0 = usig;
406 	regs->ARM_sp = (unsigned long)frame;
407 	regs->ARM_lr = retcode;
408 	regs->ARM_pc = handler;
409 
410 #ifdef CONFIG_CPU_32
411 	regs->ARM_cpsr = cpsr;
412 #endif
413 
414 	return 0;
415 }
416 
417 static int
setup_frame(int usig,struct k_sigaction * ka,sigset_t * set,struct pt_regs * regs)418 setup_frame(int usig, struct k_sigaction *ka, sigset_t *set, struct pt_regs *regs)
419 {
420 	struct sigframe *frame = get_sigframe(ka, regs, sizeof(*frame));
421 	int err = 0;
422 
423 	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
424 		return 1;
425 
426 	err |= setup_sigcontext(&frame->sc, /*&frame->fpstate,*/ regs, set->sig[0]);
427 
428 	if (_NSIG_WORDS > 1) {
429 		err |= __copy_to_user(frame->extramask, &set->sig[1],
430 				      sizeof(frame->extramask));
431 	}
432 
433 	if (err == 0)
434 		err = setup_return(regs, ka, &frame->retcode, frame, usig);
435 
436 	return err;
437 }
438 
439 static int
setup_rt_frame(int usig,struct k_sigaction * ka,siginfo_t * info,sigset_t * set,struct pt_regs * regs)440 setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
441 	       sigset_t *set, struct pt_regs *regs)
442 {
443 	struct rt_sigframe *frame = get_sigframe(ka, regs, sizeof(*frame));
444 	int err = 0;
445 
446 	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
447 		return 1;
448 
449 	__put_user_error(&frame->info, &frame->pinfo, err);
450 	__put_user_error(&frame->uc, &frame->puc, err);
451 	err |= copy_siginfo_to_user(&frame->info, info);
452 
453 	/* Clear all the bits of the ucontext we don't use.  */
454 	err |= __clear_user(&frame->uc, offsetof(struct ucontext, uc_mcontext));
455 
456 	err |= setup_sigcontext(&frame->uc.uc_mcontext, /*&frame->fpstate,*/
457 				regs, set->sig[0]);
458 	err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
459 
460 	if (err == 0)
461 		err = setup_return(regs, ka, &frame->retcode, frame, usig);
462 
463 	if (err == 0) {
464 		/*
465 		 * For realtime signals we must also set the second and third
466 		 * arguments for the signal handler.
467 		 *   -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
468 		 */
469 		regs->ARM_r1 = (unsigned long)&frame->info;
470 		regs->ARM_r2 = (unsigned long)&frame->uc;
471 	}
472 
473 	return err;
474 }
475 
476 /*
477  * OK, we're invoking a handler
478  */
479 static void
handle_signal(unsigned long sig,struct k_sigaction * ka,siginfo_t * info,sigset_t * oldset,struct pt_regs * regs)480 handle_signal(unsigned long sig, struct k_sigaction *ka,
481 	      siginfo_t *info, sigset_t *oldset, struct pt_regs * regs)
482 {
483 	struct task_struct *tsk = current;
484 	int usig = sig;
485 	int ret;
486 
487 	/*
488 	 * translate the signal
489 	 */
490 	if (usig < 32 && tsk->exec_domain && tsk->exec_domain->signal_invmap)
491 		usig = tsk->exec_domain->signal_invmap[usig];
492 
493 	/*
494 	 * Set up the stack frame
495 	 */
496 	if (ka->sa.sa_flags & SA_SIGINFO)
497 		ret = setup_rt_frame(usig, ka, info, oldset, regs);
498 	else
499 		ret = setup_frame(usig, ka, oldset, regs);
500 
501 	/*
502 	 * Check that the resulting registers are actually sane.
503 	 */
504 	ret |= !valid_user_regs(regs);
505 
506 	if (ret == 0) {
507 		if (ka->sa.sa_flags & SA_ONESHOT)
508 			ka->sa.sa_handler = SIG_DFL;
509 
510 		if (!(ka->sa.sa_flags & SA_NODEFER)) {
511 			spin_lock_irq(&tsk->sigmask_lock);
512 			sigorsets(&tsk->blocked, &tsk->blocked,
513 				  &ka->sa.sa_mask);
514 			sigaddset(&tsk->blocked, sig);
515 			recalc_sigpending(tsk);
516 			spin_unlock_irq(&tsk->sigmask_lock);
517 		}
518 		return;
519 	}
520 
521 	if (sig == SIGSEGV)
522 		ka->sa.sa_handler = SIG_DFL;
523 	force_sig(SIGSEGV, tsk);
524 }
525 
526 /*
527  * Note that 'init' is a special process: it doesn't get signals it doesn't
528  * want to handle. Thus you cannot kill init even with a SIGKILL even by
529  * mistake.
530  *
531  * Note that we go through the signals twice: once to check the signals that
532  * the kernel can handle, and then we build all the user-level signal handling
533  * stack-frames in one go after that.
534  */
do_signal(sigset_t * oldset,struct pt_regs * regs,int syscall)535 asmlinkage int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)
536 {
537 	struct k_sigaction *ka;
538 	siginfo_t info;
539 	int single_stepping;
540 
541 	/*
542 	 * We want the common case to go fast, which
543 	 * is why we may in certain cases get here from
544 	 * kernel mode. Just return without doing anything
545 	 * if so.
546 	 */
547 	if (!user_mode(regs))
548 		return 0;
549 
550 	if (!oldset)
551 		oldset = &current->blocked;
552 
553 	single_stepping = ptrace_cancel_bpt(current);
554 
555 	for (;;) {
556 		unsigned long signr;
557 
558 		spin_lock_irq (&current->sigmask_lock);
559 		signr = dequeue_signal(&current->blocked, &info);
560 		spin_unlock_irq (&current->sigmask_lock);
561 
562 		if (!signr)
563 			break;
564 
565 		if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) {
566 			/* Let the debugger run.  */
567 			current->exit_code = signr;
568 			current->state = TASK_STOPPED;
569 			notify_parent(current, SIGCHLD);
570 			schedule();
571 			single_stepping |= ptrace_cancel_bpt(current);
572 
573 			/* We're back.  Did the debugger cancel the sig?  */
574 			if (!(signr = current->exit_code))
575 				continue;
576 			current->exit_code = 0;
577 
578 			/* The debugger continued.  Ignore SIGSTOP.  */
579 			if (signr == SIGSTOP)
580 				continue;
581 
582 			/* Update the siginfo structure.  Is this good? */
583 			if (signr != info.si_signo) {
584 				info.si_signo = signr;
585 				info.si_errno = 0;
586 				info.si_code = SI_USER;
587 				info.si_pid = current->p_pptr->pid;
588 				info.si_uid = current->p_pptr->uid;
589 			}
590 
591 			/* If the (new) signal is now blocked, requeue it.  */
592 			if (sigismember(&current->blocked, signr)) {
593 				send_sig_info(signr, &info, current);
594 				continue;
595 			}
596 		}
597 
598 		ka = &current->sig->action[signr-1];
599 		if (ka->sa.sa_handler == SIG_IGN) {
600 			if (signr != SIGCHLD)
601 				continue;
602 			/* Check for SIGCHLD: it's special.  */
603 			while (sys_wait4(-1, NULL, WNOHANG, NULL) > 0)
604 				/* nothing */;
605 			continue;
606 		}
607 
608 		if (ka->sa.sa_handler == SIG_DFL) {
609 			int exit_code = signr;
610 
611 			/* Init gets no signals it doesn't want.  */
612 			if (current->pid == 1)
613 				continue;
614 
615 			switch (signr) {
616 			case SIGCONT: case SIGCHLD: case SIGWINCH: case SIGURG:
617 				continue;
618 
619 			case SIGTSTP: case SIGTTIN: case SIGTTOU:
620 				if (is_orphaned_pgrp(current->pgrp))
621 					continue;
622 				/* FALLTHRU */
623 
624 			case SIGSTOP: {
625 				struct signal_struct *sig;
626 				current->state = TASK_STOPPED;
627 				current->exit_code = signr;
628 				sig = current->p_pptr->sig;
629 				if (sig && !(sig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP))
630 					notify_parent(current, SIGCHLD);
631 				schedule();
632 				single_stepping |= ptrace_cancel_bpt(current);
633 				continue;
634 			}
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 		/* Are we from a system call? */
653 		if (syscall) {
654 			switch (regs->ARM_r0) {
655 			case -ERESTARTNOHAND:
656 				regs->ARM_r0 = -EINTR;
657 				break;
658 
659 			case -ERESTARTSYS:
660 				if (!(ka->sa.sa_flags & SA_RESTART)) {
661 					regs->ARM_r0 = -EINTR;
662 					break;
663 				}
664 				/* fallthrough */
665 			case -ERESTARTNOINTR:
666 				regs->ARM_r0 = regs->ARM_ORIG_r0;
667 				regs->ARM_pc -= 4;
668 			}
669 		}
670 		/* Whee!  Actually deliver the signal.  */
671 		handle_signal(signr, ka, &info, oldset, regs);
672 		if (single_stepping)
673 		    	ptrace_set_bpt(current);
674 		return 1;
675 	}
676 
677 	if (syscall &&
678 	    (regs->ARM_r0 == -ERESTARTNOHAND ||
679 	     regs->ARM_r0 == -ERESTARTSYS ||
680 	     regs->ARM_r0 == -ERESTARTNOINTR)) {
681 		regs->ARM_r0 = regs->ARM_ORIG_r0;
682 		regs->ARM_pc -= 4;
683 	}
684 	if (single_stepping)
685 		ptrace_set_bpt(current);
686 	return 0;
687 }
688