signal.c 16.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 1991, 1992  Linus Torvalds
 * Copyright (C) 1994 - 2000  Ralf Baechle
 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
9
 * Copyright (C) 2014, Imagination Technologies Ltd.
L
Linus Torvalds 已提交
10
 */
11
#include <linux/cache.h>
12
#include <linux/context_tracking.h>
13
#include <linux/irqflags.h>
L
Linus Torvalds 已提交
14 15 16 17 18 19 20 21 22 23 24
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/personality.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/compiler.h>
25
#include <linux/syscalls.h>
26
#include <linux/uaccess.h>
27
#include <linux/tracehook.h>
L
Linus Torvalds 已提交
28

29
#include <asm/abi.h>
L
Linus Torvalds 已提交
30 31 32 33 34 35 36
#include <asm/asm.h>
#include <linux/bitops.h>
#include <asm/cacheflush.h>
#include <asm/fpu.h>
#include <asm/sim.h>
#include <asm/ucontext.h>
#include <asm/cpu-features.h>
37
#include <asm/war.h>
38
#include <asm/vdso.h>
39
#include <asm/dsp.h>
40
#include <asm/inst.h>
L
Linus Torvalds 已提交
41 42 43

#include "signal-common.h"

44 45 46 47 48 49
static int (*save_fp_context)(struct sigcontext __user *sc);
static int (*restore_fp_context)(struct sigcontext __user *sc);

extern asmlinkage int _save_fp_context(struct sigcontext __user *sc);
extern asmlinkage int _restore_fp_context(struct sigcontext __user *sc);

50 51
struct sigframe {
	u32 sf_ass[4];		/* argument save space for o32 */
52
	u32 sf_pad[2];		/* Was: signal trampoline */
53 54 55 56
	struct sigcontext sf_sc;
	sigset_t sf_mask;
};

57 58
struct rt_sigframe {
	u32 rs_ass[4];		/* argument save space for o32 */
59
	u32 rs_pad[2];		/* Was: signal trampoline */
60 61 62 63
	struct siginfo rs_info;
	struct ucontext rs_uc;
};

64 65 66 67 68 69 70 71 72
/*
 * Thread saved context copy to/from a signal context presumed to be on the
 * user stack, and therefore accessed with appropriate macros from uaccess.h.
 */
static int copy_fp_to_sigcontext(struct sigcontext __user *sc)
{
	int i;
	int err = 0;

73
	for (i = 0; i < NUM_FPU_REGS; i++) {
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
		err |=
		    __put_user(get_fpr64(&current->thread.fpu.fpr[i], 0),
			       &sc->sc_fpregs[i]);
	}
	err |= __put_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);

	return err;
}

static int copy_fp_from_sigcontext(struct sigcontext __user *sc)
{
	int i;
	int err = 0;
	u64 fpr_val;

89
	for (i = 0; i < NUM_FPU_REGS; i++) {
90 91 92 93 94 95 96 97
		err |= __get_user(fpr_val, &sc->sc_fpregs[i]);
		set_fpr64(&current->thread.fpu.fpr[i], 0, fpr_val);
	}
	err |= __get_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);

	return err;
}

98 99 100
/*
 * Helper routines
 */
101
static int protected_save_fp_context(struct sigcontext __user *sc)
102 103
{
	int err;
104
#ifndef CONFIG_EVA
105 106
	while (1) {
		lock_fpu_owner();
107 108 109 110 111 112 113
		if (is_fpu_owner()) {
			err = save_fp_context(sc);
			unlock_fpu_owner();
		} else {
			unlock_fpu_owner();
			err = copy_fp_to_sigcontext(sc);
		}
114 115 116 117 118 119 120 121 122
		if (likely(!err))
			break;
		/* touch the sigcontext and try again */
		err = __put_user(0, &sc->sc_fpregs[0]) |
			__put_user(0, &sc->sc_fpregs[31]) |
			__put_user(0, &sc->sc_fpc_csr);
		if (err)
			break;	/* really bad sigcontext */
	}
123 124 125 126 127 128 129 130
#else
	/*
	 * EVA does not have FPU EVA instructions so saving fpu context directly
	 * does not work.
	 */
	lose_fpu(1);
	err = save_fp_context(sc); /* this might fail */
#endif
131 132 133
	return err;
}

134
static int protected_restore_fp_context(struct sigcontext __user *sc)
135
{
136
	int err, tmp __maybe_unused;
137
#ifndef CONFIG_EVA
138 139
	while (1) {
		lock_fpu_owner();
140 141 142 143 144 145 146
		if (is_fpu_owner()) {
			err = restore_fp_context(sc);
			unlock_fpu_owner();
		} else {
			unlock_fpu_owner();
			err = copy_fp_from_sigcontext(sc);
		}
147 148 149 150 151 152 153 154 155
		if (likely(!err))
			break;
		/* touch the sigcontext and try again */
		err = __get_user(tmp, &sc->sc_fpregs[0]) |
			__get_user(tmp, &sc->sc_fpregs[31]) |
			__get_user(tmp, &sc->sc_fpc_csr);
		if (err)
			break;	/* really bad sigcontext */
	}
156 157 158 159 160 161 162 163
#else
	/*
	 * EVA does not have FPU EVA instructions so restoring fpu context
	 * directly does not work.
	 */
	lose_fpu(0);
	err = restore_fp_context(sc); /* this might fail */
#endif
164 165 166
	return err;
}

167 168 169 170
int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
{
	int err = 0;
	int i;
171
	unsigned int used_math;
172 173 174 175 176 177 178

	err |= __put_user(regs->cp0_epc, &sc->sc_pc);

	err |= __put_user(0, &sc->sc_regs[0]);
	for (i = 1; i < 32; i++)
		err |= __put_user(regs->regs[i], &sc->sc_regs[i]);

179 180 181
#ifdef CONFIG_CPU_HAS_SMARTMIPS
	err |= __put_user(regs->acx, &sc->sc_acx);
#endif
182 183 184 185 186 187 188 189 190 191 192 193
	err |= __put_user(regs->hi, &sc->sc_mdhi);
	err |= __put_user(regs->lo, &sc->sc_mdlo);
	if (cpu_has_dsp) {
		err |= __put_user(mfhi1(), &sc->sc_hi1);
		err |= __put_user(mflo1(), &sc->sc_lo1);
		err |= __put_user(mfhi2(), &sc->sc_hi2);
		err |= __put_user(mflo2(), &sc->sc_lo2);
		err |= __put_user(mfhi3(), &sc->sc_hi3);
		err |= __put_user(mflo3(), &sc->sc_lo3);
		err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
	}

194
	used_math = !!used_math();
195
	err |= __put_user(used_math, &sc->sc_used_math);
196

197
	if (used_math) {
198 199 200 201
		/*
		 * Save FPU state to signal context. Signal handler
		 * will "inherit" current FPU state.
		 */
202
		err |= protected_save_fp_context(sc);
203 204 205 206
	}
	return err;
}

207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
int fpcsr_pending(unsigned int __user *fpcsr)
{
	int err, sig = 0;
	unsigned int csr, enabled;

	err = __get_user(csr, fpcsr);
	enabled = FPU_CSR_UNI_X | ((csr & FPU_CSR_ALL_E) << 5);
	/*
	 * If the signal handler set some FPU exceptions, clear it and
	 * send SIGFPE.
	 */
	if (csr & enabled) {
		csr &= ~enabled;
		err |= __put_user(csr, fpcsr);
		sig = SIGFPE;
	}
	return err ?: sig;
}

static int
227
check_and_restore_fp_context(struct sigcontext __user *sc)
228 229 230 231 232 233
{
	int err, sig;

	err = sig = fpcsr_pending(&sc->sc_fpc_csr);
	if (err > 0)
		err = 0;
234
	err |= protected_restore_fp_context(sc);
235 236 237
	return err ?: sig;
}

