signal_32.c 16.8 KB
Newer Older
1
/*  linux/arch/sparc/kernel/signal.c
L
Linus Torvalds 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 *  Copyright (C) 1991, 1992  Linus Torvalds
 *  Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
 *  Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
 *  Copyright (C) 1997 Eddie C. Dost   (ecd@skynet.be)
 */

#include <linux/sched.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/mm.h>
#include <linux/tty.h>
#include <linux/smp.h>
#include <linux/binfmts.h>	/* do_coredum */
#include <linux/bitops.h>
21
#include <linux/tracehook.h>
L
Linus Torvalds 已提交
22 23 24 25 26 27 28

#include <asm/uaccess.h>
#include <asm/ptrace.h>
#include <asm/pgalloc.h>
#include <asm/pgtable.h>
#include <asm/cacheflush.h>	/* flush_sig_insns */

29 30
#include "sigutil.h"

L
Linus Torvalds 已提交
31 32 33 34 35 36
#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))

extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
		   void *fpqueue, unsigned long *fpqdepth);
extern void fpload(unsigned long *fpregs, unsigned long *fsr);

37
struct signal_frame {
L
Linus Torvalds 已提交
38
	struct sparc_stackf	ss;
39
	__siginfo32_t		info;
L
Linus Torvalds 已提交
40 41 42 43
	__siginfo_fpu_t __user	*fpu_save;
	unsigned long		insns[2] __attribute__ ((aligned (8)));
	unsigned int		extramask[_NSIG_WORDS - 1];
	unsigned int		extra_size; /* Should be 0 */
44 45
	__siginfo_rwin_t __user	*rwin_save;
} __attribute__((aligned(8)));
L
Linus Torvalds 已提交
46 47 48 49 50 51 52 53 54 55

struct rt_signal_frame {
	struct sparc_stackf	ss;
	siginfo_t		info;
	struct pt_regs		regs;
	sigset_t		mask;
	__siginfo_fpu_t __user	*fpu_save;
	unsigned int		insns[2];
	stack_t			stack;
	unsigned int		extra_size; /* Should be 0 */
56 57
	__siginfo_rwin_t __user	*rwin_save;
} __attribute__((aligned(8)));
L
Linus Torvalds 已提交
58 59

/* Align macros */
60
#define SF_ALIGNEDSZ  (((sizeof(struct signal_frame) + 7) & (~7)))
L
Linus Torvalds 已提交
61 62
#define RT_ALIGNEDSZ  (((sizeof(struct rt_signal_frame) + 7) & (~7)))

63
static int _sigpause_common(old_sigset_t set)
L
Linus Torvalds 已提交
64
{
M
Matt Fleming 已提交
65 66
	sigset_t blocked;

67
	current->saved_sigmask = current->blocked;
M
Matt Fleming 已提交
68 69 70 71

	set &= _BLOCKABLE;
	siginitset(&blocked, set);
	set_current_blocked(&blocked);
L
Linus Torvalds 已提交
72

73 74 75
	current->state = TASK_INTERRUPTIBLE;
	schedule();
	set_thread_flag(TIF_RESTORE_SIGMASK);
L
Linus Torvalds 已提交
76

77
	return -ERESTARTNOHAND;
L
Linus Torvalds 已提交
78 79
}

80
asmlinkage int sys_sigsuspend(old_sigset_t set)
L
Linus Torvalds 已提交
81
{
82
	return _sigpause_common(set);
L
Linus Torvalds 已提交
83 84
}

