| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (C) 2003 Broadcom Corporation | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software | 
					
						
							|  |  |  |  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2005-06-15 13:00:12 +00:00
										 |  |  | #include <linux/cache.h>
 | 
					
						
							|  |  |  | #include <linux/sched.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include <linux/mm.h>
 | 
					
						
							|  |  |  | #include <linux/smp.h>
 | 
					
						
							|  |  |  | #include <linux/kernel.h>
 | 
					
						
							|  |  |  | #include <linux/signal.h>
 | 
					
						
							|  |  |  | #include <linux/errno.h>
 | 
					
						
							|  |  |  | #include <linux/wait.h>
 | 
					
						
							|  |  |  | #include <linux/ptrace.h>
 | 
					
						
							|  |  |  | #include <linux/unistd.h>
 | 
					
						
							|  |  |  | #include <linux/compat.h>
 | 
					
						
							|  |  |  | #include <linux/bitops.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-15 11:40:37 +00:00
										 |  |  | #include <asm/abi.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include <asm/asm.h>
 | 
					
						
							|  |  |  | #include <asm/cacheflush.h>
 | 
					
						
							| 
									
										
										
										
											2007-02-13 00:05:11 +00:00
										 |  |  | #include <asm/compat-signal.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include <asm/sim.h>
 | 
					
						
							|  |  |  | #include <asm/uaccess.h>
 | 
					
						
							|  |  |  | #include <asm/ucontext.h>
 | 
					
						
							|  |  |  | #include <asm/system.h>
 | 
					
						
							|  |  |  | #include <asm/fpu.h>
 | 
					
						
							|  |  |  | #include <asm/cpu-features.h>
 | 
					
						
							| 
									
										
										
										
											2005-06-15 13:00:12 +00:00
										 |  |  | #include <asm/war.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "signal-common.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Including <asm/unistd.h> would give use the 64-bit syscall numbers ... | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define __NR_N32_rt_sigreturn		6211
 | 
					
						
							|  |  |  | #define __NR_N32_restart_syscall	6214
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-13 01:28:09 +00:00
										 |  |  | extern int setup_sigcontext(struct pt_regs *, struct sigcontext __user *); | 
					
						
							|  |  |  | extern int restore_sigcontext(struct pt_regs *, struct sigcontext __user *); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /* IRIX compatible stack_t  */ | 
					
						
							|  |  |  | typedef struct sigaltstack32 { | 
					
						
							|  |  |  | 	s32 ss_sp; | 
					
						
							|  |  |  | 	compat_size_t ss_size; | 
					
						
							|  |  |  | 	int ss_flags; | 
					
						
							|  |  |  | } stack32_t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct ucontextn32 { | 
					
						
							|  |  |  | 	u32                 uc_flags; | 
					
						
							|  |  |  | 	s32                 uc_link; | 
					
						
							|  |  |  | 	stack32_t           uc_stack; | 
					
						
							|  |  |  | 	struct sigcontext   uc_mcontext; | 
					
						
							| 
									
										
										
										
											2007-02-13 00:05:11 +00:00
										 |  |  | 	compat_sigset_t     uc_sigmask;   /* mask last for extensibility */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-05 15:24:21 +01:00
										 |  |  | #if ICACHE_REFILLS_WORKAROUND_WAR == 0
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | struct rt_sigframe_n32 { | 
					
						
							|  |  |  | 	u32 rs_ass[4];			/* argument save space for o32 */ | 
					
						
							| 
									
										
										
										
											2005-06-15 13:00:12 +00:00
										 |  |  | 	u32 rs_code[2];			/* signal trampoline */ | 
					
						
							| 
									
										
										
										
											2007-06-05 13:42:20 +04:00
										 |  |  | 	struct compat_siginfo rs_info; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	struct ucontextn32 rs_uc; | 
					
						
							| 
									
										
										
										
											2007-02-05 15:24:21 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else  /* ICACHE_REFILLS_WORKAROUND_WAR */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct rt_sigframe_n32 { | 
					
						
							|  |  |  | 	u32 rs_ass[4];			/* argument save space for o32 */ | 
					
						
							|  |  |  | 	u32 rs_pad[2]; | 
					
						
							| 
									
										
										
										
											2007-06-05 13:42:20 +04:00
										 |  |  | 	struct compat_siginfo rs_info; | 
					
						
							| 
									
										
										
										
											2007-02-05 15:24:21 +01:00
										 |  |  | 	struct ucontextn32 rs_uc; | 
					
						
							| 
									
										
										
										
											2005-06-15 13:00:12 +00:00
										 |  |  | 	u32 rs_code[8] ____cacheline_aligned;		/* signal trampoline */ | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-05 15:24:21 +01:00
										 |  |  | #endif	/* !ICACHE_REFILLS_WORKAROUND_WAR */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-11 23:46:15 +01:00
										 |  |  | extern void sigset_from_compat(sigset_t *set, compat_sigset_t *compat); | 
					
						
							| 
									
										
										
										
											2006-10-02 14:12:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-05 15:24:27 +01:00
										 |  |  | asmlinkage int sysn32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs) | 
					
						
							| 
									
										
										
										
											2006-02-18 22:47:26 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-21 01:27:59 +09:00
										 |  |  | 	compat_sigset_t __user *unewset; | 
					
						
							|  |  |  | 	compat_sigset_t uset; | 
					
						
							| 
									
										
										
										
											2006-02-18 22:47:26 +00:00
										 |  |  | 	size_t sigsetsize; | 
					
						
							|  |  |  | 	sigset_t newset; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* XXX Don't preclude handling different sized sigset_t's.  */ | 
					
						
							|  |  |  | 	sigsetsize = regs.regs[5]; | 
					
						
							|  |  |  | 	if (sigsetsize != sizeof(sigset_t)) | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	unewset = (compat_sigset_t __user *) regs.regs[4]; | 
					
						
							|  |  |  | 	if (copy_from_user(&uset, unewset, sizeof(uset))) | 
					
						
							|  |  |  | 		return -EFAULT; | 
					
						
							| 
									
										
										
										
											2007-10-11 23:46:15 +01:00
										 |  |  | 	sigset_from_compat(&newset, &uset); | 
					
						
							| 
									
										
										
										
											2006-02-18 22:47:26 +00:00
										 |  |  | 	sigdelsetmask(&newset, ~_BLOCKABLE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irq(¤t->sighand->siglock); | 
					
						
							|  |  |  | 	current->saved_sigmask = current->blocked; | 
					
						
							|  |  |  | 	current->blocked = newset; | 
					
						
							| 
									
										
										
										
											2007-02-05 00:10:11 +00:00
										 |  |  | 	recalc_sigpending(); | 
					
						
							| 
									
										
										
										
											2006-02-18 22:47:26 +00:00
										 |  |  | 	spin_unlock_irq(¤t->sighand->siglock); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	current->state = TASK_INTERRUPTIBLE; | 
					
						
							|  |  |  | 	schedule(); | 
					
						
							|  |  |  | 	set_thread_flag(TIF_RESTORE_SIGMASK); | 
					
						
							|  |  |  | 	return -ERESTARTNOHAND; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-05 15:24:27 +01:00
										 |  |  | asmlinkage void sysn32_rt_sigreturn(nabi_no_regargs struct pt_regs regs) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-01 01:41:09 +09:00
										 |  |  | 	struct rt_sigframe_n32 __user *frame; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	sigset_t set; | 
					
						
							|  |  |  | 	stack_t st; | 
					
						
							|  |  |  | 	s32 sp; | 
					
						
							| 
									
										
										
										
											2007-03-10 01:03:48 +09:00
										 |  |  | 	int sig; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-01 01:41:09 +09:00
										 |  |  | 	frame = (struct rt_sigframe_n32 __user *) regs.regs[29]; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) | 
					
						
							|  |  |  | 		goto badframe; | 
					
						
							| 
									
										
										
										
											2007-02-13 00:05:11 +00:00
										 |  |  | 	if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		goto badframe; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sigdelsetmask(&set, ~_BLOCKABLE); | 
					
						
							|  |  |  | 	spin_lock_irq(¤t->sighand->siglock); | 
					
						
							|  |  |  | 	current->blocked = set; | 
					
						
							|  |  |  | 	recalc_sigpending(); | 
					
						
							|  |  |  | 	spin_unlock_irq(¤t->sighand->siglock); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-10 01:03:48 +09:00
										 |  |  | 	sig = restore_sigcontext(®s, &frame->rs_uc.uc_mcontext); | 
					
						
							|  |  |  | 	if (sig < 0) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		goto badframe; | 
					
						
							| 
									
										
										
										
											2007-03-10 01:03:48 +09:00
										 |  |  | 	else if (sig) | 
					
						
							|  |  |  | 		force_sig(sig, current); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* The ucontext contains a stack32_t, so we must convert!  */ | 
					
						
							|  |  |  | 	if (__get_user(sp, &frame->rs_uc.uc_stack.ss_sp)) | 
					
						
							|  |  |  | 		goto badframe; | 
					
						
							| 
									
										
										
										
											2006-02-19 23:46:44 +09:00
										 |  |  | 	st.ss_sp = (void __user *)(long) sp; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (__get_user(st.ss_size, &frame->rs_uc.uc_stack.ss_size)) | 
					
						
							|  |  |  | 		goto badframe; | 
					
						
							|  |  |  | 	if (__get_user(st.ss_flags, &frame->rs_uc.uc_stack.ss_flags)) | 
					
						
							|  |  |  | 		goto badframe; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* It is more difficult to avoid calling this function than to
 | 
					
						
							|  |  |  | 	   call it and ignore errors.  */ | 
					
						
							| 
									
										
										
										
											2006-02-01 01:41:09 +09:00
										 |  |  | 	do_sigaltstack((stack_t __user *)&st, NULL, regs.regs[29]); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Don't let your children do this ... | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	__asm__ __volatile__( | 
					
						
							|  |  |  | 		"move\t$29, %0\n\t" | 
					
						
							|  |  |  | 		"j\tsyscall_exit" | 
					
						
							|  |  |  | 		:/* no outputs */ | 
					
						
							|  |  |  | 		:"r" (®s)); | 
					
						
							|  |  |  | 	/* Unreached */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | badframe: | 
					
						
							|  |  |  | 	force_sig(SIGSEGV, current); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-15 11:40:37 +00:00
										 |  |  | static int setup_rt_frame_n32(struct k_sigaction * ka, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	struct pt_regs *regs, int signr, sigset_t *set, siginfo_t *info) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-01 01:41:09 +09:00
										 |  |  | 	struct rt_sigframe_n32 __user *frame; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	int err = 0; | 
					
						
							|  |  |  | 	s32 sp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	frame = get_sigframe(ka, regs, sizeof(*frame)); | 
					
						
							|  |  |  | 	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame))) | 
					
						
							|  |  |  | 		goto give_sigsegv; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-15 13:00:12 +00:00
										 |  |  | 	install_sigtramp(frame->rs_code, __NR_N32_rt_sigreturn); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Create siginfo.  */ | 
					
						
							| 
									
										
										
										
											2007-06-05 13:42:20 +04:00
										 |  |  | 	err |= copy_siginfo_to_user32(&frame->rs_info, info); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Create the ucontext.  */ | 
					
						
							|  |  |  | 	err |= __put_user(0, &frame->rs_uc.uc_flags); | 
					
						
							|  |  |  | 	err |= __put_user(0, &frame->rs_uc.uc_link); | 
					
						
							| 
									
										
										
										
											2007-02-05 00:10:11 +00:00
										 |  |  | 	sp = (int) (long) current->sas_ss_sp; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	err |= __put_user(sp, | 
					
						
							|  |  |  | 	                  &frame->rs_uc.uc_stack.ss_sp); | 
					
						
							|  |  |  | 	err |= __put_user(sas_ss_flags(regs->regs[29]), | 
					
						
							|  |  |  | 	                  &frame->rs_uc.uc_stack.ss_flags); | 
					
						
							|  |  |  | 	err |= __put_user(current->sas_ss_size, | 
					
						
							|  |  |  | 	                  &frame->rs_uc.uc_stack.ss_size); | 
					
						
							|  |  |  | 	err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext); | 
					
						
							| 
									
										
										
										
											2007-02-13 00:05:11 +00:00
										 |  |  | 	err |= __copy_conv_sigset_to_user(&frame->rs_uc.uc_sigmask, set); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (err) | 
					
						
							|  |  |  | 		goto give_sigsegv; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Arguments to signal handler: | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 *   a0 = signal number | 
					
						
							|  |  |  | 	 *   a1 = 0 (should be cause) | 
					
						
							|  |  |  | 	 *   a2 = pointer to ucontext | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * $25 and c0_epc point to the signal handler, $29 points to | 
					
						
							|  |  |  | 	 * the struct rt_sigframe. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	regs->regs[ 4] = signr; | 
					
						
							|  |  |  | 	regs->regs[ 5] = (unsigned long) &frame->rs_info; | 
					
						
							|  |  |  | 	regs->regs[ 6] = (unsigned long) &frame->rs_uc; | 
					
						
							|  |  |  | 	regs->regs[29] = (unsigned long) frame; | 
					
						
							|  |  |  | 	regs->regs[31] = (unsigned long) frame->rs_code; | 
					
						
							|  |  |  | 	regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-05 15:24:24 +01:00
										 |  |  | 	DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n", | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	       current->comm, current->pid, | 
					
						
							|  |  |  | 	       frame, regs->cp0_epc, regs->regs[31]); | 
					
						
							| 
									
										
										
										
											2007-02-05 15:24:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-08 12:58:41 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | give_sigsegv: | 
					
						
							|  |  |  | 	force_sigsegv(signr, current); | 
					
						
							| 
									
										
										
										
											2006-02-08 12:58:41 +00:00
										 |  |  | 	return -EFAULT; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2007-02-15 11:40:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct mips_abi mips_abi_n32 = { | 
					
						
							|  |  |  | 	.setup_rt_frame	= setup_rt_frame_n32, | 
					
						
							|  |  |  | 	.restart	= __NR_N32_restart_syscall | 
					
						
							|  |  |  | }; |