238 239 240 241 242 243 244 245 246 247 248
int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
{
	unsigned int used_math;
	unsigned long treg;
	int err = 0;
	int i;

	/* Always make any pending restarted system calls return -EINTR */
	current_thread_info()->restart_block.fn = do_no_restart_syscall;

	err |= __get_user(regs->cp0_epc, &sc->sc_pc);
249 250 251 252

#ifdef CONFIG_CPU_HAS_SMARTMIPS
	err |= __get_user(regs->acx, &sc->sc_acx);
#endif
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
	err |= __get_user(regs->hi, &sc->sc_mdhi);
	err |= __get_user(regs->lo, &sc->sc_mdlo);
	if (cpu_has_dsp) {
		err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
		err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
		err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
		err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
		err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
		err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
		err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
	}

	for (i = 1; i < 32; i++)
		err |= __get_user(regs->regs[i], &sc->sc_regs[i]);

	err |= __get_user(used_math, &sc->sc_used_math);
	conditional_used_math(used_math);

271
	if (used_math) {
272
		/* restore fpu context if we have used it before */
273
		if (!err)
274
			err = check_and_restore_fp_context(sc);
275
	} else {
276
		/* signal handler may have used FPU.  Give it up. */
277
		lose_fpu(0);
278 279 280 281 282
	}

	return err;
}

R
Richard Weinberger 已提交
283
void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
284 285 286 287 288 289 290 291 292 293 294 295 296 297
			  size_t frame_size)
{
	unsigned long sp;

	/* Default to using normal stack */
	sp = regs->regs[29];

	/*
	 * FPU emulator may have it's own trampoline active just
	 * above the user stack, 16-bytes before the next lowest
	 * 16 byte boundary.  Try to avoid trashing it.
	 */
	sp -= 32;

R
Richard Weinberger 已提交
298
	sp = sigsp(sp, ksig);
299 300 301 302

	return (void __user *)((sp - frame_size) & (ICACHE_REFILLS_WORKAROUND_WAR ? ~(cpu_icache_line_size()-1) : ALMASK));
}

L
Linus Torvalds 已提交
303 304 305 306 307
/*
 * Atomically swap in the new signal mask, and wait for a signal.
 */

#ifdef CONFIG_TRAD_SIGNALS
308
SYSCALL_DEFINE1(sigsuspend, sigset_t __user *, uset)
L
Linus Torvalds 已提交
309
{
310
	return sys_rt_sigsuspend(uset, sizeof(sigset_t));
L
Linus Torvalds 已提交
311 312 313 314
}
#endif

#ifdef CONFIG_TRAD_SIGNALS
315 316
SYSCALL_DEFINE3(sigaction, int, sig, const struct sigaction __user *, act,
	struct sigaction __user *, oact)
L
Linus Torvalds 已提交
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
{
	struct k_sigaction new_ka, old_ka;
	int ret;
	int err = 0;

	if (act) {
		old_sigset_t mask;

		if (!access_ok(VERIFY_READ, act, sizeof(*act)))
			return -EFAULT;
		err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler);
		err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
		err |= __get_user(mask, &act->sa_mask.sig[0]);
		if (err)
			return -EFAULT;

		siginitset(&new_ka.sa.sa_mask, mask);
	}

	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);

	if (!ret && oact) {
		if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
R
Ralf Baechle 已提交
340
			return -EFAULT;
L
Linus Torvalds 已提交
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
		err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
		err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler);
		err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
		err |= __put_user(0, &oact->sa_mask.sig[1]);
		err |= __put_user(0, &oact->sa_mask.sig[2]);
		err |= __put_user(0, &oact->sa_mask.sig[3]);
		if (err)
			return -EFAULT;
	}

	return ret;
}
#endif

#ifdef CONFIG_TRAD_SIGNALS
356
asmlinkage void sys_sigreturn(nabi_no_regargs struct pt_regs regs)
L
Linus Torvalds 已提交
357
{
358
	struct sigframe __user *frame;
L
Linus Torvalds 已提交
359
	sigset_t blocked;
360
	int sig;
L
Linus Torvalds 已提交
361

362
	frame = (struct sigframe __user *) regs.regs[29];
L
Linus Torvalds 已提交
363 364 365 366 367
	if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
		goto badframe;
	if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
		goto badframe;

368
	set_current_blocked(&blocked);
L
Linus Torvalds 已提交
369

370 371
	sig = restore_sigcontext(&regs, &frame->sf_sc);
	if (sig < 0)
L
Linus Torvalds 已提交
372
		goto badframe;
373 374
	else if (sig)
		force_sig(sig, current);
L
Linus Torvalds 已提交
375 376 377 378 379 380 381 382 383 384 385 386 387 388

	/*
	 * 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);
}
389
#endif /* CONFIG_TRAD_SIGNALS */
L
Linus Torvalds 已提交
390

391
asmlinkage void sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
L
Linus Torvalds 已提交
392
{
393
	struct rt_sigframe __user *frame;
L
Linus Torvalds 已提交
394
	sigset_t set;
395
	int sig;
L
Linus Torvalds 已提交
396

397
	frame = (struct rt_sigframe __user *) regs.regs[29];
L
Linus Torvalds 已提交
398 399 400 401 402
	if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
		goto badframe;
	if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
		goto badframe;

403
	set_current_blocked(&set);
L
Linus Torvalds 已提交
404

405 406
	sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext);
	if (sig < 0)
L
Linus Torvalds 已提交
407
		goto badframe;
408 409
	else if (sig)
		force_sig(sig, current);
L
Linus Torvalds 已提交
410

A
Al Viro 已提交
411 412
	if (restore_altstack(&frame->rs_uc.uc_stack))
		goto badframe;
L
Linus Torvalds 已提交
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428

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

#ifdef CONFIG_TRAD_SIGNALS
429 430
static int setup_frame(void *sig_return, struct ksignal *ksig,
		       struct pt_regs *regs, sigset_t *set)
L
Linus Torvalds 已提交
431
{
432
	struct sigframe __user *frame;
L
Linus Torvalds 已提交
433 434
	int err = 0;

R
Richard Weinberger 已提交
435
	frame = get_sigframe(ksig, regs, sizeof(*frame));
L
Linus Torvalds 已提交
436
	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
437
		return -EFAULT;
L
Linus Torvalds 已提交
438 439 440 441

	err |= setup_sigcontext(regs, &frame->sf_sc);
	err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
	if (err)
442
		return -EFAULT;
L
Linus Torvalds 已提交
443 444 445 446 447 448 449 450 451 452 453

	/*
	 * Arguments to signal handler:
	 *
	 *   a0 = signal number
	 *   a1 = 0 (should be cause)
	 *   a2 = pointer to struct sigcontext
	 *
	 * $25 and c0_epc point to the signal handler, $29 points to the
	 * struct sigframe.
	 */
454
	regs->regs[ 4] = ksig->sig;
L
Linus Torvalds 已提交
455 456 457
	regs->regs[ 5] = 0;
	regs->regs[ 6] = (unsigned long) &frame->sf_sc;
	regs->regs[29] = (unsigned long) frame;
458
	regs->regs[31] = (unsigned long) sig_return;
459
	regs->cp0_epc = regs->regs[25] = (unsigned long) ksig->ka.sa.sa_handler;
L
Linus Torvalds 已提交
460

461
	DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
L
Linus Torvalds 已提交
462
	       current->comm, current->pid,
463
	       frame, regs->cp0_epc, regs->regs[31]);
R
Ralf Baechle 已提交
464
	return 0;
L
Linus Torvalds 已提交
465 466 467
}
#endif

468 469
static int setup_rt_frame(void *sig_return, struct ksignal *ksig,
			  struct pt_regs *regs, sigset_t *set)