85
asmlinkage void do_sigreturn(struct pt_regs *regs)
L
Linus Torvalds 已提交
86
{
87
	struct signal_frame __user *sf;
L
Linus Torvalds 已提交
88 89 90
	unsigned long up_psr, pc, npc;
	sigset_t set;
	__siginfo_fpu_t __user *fpu_save;
91
	__siginfo_rwin_t __user *rwin_save;
L
Linus Torvalds 已提交
92 93
	int err;

94 95 96 97 98 99
	/* Always make any pending restarted system calls return -EINTR */
	current_thread_info()->restart_block.fn = do_no_restart_syscall;

	synchronize_user_stack();

	sf = (struct signal_frame __user *) regs->u_regs[UREG_FP];
L
Linus Torvalds 已提交
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121

	/* 1. Make sure we are not getting garbage from the user */
	if (!access_ok(VERIFY_READ, sf, sizeof(*sf)))
		goto segv_and_exit;

	if (((unsigned long) sf) & 3)
		goto segv_and_exit;

	err = __get_user(pc,  &sf->info.si_regs.pc);
	err |= __get_user(npc, &sf->info.si_regs.npc);

	if ((pc | npc) & 3)
		goto segv_and_exit;

	/* 2. Restore the state */
	up_psr = regs->psr;
	err |= __copy_from_user(regs, &sf->info.si_regs, sizeof(struct pt_regs));

	/* User can only change condition codes and FPU enabling in %psr. */
	regs->psr = (up_psr & ~(PSR_ICC | PSR_EF))
		  | (regs->psr & (PSR_ICC | PSR_EF));

122 123 124
	/* Prevent syscall restart.  */
	pt_regs_clear_syscall(regs);

L
Linus Torvalds 已提交
125 126 127
	err |= __get_user(fpu_save, &sf->fpu_save);
	if (fpu_save)
		err |= restore_fpu_state(regs, fpu_save);
128 129 130
	err |= __get_user(rwin_save, &sf->rwin_save);
	if (rwin_save)
		err |= restore_rwin_state(rwin_save);
L
Linus Torvalds 已提交
131 132 133 134 135 136 137 138 139 140 141 142

	/* This is pretty much atomic, no amount locking would prevent
	 * the races which exist anyways.
	 */
	err |= __get_user(set.sig[0], &sf->info.si_mask);
	err |= __copy_from_user(&set.sig[1], &sf->extramask,
			        (_NSIG_WORDS-1) * sizeof(unsigned int));
			   
	if (err)
		goto segv_and_exit;

	sigdelsetmask(&set, ~_BLOCKABLE);
M
Matt Fleming 已提交
143
	set_current_blocked(&set);
L
Linus Torvalds 已提交
144 145 146 147 148 149 150 151 152 153 154
	return;

segv_and_exit:
	force_sig(SIGSEGV, current);
}

asmlinkage void do_rt_sigreturn(struct pt_regs *regs)
{
	struct rt_signal_frame __user *sf;
	unsigned int psr, pc, npc;
	__siginfo_fpu_t __user *fpu_save;
155
	__siginfo_rwin_t __user *rwin_save;
L
Linus Torvalds 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
	mm_segment_t old_fs;
	sigset_t set;
	stack_t st;
	int err;

	synchronize_user_stack();
	sf = (struct rt_signal_frame __user *) regs->u_regs[UREG_FP];
	if (!access_ok(VERIFY_READ, sf, sizeof(*sf)) ||
	    (((unsigned long) sf) & 0x03))
		goto segv;

	err = __get_user(pc, &sf->regs.pc);
	err |= __get_user(npc, &sf->regs.npc);
	err |= ((pc | npc) & 0x03);

	err |= __get_user(regs->y, &sf->regs.y);
	err |= __get_user(psr, &sf->regs.psr);

	err |= __copy_from_user(&regs->u_regs[UREG_G1],
				&sf->regs.u_regs[UREG_G1], 15 * sizeof(u32));

	regs->psr = (regs->psr & ~PSR_ICC) | (psr & PSR_ICC);

179 180 181
	/* Prevent syscall restart.  */
	pt_regs_clear_syscall(regs);

L
Linus Torvalds 已提交
182
	err |= __get_user(fpu_save, &sf->fpu_save);
183
	if (!err && fpu_save)
L
Linus Torvalds 已提交
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
		err |= restore_fpu_state(regs, fpu_save);
	err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
	
	err |= __copy_from_user(&st, &sf->stack, sizeof(stack_t));
	
	if (err)
		goto segv;
		
	regs->pc = pc;
	regs->npc = npc;
	
	/* It is more difficult to avoid calling this function than to
	 * call it and ignore errors.
	 */
	old_fs = get_fs();
	set_fs(KERNEL_DS);
	do_sigaltstack((const stack_t __user *) &st, NULL, (unsigned long)sf);
	set_fs(old_fs);

203 204 205 206 207 208
	err |= __get_user(rwin_save, &sf->rwin_save);
	if (!err && rwin_save) {
		if (restore_rwin_state(rwin_save))
			goto segv;
	}

L
Linus Torvalds 已提交
209
	sigdelsetmask(&set, ~_BLOCKABLE);
M
Matt Fleming 已提交
210
	set_current_blocked(&set);
L
Linus Torvalds 已提交
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
	return;
segv:
	force_sig(SIGSEGV, current);
}

