📄 signal.c
字号:
/* * linux/arch/sh/kernel/signal.c * * Copyright (C) 1991, 1992 Linus Torvalds * * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson * * SuperH version: Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima * */#include <linux/sched.h>#include <linux/mm.h>#include <linux/smp.h>#include <linux/smp_lock.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/stddef.h>#include <linux/tty.h>#include <linux/personality.h>#include <linux/binfmts.h>#include <asm/ucontext.h>#include <asm/uaccess.h>#include <asm/pgtable.h>#include <asm/cacheflush.h>#define DEBUG_SIG 0#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))asmlinkage int do_signal(struct pt_regs *regs, sigset_t *oldset);/* * Atomically swap in the new signal mask, and wait for a signal. */asmlinkage intsys_sigsuspend(old_sigset_t mask, unsigned long r5, unsigned long r6, unsigned long r7, struct pt_regs regs){ sigset_t saveset; mask &= _BLOCKABLE; spin_lock_irq(¤t->sighand->siglock); saveset = current->blocked; siginitset(¤t->blocked, mask); recalc_sigpending(); spin_unlock_irq(¤t->sighand->siglock); regs.regs[0] = -EINTR; while (1) { current->state = TASK_INTERRUPTIBLE; schedule(); if (do_signal(®s, &saveset)) return -EINTR; }}asmlinkage intsys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize, unsigned long r6, unsigned long r7, struct pt_regs regs){ sigset_t saveset, newset; /* XXX: Don't preclude handling different sized sigset_t's. */ if (sigsetsize != sizeof(sigset_t)) return -EINVAL; if (copy_from_user(&newset, unewset, sizeof(newset))) return -EFAULT; sigdelsetmask(&newset, ~_BLOCKABLE); spin_lock_irq(¤t->sighand->siglock); saveset = current->blocked; current->blocked = newset; recalc_sigpending(); spin_unlock_irq(¤t->sighand->siglock); regs.regs[0] = -EINTR; while (1) { current->state = TASK_INTERRUPTIBLE; schedule(); if (do_signal(®s, &saveset)) return -EINTR; }}asmlinkage int sys_sigaction(int sig, const struct old_sigaction __user *act, struct old_sigaction __user *oact){ 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) || __get_user(new_ka.sa.sa_restorer, &act->sa_restorer)) return -EFAULT; __get_user(new_ka.sa.sa_flags, &act->sa_flags); __get_user(mask, &act->sa_mask); siginitset(&new_ka.sa.sa_mask, mask); } ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); if (!ret && oact) { if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer)) return -EFAULT; __put_user(old_ka.sa.sa_flags, &oact->sa_flags); __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); } return ret;}asmlinkage intsys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, unsigned long r6, unsigned long r7, struct pt_regs regs){ return do_sigaltstack(uss, uoss, regs.regs[15]);}/* * Do a signal return; undo the signal stack. */#define MOVW(n) (0x9300|((n)-2)) /* Move mem word at PC+n to R3 */#define TRAP16 0xc310 /* Syscall w/no args (NR in R3) */#define OR_R0_R0 0x200b /* or r0,r0 (insert to avoid hardware bug) */struct sigframe{ struct sigcontext sc; unsigned long extramask[_NSIG_WORDS-1]; u16 retcode[8];};struct rt_sigframe{ struct siginfo info; struct ucontext uc; u16 retcode[8];};#ifdef CONFIG_SH_FPUstatic inline int restore_sigcontext_fpu(struct sigcontext __user *sc){ struct task_struct *tsk = current; if (!(cpu_data->flags & CPU_HAS_FPU)) return 0; set_used_math(); return __copy_from_user(&tsk->thread.fpu.hard, &sc->sc_fpregs[0], sizeof(long)*(16*2+2));}static inline int save_sigcontext_fpu(struct sigcontext __user *sc, struct pt_regs *regs){ struct task_struct *tsk = current; if (!(cpu_data->flags & CPU_HAS_FPU)) return 0; if (!used_math()) { __put_user(0, &sc->sc_ownedfp); return 0; } __put_user(1, &sc->sc_ownedfp); /* This will cause a "finit" to be triggered by the next attempted FPU operation by the 'current' process. */ clear_used_math(); unlazy_fpu(tsk, regs); return __copy_to_user(&sc->sc_fpregs[0], &tsk->thread.fpu.hard, sizeof(long)*(16*2+2));}#endif /* CONFIG_SH_FPU */static intrestore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *r0_p){ unsigned int err = 0;#define COPY(x) err |= __get_user(regs->x, &sc->sc_##x) COPY(regs[1]); COPY(regs[2]); COPY(regs[3]); COPY(regs[4]); COPY(regs[5]); COPY(regs[6]); COPY(regs[7]); COPY(regs[8]); COPY(regs[9]); COPY(regs[10]); COPY(regs[11]); COPY(regs[12]); COPY(regs[13]); COPY(regs[14]); COPY(regs[15]); COPY(gbr); COPY(mach); COPY(macl); COPY(pr); COPY(sr); COPY(pc);#undef COPY#ifdef CONFIG_SH_FPU if (cpu_data->flags & CPU_HAS_FPU) { int owned_fp; struct task_struct *tsk = current; regs->sr |= SR_FD; /* Release FPU */ clear_fpu(tsk, regs); clear_used_math(); __get_user (owned_fp, &sc->sc_ownedfp); if (owned_fp) err |= restore_sigcontext_fpu(sc); }#endif regs->tra = -1; /* disable syscall checks */ err |= __get_user(*r0_p, &sc->sc_regs[0]); return err;}asmlinkage int sys_sigreturn(unsigned long r4, unsigned long r5, unsigned long r6, unsigned long r7, struct pt_regs regs){ struct sigframe __user *frame = (struct sigframe __user *)regs.regs[15]; sigset_t set; int r0; if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) goto badframe; if (__get_user(set.sig[0], &frame->sc.oldmask) || (_NSIG_WORDS > 1 && __copy_from_user(&set.sig[1], &frame->extramask, sizeof(frame->extramask)))) goto badframe; sigdelsetmask(&set, ~_BLOCKABLE); spin_lock_irq(¤t->sighand->siglock); current->blocked = set; recalc_sigpending(); spin_unlock_irq(¤t->sighand->siglock); if (restore_sigcontext(®s, &frame->sc, &r0)) goto badframe; return r0;badframe: force_sig(SIGSEGV, current); return 0;}asmlinkage int sys_rt_sigreturn(unsigned long r4, unsigned long r5, unsigned long r6, unsigned long r7, struct pt_regs regs){ struct rt_sigframe __user *frame = (struct rt_sigframe __user *)regs.regs[15]; sigset_t set; stack_t st; int r0; if (!access_ok(VERIFY_READ, frame, sizeof(*frame))) goto badframe; if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) goto badframe; sigdelsetmask(&set, ~_BLOCKABLE); spin_lock_irq(¤t->sighand->siglock); current->blocked = set; recalc_sigpending(); spin_unlock_irq(¤t->sighand->siglock); if (restore_sigcontext(®s, &frame->uc.uc_mcontext, &r0)) goto badframe; if (__copy_from_user(&st, &frame->uc.uc_stack, sizeof(st))) goto badframe; /* It is more difficult to avoid calling this function than to call it and ignore errors. */ do_sigaltstack(&st, NULL, regs.regs[15]); return r0;badframe: force_sig(SIGSEGV, current); return 0;} /* * Set up a signal frame.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -