Blame view

arch/alpha/kernel/signal.c 17.4 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  /*
   *  linux/arch/alpha/kernel/signal.c
   *
   *  Copyright (C) 1995  Linus Torvalds
   *
   *  1997-11-02  Modified for POSIX.1b signals by Richard Henderson
   */
  
  #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/smp.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
19
20
21
  #include <linux/stddef.h>
  #include <linux/tty.h>
  #include <linux/binfmts.h>
  #include <linux/bitops.h>
e5d9a90c3   Ivan Kokshaysky   alpha: use syscal...
22
  #include <linux/syscalls.h>
733e5e4b4   David Howells   KEYS: Add missing...
23
  #include <linux/tracehook.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
26
27
28
29
30
31
32
33
34
35
36
  
  #include <asm/uaccess.h>
  #include <asm/sigcontext.h>
  #include <asm/ucontext.h>
  
  #include "proto.h"
  
  
  #define DEBUG_SIG 0
  
  #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  
  asmlinkage void ret_from_sys_call(void);
b927b3e2c   Richard Henderson   alpha: support ne...
37
38
  static void do_signal(struct pt_regs *, struct switch_stack *,
  		      unsigned long, unsigned long);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
40
41
42
43
  
  
  /*
   * The OSF/1 sigprocmask calling sequence is different from the
   * C sigprocmask() sequence..
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
   */
c52c2ddc1   Al Viro   alpha: switch osf...
45
  SYSCALL_DEFINE2(osf_sigprocmask, int, how, unsigned long, newmask)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
  {
c52c2ddc1   Al Viro   alpha: switch osf...
47
48
49
  	sigset_t oldmask;
  	sigset_t mask;
  	unsigned long res;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50

87400e540   Linus Torvalds   Fix up more fallo...
51
  	siginitset(&mask, newmask & _BLOCKABLE);
0f44fbd29   Linus Torvalds   alpha: fix compil...
52
  	res = sigprocmask(how, &mask, &oldmask);
c52c2ddc1   Al Viro   alpha: switch osf...
53
54
  	if (!res) {
  		force_successful_syscall_return();
0f44fbd29   Linus Torvalds   alpha: fix compil...
55
  		res = oldmask.sig[0];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56
  	}
c52c2ddc1   Al Viro   alpha: switch osf...
57
  	return res;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
58
  }
e5d9a90c3   Ivan Kokshaysky   alpha: use syscal...
59
60
61
  SYSCALL_DEFINE3(osf_sigaction, int, sig,
  		const struct osf_sigaction __user *, act,
  		struct osf_sigaction __user *, oact)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62
63
64
65
66
67
68
69
  {
  	struct k_sigaction new_ka, old_ka;
  	int ret;
  
  	if (act) {
  		old_sigset_t mask;
  		if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  		    __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
18e6bfa96   Al Viro   alpha: __get_user...
70
71
  		    __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
  		    __get_user(mask, &act->sa_mask))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
  			return -EFAULT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
74
75
76
77
78
79
80
81
  		siginitset(&new_ka.sa.sa_mask, mask);
  		new_ka.ka_restorer = NULL;
  	}
  
  	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  
  	if (!ret && oact) {
  		if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  		    __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
18e6bfa96   Al Viro   alpha: __get_user...
82
83
  		    __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
  		    __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
84
  			return -EFAULT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
86
87
88
  	}
  
  	return ret;
  }
e5d9a90c3   Ivan Kokshaysky   alpha: use syscal...
89
90
91
  SYSCALL_DEFINE5(rt_sigaction, int, sig, const struct sigaction __user *, act,
  		struct sigaction __user *, oact,
  		size_t, sigsetsize, void __user *, restorer)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  {
  	struct k_sigaction new_ka, old_ka;
  	int ret;
  
  	/* XXX: Don't preclude handling different sized sigset_t's.  */
  	if (sigsetsize != sizeof(sigset_t))
  		return -EINVAL;
  
  	if (act) {
  		new_ka.ka_restorer = restorer;
  		if (copy_from_user(&new_ka.sa, act, sizeof(*act)))
  			return -EFAULT;
  	}
  
  	ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  
  	if (!ret && oact) {
  		if (copy_to_user(oact, &old_ka.sa, sizeof(*oact)))
  			return -EFAULT;
  	}
  
  	return ret;
  }
  
  /*
   * Atomically swap in the new signal mask, and wait for a signal.
   */