/* Checks if the fp is valid */
static inline int invalid_frame_pointer(void __user *fp, int fplen)
{
	if ((((unsigned long) fp) & 7) ||
	    !__access_ok((unsigned long)fp, fplen) ||
	    ((sparc_cpu_model == sun4 || sparc_cpu_model == sun4c) &&
	     ((unsigned long) fp < 0xe0000000 && (unsigned long) fp >= 0x20000000)))
		return 1;
	
	return 0;
}

static inline void __user *get_sigframe(struct sigaction *sa, struct pt_regs *regs, unsigned long framesize)
{
230
	unsigned long sp = regs->u_regs[UREG_FP];
L
Linus Torvalds 已提交
231

232 233 234 235 236 237
	/*
	 * If we are on the alternate signal stack and would overflow it, don't.
	 * Return an always-bogus address instead so we will die with SIGSEGV.
	 */
	if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize)))
		return (void __user *) -1L;
L
Linus Torvalds 已提交
238 239 240

	/* This is the X/Open sanctioned signal stack switching.  */
	if (sa->sa_flags & SA_ONSTACK) {
241
		if (sas_ss_flags(sp) == 0)
L
Linus Torvalds 已提交
242 243
			sp = current->sas_ss_sp + current->sas_ss_size;
	}
244

245 246
	sp -= framesize;

247 248 249 250 251 252
	/* Always align the stack frame.  This handles two cases.  First,
	 * sigaltstack need not be mindful of platform specific stack
	 * alignment.  Second, if we took this signal because the stack
	 * is not aligned properly, we'd like to take the signal cleanly
	 * and report that.
	 */
253
	sp &= ~15UL;
254

255
	return (void __user *) sp;
L
Linus Torvalds 已提交
256 257
}

258 259
static int setup_frame(struct k_sigaction *ka, struct pt_regs *regs,
		       int signo, sigset_t *oldset)
L
Linus Torvalds 已提交
260
{
261
	struct signal_frame __user *sf;
262 263
	int sigframe_size, err, wsaved;
	void __user *tail;
L
Linus Torvalds 已提交
264 265 266 267

	/* 1. Make sure everything is clean */
	synchronize_user_stack();

268 269 270 271 272 273 274
	wsaved = current_thread_info()->w_saved;

	sigframe_size = sizeof(*sf);
	if (used_math())
		sigframe_size += sizeof(__siginfo_fpu_t);
	if (wsaved)
		sigframe_size += sizeof(__siginfo_rwin_t);
L
Linus Torvalds 已提交
275

276
	sf = (struct signal_frame __user *)
L
Linus Torvalds 已提交
277 278 279 280 281
		get_sigframe(&ka->sa, regs, sigframe_size);

	if (invalid_frame_pointer(sf, sigframe_size))
		goto sigill_and_return;

282
	tail = sf + 1;
L
Linus Torvalds 已提交
283 284 285 286 287 288 289

	/* 2. Save the current process state */
	err = __copy_to_user(&sf->info.si_regs, regs, sizeof(struct pt_regs));
	
	err |= __put_user(0, &sf->extra_size);

	if (used_math()) {
290 291 292 293
		__siginfo_fpu_t __user *fp = tail;
		tail += sizeof(*fp);
		err |= save_fpu_state(regs, fp);
		err |= __put_user(fp, &sf->fpu_save);
L
Linus Torvalds 已提交
294 295 296
	} else {
		err |= __put_user(0, &sf->fpu_save);
	}
297 298 299 300 301 302 303 304
	if (wsaved) {
		__siginfo_rwin_t __user *rwp = tail;
		tail += sizeof(*rwp);
		err |= save_rwin_state(wsaved, rwp);
		err |= __put_user(rwp, &sf->rwin_save);
	} else {
		err |= __put_user(0, &sf->rwin_save);
	}
L
Linus Torvalds 已提交
305 306 307 308

	err |= __put_user(oldset->sig[0], &sf->info.si_mask);
	err |= __copy_to_user(sf->extramask, &oldset->sig[1],
			      (_NSIG_WORDS - 1) * sizeof(unsigned int));
309 310 311 312 313 314 315 316 317
	if (!wsaved) {
		err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
				      sizeof(struct reg_window32));
	} else {
		struct reg_window32 *rp;

		rp = &current_thread_info()->reg_window[wsaved - 1];
		err |= __copy_to_user(sf, rp, sizeof(struct reg_window32));
	}
