signal_n32.c 4.3 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
#include <asm/sim.h>
#include <asm/uaccess.h>
#include <asm/ucontext.h>
#include <asm/fpu.h>
#include <asm/cpu-features.h>
40
#include <asm/war.h>
41
#include <asm/vdso.h>
L
Linus Torvalds 已提交
42 43 44 45 46 47 48 49

#include "signal-common.h"

/*
 * Including <asm/unistd.h> would give use the 64-bit syscall numbers ...
 */
#define __NR_N32_restart_syscall	6214

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

L
Linus Torvalds 已提交
53
struct ucontextn32 {
R
Ralf Baechle 已提交
54 55
	u32		    uc_flags;
	s32		    uc_link;
A
Al Viro 已提交
56
	compat_stack_t      uc_stack;
L
Linus Torvalds 已提交
57
	struct sigcontext   uc_mcontext;
R
Ralf Baechle 已提交
58
	compat_sigset_t	    uc_sigmask;	  /* mask last for extensibility */
L
Linus Torvalds 已提交
59 60
};

61 62
struct rt_sigframe_n32 {
	u32 rs_ass[4];			/* argument save space for o32 */
63
	u32 rs_pad[2];			/* Was: signal trampoline */
64
	struct compat_siginfo rs_info;
65
	struct ucontextn32 rs_uc;
L
Linus Torvalds 已提交
66 67
};

68
asmlinkage void sysn32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
L
Linus Torvalds 已提交
69
{
70
	struct rt_sigframe_n32 __user *frame;
L
Linus Torvalds 已提交
71
	sigset_t set;
72
	int sig;
L
Linus Torvalds 已提交
73

74
	frame = (struct rt_sigframe_n32 __user *) regs.regs[29];
L
Linus Torvalds 已提交
75 76
	if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
		goto badframe;
77
	if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask))
L
Linus Torvalds 已提交
78 79
		goto badframe;

80
	set_current_blocked(&set);
L
Linus Torvalds 已提交
81

82 83
	sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext);
	if (sig < 0)
L
Linus Torvalds 已提交
84
		goto badframe;
85 86
	else if (sig)
		force_sig(sig, current);
L
Linus Torvalds 已提交
87

A
Al Viro 已提交
88
	if (compat_restore_altstack(&frame->rs_uc.uc_stack))
L
Linus Torvalds 已提交
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
		goto badframe;

	/*
	 * 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);
}

105 106
static int setup_rt_frame_n32(void *sig_return, struct ksignal *ksig,
			      struct pt_regs *regs, sigset_t *set)
L
Linus Torvalds 已提交
107
{
108
	struct rt_sigframe_n32 __user *frame;
L
Linus Torvalds 已提交
109 110
	int err = 0;

111
	frame = get_sigframe(&ksig->ka, regs, sizeof(*frame));
L
Linus Torvalds 已提交
112
	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
113
		return -EFAULT;
L
Linus Torvalds 已提交
114 115

	/* Create siginfo.  */
116
	err |= copy_siginfo_to_user32(&frame->rs_info, &ksig->info);
L
Linus Torvalds 已提交
117

R
Ralf Baechle 已提交
118
	/* Create the ucontext.	 */
L
Linus Torvalds 已提交
119 120
	err |= __put_user(0, &frame->rs_uc.uc_flags);
	err |= __put_user(0, &frame->rs_uc.uc_link);
A
Al Viro 已提交
121
	err |= __compat_save_altstack(&frame->rs_uc.uc_stack, regs->regs[29]);
L
Linus Torvalds 已提交
122
	err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
123
	err |= __copy_conv_sigset_to_user(&frame->rs_uc.uc_sigmask, set);
L
Linus Torvalds 已提交
124 125

	if (err)
126
		return -EFAULT;
L
Linus Torvalds 已提交
127 128 129 130 131 132 133 134 135 136 137

	/*
	 * 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.
	 */
138
	regs->regs[ 4] = ksig->sig;
L
Linus Torvalds 已提交
139 140 141
	regs->regs[ 5] = (unsigned long) &frame->rs_info;
	regs->regs[ 6] = (unsigned long) &frame->rs_uc;
	regs->regs[29] = (unsigned long) frame;
142
	regs->regs[31] = (unsigned long) sig_return;
143
	regs->cp0_epc = regs->regs[25] = (unsigned long) ksig->ka.sa.sa_handler;
L
Linus Torvalds 已提交
144

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

149
	return 0;
L
Linus Torvalds 已提交
150
}
151 152

struct mips_abi mips_abi_n32 = {
R
Ralf Baechle 已提交
153
	.setup_rt_frame = setup_rt_frame_n32,
154 155
	.rt_signal_return_offset =
		offsetof(struct mips_vdso, n32_rt_signal_trampoline),
156 157
	.restart	= __NR_N32_restart_syscall
};