L
Linus Torvalds 已提交
470
{
471
	struct rt_sigframe __user *frame;
L
Linus Torvalds 已提交
472 473
	int err = 0;

R
Richard Weinberger 已提交
474
	frame = get_sigframe(ksig, regs, sizeof(*frame));
L
Linus Torvalds 已提交
475
	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
476
		return -EFAULT;
L
Linus Torvalds 已提交
477 478

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

R
Ralf Baechle 已提交
481
	/* Create the ucontext.	 */
L
Linus Torvalds 已提交
482
	err |= __put_user(0, &frame->rs_uc.uc_flags);
483
	err |= __put_user(NULL, &frame->rs_uc.uc_link);
A
Al Viro 已提交
484
	err |= __save_altstack(&frame->rs_uc.uc_stack, regs->regs[29]);
L
Linus Torvalds 已提交
485 486 487 488
	err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
	err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));

	if (err)
489
		return -EFAULT;
L
Linus Torvalds 已提交
490 491 492 493 494 495 496 497 498 499 500

	/*
	 * 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.
	 */
501
	regs->regs[ 4] = ksig->sig;
L
Linus Torvalds 已提交
502 503 504
	regs->regs[ 5] = (unsigned long) &frame->rs_info;
	regs->regs[ 6] = (unsigned long) &frame->rs_uc;
	regs->regs[29] = (unsigned long) frame;
505
	regs->regs[31] = (unsigned long) sig_return;
506
	regs->cp0_epc = regs->regs[25] = (unsigned long) ksig->ka.sa.sa_handler;
L
Linus Torvalds 已提交
507

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

512
	return 0;
L
Linus Torvalds 已提交
513 514
}

515 516 517
struct mips_abi mips_abi = {
#ifdef CONFIG_TRAD_SIGNALS
	.setup_frame	= setup_frame,
518
	.signal_return_offset = offsetof(struct mips_vdso, signal_trampoline),
519
#endif
R
Ralf Baechle 已提交
520
	.setup_rt_frame = setup_rt_frame,
521 522
	.rt_signal_return_offset =
		offsetof(struct mips_vdso, rt_signal_trampoline),
523 524 525
	.restart	= __NR_restart_syscall
};

526
static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
L
Linus Torvalds 已提交
527
{
A
Al Viro 已提交
528
	sigset_t *oldset = sigmask_to_save();
529
	int ret;
530
	struct mips_abi *abi = current->thread.abi;
531 532 533 534 535 536 537
#ifdef CONFIG_CPU_MICROMIPS
	void *vdso;
	unsigned int tmp = (unsigned int)current->mm->context.vdso;

	set_isa16_mode(tmp);
	vdso = (void *)tmp;
#else
538
	void *vdso = current->mm->context.vdso;
539
#endif
540

A
Al Viro 已提交
541 542 543 544
	if (regs->regs[0]) {
		switch(regs->regs[2]) {
		case ERESTART_RESTARTBLOCK:
		case ERESTARTNOHAND:
L
Linus Torvalds 已提交
545 546
			regs->regs[2] = EINTR;
			break;
A
Al Viro 已提交
547
		case ERESTARTSYS:
548
			if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
A
Al Viro 已提交
549 550 551 552 553 554 555 556
				regs->regs[2] = EINTR;
				break;
			}
		/* fallthrough */
		case ERESTARTNOINTR:
			regs->regs[7] = regs->regs[26];
			regs->regs[2] = regs->regs[0];
			regs->cp0_epc -= 4;
L
Linus Torvalds 已提交
557 558
		}

R
Ralf Baechle 已提交
559
		regs->regs[0] = 0;		/* Don't deal with this again.	*/
A
Al Viro 已提交
560
	}
L
Linus Torvalds 已提交
561

562
	if (sig_uses_siginfo(&ksig->ka))
563
		ret = abi->setup_rt_frame(vdso + abi->rt_signal_return_offset,
564
					  ksig, regs, oldset);
L
Linus Torvalds 已提交
565
	else
566 567
		ret = abi->setup_frame(vdso + abi->signal_return_offset, ksig,
				       regs, oldset);
568

569
	signal_setup_done(ret, ksig, 0);
L
Linus Torvalds 已提交
570 571
}