392fb6e35   Al Viro   alpha: unb0rk sig...
119
  SYSCALL_DEFINE1(sigsuspend, old_sigset_t, mask)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121
122
  	mask &= _BLOCKABLE;
  	spin_lock_irq(&current->sighand->siglock);
b927b3e2c   Richard Henderson   alpha: support ne...
123
  	current->saved_sigmask = current->blocked;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
124
125
126
  	siginitset(&current->blocked, mask);
  	recalc_sigpending();
  	spin_unlock_irq(&current->sighand->siglock);
b927b3e2c   Richard Henderson   alpha: support ne...
127
128
129
130
  	current->state = TASK_INTERRUPTIBLE;
  	schedule();
  	set_thread_flag(TIF_RESTORE_SIGMASK);
  	return -ERESTARTNOHAND;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
  }
  
  asmlinkage int
  sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
  {
  	return do_sigaltstack(uss, uoss, rdusp());
  }
  
  /*
   * Do a signal return; undo the signal stack.
   */
  
  #if _NSIG_WORDS > 1
  # error "Non SA_SIGINFO frame needs rearranging"
  #endif
  
  struct sigframe
  {
  	struct sigcontext sc;
  	unsigned int retcode[3];
  };
  
  struct rt_sigframe
  {
  	struct siginfo info;
  	struct ucontext uc;
  	unsigned int retcode[3];
  };
  
  /* If this changes, userland unwinders that Know Things about our signal
     frame will break.  Do not undertake lightly.  It also implies an ABI
     change wrt the size of siginfo_t, which may cause some pain.  */
  extern char compile_time_assert
          [offsetof(struct rt_sigframe, uc.uc_mcontext) == 176 ? 1 : -1];
  
  #define INSN_MOV_R30_R16	0x47fe0410
  #define INSN_LDI_R0		0x201f0000
  #define INSN_CALLSYS		0x00000083
  
  static long
  restore_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
  		   struct switch_stack *sw)
  {
  	unsigned long usp;
  	long i, err = __get_user(regs->pc, &sc->sc_pc);
2deba1bd7   Al Viro   alpha: belated ER...
176
  	current_thread_info()->restart_block.fn = do_no_restart_syscall;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
  	sw->r26 = (unsigned long) ret_from_sys_call;
  
  	err |= __get_user(regs->r0, sc->sc_regs+0);
  	err |= __get_user(regs->r1, sc->sc_regs+1);
  	err |= __get_user(regs->r2, sc->sc_regs+2);
  	err |= __get_user(regs->r3, sc->sc_regs+3);
  	err |= __get_user(regs->r4, sc->sc_regs+4);
  	err |= __get_user(regs->r5, sc->sc_regs+5);
  	err |= __get_user(regs->r6, sc->sc_regs+6);
  	err |= __get_user(regs->r7, sc->sc_regs+7);
  	err |= __get_user(regs->r8, sc->sc_regs+8);
  	err |= __get_user(sw->r9, sc->sc_regs+9);
  	err |= __get_user(sw->r10, sc->sc_regs+10);
  	err |= __get_user(sw->r11, sc->sc_regs+11);
  	err |= __get_user(sw->r12, sc->sc_regs+12);
  	err |= __get_user(sw->r13, sc->sc_regs+13);
  	err |= __get_user(sw->r14, sc->sc_regs+14);
  	err |= __get_user(sw->r15, sc->sc_regs+15);
  	err |= __get_user(regs->r16, sc->sc_regs+16);
  	err |= __get_user(regs->r17, sc->sc_regs+17);
  	err |= __get_user(regs->r18, sc->sc_regs+18);
  	err |= __get_user(regs->r19, sc->sc_regs+19);
  	err |= __get_user(regs->r20, sc->sc_regs+20);
  	err |= __get_user(regs->r21, sc->sc_regs+21);
  	err |= __get_user(regs->r22, sc->sc_regs+22);
  	err |= __get_user(regs->r23, sc->sc_regs+23);
  	err |= __get_user(regs->r24, sc->sc_regs+24);
  	err |= __get_user(regs->r25, sc->sc_regs+25);
  	err |= __get_user(regs->r26, sc->sc_regs+26);
  	err |= __get_user(regs->r27, sc->sc_regs+27);
  	err |= __get_user(regs->r28, sc->sc_regs+28);
  	err |= __get_user(regs->gp, sc->sc_regs+29);
  	err |= __get_user(usp, sc->sc_regs+30);
  	wrusp(usp);
  
  	for (i = 0; i < 31; i++)
  		err |= __get_user(sw->fp[i], sc->sc_fpregs+i);
  	err |= __get_user(sw->fp[31], &sc->sc_fpcr);
  
  	return err;
  }
  
  /* Note that this syscall is also used by setcontext(3) to install
     a given sigcontext.  This because it's impossible to set *all*
     registers and transfer control from userland.  */
  
  asmlinkage void
  do_sigreturn(struct sigcontext __user *sc, struct pt_regs *regs,
  	     struct switch_stack *sw)
  {
  	sigset_t set;
  
  	/* Verify that it's a good sigcontext before using it */
  	if (!access_ok(VERIFY_READ, sc, sizeof(*sc)))
  		goto give_sigsegv;
  	if (__get_user(set.sig[0], &sc->sc_mask))
  		goto give_sigsegv;
  
  	sigdelsetmask(&set, ~_BLOCKABLE);
  	spin_lock_irq(&current->sighand->siglock);
  	current->blocked = set;
  	recalc_sigpending();
  	spin_unlock_irq(&current->sighand->siglock);
  
  	if (restore_sigcontext(sc, regs, sw))
  		goto give_sigsegv;
  
  	/* Send SIGTRAP if we're single-stepping: */
  	if (ptrace_cancel_bpt (current)) {
  		siginfo_t info;
  
  		info.si_signo = SIGTRAP;
  		info.si_errno = 0;
  		info.si_code = TRAP_BRKPT;
  		info.si_addr = (void __user *) regs->pc;
  		info.si_trapno = 0;
  		send_sig_info(SIGTRAP, &info, current);
  	}
  	return;
  
  give_sigsegv:
  	force_sig(SIGSEGV, current);
  }
  
  asmlinkage void
  do_rt_sigreturn(struct rt_sigframe __user *frame, struct pt_regs *regs,
  		struct switch_stack *sw)
  {
  	sigset_t set;
  
  	/* Verify that it's a good ucontext_t before using it */
  	if (!access_ok(VERIFY_READ, &frame->uc, sizeof(frame->uc)))
  		goto give_sigsegv;
  	if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
  		goto give_sigsegv;
  
  	sigdelsetmask(&set, ~_BLOCKABLE);
  	spin_lock_irq(&current->sighand->siglock);
  	current->blocked = set;
  	recalc_sigpending();
  	spin_unlock_irq(&current->sighand->siglock);
  
  	if (restore_sigcontext(&frame->uc.uc_mcontext, regs, sw))
  		goto give_sigsegv;
  
  	/* Send SIGTRAP if we're single-stepping: */
  	if (ptrace_cancel_bpt (current)) {
  		siginfo_t info;
  
  		info.si_signo = SIGTRAP;
  		info.si_errno = 0;
  		info.si_code = TRAP_BRKPT;
  		info.si_addr = (void __user *) regs->pc;
  		info.si_trapno = 0;
  		send_sig_info(SIGTRAP, &info, current);
  	}
  	return;
  
  give_sigsegv:
  	force_sig(SIGSEGV, current);
  }
  
  
  /*
   * Set up a signal frame.
   */
  
  static inline void __user *
  get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
  {
d09042da7   Laurent MEYER   [PATCH] fix incor...
307
  	if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! sas_ss_flags(sp))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