L
Linus Torvalds 已提交
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
	if (err)
		goto sigsegv;
	
	/* 3. signal handler back-trampoline and parameters */
	regs->u_regs[UREG_FP] = (unsigned long) sf;
	regs->u_regs[UREG_I0] = signo;
	regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
	regs->u_regs[UREG_I2] = (unsigned long) &sf->info;

	/* 4. signal handler */
	regs->pc = (unsigned long) ka->sa.sa_handler;
	regs->npc = (regs->pc + 4);

	/* 5. return to kernel instructions */
	if (ka->ka_restorer)
		regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
	else {
		regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2);

		/* mov __NR_sigreturn, %g1 */
		err |= __put_user(0x821020d8, &sf->insns[0]);

		/* t 0x10 */
		err |= __put_user(0x91d02010, &sf->insns[1]);
		if (err)
			goto sigsegv;

		/* Flush instruction space. */
		flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
	}
348
	return 0;
L
Linus Torvalds 已提交
349 350 351

sigill_and_return:
	do_exit(SIGILL);
352 353
	return -EINVAL;

L
Linus Torvalds 已提交
354 355
sigsegv:
	force_sigsegv(signo, current);
356
	return -EFAULT;
L
Linus Torvalds 已提交
357 358
}

359 360
static int setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs,
			  int signo, sigset_t *oldset, siginfo_t *info)
L
Linus Torvalds 已提交
361 362
{
	struct rt_signal_frame __user *sf;
363 364
	int sigframe_size, wsaved;
	void __user *tail;
L
Linus Torvalds 已提交
365 366 367 368
	unsigned int psr;
	int err;

	synchronize_user_stack();
369 370 371 372 373 374
	wsaved = current_thread_info()->w_saved;
	sigframe_size = sizeof(*sf);
	if (used_math())
		sigframe_size += sizeof(__siginfo_fpu_t);
	if (wsaved)
		sigframe_size += sizeof(__siginfo_rwin_t);
L
Linus Torvalds 已提交
375 376 377 378 379
	sf = (struct rt_signal_frame __user *)
		get_sigframe(&ka->sa, regs, sigframe_size);
	if (invalid_frame_pointer(sf, sigframe_size))
		goto sigill;

380
	tail = sf + 1;
L
Linus Torvalds 已提交
381 382 383 384 385 386 387 388 389 390 391
	err  = __put_user(regs->pc, &sf->regs.pc);
	err |= __put_user(regs->npc, &sf->regs.npc);
	err |= __put_user(regs->y, &sf->regs.y);
	psr = regs->psr;
	if (used_math())
		psr |= PSR_EF;
	err |= __put_user(psr, &sf->regs.psr);
	err |= __copy_to_user(&sf->regs.u_regs, regs->u_regs, sizeof(regs->u_regs));
	err |= __put_user(0, &sf->extra_size);

	if (psr & PSR_EF) {
392 393 394 395
		__siginfo_fpu_t *fp = tail;
		tail += sizeof(*fp);
		err |= save_fpu_state(regs, fp);
		err |= __put_user(fp, &sf->fpu_save);
L
Linus Torvalds 已提交
396 397 398
	} else {
		err |= __put_user(0, &sf->fpu_save);
	}
399 400 401 402 403 404 405 406
	if (wsaved) {
		__siginfo_rwin_t *rwp = tail;
		tail += sizeof(*rwp);
		err |= save_rwin_state(wsaved, rwp);
		err |= __put_user(rwp, &sf->rwin_save);
	} else {
		err |= __put_user(0, &sf->rwin_save);
	}
L
Linus Torvalds 已提交
407 408 409 410 411 412 413
	err |= __copy_to_user(&sf->mask, &oldset->sig[0], sizeof(sigset_t));
	
	/* Setup sigaltstack */
	err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp);
	err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags);
	err |= __put_user(current->sas_ss_size, &sf->stack.ss_size);
	
414 415 416 417 418 419 420 421 422
	if (!wsaved) {
		err |= __copy_to_user(sf, (char *) regs->u_regs[UREG_FP],
				      sizeof(struct reg_window32));
	} else {
		struct reg_window32 *rp;

		rp = &current_thread_info()->reg_window[wsaved - 1];
		err |= __copy_to_user(sf, rp, sizeof(struct reg_window32));
	}
L
Linus Torvalds 已提交
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452

	err |= copy_siginfo_to_user(&sf->info, info);

	if (err)
		goto sigsegv;

	regs->u_regs[UREG_FP] = (unsigned long) sf;
	regs->u_regs[UREG_I0] = signo;
	regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
	regs->u_regs[UREG_I2] = (unsigned long) &sf->regs;

	regs->pc = (unsigned long) ka->sa.sa_handler;
	regs->npc = (regs->pc + 4);

	if (ka->ka_restorer)
		regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
	else {
		regs->u_regs[UREG_I7] = (unsigned long)(&(sf->insns[0]) - 2);

		/* mov __NR_sigreturn, %g1 */
		err |= __put_user(0x821020d8, &sf->insns[0]);

		/* t 0x10 */
		err |= __put_user(0x91d02010, &sf->insns[1]);
		if (err)
			goto sigsegv;

		/* Flush instruction space. */
		flush_sig_insns(current->mm, (unsigned long) &(sf->insns[0]));
	}
453
	return 0;
L
Linus Torvalds 已提交
454 455 456

sigill:
	do_exit(SIGILL);
457 458
	return -EINVAL;

L
Linus Torvalds 已提交
459 460
sigsegv:
	force_sigsegv(signo, current);
461
	return -EFAULT;
L
Linus Torvalds 已提交
462 463
}

464
static inline int
L
Linus Torvalds 已提交
465
handle_signal(unsigned long signr, struct k_sigaction *ka,
466
	      siginfo_t *info, sigset_t *oldset, struct pt_regs *regs)
L
Linus Torvalds 已提交
467
{
M
Matt Fleming 已提交
468
	sigset_t blocked;
469 470
	int err;

471
	if (ka->sa.sa_flags & SA_SIGINFO)
472
		err = setup_rt_frame(ka, regs, signr, oldset, info);
473
	else
474 475 476 477
		err = setup_frame(ka, regs, signr, oldset);

	if (err)
		return err;
478

M
Matt Fleming 已提交
479
	sigorsets(&blocked, &current->blocked, &ka->sa.sa_mask);
480
	if (!(ka->sa.sa_flags & SA_NOMASK))
M
Matt Fleming 已提交
481 482
		sigaddset(&blocked, signr);
	set_current_blocked(&blocked);
483 484 485 486

	tracehook_signal_handler(signr, info, ka, regs, 0);

	return 0;
L
Linus Torvalds 已提交
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
}

static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
				   struct sigaction *sa)
{
	switch(regs->u_regs[UREG_I0]) {
	case ERESTART_RESTARTBLOCK:
	case ERESTARTNOHAND:
	no_system_call_restart:
		regs->u_regs[UREG_I0] = EINTR;
		regs->psr |= PSR_C;
		break;
	case ERESTARTSYS:
		if (!(sa->sa_flags & SA_RESTART))
			goto no_system_call_restart;
		/* fallthrough */
	case ERESTARTNOINTR:
		regs->u_regs[UREG_I0] = orig_i0;
		regs->pc -= 4;
		regs->npc -= 4;
	}
}

/* Note that 'init' is a special process: it doesn't get signals it doesn't
 * want to handle. Thus you cannot kill init even with a SIGKILL even by
 * mistake.
 */
514
static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
L
Linus Torvalds 已提交
515 516
{
	struct k_sigaction ka;
517
	int restart_syscall;
518
	sigset_t *oldset;
519 520
	siginfo_t info;
	int signr;
L
Linus Torvalds 已提交
521

522 523 524 525 526 527 528 529
	/* It's a lot of work and synchronization to add a new ptrace
	 * register for GDB to save and restore in order to get
	 * orig_i0 correct for syscall restarts when debugging.
	 *
	 * However, we luckily can use the fact that several registers
	 * are volatile across system calls.  One such register is
	 * %g2, so use that as a place to save away orig_i0.
	 */
530
	if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C))
531
		regs->u_regs[UREG_G2] = orig_i0;