572
static void do_signal(struct pt_regs *regs)
L
Linus Torvalds 已提交
573
{
574
	struct ksignal ksig;
L
Linus Torvalds 已提交
575

576
	if (get_signal(&ksig)) {
R
Ralf Baechle 已提交
577
		/* Whee!  Actually deliver the signal.	*/
578
		handle_signal(&ksig, regs);
579
		return;
580
	}
L
Linus Torvalds 已提交
581 582

	if (regs->regs[0]) {
583 584 585 586
		switch (regs->regs[2]) {
		case ERESTARTNOHAND:
		case ERESTARTSYS:
		case ERESTARTNOINTR:
A
Al Viro 已提交
587
			regs->regs[2] = regs->regs[0];
L
Linus Torvalds 已提交
588
			regs->regs[7] = regs->regs[26];
A
Al Viro 已提交
589
			regs->cp0_epc -= 4;
590 591 592
			break;

		case ERESTART_RESTARTBLOCK:
593
			regs->regs[2] = current->thread.abi->restart;
L
Linus Torvalds 已提交
594 595
			regs->regs[7] = regs->regs[26];
			regs->cp0_epc -= 4;
596
			break;
L
Linus Torvalds 已提交
597
		}
R
Ralf Baechle 已提交
598
		regs->regs[0] = 0;	/* Don't deal with this again.	*/
L
Linus Torvalds 已提交
599
	}
600 601 602 603 604

	/*
	 * If there's no signal to deliver, we just put the saved sigmask
	 * back
	 */
A
Al Viro 已提交
605
	restore_saved_sigmask();
L
Linus Torvalds 已提交
606 607 608 609
}

/*
 * notification of userspace execution resumption
610
 * - triggered by the TIF_WORK_MASK flags
L
Linus Torvalds 已提交
611
 */
612
asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
L
Linus Torvalds 已提交
613 614
	__u32 thread_info_flags)
{
615 616
	local_irq_enable();

617 618
	user_exit();

L
Linus Torvalds 已提交
619
	/* deal with pending signal delivery */
620
	if (thread_info_flags & _TIF_SIGPENDING)
621
		do_signal(regs);
622 623 624 625 626

	if (thread_info_flags & _TIF_NOTIFY_RESUME) {
		clear_thread_flag(TIF_NOTIFY_RESUME);
		tracehook_notify_resume(regs);
	}
627 628

	user_enter();
L
Linus Torvalds 已提交
629
}
630 631

#ifdef CONFIG_SMP
632
#ifndef CONFIG_EVA
633 634 635 636
static int smp_save_fp_context(struct sigcontext __user *sc)
{
	return raw_cpu_has_fpu
	       ? _save_fp_context(sc)
637
	       : copy_fp_to_sigcontext(sc);
638 639 640 641 642 643
}

static int smp_restore_fp_context(struct sigcontext __user *sc)
{
	return raw_cpu_has_fpu
	       ? _restore_fp_context(sc)
644
	       : copy_fp_from_sigcontext(sc);
645
}
646
#endif /* CONFIG_EVA */
647 648 649 650
#endif

static int signal_setup(void)
{
651
#ifndef CONFIG_EVA
652 653 654 655 656 657 658 659 660
#ifdef CONFIG_SMP
	/* For now just do the cpu_has_fpu check when the functions are invoked */
	save_fp_context = smp_save_fp_context;
	restore_fp_context = smp_restore_fp_context;
#else
	if (cpu_has_fpu) {
		save_fp_context = _save_fp_context;
		restore_fp_context = _restore_fp_context;
	} else {
661 662
		save_fp_context = copy_fp_to_sigcontext;
		restore_fp_context = copy_fp_from_sigcontext;
663
	}
664 665
#endif /* CONFIG_SMP */
#else
666 667
	save_fp_context = copy_fp_to_sigcontext;
	restore_fp_context = copy_fp_from_sigcontext;
668 669 670 671 672 673
#endif

	return 0;
}

arch_initcall(signal_setup);