308
309
310
311
312
313
314
315
316
317
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
  		sp = current->sas_ss_sp + current->sas_ss_size;
  
  	return (void __user *)((sp - frame_size) & -32ul);
  }
  
  static long
  setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, 
  		 struct switch_stack *sw, unsigned long mask, unsigned long sp)
  {
  	long i, err = 0;
  
  	err |= __put_user(on_sig_stack((unsigned long)sc), &sc->sc_onstack);
  	err |= __put_user(mask, &sc->sc_mask);
  	err |= __put_user(regs->pc, &sc->sc_pc);
  	err |= __put_user(8, &sc->sc_ps);
  
  	err |= __put_user(regs->r0 , sc->sc_regs+0);
  	err |= __put_user(regs->r1 , sc->sc_regs+1);
  	err |= __put_user(regs->r2 , sc->sc_regs+2);
  	err |= __put_user(regs->r3 , sc->sc_regs+3);
  	err |= __put_user(regs->r4 , sc->sc_regs+4);
  	err |= __put_user(regs->r5 , sc->sc_regs+5);
  	err |= __put_user(regs->r6 , sc->sc_regs+6);
  	err |= __put_user(regs->r7 , sc->sc_regs+7);
  	err |= __put_user(regs->r8 , sc->sc_regs+8);
  	err |= __put_user(sw->r9   , sc->sc_regs+9);
  	err |= __put_user(sw->r10  , sc->sc_regs+10);
  	err |= __put_user(sw->r11  , sc->sc_regs+11);
  	err |= __put_user(sw->r12  , sc->sc_regs+12);
  	err |= __put_user(sw->r13  , sc->sc_regs+13);
  	err |= __put_user(sw->r14  , sc->sc_regs+14);
  	err |= __put_user(sw->r15  , sc->sc_regs+15);
  	err |= __put_user(regs->r16, sc->sc_regs+16);
  	err |= __put_user(regs->r17, sc->sc_regs+17);
  	err |= __put_user(regs->r18, sc->sc_regs+18);
  	err |= __put_user(regs->r19, sc->sc_regs+19);
  	err |= __put_user(regs->r20, sc->sc_regs+20);
  	err |= __put_user(regs->r21, sc->sc_regs+21);
  	err |= __put_user(regs->r22, sc->sc_regs+22);
  	err |= __put_user(regs->r23, sc->sc_regs+23);
  	err |= __put_user(regs->r24, sc->sc_regs+24);
  	err |= __put_user(regs->r25, sc->sc_regs+25);
  	err |= __put_user(regs->r26, sc->sc_regs+26);
  	err |= __put_user(regs->r27, sc->sc_regs+27);
  	err |= __put_user(regs->r28, sc->sc_regs+28);
  	err |= __put_user(regs->gp , sc->sc_regs+29);
  	err |= __put_user(sp, sc->sc_regs+30);
  	err |= __put_user(0, sc->sc_regs+31);
  
  	for (i = 0; i < 31; i++)
  		err |= __put_user(sw->fp[i], sc->sc_fpregs+i);
  	err |= __put_user(0, sc->sc_fpregs+31);
  	err |= __put_user(sw->fp[31], &sc->sc_fpcr);
  
  	err |= __put_user(regs->trap_a0, &sc->sc_traparg_a0);
  	err |= __put_user(regs->trap_a1, &sc->sc_traparg_a1);
  	err |= __put_user(regs->trap_a2, &sc->sc_traparg_a2);
  
  	return err;
  }