L
Linus Torvalds 已提交
532

533 534 535
	if (test_thread_flag(TIF_RESTORE_SIGMASK))
		oldset = &current->saved_sigmask;
	else
L
Linus Torvalds 已提交
536 537
		oldset = &current->blocked;

538 539 540 541 542 543
	signr = get_signal_to_deliver(&info, &ka, regs, NULL);

	/* If the debugger messes with the program counter, it clears
	 * the software "in syscall" bit, directing us to not perform
	 * a syscall restart.
	 */
544 545 546 547 548 549
	restart_syscall = 0;
	if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C)) {
		restart_syscall = 1;
		orig_i0 = regs->u_regs[UREG_G2];
	}

550

L
Linus Torvalds 已提交
551
	if (signr > 0) {
552 553
		if (restart_syscall)
			syscall_restart(orig_i0, regs, &ka.sa);
554 555 556 557 558 559 560 561 562
		if (handle_signal(signr, &ka, &info, oldset, regs) == 0) {
			/* a signal was successfully delivered; the saved
			 * sigmask will have been stored in the signal frame,
			 * and will be restored by sigreturn, so we can simply
			 * clear the TIF_RESTORE_SIGMASK flag.
			 */
			if (test_thread_flag(TIF_RESTORE_SIGMASK))
				clear_thread_flag(TIF_RESTORE_SIGMASK);
		}
563
		return;
L
Linus Torvalds 已提交
564
	}
565
	if (restart_syscall &&
L
Linus Torvalds 已提交
566 567 568 569
	    (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
	     regs->u_regs[UREG_I0] == ERESTARTSYS ||
	     regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
		/* replay the system call when we are done */
570
		regs->u_regs[UREG_I0] = orig_i0;
L
Linus Torvalds 已提交
571 572
		regs->pc -= 4;
		regs->npc -= 4;
573
		pt_regs_clear_syscall(regs);
L
Linus Torvalds 已提交
574
	}
575
	if (restart_syscall &&
L
Linus Torvalds 已提交
576 577 578 579
	    regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
		regs->u_regs[UREG_G1] = __NR_restart_syscall;
		regs->pc -= 4;
		regs->npc -= 4;
580
		pt_regs_clear_syscall(regs);
L
Linus Torvalds 已提交
581
	}
582 583 584 585 586 587

	/* if there's no signal to deliver, we just put the saved sigmask
	 * back
	 */
	if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
		clear_thread_flag(TIF_RESTORE_SIGMASK);
588
		set_current_blocked(&current->saved_sigmask);
589
	}
L
Linus Torvalds 已提交
590 591
}

592 593 594 595 596 597 598 599
void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0,
		      unsigned long thread_info_flags)
{
	if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
		do_signal(regs, orig_i0);
	if (thread_info_flags & _TIF_NOTIFY_RESUME) {
		clear_thread_flag(TIF_NOTIFY_RESUME);
		tracehook_notify_resume(regs);
600 601
		if (current->replacement_session_keyring)
			key_replace_session_keyring();
602 603 604
	}
}

L
Linus Torvalds 已提交
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
asmlinkage int
do_sys_sigstack(struct sigstack __user *ssptr, struct sigstack __user *ossptr,
		unsigned long sp)
{
	int ret = -EFAULT;

	/* First see if old state is wanted. */
	if (ossptr) {
		if (put_user(current->sas_ss_sp + current->sas_ss_size,
			     &ossptr->the_stack) ||
		    __put_user(on_sig_stack(sp), &ossptr->cur_status))
			goto out;
	}

	/* Now see if we want to update the new state. */
	if (ssptr) {
		char *ss_sp;

		if (get_user(ss_sp, &ssptr->the_stack))
			goto out;
		/* If the current stack was set with sigaltstack, don't
		   swap stacks while we are on it.  */
		ret = -EPERM;
		if (current->sas_ss_sp && on_sig_stack(sp))
			goto out;

		/* Since we don't know the extent of the stack, and we don't
		   track onstack-ness, but rather calculate it, we must
		   presume a size.  Ho hum this interface is lossy.  */
		current->sas_ss_sp = (unsigned long)ss_sp - SIGSTKSZ;
		current->sas_ss_size = SIGSTKSZ;
	}
	ret = 0;
out:
	return ret;
}