blob: 0bb4a8f94276ea80c1d7b3731d3c2ce08c13816e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * arch/sh64/kernel/signal.c
7 *
8 * Copyright (C) 2000, 2001 Paolo Alberelli
9 * Copyright (C) 2003 Paul Mundt
10 * Copyright (C) 2004 Richard Curnow
11 *
12 * Started from sh version.
13 *
14 */
15#include <linux/rwsem.h>
16#include <linux/sched.h>
17#include <linux/mm.h>
18#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/kernel.h>
20#include <linux/signal.h>
21#include <linux/errno.h>
22#include <linux/wait.h>
23#include <linux/personality.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080024#include <linux/freezer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/ptrace.h>
26#include <linux/unistd.h>
27#include <linux/stddef.h>
28#include <linux/personality.h>
29#include <asm/ucontext.h>
30#include <asm/uaccess.h>
31#include <asm/pgtable.h>
32
33
34#define REG_RET 9
35#define REG_ARG1 2
36#define REG_ARG2 3
37#define REG_ARG3 4
38#define REG_SP 15
39#define REG_PR 18
40#define REF_REG_RET regs->regs[REG_RET]
41#define REF_REG_SP regs->regs[REG_SP]
42#define DEREF_REG_PR regs->regs[REG_PR]
43
44#define DEBUG_SIG 0
45
46#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
47
48asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset);
49
50/*
51 * Atomically swap in the new signal mask, and wait for a signal.
52 */
53
54asmlinkage int
55sys_sigsuspend(old_sigset_t mask,
56 unsigned long r3, unsigned long r4, unsigned long r5,
57 unsigned long r6, unsigned long r7,
58 struct pt_regs * regs)
59{
60 sigset_t saveset;
61
62 mask &= _BLOCKABLE;
63 spin_lock_irq(&current->sighand->siglock);
64 saveset = current->blocked;
65 siginitset(&current->blocked, mask);
66 recalc_sigpending();
67 spin_unlock_irq(&current->sighand->siglock);
68
69 REF_REG_RET = -EINTR;
70 while (1) {
71 current->state = TASK_INTERRUPTIBLE;
72 schedule();
73 regs->pc += 4; /* because sys_sigreturn decrements the pc */
74 if (do_signal(regs, &saveset)) {
75 /* pc now points at signal handler. Need to decrement
76 it because entry.S will increment it. */
77 regs->pc -= 4;
78 return -EINTR;
79 }
80 }
81}
82
83asmlinkage int
84sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize,
85 unsigned long r4, unsigned long r5, unsigned long r6,
86 unsigned long r7,
87 struct pt_regs * regs)
88{
89 sigset_t saveset, newset;
90
91 /* XXX: Don't preclude handling different sized sigset_t's. */
92 if (sigsetsize != sizeof(sigset_t))
93 return -EINVAL;
94
95 if (copy_from_user(&newset, unewset, sizeof(newset)))
96 return -EFAULT;
97 sigdelsetmask(&newset, ~_BLOCKABLE);
98 spin_lock_irq(&current->sighand->siglock);
99 saveset = current->blocked;
100 current->blocked = newset;
101 recalc_sigpending();
102 spin_unlock_irq(&current->sighand->siglock);
103
104 REF_REG_RET = -EINTR;
105 while (1) {
106 current->state = TASK_INTERRUPTIBLE;
107 schedule();
108 regs->pc += 4; /* because sys_sigreturn decrements the pc */
109 if (do_signal(regs, &saveset)) {
110 /* pc now points at signal handler. Need to decrement
111 it because entry.S will increment it. */
112 regs->pc -= 4;
113 return -EINTR;
114 }
115 }
116}
117
118asmlinkage int
119sys_sigaction(int sig, const struct old_sigaction __user *act,
120 struct old_sigaction __user *oact)
121{
122 struct k_sigaction new_ka, old_ka;
123 int ret;
124
125 if (act) {
126 old_sigset_t mask;
127 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
128 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
129 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
130 return -EFAULT;
131 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
132 __get_user(mask, &act->sa_mask);
133 siginitset(&new_ka.sa.sa_mask, mask);
134 }
135
136 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
137
138 if (!ret && oact) {
139 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
140 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
141 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
142 return -EFAULT;
143 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
144 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
145 }
146
147 return ret;
148}
149
150asmlinkage int
151sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
152 unsigned long r4, unsigned long r5, unsigned long r6,
153 unsigned long r7,
154 struct pt_regs * regs)
155{
156 return do_sigaltstack(uss, uoss, REF_REG_SP);
157}
158
159
160/*
161 * Do a signal return; undo the signal stack.
162 */
163
164struct sigframe
165{
166 struct sigcontext sc;
167 unsigned long extramask[_NSIG_WORDS-1];
168 long long retcode[2];
169};
170
171struct rt_sigframe
172{
173 struct siginfo __user *pinfo;
174 void *puc;
175 struct siginfo info;
176 struct ucontext uc;
177 long long retcode[2];
178};
179
180#ifdef CONFIG_SH_FPU
181static inline int
182restore_sigcontext_fpu(struct pt_regs *regs, struct sigcontext __user *sc)
183{
184 int err = 0;
185 int fpvalid;
186
187 err |= __get_user (fpvalid, &sc->sc_fpvalid);
188 conditional_used_math(fpvalid);
189 if (! fpvalid)
190 return err;
191
192 if (current == last_task_used_math) {
193 last_task_used_math = NULL;
194 regs->sr |= SR_FD;
195 }
196
197 err |= __copy_from_user(&current->thread.fpu.hard, &sc->sc_fpregs[0],
198 (sizeof(long long) * 32) + (sizeof(int) * 1));
199
200 return err;
201}
202
203static inline int
204setup_sigcontext_fpu(struct pt_regs *regs, struct sigcontext __user *sc)
205{
206 int err = 0;
207 int fpvalid;
208
209 fpvalid = !!used_math();
210 err |= __put_user(fpvalid, &sc->sc_fpvalid);
211 if (! fpvalid)
212 return err;
213
214 if (current == last_task_used_math) {
215 grab_fpu();
216 fpsave(&current->thread.fpu.hard);
217 release_fpu();
218 last_task_used_math = NULL;
219 regs->sr |= SR_FD;
220 }
221
222 err |= __copy_to_user(&sc->sc_fpregs[0], &current->thread.fpu.hard,
223 (sizeof(long long) * 32) + (sizeof(int) * 1));
224 clear_used_math();
225
226 return err;
227}
228#else
229static inline int
230restore_sigcontext_fpu(struct pt_regs *regs, struct sigcontext __user *sc)
231{}
232static inline int
233setup_sigcontext_fpu(struct pt_regs *regs, struct sigcontext __user *sc)
234{}
235#endif
236
237static int
238restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, long long *r2_p)
239{
240 unsigned int err = 0;
241 unsigned long long current_sr, new_sr;
242#define SR_MASK 0xffff8cfd
243
244#define COPY(x) err |= __get_user(regs->x, &sc->sc_##x)
245
246 COPY(regs[0]); COPY(regs[1]); COPY(regs[2]); COPY(regs[3]);
247 COPY(regs[4]); COPY(regs[5]); COPY(regs[6]); COPY(regs[7]);
248 COPY(regs[8]); COPY(regs[9]); COPY(regs[10]); COPY(regs[11]);
249 COPY(regs[12]); COPY(regs[13]); COPY(regs[14]); COPY(regs[15]);
250 COPY(regs[16]); COPY(regs[17]); COPY(regs[18]); COPY(regs[19]);
251 COPY(regs[20]); COPY(regs[21]); COPY(regs[22]); COPY(regs[23]);
252 COPY(regs[24]); COPY(regs[25]); COPY(regs[26]); COPY(regs[27]);
253 COPY(regs[28]); COPY(regs[29]); COPY(regs[30]); COPY(regs[31]);
254 COPY(regs[32]); COPY(regs[33]); COPY(regs[34]); COPY(regs[35]);
255 COPY(regs[36]); COPY(regs[37]); COPY(regs[38]); COPY(regs[39]);
256 COPY(regs[40]); COPY(regs[41]); COPY(regs[42]); COPY(regs[43]);
257 COPY(regs[44]); COPY(regs[45]); COPY(regs[46]); COPY(regs[47]);
258 COPY(regs[48]); COPY(regs[49]); COPY(regs[50]); COPY(regs[51]);
259 COPY(regs[52]); COPY(regs[53]); COPY(regs[54]); COPY(regs[55]);
260 COPY(regs[56]); COPY(regs[57]); COPY(regs[58]); COPY(regs[59]);
261 COPY(regs[60]); COPY(regs[61]); COPY(regs[62]);
262 COPY(tregs[0]); COPY(tregs[1]); COPY(tregs[2]); COPY(tregs[3]);
263 COPY(tregs[4]); COPY(tregs[5]); COPY(tregs[6]); COPY(tregs[7]);
264
265 /* Prevent the signal handler manipulating SR in a way that can
266 crash the kernel. i.e. only allow S, Q, M, PR, SZ, FR to be
267 modified */
268 current_sr = regs->sr;
269 err |= __get_user(new_sr, &sc->sc_sr);
270 regs->sr &= SR_MASK;
271 regs->sr |= (new_sr & ~SR_MASK);
272
273 COPY(pc);
274
275#undef COPY
276
277 /* Must do this last in case it sets regs->sr.fd (i.e. after rest of sr
278 * has been restored above.) */
279 err |= restore_sigcontext_fpu(regs, sc);
280
281 regs->syscall_nr = -1; /* disable syscall checks */
282 err |= __get_user(*r2_p, &sc->sc_regs[REG_RET]);
283 return err;
284}
285
286asmlinkage int sys_sigreturn(unsigned long r2, unsigned long r3,
287 unsigned long r4, unsigned long r5,
288 unsigned long r6, unsigned long r7,
289 struct pt_regs * regs)
290{
291 struct sigframe __user *frame = (struct sigframe __user *) (long) REF_REG_SP;
292 sigset_t set;
293 long long ret;
294
295 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
296 goto badframe;
297
298 if (__get_user(set.sig[0], &frame->sc.oldmask)
299 || (_NSIG_WORDS > 1
300 && __copy_from_user(&set.sig[1], &frame->extramask,
301 sizeof(frame->extramask))))
302 goto badframe;
303
304 sigdelsetmask(&set, ~_BLOCKABLE);
305
306 spin_lock_irq(&current->sighand->siglock);
307 current->blocked = set;
308 recalc_sigpending();
309 spin_unlock_irq(&current->sighand->siglock);
310
311 if (restore_sigcontext(regs, &frame->sc, &ret))
312 goto badframe;
313 regs->pc -= 4;
314
315 return (int) ret;
316
317badframe:
318 force_sig(SIGSEGV, current);
319 return 0;
320}
321
322asmlinkage int sys_rt_sigreturn(unsigned long r2, unsigned long r3,
323 unsigned long r4, unsigned long r5,
324 unsigned long r6, unsigned long r7,
325 struct pt_regs * regs)
326{
327 struct rt_sigframe __user *frame = (struct rt_sigframe __user *) (long) REF_REG_SP;
328 sigset_t set;
329 stack_t __user st;
330 long long ret;
331
332 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
333 goto badframe;
334
335 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
336 goto badframe;
337
338 sigdelsetmask(&set, ~_BLOCKABLE);
339 spin_lock_irq(&current->sighand->siglock);
340 current->blocked = set;
341 recalc_sigpending();
342 spin_unlock_irq(&current->sighand->siglock);
343
344 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ret))
345 goto badframe;
346 regs->pc -= 4;
347
348 if (__copy_from_user(&st, &frame->uc.uc_stack, sizeof(st)))
349 goto badframe;
350 /* It is more difficult to avoid calling this function than to
351 call it and ignore errors. */
352 do_sigaltstack(&st, NULL, REF_REG_SP);
353
354 return (int) ret;
355
356badframe:
357 force_sig(SIGSEGV, current);
358 return 0;
359}
360
361/*
362 * Set up a signal frame.
363 */
364
365static int
366setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
367 unsigned long mask)
368{
369 int err = 0;
370
371 /* Do this first, otherwise is this sets sr->fd, that value isn't preserved. */
372 err |= setup_sigcontext_fpu(regs, sc);
373
374#define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
375
376 COPY(regs[0]); COPY(regs[1]); COPY(regs[2]); COPY(regs[3]);
377 COPY(regs[4]); COPY(regs[5]); COPY(regs[6]); COPY(regs[7]);
378 COPY(regs[8]); COPY(regs[9]); COPY(regs[10]); COPY(regs[11]);
379 COPY(regs[12]); COPY(regs[13]); COPY(regs[14]); COPY(regs[15]);
380 COPY(regs[16]); COPY(regs[17]); COPY(regs[18]); COPY(regs[19]);
381 COPY(regs[20]); COPY(regs[21]); COPY(regs[22]); COPY(regs[23]);
382 COPY(regs[24]); COPY(regs[25]); COPY(regs[26]); COPY(regs[27]);
383 COPY(regs[28]); COPY(regs[29]); COPY(regs[30]); COPY(regs[31]);
384 COPY(regs[32]); COPY(regs[33]); COPY(regs[34]); COPY(regs[35]);
385 COPY(regs[36]); COPY(regs[37]); COPY(regs[38]); COPY(regs[39]);
386 COPY(regs[40]); COPY(regs[41]); COPY(regs[42]); COPY(regs[43]);
387 COPY(regs[44]); COPY(regs[45]); COPY(regs[46]); COPY(regs[47]);
388 COPY(regs[48]); COPY(regs[49]); COPY(regs[50]); COPY(regs[51]);
389 COPY(regs[52]); COPY(regs[53]); COPY(regs[54]); COPY(regs[55]);
390 COPY(regs[56]); COPY(regs[57]); COPY(regs[58]); COPY(regs[59]);
391 COPY(regs[60]); COPY(regs[61]); COPY(regs[62]);
392 COPY(tregs[0]); COPY(tregs[1]); COPY(tregs[2]); COPY(tregs[3]);
393 COPY(tregs[4]); COPY(tregs[5]); COPY(tregs[6]); COPY(tregs[7]);
394 COPY(sr); COPY(pc);
395
396#undef COPY
397
398 err |= __put_user(mask, &sc->oldmask);
399
400 return err;
401}
402
403/*
404 * Determine which stack to use..
405 */
406static inline void __user *
407get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
408{
Laurent MEYERd09042d2006-06-23 02:05:36 -0700409 if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! sas_ss_flags(sp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 sp = current->sas_ss_sp + current->sas_ss_size;
411
412 return (void __user *)((sp - frame_size) & -8ul);
413}
414
415void sa_default_restorer(void); /* See comments below */
416void sa_default_rt_restorer(void); /* See comments below */
417
418static void setup_frame(int sig, struct k_sigaction *ka,
419 sigset_t *set, struct pt_regs *regs)
420{
421 struct sigframe __user *frame;
422 int err = 0;
423 int signal;
424
425 frame = get_sigframe(ka, regs->regs[REG_SP], sizeof(*frame));
426
427 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
428 goto give_sigsegv;
429
430 signal = current_thread_info()->exec_domain
431 && current_thread_info()->exec_domain->signal_invmap
432 && sig < 32
433 ? current_thread_info()->exec_domain->signal_invmap[sig]
434 : sig;
435
436 err |= setup_sigcontext(&frame->sc, regs, set->sig[0]);
437
438 /* Give up earlier as i386, in case */
439 if (err)
440 goto give_sigsegv;
441
442 if (_NSIG_WORDS > 1) {
443 err |= __copy_to_user(frame->extramask, &set->sig[1],
444 sizeof(frame->extramask)); }
445
446 /* Give up earlier as i386, in case */
447 if (err)
448 goto give_sigsegv;
449
450 /* Set up to return from userspace. If provided, use a stub
451 already in userspace. */
452 if (ka->sa.sa_flags & SA_RESTORER) {
453 DEREF_REG_PR = (unsigned long) ka->sa.sa_restorer | 0x1;
454
455 /*
456 * On SH5 all edited pointers are subject to NEFF
457 */
458 DEREF_REG_PR = (DEREF_REG_PR & NEFF_SIGN) ?
459 (DEREF_REG_PR | NEFF_MASK) : DEREF_REG_PR;
460 } else {
461 /*
462 * Different approach on SH5.
463 * . Endianness independent asm code gets placed in entry.S .
464 * This is limited to four ASM instructions corresponding
465 * to two long longs in size.
466 * . err checking is done on the else branch only
467 * . flush_icache_range() is called upon __put_user() only
468 * . all edited pointers are subject to NEFF
469 * . being code, linker turns ShMedia bit on, always
470 * dereference index -1.
471 */
472 DEREF_REG_PR = (unsigned long) frame->retcode | 0x01;
473 DEREF_REG_PR = (DEREF_REG_PR & NEFF_SIGN) ?
474 (DEREF_REG_PR | NEFF_MASK) : DEREF_REG_PR;
475
476 if (__copy_to_user(frame->retcode,
477 (unsigned long long)sa_default_restorer & (~1), 16) != 0)
478 goto give_sigsegv;
479
480 /* Cohere the trampoline with the I-cache. */
481 flush_cache_sigtramp(DEREF_REG_PR-1, DEREF_REG_PR-1+16);
482 }
483
484 /*
485 * Set up registers for signal handler.
486 * All edited pointers are subject to NEFF.
487 */
488 regs->regs[REG_SP] = (unsigned long) frame;
489 regs->regs[REG_SP] = (regs->regs[REG_SP] & NEFF_SIGN) ?
490 (regs->regs[REG_SP] | NEFF_MASK) : regs->regs[REG_SP];
491 regs->regs[REG_ARG1] = signal; /* Arg for signal handler */
492
493 /* FIXME:
494 The glibc profiling support for SH-5 needs to be passed a sigcontext
495 so it can retrieve the PC. At some point during 2003 the glibc
496 support was changed to receive the sigcontext through the 2nd
497 argument, but there are still versions of libc.so in use that use
498 the 3rd argument. Until libc.so is stabilised, pass the sigcontext
499 through both 2nd and 3rd arguments.
500 */
501
502 regs->regs[REG_ARG2] = (unsigned long long)(unsigned long)(signed long)&frame->sc;
503 regs->regs[REG_ARG3] = (unsigned long long)(unsigned long)(signed long)&frame->sc;
504
505 regs->pc = (unsigned long) ka->sa.sa_handler;
506 regs->pc = (regs->pc & NEFF_SIGN) ? (regs->pc | NEFF_MASK) : regs->pc;
507
508 set_fs(USER_DS);
509
510#if DEBUG_SIG
511 /* Broken %016Lx */
512 printk("SIG deliver (#%d,%s:%d): sp=%p pc=%08Lx%08Lx link=%08Lx%08Lx\n",
513 signal,
514 current->comm, current->pid, frame,
515 regs->pc >> 32, regs->pc & 0xffffffff,
516 DEREF_REG_PR >> 32, DEREF_REG_PR & 0xffffffff);
517#endif
518
519 return;
520
521give_sigsegv:
522 force_sigsegv(sig, current);
523}
524
525static void setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
526 sigset_t *set, struct pt_regs *regs)
527{
528 struct rt_sigframe __user *frame;
529 int err = 0;
530 int signal;
531
532 frame = get_sigframe(ka, regs->regs[REG_SP], sizeof(*frame));
533
534 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
535 goto give_sigsegv;
536
537 signal = current_thread_info()->exec_domain
538 && current_thread_info()->exec_domain->signal_invmap
539 && sig < 32
540 ? current_thread_info()->exec_domain->signal_invmap[sig]
541 : sig;
542
543 err |= __put_user(&frame->info, &frame->pinfo);
544 err |= __put_user(&frame->uc, &frame->puc);
545 err |= copy_siginfo_to_user(&frame->info, info);
546
547 /* Give up earlier as i386, in case */
548 if (err)
549 goto give_sigsegv;
550
551 /* Create the ucontext. */
552 err |= __put_user(0, &frame->uc.uc_flags);
553 err |= __put_user(0, &frame->uc.uc_link);
554 err |= __put_user((void *)current->sas_ss_sp,
555 &frame->uc.uc_stack.ss_sp);
556 err |= __put_user(sas_ss_flags(regs->regs[REG_SP]),
557 &frame->uc.uc_stack.ss_flags);
558 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
559 err |= setup_sigcontext(&frame->uc.uc_mcontext,
560 regs, set->sig[0]);
561 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
562
563 /* Give up earlier as i386, in case */
564 if (err)
565 goto give_sigsegv;
566
567 /* Set up to return from userspace. If provided, use a stub
568 already in userspace. */
569 if (ka->sa.sa_flags & SA_RESTORER) {
570 DEREF_REG_PR = (unsigned long) ka->sa.sa_restorer | 0x1;
571
572 /*
573 * On SH5 all edited pointers are subject to NEFF
574 */
575 DEREF_REG_PR = (DEREF_REG_PR & NEFF_SIGN) ?
576 (DEREF_REG_PR | NEFF_MASK) : DEREF_REG_PR;
577 } else {
578 /*
579 * Different approach on SH5.
580 * . Endianness independent asm code gets placed in entry.S .
581 * This is limited to four ASM instructions corresponding
582 * to two long longs in size.
583 * . err checking is done on the else branch only
584 * . flush_icache_range() is called upon __put_user() only
585 * . all edited pointers are subject to NEFF
586 * . being code, linker turns ShMedia bit on, always
587 * dereference index -1.
588 */
589
590 DEREF_REG_PR = (unsigned long) frame->retcode | 0x01;
591 DEREF_REG_PR = (DEREF_REG_PR & NEFF_SIGN) ?
592 (DEREF_REG_PR | NEFF_MASK) : DEREF_REG_PR;
593
594 if (__copy_to_user(frame->retcode,
595 (unsigned long long)sa_default_rt_restorer & (~1), 16) != 0)
596 goto give_sigsegv;
597
598 flush_icache_range(DEREF_REG_PR-1, DEREF_REG_PR-1+15);
599 }
600
601 /*
602 * Set up registers for signal handler.
603 * All edited pointers are subject to NEFF.
604 */
605 regs->regs[REG_SP] = (unsigned long) frame;
606 regs->regs[REG_SP] = (regs->regs[REG_SP] & NEFF_SIGN) ?
607 (regs->regs[REG_SP] | NEFF_MASK) : regs->regs[REG_SP];
608 regs->regs[REG_ARG1] = signal; /* Arg for signal handler */
609 regs->regs[REG_ARG2] = (unsigned long long)(unsigned long)(signed long)&frame->info;
610 regs->regs[REG_ARG3] = (unsigned long long)(unsigned long)(signed long)&frame->uc.uc_mcontext;
611 regs->pc = (unsigned long) ka->sa.sa_handler;
612 regs->pc = (regs->pc & NEFF_SIGN) ? (regs->pc | NEFF_MASK) : regs->pc;
613
614 set_fs(USER_DS);
615
616#if DEBUG_SIG
617 /* Broken %016Lx */
618 printk("SIG deliver (#%d,%s:%d): sp=%p pc=%08Lx%08Lx link=%08Lx%08Lx\n",
619 signal,
620 current->comm, current->pid, frame,
621 regs->pc >> 32, regs->pc & 0xffffffff,
622 DEREF_REG_PR >> 32, DEREF_REG_PR & 0xffffffff);
623#endif
624
625 return;
626
627give_sigsegv:
628 force_sigsegv(sig, current);
629}
630
631/*
632 * OK, we're invoking a handler
633 */
634
635static void
636handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
637 sigset_t *oldset, struct pt_regs * regs)
638{
639 /* Are we from a system call? */
640 if (regs->syscall_nr >= 0) {
641 /* If so, check system call restarting.. */
642 switch (regs->regs[REG_RET]) {
Paul Mundte227e8f2007-06-19 12:41:32 +0900643 case -ERESTART_RESTARTBLOCK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 case -ERESTARTNOHAND:
645 regs->regs[REG_RET] = -EINTR;
646 break;
647
648 case -ERESTARTSYS:
649 if (!(ka->sa.sa_flags & SA_RESTART)) {
650 regs->regs[REG_RET] = -EINTR;
651 break;
652 }
653 /* fallthrough */
654 case -ERESTARTNOINTR:
655 /* Decode syscall # */
656 regs->regs[REG_RET] = regs->syscall_nr;
657 regs->pc -= 4;
658 }
659 }
660
661 /* Set up the stack frame */
662 if (ka->sa.sa_flags & SA_SIGINFO)
663 setup_rt_frame(sig, ka, info, oldset, regs);
664 else
665 setup_frame(sig, ka, oldset, regs);
666
Steven Rostedt69be8f12005-08-29 11:44:09 -0400667 spin_lock_irq(&current->sighand->siglock);
668 sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
669 if (!(ka->sa.sa_flags & SA_NODEFER))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 sigaddset(&current->blocked,sig);
Steven Rostedt69be8f12005-08-29 11:44:09 -0400671 recalc_sigpending();
672 spin_unlock_irq(&current->sighand->siglock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673}
674
675/*
676 * Note that 'init' is a special process: it doesn't get signals it doesn't
677 * want to handle. Thus you cannot kill init even with a SIGKILL even by
678 * mistake.
679 *
680 * Note that we go through the signals twice: once to check the signals that
681 * the kernel can handle, and then we build all the user-level signal handling
682 * stack-frames in one go after that.
683 */
684int do_signal(struct pt_regs *regs, sigset_t *oldset)
685{
686 siginfo_t info;
687 int signr;
688 struct k_sigaction ka;
689
690 /*
691 * We want the common case to go fast, which
692 * is why we may in certain cases get here from
693 * kernel mode. Just return without doing anything
694 * if so.
695 */
696 if (!user_mode(regs))
697 return 1;
698
Nigel Cunningham0e6c1f52005-07-27 11:43:34 -0700699 if (try_to_freeze())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 goto no_signal;
701
Paul Mundtc18fe9a2007-05-14 09:12:39 +0900702 if (test_thread_flag(TIF_RESTORE_SIGMASK))
703 oldset = &current->saved_sigmask;
704 else if (!oldset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 oldset = &current->blocked;
706
707 signr = get_signal_to_deliver(&info, &ka, regs, 0);
708
709 if (signr > 0) {
710 /* Whee! Actually deliver the signal. */
711 handle_signal(signr, &info, &ka, oldset, regs);
Paul Mundtc18fe9a2007-05-14 09:12:39 +0900712
713 /*
714 * If a signal was successfully delivered, the saved sigmask
715 * is in its frame, and we can clear the TIF_RESTORE_SIGMASK
716 * flag.
717 */
718 if (test_thread_flag(TIF_RESTORE_SIGMASK))
719 clear_thread_flag(TIF_RESTORE_SIGMASK);
720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 return 1;
722 }
723
724no_signal:
725 /* Did we come from a system call? */
726 if (regs->syscall_nr >= 0) {
727 /* Restart the system call - no handlers present */
Paul Mundtc18fe9a2007-05-14 09:12:39 +0900728 switch (regs->regs[REG_RET]) {
729 case -ERESTARTNOHAND:
730 case -ERESTARTSYS:
731 case -ERESTARTNOINTR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 /* Decode Syscall # */
733 regs->regs[REG_RET] = regs->syscall_nr;
734 regs->pc -= 4;
Paul Mundtc18fe9a2007-05-14 09:12:39 +0900735 break;
736
737 case -ERESTART_RESTARTBLOCK:
738 regs->regs[REG_RET] = __NR_restart_syscall;
739 regs->pc -= 4;
740 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 }
742 }
Paul Mundtc18fe9a2007-05-14 09:12:39 +0900743
744 /* No signal to deliver -- put the saved sigmask back */
745 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
746 clear_thread_flag(TIF_RESTORE_SIGMASK);
747 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
748 }
749
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 return 0;
751}