b927b3e2c   Richard Henderson   alpha: support ne...
368
  static int
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
  setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
  	    struct pt_regs *regs, struct switch_stack * sw)
  {
  	unsigned long oldsp, r26, err = 0;
  	struct sigframe __user *frame;
  
  	oldsp = rdusp();
  	frame = get_sigframe(ka, oldsp, sizeof(*frame));
  	if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  		goto give_sigsegv;
  
  	err |= setup_sigcontext(&frame->sc, regs, sw, set->sig[0], oldsp);
  	if (err)
  		goto give_sigsegv;
  
  	/* Set up to return from userspace.  If provided, use a stub
  	   already in userspace.  */
  	if (ka->ka_restorer) {
  		r26 = (unsigned long) ka->ka_restorer;
  	} else {
  		err |= __put_user(INSN_MOV_R30_R16, frame->retcode+0);
  		err |= __put_user(INSN_LDI_R0+__NR_sigreturn, frame->retcode+1);
  		err |= __put_user(INSN_CALLSYS, frame->retcode+2);
  		imb();
  		r26 = (unsigned long) frame->retcode;
  	}
  
  	/* Check that everything was written properly.  */
  	if (err)
  		goto give_sigsegv;
  
  	/* "Return" to the handler */
  	regs->r26 = r26;
  	regs->r27 = regs->pc = (unsigned long) ka->sa.sa_handler;
  	regs->r16 = sig;			/* a0: signal number */
  	regs->r17 = 0;				/* a1: exception code */
  	regs->r18 = (unsigned long) &frame->sc;	/* a2: sigcontext pointer */
  	wrusp((unsigned long) frame);
  	
  #if DEBUG_SIG
  	printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p
  ",
  		current->comm, current->pid, frame, regs->pc, regs->r26);
  #endif
b927b3e2c   Richard Henderson   alpha: support ne...
413
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
414
415
416
  
  give_sigsegv:
  	force_sigsegv(sig, current);
b927b3e2c   Richard Henderson   alpha: support ne...
417
  	return -EFAULT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
418
  }
