1 /*
2  * signal32.c: Support 32bit signal syscalls.
3  *
4  * Copyright (C) 2001 IBM
5  * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6  * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
7  *
8  * These routines maintain argument size conversion between 32bit and 64bit
9  * environment.
10  *
11  *      This program is free software; you can redistribute it and/or
12  *      modify it under the terms of the GNU General Public License
13  *      as published by the Free Software Foundation; either version
14  *      2 of the License, or (at your option) any later version.
15  */
16 
17 #include <asm/ptrace.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/fs.h>
21 #include <linux/mm.h>
22 #include <linux/file.h>
23 #include <linux/signal.h>
24 #include <linux/utime.h>
25 #include <linux/resource.h>
26 #include <linux/times.h>
27 #include <linux/utsname.h>
28 #include <linux/timex.h>
29 #include <linux/smp.h>
30 #include <linux/smp_lock.h>
31 #include <linux/sem.h>
32 #include <linux/msg.h>
33 #include <linux/shm.h>
34 #include <linux/slab.h>
35 #include <linux/uio.h>
36 #include <linux/nfs_fs.h>
37 #include <linux/smb_fs.h>
38 #include <linux/smb_mount.h>
39 #include <linux/ncp_fs.h>
40 #include <linux/quota.h>
41 #include <linux/module.h>
42 #include <linux/poll.h>
43 #include <linux/personality.h>
44 #include <linux/stat.h>
45 #include <linux/filter.h>
46 #include <asm/types.h>
47 #include <asm/ipc.h>
48 #include <asm/uaccess.h>
49 #include <linux/elf.h>
50 #include <asm/ppc32.h>
51 #include <asm/unistd.h>
52 #include <asm/ucontext.h>
53 
54 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
55 /*
56  * These are the flags in the MSR that the user is allowed to change
57  * by modifying the saved value of the MSR on the stack.  SE and BE
58  * should not be in this list since gdb may want to change these.  I.e,
59  * you should be able to step out of a signal handler to see what
60  * instruction executes next after the signal handler completes.
61  * Alternately, if you stepped into a signal handler, you should be
62  * able to continue 'til the next breakpoint from within the signal
63  * handler, even if the handler returns.
64  */
65 #define MSR_USERCHANGE	(MSR_FE0 | MSR_FE1)
66 
67 struct timespec32 {
68 	s32    tv_sec;
69 	s32    tv_nsec;
70 };
71 
72 struct sigregs32 {
73 	/*
74 	 * the gp_regs array is 32 bit representation of the pt_regs
75 	 * structure that was stored on the kernle stack during the
76 	 * system call that was interrupted for the signal.
77 	 *
78 	 * Note that the entire pt_regs regs structure will fit in
79 	 * the gp_regs structure because the ELF_NREG value is 48 for
80 	 * PPC and the pt_regs structure contains 44 registers
81 	 */
82 	elf_gregset_t32	gp_regs;
83 	double		fp_regs[ELF_NFPREG];
84 	unsigned int	tramp[2];
85 	/*
86 	 * Programs using the rs6000/xcoff abi can save up to 19 gp
87 	 * regs and 18 fp regs below sp before decrementing it.
88 	 */
89 	int		abigap[56];
90 };
91 
92 
93 struct rt_sigframe_32 {
94 	/*
95 	 * Unused space at start of frame to allow for storing of
96 	 * stack pointers
97 	 */
98 	unsigned long _unused;
99 	/*
100 	 * This is a 32 bit pointer in user address space
101 	 *     it is a pointer to the siginfo stucture in the rt stack frame
102 	 */
103 	u32 pinfo;
104 	/*
105 	 * This is a 32 bit pointer in user address space
106 	 * it is a pointer to the user context in the rt stack frame
107 	 */
108 	u32 puc;
109 	struct siginfo32  info;
110 	struct ucontext32 uc;
111 };
112 
113 
114 
115 
116 
117 extern asmlinkage long sys_wait4(pid_t pid,unsigned int * stat_addr, int options, struct rusage * ru);
118 
119 
120 /****************************************************************************/
121 /*  Start of nonRT signal support                                           */
122 /*                                                                          */
123 /*     sigset_t is 32 bits for non-rt signals                               */
124 /*                                                                          */
125 /*  System Calls                                                            */
126 /*       sigaction                sys32_sigaction                           */
127 /*       sigpending               sys32_sigpending                          */
128 /*       sigprocmask              sys32_sigprocmask                         */
129 /*       sigreturn                sys32_sigreturn                           */
130 /*                                                                          */
131 /*  Note sigsuspend has no special 32 bit routine - uses the 64 bit routine */
132 /*                                                                          */
133 /*  Other routines                                                          */
134 /*        setup_frame32                                                     */
135 /*                                                                          */
136 /****************************************************************************/
137 
138 
sys32_sigaction(int sig,struct old_sigaction32 * act,struct old_sigaction32 * oact)139 asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 *act, struct old_sigaction32 *oact)
140 {
141 	struct k_sigaction new_ka, old_ka;
142 	int ret;
143 	u32 handler, restorer;
144 
145 	if (sig < 0)
146 		sig = -sig;
147 
148 	if (act) {
149 		old_sigset_t32 mask;
150 
151 		ret = get_user(handler, &act->sa_handler);
152 		ret |= __get_user(restorer, &act->sa_restorer);
153 		ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
154 		ret |= __get_user(mask, &act->sa_mask);
155 		if (ret)
156 			return ret;
157 		new_ka.sa.sa_handler = (__sighandler_t)(long) handler;
158 		new_ka.sa.sa_restorer = (void (*)(void))(long) restorer;
159 		siginitset(&new_ka.sa.sa_mask, mask);
160 	}
161 
162 	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
163 
164 	if (!ret && oact)
165 	{
166 		ret = put_user((long)old_ka.sa.sa_handler, &oact->sa_handler);
167 		ret |= __put_user((long)old_ka.sa.sa_restorer, &oact->sa_restorer);
168 		ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
169 		ret |= __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
170 	}
171 
172 	return ret;
173 }
174 
175 
176 
177 
178 extern asmlinkage long sys_sigpending(old_sigset_t *set);
179 
sys32_sigpending(old_sigset_t32 * set)180 asmlinkage long sys32_sigpending(old_sigset_t32 *set)
181 {
182 	old_sigset_t s;
183 	int ret;
184 	mm_segment_t old_fs = get_fs();
185 
186 	set_fs (KERNEL_DS);
187 	ret = sys_sigpending(&s);
188 	set_fs (old_fs);
189 	if (put_user (s, set)) return -EFAULT;
190 
191 	return ret;
192 }
193 
194 
195 
196 
197 extern asmlinkage long sys_sigprocmask(int how, old_sigset_t *set, old_sigset_t *oset);
198 
199 /* Note: it is necessary to treat how as an unsigned int,
200  * with the corresponding cast to a signed int to insure that the
201  * proper conversion (sign extension) between the register representation of a signed int (msr in 32-bit mode)
202  * and the register representation of a signed int (msr in 64-bit mode) is performed.
203  */
sys32_sigprocmask(u32 how,old_sigset_t32 * set,old_sigset_t32 * oset)204 asmlinkage long sys32_sigprocmask(u32 how, old_sigset_t32 *set, old_sigset_t32 *oset)
205 {
206 	old_sigset_t s;
207 	int ret;
208 	mm_segment_t old_fs = get_fs();
209 
210 	if (set && get_user(s, set))
211 		return -EFAULT;
212 	set_fs (KERNEL_DS);
213 	ret = sys_sigprocmask((int)how, set ? &s : NULL, oset ? &s : NULL);
214 	set_fs (old_fs);
215 
216 	if (ret)
217 		return ret;
218 	if (oset && put_user (s, oset))
219 		return -EFAULT;
220 	return 0;
221 }
222 
223 
224 
225 /*
226  * When we have signals to deliver, we set up on the
227  * user stack, going down from the original stack pointer:
228  *	a sigregs struct
229  *	one or more sigcontext structs
230  *	a gap of __SIGNAL_FRAMESIZE32 bytes
231  *
232  * Each of these things must be a multiple of 16 bytes in size.
233  *
234 */
235 
236 
237 /*
238  * Do a signal return; undo the signal stack.
239  */
sys32_sigreturn(unsigned long r3,unsigned long r4,unsigned long r5,unsigned long r6,unsigned long r7,unsigned long r8,struct pt_regs * regs)240 long sys32_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5,
241 		     unsigned long r6, unsigned long r7, unsigned long r8,
242 		     struct pt_regs *regs)
243 {
244 	struct sigcontext32 *sc, sigctx;
245 	struct sigregs32 *sr;
246 	elf_gregset_t32 saved_regs;  /* an array of ELF_NGREG unsigned ints (32 bits) */
247 	sigset_t set;
248 	int i;
249 
250 	sc = (struct sigcontext32 *)(regs->gpr[1] + __SIGNAL_FRAMESIZE32);
251 	if (copy_from_user(&sigctx, sc, sizeof(sigctx)))
252 		goto badframe;
253 
254 	/*
255 	 * Note that PPC32 puts the upper 32 bits of the sigmask in the
256 	 * unused part of the signal stackframe
257 	 */
258 	set.sig[0] = sigctx.oldmask + ((long)(sigctx._unused[3])<< 32);
259 	sigdelsetmask(&set, ~_BLOCKABLE);
260 	spin_lock_irq(&current->sigmask_lock);
261 	current->blocked = set;
262 	recalc_sigpending(current);
263 	spin_unlock_irq(&current->sigmask_lock);
264 
265 	sr = (struct sigregs32*)(u64)sigctx.regs;
266 	/*
267 	 * Copy the 32 bit register values off the user stack
268 	 * into the 32 bit register area
269 	 */
270 	if (copy_from_user(saved_regs, &sr->gp_regs,sizeof(sr->gp_regs)))
271 		goto badframe;
272 
273 	/*
274 	 * The saved reg structure in the frame is an elf_grepset_t32,
275 	 * it is a 32 bit register save of the registers in the
276 	 * pt_regs structure that was stored on the kernel stack
277 	 * during the system call when the system call was interrupted
278 	 * for the signal. Only 32 bits are saved because the
279 	 * sigcontext contains a pointer to the regs and the sig
280 	 * context address is passed as a pointer to the signal
281 	 * handler.
282 	 *
283 	 * The entries in the elf_grepset have the same index as the
284 	 * elements in the pt_regs structure.
285 	 */
286 	for (i = 0; i < 32; i++)
287 		regs->gpr[i] = (u64)(saved_regs[i]) & 0xFFFFFFFF;
288 
289 	/*
290 	 *  restore the non gpr registers
291 	 */
292 	regs->nip = (u64)(saved_regs[PT_NIP]) & 0xFFFFFFFF;
293 	regs->orig_gpr3 = (u64)(saved_regs[PT_ORIG_R3]) & 0xFFFFFFFF;
294 	regs->ctr = (u64)(saved_regs[PT_CTR]) & 0xFFFFFFFF;
295 	regs->link = (u64)(saved_regs[PT_LNK]) & 0xFFFFFFFF;
296 	regs->xer = (u64)(saved_regs[PT_XER]) & 0xFFFFFFFF;
297 	regs->ccr = (u64)(saved_regs[PT_CCR]) & 0xFFFFFFFF;
298 	/* regs->softe is left unchanged (like the MSR.EE bit) */
299 	regs->result = (u64)(saved_regs[PT_RESULT]) & 0xFFFFFFFF;
300 
301 	/* force the process to reload the FP registers from
302 	   current->thread when it next does FP instructions */
303 	regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1);
304 #ifndef CONFIG_SMP
305 	if (last_task_used_math == current)
306 		last_task_used_math = NULL;
307 #endif
308 	if (copy_from_user(current->thread.fpr, &sr->fp_regs,
309 			   sizeof(sr->fp_regs)))
310 		goto badframe;
311 
312 	return regs->result;
313 
314 badframe:
315 	force_sig(SIGSEGV, current);
316 	return 0;
317 }
318 
319 /*
320  * Set up a signal frame.
321  */
322 static void
setup_frame32(struct pt_regs * regs,int sig,struct k_sigaction * ka,struct sigregs32 * frame,unsigned int newsp)323 setup_frame32(struct pt_regs *regs, int sig, struct k_sigaction *ka,
324 	      struct sigregs32 *frame, unsigned int newsp)
325 {
326 	int i;
327 
328 	if (verify_area(VERIFY_WRITE, frame, sizeof(*frame)))
329 		goto badframe;
330 	if (regs->msr & MSR_FP)
331 		giveup_fpu(current);
332 
333 	/*
334 	 * Copy the register contents for the pt_regs structure on the
335 	 *   kernel stack to the elf_gregset_t32 structure on the user
336 	 *   stack. This is a copy of 64 bit register values to 32 bit
337 	 *   register values. The high order 32 bits of the 64 bit
338 	 *   registers are not needed since a 32 bit application is
339 	 *   running and the saved registers are the contents of the
340 	 *   user registers at the time of a system call.
341 	 *
342 	 * The values saved on the user stack will be restored into
343 	 *  the registers during the signal return processing
344 	 *
345 	 * Note the +1 is needed in order to get the lower 32 bits
346 	 * of 64 bit register
347 	 */
348 	for (i = 0; i < sizeof(struct pt_regs32)/sizeof(u32); i++) {
349 		if (__copy_to_user(&frame->gp_regs[i], (u32*)(&regs->gpr[i])+1, sizeof(u32)))
350 			goto badframe;
351 	}
352 
353 	/*
354 	 * Now copy the floating point registers onto the user stack
355 	 *
356 	 * Also set up so on the completion of the signal handler, the
357 	 * sys_sigreturn will get control to reset the stack
358 	 */
359 	if (__copy_to_user(&frame->fp_regs, current->thread.fpr,
360 			   ELF_NFPREG * sizeof(double))
361 	    /* li r0, __NR_sigreturn */
362 	    || __put_user(0x38000000U + __NR_sigreturn, &frame->tramp[0])
363 	    /* sc */
364 	    || __put_user(0x44000002U, &frame->tramp[1]))
365 		goto badframe;
366 
367 	flush_icache_range((unsigned long) &frame->tramp[0],
368 			   (unsigned long) &frame->tramp[2]);
369 	current->thread.fpscr = 0;      /* turn off all fp exceptions */
370 
371 	/*
372 	 * first parameter to the signal handler is the signal number
373 	 *  - the value is in gpr3
374 	 * second parameter to the signal handler is the sigcontext
375 	 *   - set the value into gpr4
376 	 */
377 	regs->gpr[3] = sig;
378 	regs->gpr[4] = newsp;
379 	regs->nip = (u64)ka->sa.sa_handler & 0xFFFFFFFF;
380 	regs->link = (unsigned long) frame->tramp;
381 
382 	newsp -= __SIGNAL_FRAMESIZE32;
383 	if (put_user(regs->gpr[1], (u32*)(u64)newsp))
384 		goto badframe;
385 	regs->gpr[1] = newsp;
386 
387 	return;
388 
389  badframe:
390 #if DEBUG_SIG
391 	printk("badframe in setup_frame32, regs=%p frame=%p newsp=%lx\n",
392 	       regs, frame, newsp);
393 #endif
394 	if (sig == SIGSEGV)
395 		ka->sa.sa_handler = SIG_DFL;
396 	force_sig(SIGSEGV, current);
397 }
398 
399 
400 /*
401  *  Start of RT signal support
402  *
403  *     sigset_t is 64 bits for rt signals
404  *
405  *  System Calls
406  *       sigaction                sys32_rt_sigaction
407  *       sigpending               sys32_rt_sigpending
408  *       sigprocmask              sys32_rt_sigprocmask
409  *       sigreturn                sys32_rt_sigreturn
410  *       sigtimedwait             sys32_rt_sigtimedwait
411  *       sigqueueinfo             sys32_rt_sigqueueinfo
412  *       sigsuspend               sys32_rt_sigsuspend
413  *
414  *  Other routines
415  *        setup_rt_frame32
416  *        copy_siginfo_to_user32
417  *        siginfo32to64
418  */
419 
420 
421 /*
422  * This code executes after the rt signal handler in 32 bit mode has
423  * completed and returned
424  */
sys32_rt_sigreturn(unsigned long r3,unsigned long r4,unsigned long r5,unsigned long r6,unsigned long r7,unsigned long r8,struct pt_regs * regs)425 long sys32_rt_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5,
426 			unsigned long r6, unsigned long r7, unsigned long r8,
427 			struct pt_regs * regs)
428 {
429 	struct rt_sigframe_32 *rt_stack_frame;
430 	struct sigcontext32 sigctx;
431 	struct sigregs32 *signalregs;
432 
433 	int i;
434 	elf_gregset_t32 saved_regs;   /* an array of 32 bit register values */
435 	sigset_t signal_set;
436 	stack_t stack;
437 
438 	/* Adjust the inputted reg1 to point to the rt signal frame */
439 	rt_stack_frame = (struct rt_sigframe_32 *)(regs->gpr[1] + __SIGNAL_FRAMESIZE32);
440 	/* Copy the information from the user stack  */
441 	if (copy_from_user(&sigctx, &rt_stack_frame->uc.uc_mcontext,sizeof(sigctx))
442 	    || copy_from_user(&signal_set, &rt_stack_frame->uc.uc_sigmask,sizeof(signal_set))
443 	    || copy_from_user(&stack,&rt_stack_frame->uc.uc_stack,sizeof(stack)))
444 		/* unable to copy from user storage */
445 		goto badframe;
446 
447 	/*
448 	 * Unblock the signal that was processed
449 	 *   After a signal handler runs -
450 	 *     if the signal is blockable - the signal will be unblocked
451 	 *       ( sigkill and sigstop are not blockable)
452 	 */
453 	sigdelsetmask(&signal_set, ~_BLOCKABLE);
454 	/* update the current based on the sigmask found in the rt_stackframe */
455 	spin_lock_irq(&current->sigmask_lock);
456 	current->blocked = signal_set;
457 	recalc_sigpending(current);
458 	spin_unlock_irq(&current->sigmask_lock);
459 
460 	signalregs = (struct sigregs32 *) (u64)sigctx.regs;
461 
462 	if (copy_from_user(saved_regs, &signalregs->gp_regs,
463 			   sizeof(signalregs->gp_regs)))
464 		goto badframe;
465 
466 	/*
467 	 * The saved reg structure in the frame is an elf_grepset_t32,
468 	 * it is a 32 bit register save of the registers in the
469 	 * pt_regs structure that was stored on the kernel stack
470 	 * during the system call when the system call was interrupted
471 	 * for the signal. Only 32 bits are saved because the
472 	 * sigcontext contains a pointer to the regs and the sig
473 	 * context address is passed as a pointer to the signal handler
474 	 *
475 	 * The entries in the elf_grepset have the same index as
476 	 * the elements in the pt_regs structure.
477 	 */
478 	for (i = 0; i < 32; i++)
479 		regs->gpr[i] = (u64)(saved_regs[i]) & 0xFFFFFFFF;
480 	/*
481 	 * restore the non gpr registers
482 	 */
483 	regs->nip = (u64)(saved_regs[PT_NIP]) & 0xFFFFFFFF;
484 	regs->orig_gpr3 = (u64)(saved_regs[PT_ORIG_R3]) & 0xFFFFFFFF;
485 	regs->ctr = (u64)(saved_regs[PT_CTR]) & 0xFFFFFFFF;
486 	regs->link = (u64)(saved_regs[PT_LNK]) & 0xFFFFFFFF;
487 	regs->xer = (u64)(saved_regs[PT_XER]) & 0xFFFFFFFF;
488 	regs->ccr = (u64)(saved_regs[PT_CCR]) & 0xFFFFFFFF;
489 	/* regs->softe is left unchanged (like MSR.EE) */
490 	regs->result = (u64)(saved_regs[PT_RESULT]) & 0xFFFFFFFF;
491 
492 	/* force the process to reload the FP registers from
493 	   current->thread when it next does FP instructions */
494 	regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1);
495 #ifndef CONFIG_SMP
496 	if (last_task_used_math == current)
497 		last_task_used_math = NULL;
498 #endif
499 	if (copy_from_user(current->thread.fpr, &signalregs->fp_regs,
500 			   sizeof(signalregs->fp_regs)))
501 		goto badframe;
502 
503 	return regs->result;
504 
505  badframe:
506 	force_sig(SIGSEGV, current);
507 	return 0;
508 }
509 
510 
511 
sys32_rt_sigaction(int sig,const struct sigaction32 * act,struct sigaction32 * oact,size_t sigsetsize)512 asmlinkage long sys32_rt_sigaction(int sig, const struct sigaction32 *act, struct sigaction32 *oact, size_t sigsetsize)
513 {
514 	struct k_sigaction new_ka, old_ka;
515 	int ret;
516 	sigset32_t set32;
517 	u32 handler;
518 
519 	/* XXX: Don't preclude handling different sized sigset_t's.  */
520 	if (sigsetsize != sizeof(sigset32_t))
521 		return -EINVAL;
522 
523 	if (act) {
524 		ret = get_user(handler, &act->sa_handler);
525 		ret |= __copy_from_user(&set32, &act->sa_mask,
526 					sizeof(sigset32_t));
527 		switch (_NSIG_WORDS) {
528 		case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]
529 				| (((long)set32.sig[7]) << 32);
530 		case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]
531 				| (((long)set32.sig[5]) << 32);
532 		case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]
533 				| (((long)set32.sig[3]) << 32);
534 		case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]
535 				| (((long)set32.sig[1]) << 32);
536 		}
537 
538 		ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
539 
540 		if (ret)
541 			return -EFAULT;
542 		new_ka.sa.sa_handler = (__sighandler_t)(long) handler;
543 	}
544 
545 	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
546 
547 	if (!ret && oact) {
548 		switch (_NSIG_WORDS) {
549 		case 4:
550 			set32.sig[7] = (old_ka.sa.sa_mask.sig[3] >> 32);
551 			set32.sig[6] = old_ka.sa.sa_mask.sig[3];
552 		case 3:
553 			set32.sig[5] = (old_ka.sa.sa_mask.sig[2] >> 32);
554 			set32.sig[4] = old_ka.sa.sa_mask.sig[2];
555 		case 2:
556 			set32.sig[3] = (old_ka.sa.sa_mask.sig[1] >> 32);
557 			set32.sig[2] = old_ka.sa.sa_mask.sig[1];
558 		case 1:
559 			set32.sig[1] = (old_ka.sa.sa_mask.sig[0] >> 32);
560 			set32.sig[0] = old_ka.sa.sa_mask.sig[0];
561 		}
562 		ret = put_user((long)old_ka.sa.sa_handler, &oact->sa_handler);
563 		ret |= __copy_to_user(&oact->sa_mask, &set32,
564 				      sizeof(sigset32_t));
565 		ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
566 	}
567 
568   	return ret;
569 }
570 
571 
572 extern asmlinkage long sys_rt_sigprocmask(int how, sigset_t *set, sigset_t *oset,
573 					  size_t sigsetsize);
574 
575 /*
576  * Note: it is necessary to treat how as an unsigned int, with the
577  * corresponding cast to a signed int to insure that the proper
578  * conversion (sign extension) between the register representation
579  * of a signed int (msr in 32-bit mode) and the register representation
580  * of a signed int (msr in 64-bit mode) is performed.
581  */
sys32_rt_sigprocmask(u32 how,sigset32_t * set,sigset32_t * oset,size_t sigsetsize)582 asmlinkage long sys32_rt_sigprocmask(u32 how, sigset32_t *set, sigset32_t *oset, size_t sigsetsize)
583 {
584 	sigset_t s;
585 	sigset32_t s32;
586 	int ret;
587 	mm_segment_t old_fs = get_fs();
588 
589 	if (set) {
590 		if (copy_from_user (&s32, set, sizeof(sigset32_t)))
591 			return -EFAULT;
592 
593 		switch (_NSIG_WORDS) {
594 		case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
595 		case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
596 		case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
597 		case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
598 		}
599 	}
600 
601 	set_fs (KERNEL_DS);
602 	ret = sys_rt_sigprocmask((int)how, set ? &s : NULL, oset ? &s : NULL,
603 				 sigsetsize);
604 	set_fs (old_fs);
605 	if (ret)
606 		return ret;
607 	if (oset) {
608 		switch (_NSIG_WORDS) {
609 		case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
610 		case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
611 		case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
612 		case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
613 		}
614 		if (copy_to_user (oset, &s32, sizeof(sigset32_t)))
615 			return -EFAULT;
616 	}
617 	return 0;
618 }
619 
620 
621 extern asmlinkage long sys_rt_sigpending(sigset_t *set, size_t sigsetsize);
622 
623 
624 
sys32_rt_sigpending(sigset32_t * set,__kernel_size_t32 sigsetsize)625 asmlinkage long sys32_rt_sigpending(sigset32_t *set,   __kernel_size_t32 sigsetsize)
626 {
627 
628 	sigset_t s;
629 	sigset32_t s32;
630 	int ret;
631 	mm_segment_t old_fs = get_fs();
632 
633 	set_fs (KERNEL_DS);
634 	ret = sys_rt_sigpending(&s, sigsetsize);
635 	set_fs (old_fs);
636 	if (!ret) {
637 		switch (_NSIG_WORDS) {
638 		case 4: s32.sig[7] = (s.sig[3] >> 32); s32.sig[6] = s.sig[3];
639 		case 3: s32.sig[5] = (s.sig[2] >> 32); s32.sig[4] = s.sig[2];
640 		case 2: s32.sig[3] = (s.sig[1] >> 32); s32.sig[2] = s.sig[1];
641 		case 1: s32.sig[1] = (s.sig[0] >> 32); s32.sig[0] = s.sig[0];
642 		}
643 		if (copy_to_user (set, &s32, sizeof(sigset32_t)))
644 			return -EFAULT;
645 	}
646 	return ret;
647 }
648 
649 
650 
651 siginfo_t32 *
siginfo64to32(siginfo_t32 * d,siginfo_t * s)652 siginfo64to32(siginfo_t32 *d, siginfo_t *s)
653 {
654 	memset (d, 0, sizeof(siginfo_t32));
655 	d->si_signo = s->si_signo;
656 	d->si_errno = s->si_errno;
657 	d->si_code = (short)s->si_code;
658 	if (s->si_signo >= SIGRTMIN) {
659 		d->si_pid = s->si_pid;
660 		d->si_uid = s->si_uid;
661 
662 		d->si_int = s->si_int;
663 	} else switch (s->si_signo) {
664 	/* XXX: What about POSIX1.b timers */
665 	case SIGCHLD:
666 		d->si_pid = s->si_pid;
667 		d->si_status = s->si_status;
668 		d->si_utime = s->si_utime;
669 		d->si_stime = s->si_stime;
670 		break;
671 	case SIGSEGV:
672 	case SIGBUS:
673 	case SIGFPE:
674 	case SIGILL:
675 		d->si_addr = (unsigned int)(u64)(s->si_addr);
676         break;
677 	case SIGPOLL:
678 		d->si_band = s->si_band;
679 		d->si_fd = s->si_fd;
680 		break;
681 	default:
682 		d->si_pid = s->si_pid;
683 		d->si_uid = s->si_uid;
684 		break;
685 	}
686 	return d;
687 }
688 
689 extern asmlinkage long
690 sys_rt_sigtimedwait(const sigset_t *uthese, siginfo_t *uinfo,
691 		    const struct timespec *uts, size_t sigsetsize);
692 
693 asmlinkage long
sys32_rt_sigtimedwait(sigset32_t * uthese,siginfo_t32 * uinfo,struct timespec32 * uts,__kernel_size_t32 sigsetsize)694 sys32_rt_sigtimedwait(sigset32_t *uthese, siginfo_t32 *uinfo,
695 		      struct timespec32 *uts, __kernel_size_t32 sigsetsize)
696 {
697 	sigset_t s;
698 	sigset32_t s32;
699 	struct timespec t;
700 	int ret;
701 	mm_segment_t old_fs = get_fs();
702 	siginfo_t info;
703 	siginfo_t32 info32;
704 
705 	if (copy_from_user (&s32, uthese, sizeof(sigset32_t)))
706 		return -EFAULT;
707 	switch (_NSIG_WORDS) {
708 	case 4: s.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
709 	case 3: s.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
710 	case 2: s.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
711 	case 1: s.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
712 	}
713 	if (uts) {
714 		ret = get_user (t.tv_sec, &uts->tv_sec);
715 		ret |= __get_user (t.tv_nsec, &uts->tv_nsec);
716 		if (ret)
717 			return -EFAULT;
718 	}
719 	set_fs (KERNEL_DS);
720 	if (uts)
721 		ret = sys_rt_sigtimedwait(&s, &info, &t, sigsetsize);
722 	else
723 		ret = sys_rt_sigtimedwait(&s, &info, (struct timespec *)uts,
724 				sigsetsize);
725 	set_fs (old_fs);
726 	if (ret >= 0 && uinfo) {
727 		if (copy_to_user (uinfo, siginfo64to32(&info32, &info),
728 				  sizeof(siginfo_t32)))
729 			return -EFAULT;
730 	}
731 	return ret;
732 }
733 
734 
735 
736 siginfo_t *
siginfo32to64(siginfo_t * d,siginfo_t32 * s)737 siginfo32to64(siginfo_t *d, siginfo_t32 *s)
738 {
739 	d->si_signo = s->si_signo;
740 	d->si_errno = s->si_errno;
741 	d->si_code = s->si_code;
742 	if (s->si_signo >= SIGRTMIN) {
743 		d->si_pid = s->si_pid;
744 		d->si_uid = s->si_uid;
745 		d->si_int = s->si_int;
746 
747 	} else switch (s->si_signo) {
748 	/* XXX: What about POSIX1.b timers */
749 	case SIGCHLD:
750 		d->si_pid = s->si_pid;
751 		d->si_status = s->si_status;
752 		d->si_utime = s->si_utime;
753 		d->si_stime = s->si_stime;
754 		break;
755 	case SIGSEGV:
756 	case SIGBUS:
757 	case SIGFPE:
758 	case SIGILL:
759 		d->si_addr = (void *)A(s->si_addr);
760   		break;
761 	case SIGPOLL:
762 		d->si_band = s->si_band;
763 		d->si_fd = s->si_fd;
764 		break;
765 	default:
766 		d->si_pid = s->si_pid;
767 		d->si_uid = s->si_uid;
768 		break;
769 	}
770 	return d;
771 }
772 
773 
774 extern asmlinkage long sys_rt_sigqueueinfo(int pid, int sig, siginfo_t *uinfo);
775 
776 /*
777  * Note: it is necessary to treat pid and sig as unsigned ints, with the
778  * corresponding cast to a signed int to insure that the proper conversion
779  * (sign extension) between the register representation of a signed int
780  * (msr in 32-bit mode) and the register representation of a signed int
781  * (msr in 64-bit mode) is performed.
782  */
sys32_rt_sigqueueinfo(u32 pid,u32 sig,siginfo_t32 * uinfo)783 asmlinkage long sys32_rt_sigqueueinfo(u32 pid, u32 sig, siginfo_t32 *uinfo)
784 {
785 	siginfo_t info;
786 	siginfo_t32 info32;
787 	int ret;
788 	mm_segment_t old_fs = get_fs();
789 
790 	if (copy_from_user (&info32, uinfo, sizeof(siginfo_t32)))
791 		return -EFAULT;
792     	/* XXX: Is this correct? */
793 	siginfo32to64(&info, &info32);
794 
795 	set_fs (KERNEL_DS);
796 	ret = sys_rt_sigqueueinfo((int)pid, (int)sig, &info);
797 	set_fs (old_fs);
798 	return ret;
799 }
800 
801 
802 int do_signal(sigset_t *oldset, struct pt_regs *regs);
sys32_rt_sigsuspend(sigset32_t * unewset,size_t sigsetsize,int p3,int p4,int p6,int p7,struct pt_regs * regs)803 int sys32_rt_sigsuspend(sigset32_t* unewset, size_t sigsetsize, int p3, int p4, int p6, int p7, struct pt_regs *regs)
804 {
805 	sigset_t saveset, newset;
806 
807 	sigset32_t s32;
808 
809 	/* XXX: Don't preclude handling different sized sigset_t's.  */
810 	if (sigsetsize != sizeof(sigset_t))
811 		return -EINVAL;
812 
813 	if (copy_from_user(&s32, unewset, sizeof(s32)))
814 		return -EFAULT;
815 
816 	/*
817 	 * Swap the 2 words of the 64-bit sigset_t (they are stored
818 	 * in the "wrong" endian in 32-bit user storage).
819 	 */
820 	switch (_NSIG_WORDS) {
821 		case 4: newset.sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
822 		case 3: newset.sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
823 		case 2: newset.sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
824 		case 1: newset.sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
825 	}
826 
827 	sigdelsetmask(&newset, ~_BLOCKABLE);
828 
829 	spin_lock_irq(&current->sigmask_lock);
830 	saveset = current->blocked;
831 	current->blocked = newset;
832 	recalc_sigpending(current);
833 	spin_unlock_irq(&current->sigmask_lock);
834 
835 	regs->result = -EINTR;
836 	regs->gpr[3] = EINTR;
837 	regs->ccr |= 0x10000000;
838 	while (1) {
839 		set_current_state(TASK_INTERRUPTIBLE);
840 		schedule();
841 		if (do_signal(&saveset, regs))
842 			/*
843 			 * If a signal handler needs to be called,
844 			 * do_signal() has set R3 to the signal number (the
845 			 * first argument of the signal handler), so don't
846 			 * overwrite that with EINTR !
847 			 * In the other cases, do_signal() doesn't touch
848 			 * R3, so it's still set to -EINTR (see above).
849 			 */
850 			return regs->gpr[3];
851 	}
852 }
853 
854 
855 /*
856  * Set up a rt signal frame.
857  */
858 static void
setup_rt_frame32(struct pt_regs * regs,int sig,struct k_sigaction * ka,struct sigregs32 * frame,unsigned int newsp)859 setup_rt_frame32(struct pt_regs *regs, int sig, struct k_sigaction *ka,
860 		 struct sigregs32 *frame, unsigned int newsp)
861 {
862 	struct rt_sigframe_32 * rt_sf = (struct rt_sigframe_32 *) (u64)newsp;
863 	int i;
864 
865 	if (verify_area(VERIFY_WRITE, frame, sizeof(*frame)))
866 		goto badframe;
867 	if (regs->msr & MSR_FP)
868 		giveup_fpu(current);
869 
870 	/*
871 	 * Copy the register contents for the pt_regs structure on the
872 	 *   kernel stack to the elf_gregset_t32 structure on the user
873 	 *   stack. This is a copy of 64 bit register values to 32 bit
874 	 *   register values. The high order 32 bits of the 64 bit
875 	 *   registers are not needed since a 32 bit application is
876 	 *   running and the saved registers are the contents of the
877 	 *   user registers at the time of a system call.
878 	 *
879 	 * The values saved on the user stack will be restored into
880 	 *  the registers during the signal return processing.
881 	 *
882 	 * Note the +1 is needed in order to get the lower 32 bits
883 	 * of 64 bit register
884 	 */
885 	for (i = 0; i < sizeof(struct pt_regs32)/sizeof(u32); i++) {
886 		if (__copy_to_user(&frame->gp_regs[i], (u32*)(&regs->gpr[i])+1, sizeof(u32)))
887 			goto badframe;
888 	}
889 
890 
891 	/*
892 	 * Now copy the floating point registers onto the user stack
893 	 *
894 	 * Also set up so on the completion of the signal handler, the
895 	 * sys_sigreturn will get control to reset the stack
896 	 */
897 	if (__copy_to_user(&frame->fp_regs, current->thread.fpr,
898 			   ELF_NFPREG * sizeof(double))
899 	    || __put_user(0x38000000U + __NR_rt_sigreturn, &frame->tramp[0])    /* li r0, __NR_rt_sigreturn */
900 	    || __put_user(0x44000002U, &frame->tramp[1]))   /* sc */
901 		goto badframe;
902 
903 	flush_icache_range((unsigned long) &frame->tramp[0],
904 			   (unsigned long) &frame->tramp[2]);
905 	current->thread.fpscr = 0;	/* turn off all fp exceptions */
906 
907 	/*
908 	 * Set up registers for signal handler
909 	 */
910 	newsp -= __SIGNAL_FRAMESIZE32;
911 
912 	regs->gpr[1] = newsp;
913 	regs->gpr[3] = sig;
914 	regs->gpr[4] = (unsigned long) &rt_sf->info;
915 	regs->gpr[5] = (unsigned long) &rt_sf->uc;
916 	regs->gpr[6] = (unsigned long) rt_sf;
917 	regs->nip    = (unsigned long) ka->sa.sa_handler;
918 	regs->link   = (unsigned long) frame->tramp;
919 
920 	if (put_user((u32)(regs->gpr[1]), (unsigned int *)(u64)newsp))
921 		goto badframe;
922 
923 	return;
924 
925  badframe:
926 #if DEBUG_SIG
927 	printk("badframe in setup_rt_frame32, regs=%p frame=%p newsp=%lx\n",
928 	       regs, frame, newsp);
929 #endif
930 	if (sig == SIGSEGV)
931 		ka->sa.sa_handler = SIG_DFL;
932 	force_sig(SIGSEGV, current);
933 }
934 
935 
936 /*
937  * OK, we're invoking a handler
938  */
939 static void
handle_signal32(unsigned long sig,struct k_sigaction * ka,siginfo_t * info,sigset_t * oldset,struct pt_regs * regs,unsigned int * newspp,unsigned int frame)940 handle_signal32(unsigned long sig, struct k_sigaction *ka,
941 	      siginfo_t *info, sigset_t *oldset, struct pt_regs * regs,
942 	      unsigned int *newspp, unsigned int frame)
943 {
944 	struct sigcontext32 *sc;
945 	struct rt_sigframe_32 *rt_stack_frame;
946 	siginfo_t32 siginfo32bit;
947 
948 	if (regs->trap == 0x0C00 /* System Call! */
949 	    && ((int)regs->result == -ERESTARTNOHAND ||
950 		((int)regs->result == -ERESTARTSYS &&
951 		 !(ka->sa.sa_flags & SA_RESTART))))
952 		regs->result = -EINTR;
953 
954 	/* Set up the signal frame             */
955 	/*   Determine if an real time frame - siginfo required   */
956 	if (ka->sa.sa_flags & SA_SIGINFO)
957 	{
958 		siginfo64to32(&siginfo32bit,info);
959 		/* The ABI requires quadword alignment for the stack. */
960 		*newspp = (*newspp - sizeof(*rt_stack_frame)) & -16ul;
961 		rt_stack_frame = (struct rt_sigframe_32 *) (u64)(*newspp) ;
962 
963 		if (verify_area(VERIFY_WRITE, rt_stack_frame, sizeof(*rt_stack_frame)))
964 		{
965 			goto badframe;
966 		}
967 		if (__put_user((u32)(u64)ka->sa.sa_handler, &rt_stack_frame->uc.uc_mcontext.handler)
968 		    || __put_user((u32)(u64)&rt_stack_frame->info, &rt_stack_frame->pinfo)
969 		    || __put_user((u32)(u64)&rt_stack_frame->uc, &rt_stack_frame->puc)
970 		    /*  put the siginfo on the user stack                    */
971 		    || __copy_to_user(&rt_stack_frame->info,&siginfo32bit,sizeof(siginfo32bit))
972 		    /*  set the ucontext on the user stack                   */
973 		    || __put_user(0,&rt_stack_frame->uc.uc_flags)
974 		    || __put_user(0,&rt_stack_frame->uc.uc_link)
975 		    || __put_user(current->sas_ss_sp, &rt_stack_frame->uc.uc_stack.ss_sp)
976 		    || __put_user(sas_ss_flags(regs->gpr[1]),
977 				  &rt_stack_frame->uc.uc_stack.ss_flags)
978 		    || __put_user(current->sas_ss_size, &rt_stack_frame->uc.uc_stack.ss_size)
979 		    || __copy_to_user(&rt_stack_frame->uc.uc_sigmask, oldset,sizeof(*oldset))
980 		    /* point the mcontext.regs to the pramble register frame  */
981 		    || __put_user(frame, &rt_stack_frame->uc.uc_mcontext.regs)
982 		    || __put_user(sig,&rt_stack_frame->uc.uc_mcontext.signal))
983 		{
984 			goto badframe;
985 		}
986 	} else {
987 		/* Put a sigcontext on the stack */
988 		*newspp = (*newspp - sizeof(*sc)) & -16ul;
989 		sc = (struct sigcontext32 *)(u64)*newspp;
990 		if (verify_area(VERIFY_WRITE, sc, sizeof(*sc)))
991 			goto badframe;
992 		/*
993 		 * Note the upper 32 bits of the signal mask are stored
994 		 * in the unused part of the signal stack frame
995 		 */
996 		if (__put_user((u32)(u64)ka->sa.sa_handler, &sc->handler)
997 		    || __put_user(oldset->sig[0], &sc->oldmask)
998 		    || __put_user((oldset->sig[0] >> 32), &sc->_unused[3])
999 		    || __put_user((unsigned int)frame, &sc->regs)
1000 		    || __put_user(sig, &sc->signal))
1001 			goto badframe;
1002 	}
1003 
1004 	if (ka->sa.sa_flags & SA_ONESHOT)
1005 		ka->sa.sa_handler = SIG_DFL;
1006 
1007 	if (!(ka->sa.sa_flags & SA_NODEFER)) {
1008 		spin_lock_irq(&current->sigmask_lock);
1009 		sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
1010 		sigaddset(&current->blocked,sig);
1011 		recalc_sigpending(current);
1012 		spin_unlock_irq(&current->sigmask_lock);
1013 	}
1014 
1015 	return;
1016 
1017 badframe:
1018 #if DEBUG_SIG
1019 	printk("badframe in handle_signal32, regs=%p frame=%lx newsp=%lx\n",
1020 	       regs, frame, *newspp);
1021 	printk("sc=%p sig=%d ka=%p info=%p oldset=%p\n", sc, sig, ka, info, oldset);
1022 #endif
1023 	if (sig == SIGSEGV)
1024 		ka->sa.sa_handler = SIG_DFL;
1025 	force_sig(SIGSEGV, current);
1026 }
1027 
1028 
1029 /*
1030  *  Start Alternate signal stack support
1031  *
1032  *  System Calls
1033  *       sigaltatck               sys32_sigaltstack
1034  */
1035 
1036 
sys32_sigaltstack(u32 newstack,u32 oldstack,int p3,int p4,int p6,int p7,struct pt_regs * regs)1037 asmlinkage int sys32_sigaltstack(u32 newstack, u32 oldstack, int p3, int p4, int p6,
1038 				 int p7, struct pt_regs *regs)
1039 {
1040 	stack_t uss, uoss;
1041 	int ret;
1042 	mm_segment_t old_fs;
1043 	unsigned long sp;
1044 	u32 sssp;
1045 	stack_32_t *ustack;
1046 
1047 	/*
1048 	 * set sp to the user stack on entry to the system call
1049 	 * the system call router sets R9 to the saved registers
1050 	 */
1051 	sp = regs->gpr[1];
1052 
1053 	/*  Put new stack info in local 64 bit stack struct */
1054 	ustack = (stack_32_t *)(long) newstack;
1055 	if (newstack && (get_user(sssp, &ustack->ss_sp) ||
1056 			 __get_user(uss.ss_flags, &ustack->ss_flags) ||
1057 			 __get_user(uss.ss_size, &ustack->ss_size)))
1058 		return -EFAULT;
1059 	uss.ss_sp = (void *)(long) sssp;
1060 
1061 	old_fs = get_fs();
1062 	set_fs(KERNEL_DS);
1063 	ret = do_sigaltstack(newstack ? &uss : NULL, oldstack ? &uoss : NULL, sp);
1064 	set_fs(old_fs);
1065 	if (ret)
1066 		return ret;
1067 
1068 	/* Copy the stack information to the user output buffer */
1069 	ustack = (stack_32_t *)(long) oldstack;
1070 	if (oldstack && (put_user((long)uoss.ss_sp, &ustack->ss_sp) ||
1071 			 __put_user(uoss.ss_flags, &ustack->ss_flags) ||
1072 			 __put_user(uoss.ss_size, &ustack->ss_size)))
1073 		return -EFAULT;
1074 	return ret;
1075 }
1076 
1077 
1078 
1079 /*
1080  *  Start of do_signal32 routine
1081  *
1082  *   This routine gets control when a pending signal needs to be processed
1083  *     in the 32 bit target thread -
1084  *
1085  *   It handles both rt and non-rt signals
1086  */
1087 
1088 /*
1089  * Note that 'init' is a special process: it doesn't get signals it doesn't
1090  * want to handle. Thus you cannot kill init even with a SIGKILL even by
1091  * mistake.
1092  */
1093 
do_signal32(sigset_t * oldset,struct pt_regs * regs)1094 int do_signal32(sigset_t *oldset, struct pt_regs *regs)
1095 {
1096 	siginfo_t info;
1097 	struct k_sigaction *ka;
1098 	unsigned int frame, newsp;
1099 	unsigned long signr = 0;
1100 
1101 	if (!oldset)
1102 		oldset = &current->blocked;
1103 
1104 	newsp = frame = 0;
1105 
1106 	for (;;) {
1107 		spin_lock_irq(&current->sigmask_lock);
1108 		signr = dequeue_signal(&current->blocked, &info);
1109 		spin_unlock_irq(&current->sigmask_lock);
1110 
1111 		if (!signr)
1112 			break;
1113 
1114 		if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) {
1115 			/* Let the debugger run.  */
1116 			current->exit_code = signr;
1117 			current->state = TASK_STOPPED;
1118 			notify_parent(current, SIGCHLD);
1119 			schedule();
1120 
1121 			/* We're back.  Did the debugger cancel the sig?  */
1122 			if (!(signr = current->exit_code))
1123 				continue;
1124 			current->exit_code = 0;
1125 
1126 			/* The debugger continued.  Ignore SIGSTOP.  */
1127 			if (signr == SIGSTOP)
1128 				continue;
1129 
1130 			/* Update the siginfo structure.  Is this good?  */
1131 			if (signr != info.si_signo) {
1132 				info.si_signo = signr;
1133 				info.si_errno = 0;
1134 				info.si_code = SI_USER;
1135 				info.si_pid = current->p_pptr->pid;
1136 				info.si_uid = current->p_pptr->uid;
1137 			}
1138 
1139 			/* If the (new) signal is now blocked, requeue it.  */
1140 			if (sigismember(&current->blocked, signr)) {
1141 				send_sig_info(signr, &info, current);
1142 				continue;
1143 			}
1144 		}
1145 
1146 		ka = &current->sig->action[signr-1];
1147 
1148 		if (ka->sa.sa_handler == SIG_IGN) {
1149 			if (signr != SIGCHLD)
1150 				continue;
1151 			/* Check for SIGCHLD: it's special.  */
1152 			while (sys_wait4(-1, NULL, WNOHANG, NULL) > 0)
1153 				/* nothing */;
1154 			continue;
1155 		}
1156 
1157 		if (ka->sa.sa_handler == SIG_DFL) {
1158 			int exit_code = signr;
1159 
1160 			/* Init gets no signals it doesn't want.  */
1161 			if (current->pid == 1)
1162 				continue;
1163 
1164 			switch (signr) {
1165 			case SIGCONT: case SIGCHLD: case SIGWINCH: case SIGURG:
1166 				continue;
1167 
1168 			case SIGTSTP: case SIGTTIN: case SIGTTOU:
1169 				if (is_orphaned_pgrp(current->pgrp))
1170 					continue;
1171 				/* FALLTHRU */
1172 
1173 			case SIGSTOP:
1174 				current->state = TASK_STOPPED;
1175 				current->exit_code = signr;
1176 				if (!(current->p_pptr->sig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP))
1177 					notify_parent(current, SIGCHLD);
1178 				schedule();
1179 				continue;
1180 
1181 			case SIGQUIT: case SIGILL: case SIGTRAP:
1182 			case SIGABRT: case SIGFPE: case SIGSEGV:
1183 			case SIGBUS: case SIGSYS: case SIGXCPU: case SIGXFSZ:
1184 				if (do_coredump(signr, regs))
1185 					exit_code |= 0x80;
1186 				/* FALLTHRU */
1187 
1188 			default:
1189 				sig_exit(signr, exit_code, &info);
1190 				/* NOTREACHED */
1191 			}
1192 		}
1193 
1194 		if ( (ka->sa.sa_flags & SA_ONSTACK)
1195 		     && (! on_sig_stack(regs->gpr[1])))
1196 			newsp = (current->sas_ss_sp + current->sas_ss_size);
1197 		else
1198 			newsp = regs->gpr[1];
1199 		/* The ABI requires quadword alignment for the stack. */
1200 		newsp = frame = (newsp - sizeof(struct sigregs32)) & -16ul;
1201 
1202 		/* Whee!  Actually deliver the signal.  */
1203 		handle_signal32(signr, ka, &info, oldset, regs, &newsp, frame);
1204 		break;
1205 	}
1206 
1207 	if (regs->trap == 0x0C00 /* System Call! */ &&
1208 	    ((int)regs->result == -ERESTARTNOHAND ||
1209 	     (int)regs->result == -ERESTARTSYS ||
1210 	     (int)regs->result == -ERESTARTNOINTR)) {
1211 		regs->gpr[3] = regs->orig_gpr3;
1212 		regs->nip -= 4;		/* Back up & retry system call */
1213 		regs->result = 0;
1214 	}
1215 
1216 	if (newsp == frame)
1217 		return 0;		/* no signals delivered */
1218 
1219 	/* Invoke correct stack setup routine */
1220 	if (ka->sa.sa_flags & SA_SIGINFO)
1221 		setup_rt_frame32(regs, signr, ka,
1222 				 (struct sigregs32*)(u64)frame, newsp);
1223 	else
1224 		setup_frame32(regs, signr, ka,
1225 			      (struct sigregs32*)(u64)frame, newsp);
1226 	return 1;
1227 }
1228