signal_n32.c 6.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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.
 */
18 19
#include <linux/cache.h>
#include <linux/sched.h>
L
Linus Torvalds 已提交
20 21 22 23 24 25 26 27 28 29 30
#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>

31
#include <asm/abi.h>
L
Linus Torvalds 已提交
32 33
#include <asm/asm.h>
#include <asm/cacheflush.h>
34
#include <asm/compat-signal.h>
L
Linus Torvalds 已提交
35 36 37 38 39 40
#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>
41
#include <asm/war.h>
L
Linus Torvalds 已提交
42 43 44 45 46 47 48 49 50

#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

51 52 53 54
extern int setup_sigcontext(struct pt_regs *, struct sigcontext __user *);
extern int restore_sigcontext(struct pt_regs *, struct sigcontext __user *);


L
Linus Torvalds 已提交
55 56 57 58 59 60 61 62 63 64 65 66
/* 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;
67
	compat_sigset_t     uc_sigmask;   /* mask last for extensibility */
L
Linus Torvalds 已提交
68 69
};

70 71
#if ICACHE_REFILLS_WORKAROUND_WAR == 0

L
Linus Torvalds 已提交
72 73
struct rt_sigframe_n32 {
	u32 rs_ass[4];			/* argument save space for o32 */
74 75
	u32 rs_code[2];			/* signal trampoline */
	struct siginfo rs_info;
L
Linus Torvalds 已提交
76
	struct ucontextn32 rs_uc;
77 78 79 80 81 82 83 84 85
};

#else  /* ICACHE_REFILLS_WORKAROUND_WAR */

struct rt_sigframe_n32 {
	u32 rs_ass[4];			/* argument save space for o32 */
	u32 rs_pad[2];
	struct siginfo rs_info;
	struct ucontextn32 rs_uc;
86
	u32 rs_code[8] ____cacheline_aligned;		/* signal trampoline */
L
Linus Torvalds 已提交
87 88
};

89 90
#endif	/* !ICACHE_REFILLS_WORKAROUND_WAR */

91 92
extern void sigset_from_compat (sigset_t *set, compat_sigset_t *compat);

93
asmlinkage int sysn32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
94
{
95 96
	compat_sigset_t __user *unewset;
	compat_sigset_t uset;
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
	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;
	sigset_from_compat (&newset, &uset);
	sigdelsetmask(&newset, ~_BLOCKABLE);

	spin_lock_irq(&current->sighand->siglock);
	current->saved_sigmask = current->blocked;
	current->blocked = newset;
R
Ralf Baechle 已提交
114
	recalc_sigpending();
115 116 117 118 119 120 121 122
	spin_unlock_irq(&current->sighand->siglock);

	current->state = TASK_INTERRUPTIBLE;
	schedule();
	set_thread_flag(TIF_RESTORE_SIGMASK);
	return -ERESTARTNOHAND;
}

123
asmlinkage void sysn32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
L
Linus Torvalds 已提交
124
{
125
	struct rt_sigframe_n32 __user *frame;
L
Linus Torvalds 已提交
126 127 128
	sigset_t set;
	stack_t st;
	s32 sp;
129
	int sig;
L
Linus Torvalds 已提交
130

131
	frame = (struct rt_sigframe_n32 __user *) regs.regs[29];
L
Linus Torvalds 已提交
132 133
	if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
		goto badframe;
134
	if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask))
L
Linus Torvalds 已提交
135 136 137 138 139 140 141 142
		goto badframe;

	sigdelsetmask(&set, ~_BLOCKABLE);
	spin_lock_irq(&current->sighand->siglock);
	current->blocked = set;
	recalc_sigpending();
	spin_unlock_irq(&current->sighand->siglock);

143 144
	sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext);
	if (sig < 0)
L
Linus Torvalds 已提交
145
		goto badframe;
146 147
	else if (sig)
		force_sig(sig, current);
L
Linus Torvalds 已提交
148 149 150 151

	/* The ucontext contains a stack32_t, so we must convert!  */
	if (__get_user(sp, &frame->rs_uc.uc_stack.ss_sp))
		goto badframe;
A
Atsushi Nemoto 已提交
152
	st.ss_sp = (void __user *)(long) sp;
L
Linus Torvalds 已提交
153 154 155 156 157 158 159
	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.  */
160
	do_sigaltstack((stack_t __user *)&st, NULL, regs.regs[29]);
L
Linus Torvalds 已提交
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175

	/*
	 * Don't let your children do this ...
	 */
	__asm__ __volatile__(
		"move\t$29, %0\n\t"
		"j\tsyscall_exit"
		:/* no outputs */
		:"r" (&regs));
	/* Unreached */

badframe:
	force_sig(SIGSEGV, current);
}

176
static int setup_rt_frame_n32(struct k_sigaction * ka,
L
Linus Torvalds 已提交
177 178
	struct pt_regs *regs, int signr, sigset_t *set, siginfo_t *info)
{
179
	struct rt_sigframe_n32 __user *frame;
L
Linus Torvalds 已提交
180 181 182 183 184 185 186
	int err = 0;
	s32 sp;

	frame = get_sigframe(ka, regs, sizeof(*frame));
	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
		goto give_sigsegv;

187
	install_sigtramp(frame->rs_code, __NR_N32_rt_sigreturn);
L
Linus Torvalds 已提交
188 189 190 191 192 193 194

	/* Create siginfo.  */
	err |= copy_siginfo_to_user(&frame->rs_info, info);

	/* Create the ucontext.  */
	err |= __put_user(0, &frame->rs_uc.uc_flags);
	err |= __put_user(0, &frame->rs_uc.uc_link);
R
Ralf Baechle 已提交
195
	sp = (int) (long) current->sas_ss_sp;
L
Linus Torvalds 已提交
196 197 198 199 200 201 202
	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);
203
	err |= __copy_conv_sigset_to_user(&frame->rs_uc.uc_sigmask, set);
L
Linus Torvalds 已提交
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224

	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;

225
	DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
L
Linus Torvalds 已提交
226 227
	       current->comm, current->pid,
	       frame, regs->cp0_epc, regs->regs[31]);
228

229
	return 0;
L
Linus Torvalds 已提交
230 231 232

give_sigsegv:
	force_sigsegv(signr, current);
233
	return -EFAULT;
L
Linus Torvalds 已提交
234
}
235 236 237 238 239

struct mips_abi mips_abi_n32 = {
	.setup_rt_frame	= setup_rt_frame_n32,
	.restart	= __NR_N32_restart_syscall
};