b927b3e2c   Richard Henderson   alpha: support ne...
419
  static int
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
420
421
422
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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
  setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
  	       sigset_t *set, struct pt_regs *regs, struct switch_stack * sw)
  {
  	unsigned long oldsp, r26, err = 0;
  	struct rt_sigframe __user *frame;
  
  	oldsp = rdusp();
  	frame = get_sigframe(ka, oldsp, sizeof(*frame));
  	if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  		goto give_sigsegv;
  
  	err |= copy_siginfo_to_user(&frame->info, info);
  
  	/* Create the ucontext.  */
  	err |= __put_user(0, &frame->uc.uc_flags);
  	err |= __put_user(0, &frame->uc.uc_link);
  	err |= __put_user(set->sig[0], &frame->uc.uc_osf_sigmask);
  	err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
  	err |= __put_user(sas_ss_flags(oldsp), &frame->uc.uc_stack.ss_flags);
  	err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
  	err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, sw,
  				set->sig[0], oldsp);
  	err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
  	if (err)
  		goto give_sigsegv;
  
  	/* Set up to return from userspace.  If provided, use a stub
  	   already in userspace.  */
  	if (ka->ka_restorer) {
  		r26 = (unsigned long) ka->ka_restorer;
  	} else {
  		err |= __put_user(INSN_MOV_R30_R16, frame->retcode+0);
  		err |= __put_user(INSN_LDI_R0+__NR_rt_sigreturn,
  				  frame->retcode+1);
  		err |= __put_user(INSN_CALLSYS, frame->retcode+2);
  		imb();
  		r26 = (unsigned long) frame->retcode;
  	}
  
  	if (err)
  		goto give_sigsegv;
  
  	/* "Return" to the handler */
  	regs->r26 = r26;
  	regs->r27 = regs->pc = (unsigned long) ka->sa.sa_handler;
  	regs->r16 = sig;			  /* a0: signal number */
  	regs->r17 = (unsigned long) &frame->info; /* a1: siginfo pointer */
  	regs->r18 = (unsigned long) &frame->uc;	  /* a2: ucontext pointer */
  	wrusp((unsigned long) frame);
  
  #if DEBUG_SIG
  	printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p
  ",
  		current->comm, current->pid, frame, regs->pc, regs->r26);
  #endif
b927b3e2c   Richard Henderson   alpha: support ne...
475
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
476
477
478
  
  give_sigsegv:
  	force_sigsegv(sig, current);
b927b3e2c   Richard Henderson   alpha: support ne...
479
  	return -EFAULT;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
480
481
482
483
484
485
  }
  
  
  /*
   * OK, we're invoking a handler.
   */
