ia64/linux-2.6.18-xen.hg

view arch/m68knommu/kernel/signal.c @ 854:950b9eb27661

usbback: fix urb interval value for interrupt urbs.

Signed-off-by: Noboru Iwamatsu <n_iwamatsu@jp.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Apr 06 13:51:20 2009 +0100 (2009-04-06)
parents 831230e53067
children
line source
1 /*
2 * linux/arch/m68knommu/kernel/signal.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 */
11 /*
12 * Linux/m68k support by Hamish Macdonald
13 *
14 * 68060 fixes by Jesper Skov
15 *
16 * 1997-12-01 Modified for POSIX.1b signals by Andreas Schwab
17 *
18 * mathemu support by Roman Zippel
19 * (Note: fpstate in the signal context is completely ignored for the emulator
20 * and the internal floating point format is put on stack)
21 */
23 /*
24 * ++roman (07/09/96): implemented signal stacks (specially for tosemu on
25 * Atari :-) Current limitation: Only one sigstack can be active at one time.
26 * If a second signal with SA_ONSTACK set arrives while working on a sigstack,
27 * SA_ONSTACK is ignored. This behaviour avoids lots of trouble with nested
28 * signal handlers!
29 */
31 #include <linux/sched.h>
32 #include <linux/mm.h>
33 #include <linux/kernel.h>
34 #include <linux/signal.h>
35 #include <linux/syscalls.h>
36 #include <linux/errno.h>
37 #include <linux/wait.h>
38 #include <linux/ptrace.h>
39 #include <linux/unistd.h>
40 #include <linux/stddef.h>
41 #include <linux/highuid.h>
42 #include <linux/tty.h>
43 #include <linux/personality.h>
44 #include <linux/binfmts.h>
46 #include <asm/setup.h>
47 #include <asm/uaccess.h>
48 #include <asm/pgtable.h>
49 #include <asm/traps.h>
50 #include <asm/ucontext.h>
52 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
54 asmlinkage int do_signal(sigset_t *oldset, struct pt_regs *regs);
56 /*
57 * Atomically swap in the new signal mask, and wait for a signal.
58 */
59 asmlinkage int do_sigsuspend(struct pt_regs *regs)
60 {
61 old_sigset_t mask = regs->d3;
62 sigset_t saveset;
64 mask &= _BLOCKABLE;
65 spin_lock_irq(&current->sighand->siglock);
66 saveset = current->blocked;
67 siginitset(&current->blocked, mask);
68 recalc_sigpending();
69 spin_unlock_irq(&current->sighand->siglock);
71 regs->d0 = -EINTR;
72 while (1) {
73 current->state = TASK_INTERRUPTIBLE;
74 schedule();
75 if (do_signal(&saveset, regs))
76 return -EINTR;
77 }
78 }
80 asmlinkage int
81 do_rt_sigsuspend(struct pt_regs *regs)
82 {
83 sigset_t *unewset = (sigset_t *)regs->d1;
84 size_t sigsetsize = (size_t)regs->d2;
85 sigset_t saveset, newset;
87 /* XXX: Don't preclude handling different sized sigset_t's. */
88 if (sigsetsize != sizeof(sigset_t))
89 return -EINVAL;
91 if (copy_from_user(&newset, unewset, sizeof(newset)))
92 return -EFAULT;
93 sigdelsetmask(&newset, ~_BLOCKABLE);
95 spin_lock_irq(&current->sighand->siglock);
96 saveset = current->blocked;
97 current->blocked = newset;
98 recalc_sigpending();
99 spin_unlock_irq(&current->sighand->siglock);
101 regs->d0 = -EINTR;
102 while (1) {
103 current->state = TASK_INTERRUPTIBLE;
104 schedule();
105 if (do_signal(&saveset, regs))
106 return -EINTR;
107 }
108 }
110 asmlinkage int
111 sys_sigaction(int sig, const struct old_sigaction *act,
112 struct old_sigaction *oact)
113 {
114 struct k_sigaction new_ka, old_ka;
115 int ret;
117 if (act) {
118 old_sigset_t mask;
119 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
120 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
121 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
122 return -EFAULT;
123 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
124 __get_user(mask, &act->sa_mask);
125 siginitset(&new_ka.sa.sa_mask, mask);
126 }
128 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
130 if (!ret && oact) {
131 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
132 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
133 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
134 return -EFAULT;
135 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
136 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
137 }
139 return ret;
140 }
142 asmlinkage int
143 sys_sigaltstack(const stack_t *uss, stack_t *uoss)
144 {
145 return do_sigaltstack(uss, uoss, rdusp());
146 }
149 /*
150 * Do a signal return; undo the signal stack.
151 *
152 * Keep the return code on the stack quadword aligned!
153 * That makes the cache flush below easier.
154 */
156 struct sigframe
157 {
158 char *pretcode;
159 int sig;
160 int code;
161 struct sigcontext *psc;
162 char retcode[8];
163 unsigned long extramask[_NSIG_WORDS-1];
164 struct sigcontext sc;
165 };
167 struct rt_sigframe
168 {
169 char *pretcode;
170 int sig;
171 struct siginfo *pinfo;
172 void *puc;
173 char retcode[8];
174 struct siginfo info;
175 struct ucontext uc;
176 };
178 #ifdef CONFIG_FPU
180 static unsigned char fpu_version = 0; /* version number of fpu, set by setup_frame */
182 static inline int restore_fpu_state(struct sigcontext *sc)
183 {
184 int err = 1;
186 if (FPU_IS_EMU) {
187 /* restore registers */
188 memcpy(current->thread.fpcntl, sc->sc_fpcntl, 12);
189 memcpy(current->thread.fp, sc->sc_fpregs, 24);
190 return 0;
191 }
193 if (sc->sc_fpstate[0]) {
194 /* Verify the frame format. */
195 if (sc->sc_fpstate[0] != fpu_version)
196 goto out;
198 __asm__ volatile (".chip 68k/68881\n\t"
199 "fmovemx %0,%/fp0-%/fp1\n\t"
200 "fmoveml %1,%/fpcr/%/fpsr/%/fpiar\n\t"
201 ".chip 68k"
202 : /* no outputs */
203 : "m" (*sc->sc_fpregs), "m" (*sc->sc_fpcntl));
204 }
205 __asm__ volatile (".chip 68k/68881\n\t"
206 "frestore %0\n\t"
207 ".chip 68k" : : "m" (*sc->sc_fpstate));
208 err = 0;
210 out:
211 return err;
212 }
214 #define FPCONTEXT_SIZE 216
215 #define uc_fpstate uc_filler[0]
216 #define uc_formatvec uc_filler[FPCONTEXT_SIZE/4]
217 #define uc_extra uc_filler[FPCONTEXT_SIZE/4+1]
219 static inline int rt_restore_fpu_state(struct ucontext *uc)
220 {
221 unsigned char fpstate[FPCONTEXT_SIZE];
222 int context_size = 0;
223 fpregset_t fpregs;
224 int err = 1;
226 if (FPU_IS_EMU) {
227 /* restore fpu control register */
228 if (__copy_from_user(current->thread.fpcntl,
229 &uc->uc_mcontext.fpregs.f_pcr, 12))
230 goto out;
231 /* restore all other fpu register */
232 if (__copy_from_user(current->thread.fp,
233 uc->uc_mcontext.fpregs.f_fpregs, 96))
234 goto out;
235 return 0;
236 }
238 if (__get_user(*(long *)fpstate, (long *)&uc->uc_fpstate))
239 goto out;
240 if (fpstate[0]) {
241 context_size = fpstate[1];
243 /* Verify the frame format. */
244 if (fpstate[0] != fpu_version)
245 goto out;
246 if (__copy_from_user(&fpregs, &uc->uc_mcontext.fpregs,
247 sizeof(fpregs)))
248 goto out;
249 __asm__ volatile (".chip 68k/68881\n\t"
250 "fmovemx %0,%/fp0-%/fp7\n\t"
251 "fmoveml %1,%/fpcr/%/fpsr/%/fpiar\n\t"
252 ".chip 68k"
253 : /* no outputs */
254 : "m" (*fpregs.f_fpregs),
255 "m" (fpregs.f_pcr));
256 }
257 if (context_size &&
258 __copy_from_user(fpstate + 4, (long *)&uc->uc_fpstate + 1,
259 context_size))
260 goto out;
261 __asm__ volatile (".chip 68k/68881\n\t"
262 "frestore %0\n\t"
263 ".chip 68k" : : "m" (*fpstate));
264 err = 0;
266 out:
267 return err;
268 }
270 #endif
272 static inline int
273 restore_sigcontext(struct pt_regs *regs, struct sigcontext *usc, void *fp,
274 int *pd0)
275 {
276 int formatvec;
277 struct sigcontext context;
278 int err = 0;
280 /* get previous context */
281 if (copy_from_user(&context, usc, sizeof(context)))
282 goto badframe;
284 /* restore passed registers */
285 regs->d1 = context.sc_d1;
286 regs->a0 = context.sc_a0;
287 regs->a1 = context.sc_a1;
288 ((struct switch_stack *)regs - 1)->a5 = context.sc_a5;
289 regs->sr = (regs->sr & 0xff00) | (context.sc_sr & 0xff);
290 regs->pc = context.sc_pc;
291 regs->orig_d0 = -1; /* disable syscall checks */
292 wrusp(context.sc_usp);
293 formatvec = context.sc_formatvec;
294 regs->format = formatvec >> 12;
295 regs->vector = formatvec & 0xfff;
297 #ifdef CONFIG_FPU
298 err = restore_fpu_state(&context);
299 #endif
301 *pd0 = context.sc_d0;
302 return err;
304 badframe:
305 return 1;
306 }
308 static inline int
309 rt_restore_ucontext(struct pt_regs *regs, struct switch_stack *sw,
310 struct ucontext *uc, int *pd0)
311 {
312 int temp;
313 greg_t *gregs = uc->uc_mcontext.gregs;
314 unsigned long usp;
315 int err;
317 err = __get_user(temp, &uc->uc_mcontext.version);
318 if (temp != MCONTEXT_VERSION)
319 goto badframe;
320 /* restore passed registers */
321 err |= __get_user(regs->d0, &gregs[0]);
322 err |= __get_user(regs->d1, &gregs[1]);
323 err |= __get_user(regs->d2, &gregs[2]);
324 err |= __get_user(regs->d3, &gregs[3]);
325 err |= __get_user(regs->d4, &gregs[4]);
326 err |= __get_user(regs->d5, &gregs[5]);
327 err |= __get_user(sw->d6, &gregs[6]);
328 err |= __get_user(sw->d7, &gregs[7]);
329 err |= __get_user(regs->a0, &gregs[8]);
330 err |= __get_user(regs->a1, &gregs[9]);
331 err |= __get_user(regs->a2, &gregs[10]);
332 err |= __get_user(sw->a3, &gregs[11]);
333 err |= __get_user(sw->a4, &gregs[12]);
334 err |= __get_user(sw->a5, &gregs[13]);
335 err |= __get_user(sw->a6, &gregs[14]);
336 err |= __get_user(usp, &gregs[15]);
337 wrusp(usp);
338 err |= __get_user(regs->pc, &gregs[16]);
339 err |= __get_user(temp, &gregs[17]);
340 regs->sr = (regs->sr & 0xff00) | (temp & 0xff);
341 regs->orig_d0 = -1; /* disable syscall checks */
342 regs->format = temp >> 12;
343 regs->vector = temp & 0xfff;
345 if (do_sigaltstack(&uc->uc_stack, NULL, usp) == -EFAULT)
346 goto badframe;
348 *pd0 = regs->d0;
349 return err;
351 badframe:
352 return 1;
353 }
355 asmlinkage int do_sigreturn(unsigned long __unused)
356 {
357 struct switch_stack *sw = (struct switch_stack *) &__unused;
358 struct pt_regs *regs = (struct pt_regs *) (sw + 1);
359 unsigned long usp = rdusp();
360 struct sigframe *frame = (struct sigframe *)(usp - 4);
361 sigset_t set;
362 int d0;
364 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
365 goto badframe;
366 if (__get_user(set.sig[0], &frame->sc.sc_mask) ||
367 (_NSIG_WORDS > 1 &&
368 __copy_from_user(&set.sig[1], &frame->extramask,
369 sizeof(frame->extramask))))
370 goto badframe;
372 sigdelsetmask(&set, ~_BLOCKABLE);
373 spin_lock_irq(&current->sighand->siglock);
374 current->blocked = set;
375 recalc_sigpending();
376 spin_unlock_irq(&current->sighand->siglock);
378 if (restore_sigcontext(regs, &frame->sc, frame + 1, &d0))
379 goto badframe;
380 return d0;
382 badframe:
383 force_sig(SIGSEGV, current);
384 return 0;
385 }
387 asmlinkage int do_rt_sigreturn(unsigned long __unused)
388 {
389 struct switch_stack *sw = (struct switch_stack *) &__unused;
390 struct pt_regs *regs = (struct pt_regs *) (sw + 1);
391 unsigned long usp = rdusp();
392 struct rt_sigframe *frame = (struct rt_sigframe *)(usp - 4);
393 sigset_t set;
394 int d0;
396 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
397 goto badframe;
398 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
399 goto badframe;
401 sigdelsetmask(&set, ~_BLOCKABLE);
402 spin_lock_irq(&current->sighand->siglock);
403 current->blocked = set;
404 recalc_sigpending();
405 spin_unlock_irq(&current->sighand->siglock);
407 if (rt_restore_ucontext(regs, sw, &frame->uc, &d0))
408 goto badframe;
409 return d0;
411 badframe:
412 force_sig(SIGSEGV, current);
413 return 0;
414 }
416 #ifdef CONFIG_FPU
417 /*
418 * Set up a signal frame.
419 */
421 static inline void save_fpu_state(struct sigcontext *sc, struct pt_regs *regs)
422 {
423 if (FPU_IS_EMU) {
424 /* save registers */
425 memcpy(sc->sc_fpcntl, current->thread.fpcntl, 12);
426 memcpy(sc->sc_fpregs, current->thread.fp, 24);
427 return;
428 }
430 __asm__ volatile (".chip 68k/68881\n\t"
431 "fsave %0\n\t"
432 ".chip 68k"
433 : : "m" (*sc->sc_fpstate) : "memory");
435 if (sc->sc_fpstate[0]) {
436 fpu_version = sc->sc_fpstate[0];
437 __asm__ volatile (".chip 68k/68881\n\t"
438 "fmovemx %/fp0-%/fp1,%0\n\t"
439 "fmoveml %/fpcr/%/fpsr/%/fpiar,%1\n\t"
440 ".chip 68k"
441 : /* no outputs */
442 : "m" (*sc->sc_fpregs),
443 "m" (*sc->sc_fpcntl)
444 : "memory");
445 }
446 }
448 static inline int rt_save_fpu_state(struct ucontext *uc, struct pt_regs *regs)
449 {
450 unsigned char fpstate[FPCONTEXT_SIZE];
451 int context_size = 0;
452 int err = 0;
454 if (FPU_IS_EMU) {
455 /* save fpu control register */
456 err |= copy_to_user(&uc->uc_mcontext.fpregs.f_pcr,
457 current->thread.fpcntl, 12);
458 /* save all other fpu register */
459 err |= copy_to_user(uc->uc_mcontext.fpregs.f_fpregs,
460 current->thread.fp, 96);
461 return err;
462 }
464 __asm__ volatile (".chip 68k/68881\n\t"
465 "fsave %0\n\t"
466 ".chip 68k"
467 : : "m" (*fpstate) : "memory");
469 err |= __put_user(*(long *)fpstate, (long *)&uc->uc_fpstate);
470 if (fpstate[0]) {
471 fpregset_t fpregs;
472 context_size = fpstate[1];
473 fpu_version = fpstate[0];
474 __asm__ volatile (".chip 68k/68881\n\t"
475 "fmovemx %/fp0-%/fp7,%0\n\t"
476 "fmoveml %/fpcr/%/fpsr/%/fpiar,%1\n\t"
477 ".chip 68k"
478 : /* no outputs */
479 : "m" (*fpregs.f_fpregs),
480 "m" (fpregs.f_pcr)
481 : "memory");
482 err |= copy_to_user(&uc->uc_mcontext.fpregs, &fpregs,
483 sizeof(fpregs));
484 }
485 if (context_size)
486 err |= copy_to_user((long *)&uc->uc_fpstate + 1, fpstate + 4,
487 context_size);
488 return err;
489 }
491 #endif
493 static void setup_sigcontext(struct sigcontext *sc, struct pt_regs *regs,
494 unsigned long mask)
495 {
496 sc->sc_mask = mask;
497 sc->sc_usp = rdusp();
498 sc->sc_d0 = regs->d0;
499 sc->sc_d1 = regs->d1;
500 sc->sc_a0 = regs->a0;
501 sc->sc_a1 = regs->a1;
502 sc->sc_a5 = ((struct switch_stack *)regs - 1)->a5;
503 sc->sc_sr = regs->sr;
504 sc->sc_pc = regs->pc;
505 sc->sc_formatvec = regs->format << 12 | regs->vector;
506 #ifdef CONFIG_FPU
507 save_fpu_state(sc, regs);
508 #endif
509 }
511 static inline int rt_setup_ucontext(struct ucontext *uc, struct pt_regs *regs)
512 {
513 struct switch_stack *sw = (struct switch_stack *)regs - 1;
514 greg_t *gregs = uc->uc_mcontext.gregs;
515 int err = 0;
517 err |= __put_user(MCONTEXT_VERSION, &uc->uc_mcontext.version);
518 err |= __put_user(regs->d0, &gregs[0]);
519 err |= __put_user(regs->d1, &gregs[1]);
520 err |= __put_user(regs->d2, &gregs[2]);
521 err |= __put_user(regs->d3, &gregs[3]);
522 err |= __put_user(regs->d4, &gregs[4]);
523 err |= __put_user(regs->d5, &gregs[5]);
524 err |= __put_user(sw->d6, &gregs[6]);
525 err |= __put_user(sw->d7, &gregs[7]);
526 err |= __put_user(regs->a0, &gregs[8]);
527 err |= __put_user(regs->a1, &gregs[9]);
528 err |= __put_user(regs->a2, &gregs[10]);
529 err |= __put_user(sw->a3, &gregs[11]);
530 err |= __put_user(sw->a4, &gregs[12]);
531 err |= __put_user(sw->a5, &gregs[13]);
532 err |= __put_user(sw->a6, &gregs[14]);
533 err |= __put_user(rdusp(), &gregs[15]);
534 err |= __put_user(regs->pc, &gregs[16]);
535 err |= __put_user(regs->sr, &gregs[17]);
536 #ifdef CONFIG_FPU
537 err |= rt_save_fpu_state(uc, regs);
538 #endif
539 return err;
540 }
542 static inline void push_cache (unsigned long vaddr)
543 {
544 }
546 static inline void *
547 get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size)
548 {
549 unsigned long usp;
551 /* Default to using normal stack. */
552 usp = rdusp();
554 /* This is the X/Open sanctioned signal stack switching. */
555 if (ka->sa.sa_flags & SA_ONSTACK) {
556 if (!sas_ss_flags(usp))
557 usp = current->sas_ss_sp + current->sas_ss_size;
558 }
559 return (void *)((usp - frame_size) & -8UL);
560 }
562 static void setup_frame (int sig, struct k_sigaction *ka,
563 sigset_t *set, struct pt_regs *regs)
564 {
565 struct sigframe *frame;
566 struct sigcontext context;
567 int err = 0;
569 frame = get_sigframe(ka, regs, sizeof(*frame));
571 err |= __put_user((current_thread_info()->exec_domain
572 && current_thread_info()->exec_domain->signal_invmap
573 && sig < 32
574 ? current_thread_info()->exec_domain->signal_invmap[sig]
575 : sig),
576 &frame->sig);
578 err |= __put_user(regs->vector, &frame->code);
579 err |= __put_user(&frame->sc, &frame->psc);
581 if (_NSIG_WORDS > 1)
582 err |= copy_to_user(frame->extramask, &set->sig[1],
583 sizeof(frame->extramask));
585 setup_sigcontext(&context, regs, set->sig[0]);
586 err |= copy_to_user (&frame->sc, &context, sizeof(context));
588 /* Set up to return from userspace. */
589 err |= __put_user(frame->retcode, &frame->pretcode);
590 /* moveq #,d0; trap #0 */
591 err |= __put_user(0x70004e40 + (__NR_sigreturn << 16),
592 (long *)(frame->retcode));
594 if (err)
595 goto give_sigsegv;
597 push_cache ((unsigned long) &frame->retcode);
599 /* Set up registers for signal handler */
600 wrusp ((unsigned long) frame);
601 regs->pc = (unsigned long) ka->sa.sa_handler;
602 ((struct switch_stack *)regs - 1)->a5 = current->mm->start_data;
603 regs->format = 0x4; /*set format byte to make stack appear modulo 4
604 which it will be when doing the rte */
606 adjust_stack:
607 /* Prepare to skip over the extra stuff in the exception frame. */
608 if (regs->stkadj) {
609 struct pt_regs *tregs =
610 (struct pt_regs *)((ulong)regs + regs->stkadj);
611 #if defined(DEBUG)
612 printk(KERN_DEBUG "Performing stackadjust=%04x\n", regs->stkadj);
613 #endif
614 /* This must be copied with decreasing addresses to
615 handle overlaps. */
616 tregs->vector = 0;
617 tregs->format = 0;
618 tregs->pc = regs->pc;
619 tregs->sr = regs->sr;
620 }
621 return;
623 give_sigsegv:
624 force_sigsegv(sig, current);
625 goto adjust_stack;
626 }
628 static void setup_rt_frame (int sig, struct k_sigaction *ka, siginfo_t *info,
629 sigset_t *set, struct pt_regs *regs)
630 {
631 struct rt_sigframe *frame;
632 int err = 0;
634 frame = get_sigframe(ka, regs, sizeof(*frame));
636 err |= __put_user((current_thread_info()->exec_domain
637 && current_thread_info()->exec_domain->signal_invmap
638 && sig < 32
639 ? current_thread_info()->exec_domain->signal_invmap[sig]
640 : sig),
641 &frame->sig);
642 err |= __put_user(&frame->info, &frame->pinfo);
643 err |= __put_user(&frame->uc, &frame->puc);
644 err |= copy_siginfo_to_user(&frame->info, info);
646 /* Create the ucontext. */
647 err |= __put_user(0, &frame->uc.uc_flags);
648 err |= __put_user(0, &frame->uc.uc_link);
649 err |= __put_user((void *)current->sas_ss_sp,
650 &frame->uc.uc_stack.ss_sp);
651 err |= __put_user(sas_ss_flags(rdusp()),
652 &frame->uc.uc_stack.ss_flags);
653 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
654 err |= rt_setup_ucontext(&frame->uc, regs);
655 err |= copy_to_user (&frame->uc.uc_sigmask, set, sizeof(*set));
657 /* Set up to return from userspace. */
658 err |= __put_user(frame->retcode, &frame->pretcode);
659 /* moveq #,d0; notb d0; trap #0 */
660 err |= __put_user(0x70004600 + ((__NR_rt_sigreturn ^ 0xff) << 16),
661 (long *)(frame->retcode + 0));
662 err |= __put_user(0x4e40, (short *)(frame->retcode + 4));
664 if (err)
665 goto give_sigsegv;
667 push_cache ((unsigned long) &frame->retcode);
669 /* Set up registers for signal handler */
670 wrusp ((unsigned long) frame);
671 regs->pc = (unsigned long) ka->sa.sa_handler;
672 ((struct switch_stack *)regs - 1)->a5 = current->mm->start_data;
673 regs->format = 0x4; /*set format byte to make stack appear modulo 4
674 which it will be when doing the rte */
676 adjust_stack:
677 /* Prepare to skip over the extra stuff in the exception frame. */
678 if (regs->stkadj) {
679 struct pt_regs *tregs =
680 (struct pt_regs *)((ulong)regs + regs->stkadj);
681 #if defined(DEBUG)
682 printk(KERN_DEBUG "Performing stackadjust=%04x\n", regs->stkadj);
683 #endif
684 /* This must be copied with decreasing addresses to
685 handle overlaps. */
686 tregs->vector = 0;
687 tregs->format = 0;
688 tregs->pc = regs->pc;
689 tregs->sr = regs->sr;
690 }
691 return;
693 give_sigsegv:
694 force_sigsegv(sig, current);
695 goto adjust_stack;
696 }
698 static inline void
699 handle_restart(struct pt_regs *regs, struct k_sigaction *ka, int has_handler)
700 {
701 switch (regs->d0) {
702 case -ERESTARTNOHAND:
703 if (!has_handler)
704 goto do_restart;
705 regs->d0 = -EINTR;
706 break;
708 case -ERESTARTSYS:
709 if (has_handler && !(ka->sa.sa_flags & SA_RESTART)) {
710 regs->d0 = -EINTR;
711 break;
712 }
713 /* fallthrough */
714 case -ERESTARTNOINTR:
715 do_restart:
716 regs->d0 = regs->orig_d0;
717 regs->pc -= 2;
718 break;
719 }
720 }
722 /*
723 * OK, we're invoking a handler
724 */
725 static void
726 handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
727 sigset_t *oldset, struct pt_regs *regs)
728 {
729 /* are we from a system call? */
730 if (regs->orig_d0 >= 0)
731 /* If so, check system call restarting.. */
732 handle_restart(regs, ka, 1);
734 /* set up the stack frame */
735 if (ka->sa.sa_flags & SA_SIGINFO)
736 setup_rt_frame(sig, ka, info, oldset, regs);
737 else
738 setup_frame(sig, ka, oldset, regs);
740 if (ka->sa.sa_flags & SA_ONESHOT)
741 ka->sa.sa_handler = SIG_DFL;
743 spin_lock_irq(&current->sighand->siglock);
744 sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
745 if (!(ka->sa.sa_flags & SA_NODEFER))
746 sigaddset(&current->blocked,sig);
747 recalc_sigpending();
748 spin_unlock_irq(&current->sighand->siglock);
749 }
751 /*
752 * Note that 'init' is a special process: it doesn't get signals it doesn't
753 * want to handle. Thus you cannot kill init even with a SIGKILL even by
754 * mistake.
755 */
756 asmlinkage int do_signal(sigset_t *oldset, struct pt_regs *regs)
757 {
758 struct k_sigaction ka;
759 siginfo_t info;
760 int signr;
762 /*
763 * We want the common case to go fast, which
764 * is why we may in certain cases get here from
765 * kernel mode. Just return without doing anything
766 * if so.
767 */
768 if (!user_mode(regs))
769 return 1;
771 if (!oldset)
772 oldset = &current->blocked;
774 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
775 if (signr > 0) {
776 /* Whee! Actually deliver the signal. */
777 handle_signal(signr, &ka, &info, oldset, regs);
778 return 1;
779 }
781 /* Did we come from a system call? */
782 if (regs->orig_d0 >= 0) {
783 /* Restart the system call - no handlers present */
784 if (regs->d0 == -ERESTARTNOHAND
785 || regs->d0 == -ERESTARTSYS
786 || regs->d0 == -ERESTARTNOINTR) {
787 regs->d0 = regs->orig_d0;
788 regs->pc -= 2;
789 } else if (regs->d0 == -ERESTART_RESTARTBLOCK) {
790 regs->d0 = __NR_restart_syscall;
791 regs->pc -= 2;
792 }
793 }
794 return 0;
795 }