b927b3e2c   Richard Henderson   alpha: support ne...
486
  static inline int
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
487
488
489
  handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
  	      sigset_t *oldset, struct pt_regs * regs, struct switch_stack *sw)
  {
b927b3e2c   Richard Henderson   alpha: support ne...
490
  	int ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
491
  	if (ka->sa.sa_flags & SA_SIGINFO)
b927b3e2c   Richard Henderson   alpha: support ne...
492
  		ret = setup_rt_frame(sig, ka, info, oldset, regs, sw);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
493
  	else
b927b3e2c   Richard Henderson   alpha: support ne...
494
  		ret = setup_frame(sig, ka, oldset, regs, sw);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
495

b927b3e2c   Richard Henderson   alpha: support ne...
496
497
498
499
500
501
502
503
  	if (ret == 0) {
  		spin_lock_irq(&current->sighand->siglock);
  		sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
  		if (!(ka->sa.sa_flags & SA_NODEFER)) 
  			sigaddset(&current->blocked,sig);
  		recalc_sigpending();
  		spin_unlock_irq(&current->sighand->siglock);
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
504

b927b3e2c   Richard Henderson   alpha: support ne...
505
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
  }
  
  static inline void
  syscall_restart(unsigned long r0, unsigned long r19,
  		struct pt_regs *regs, struct k_sigaction *ka)
  {
  	switch (regs->r0) {
  	case ERESTARTSYS:
  		if (!(ka->sa.sa_flags & SA_RESTART)) {
  		case ERESTARTNOHAND:
  			regs->r0 = EINTR;
  			break;
  		}
  		/* fallthrough */
  	case ERESTARTNOINTR:
  		regs->r0 = r0;	/* reset v0 and a3 and replay syscall */
  		regs->r19 = r19;
  		regs->pc -= 4;
  		break;
  	case ERESTART_RESTARTBLOCK:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
  		regs->r0 = EINTR;
  		break;
  	}
  }
  
  
  /*
   * 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.
   *
   * Note that we go through the signals twice: once to check the signals that
   * the kernel can handle, and then we build all the user-level signal handling
   * stack-frames in one go after that.
   *
   * "r0" and "r19" are the registers we need to restore for system call
   * restart. "r0" is also used as an indicator whether we can restart at
   * all (if we get here from anything but a syscall return, it will be 0)
   */
b927b3e2c   Richard Henderson   alpha: support ne...
545
546
  static void
  do_signal(struct pt_regs * regs, struct switch_stack * sw,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
547
548
549
550
551
552
  	  unsigned long r0, unsigned long r19)
  {
  	siginfo_t info;
  	int signr;
  	unsigned long single_stepping = ptrace_cancel_bpt(current);
  	struct k_sigaction ka;
b927b3e2c   Richard Henderson   alpha: support ne...
553
  	sigset_t *oldset;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
554

b927b3e2c   Richard Henderson   alpha: support ne...
555
556
557
  	if (test_thread_flag(TIF_RESTORE_SIGMASK))
  		oldset = &current->saved_sigmask;
  	else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
558
559
560
561
  		oldset = &current->blocked;
  
  	/* This lets the debugger run, ... */
  	signr = get_signal_to_deliver(&info, &ka, regs, NULL);
b927b3e2c   Richard Henderson   alpha: support ne...
562

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
563
564
565
566
567
  	/* ... so re-check the single stepping. */
  	single_stepping |= ptrace_cancel_bpt(current);
  
  	if (signr > 0) {
  		/* Whee!  Actually deliver the signal.  */
b927b3e2c   Richard Henderson   alpha: support ne...
568
569
570
571
572
573
574
575
576
577
  		if (r0)
  			syscall_restart(r0, r19, regs, &ka);
  		if (handle_signal(signr, &ka, &info, oldset, regs, sw) == 0) {
  			/* A signal was successfully delivered, and the
  			   saved sigmask was stored on the signal frame,
  			   and will be restored by sigreturn.  So we can
  			   simply clear the restore sigmask flag.  */
  			if (test_thread_flag(TIF_RESTORE_SIGMASK))
  				clear_thread_flag(TIF_RESTORE_SIGMASK);
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
578
579
  		if (single_stepping) 
  			ptrace_set_bpt(current); /* re-set bpt */
b927b3e2c   Richard Henderson   alpha: support ne...
580
  		return;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
  	}
  
  	if (r0) {
  	  	switch (regs->r0) {
  		case ERESTARTNOHAND:
  		case ERESTARTSYS:
  		case ERESTARTNOINTR:
  			/* Reset v0 and a3 and replay syscall.  */
  			regs->r0 = r0;
  			regs->r19 = r19;
  			regs->pc -= 4;
  			break;
  		case ERESTART_RESTARTBLOCK:
  			/* Force v0 to the restart syscall and reply.  */
  			regs->r0 = __NR_restart_syscall;
  			regs->pc -= 4;
  			break;
  		}
  	}
b927b3e2c   Richard Henderson   alpha: support ne...
600
601
602
603
604
605
  
  	/* If there's no signal to deliver, we just restore the saved mask.  */
  	if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
  		clear_thread_flag(TIF_RESTORE_SIGMASK);
  		sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
606
607
  	if (single_stepping)
  		ptrace_set_bpt(current);	/* re-set breakpoint */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
608
609
610
  }
  
  void
b927b3e2c   Richard Henderson   alpha: support ne...
611
612
613
  do_notify_resume(struct pt_regs *regs, struct switch_stack *sw,
  		 unsigned long thread_info_flags,
  		 unsigned long r0, unsigned long r19)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
614
  {
b927b3e2c   Richard Henderson   alpha: support ne...
615
616
  	if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
  		do_signal(regs, sw, r0, r19);
d0420c83f   David Howells   KEYS: Extend TIF_...
617
618
619
620
  
  	if (thread_info_flags & _TIF_NOTIFY_RESUME) {
  		clear_thread_flag(TIF_NOTIFY_RESUME);
  		tracehook_notify_resume(regs);
ee18d64c1   David Howells   KEYS: Add a keyct...
621
622
  		if (current->replacement_session_keyring)
  			key_replace_session_keyring();
d0420c83f   David Howells   KEYS: Extend TIF_...
623
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
624
  }