📄 signal.c
字号:
/* $Id: signal.c,v 1.108 2001/01/24 21:05:12 davem Exp $ * linux/arch/sparc/kernel/signal.c * * 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/config.h>#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>#include <linux/smp_lock.h>#include <asm/uaccess.h>#include <asm/bitops.h>#include <asm/ptrace.h>#include <asm/svr4.h>#include <asm/pgalloc.h>#include <asm/pgtable.h>#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);asmlinkage int do_signal(sigset_t *oldset, struct pt_regs * regs, unsigned long orig_o0, int ret_from_syscall);/* This turned off for production... *//* #define DEBUG_SIGNALS 1 *//* #define DEBUG_SIGNALS_TRACE 1 *//* #define DEBUG_SIGNALS_MAPS 1 *//* Signal frames: the original one (compatible with SunOS): * * Set up a signal frame... Make the stack look the way SunOS * expects it to look which is basically: * * ---------------------------------- <-- %sp at signal time * Struct sigcontext * Signal address * Ptr to sigcontext area above * Signal code * The signal number itself * One register window * ---------------------------------- <-- New %sp */struct signal_sframe { struct reg_window sig_window; int sig_num; int sig_code; struct sigcontext *sig_scptr; int sig_address; struct sigcontext sig_context; unsigned int extramask[_NSIG_WORDS - 1];};/* * And the new one, intended to be used for Linux applications only * (we have enough in there to work with clone). * All the interesting bits are in the info field. */struct new_signal_frame { struct sparc_stackf ss; __siginfo_t info; __siginfo_fpu_t *fpu_save; unsigned long insns [2] __attribute__ ((aligned (8))); unsigned int extramask[_NSIG_WORDS - 1]; unsigned int extra_size; /* Should be 0 */ __siginfo_fpu_t fpu_state;};struct rt_signal_frame { struct sparc_stackf ss; siginfo_t info; struct pt_regs regs; sigset_t mask; __siginfo_fpu_t *fpu_save; unsigned int insns [2]; stack_t stack; unsigned int extra_size; /* Should be 0 */ __siginfo_fpu_t fpu_state;};int copy_siginfo_to_user(siginfo_t *to, siginfo_t *from){ if (!access_ok(VERIFY_WRITE, to, sizeof(siginfo_t))) return -EFAULT; if (from->si_code < 0) return __copy_to_user(to, from, sizeof(siginfo_t)); else { int err; /* If you change siginfo_t structure, please be sure this code is fixed accordingly. It should never copy any pad contained in the structure to avoid security leaks, but must copy the generic 3 ints plus the relevant union member. */ err = __put_user(from->si_signo, &to->si_signo); err |= __put_user(from->si_errno, &to->si_errno); err |= __put_user((short)from->si_code, &to->si_code); switch (from->si_code >> 16) { case __SI_CHLD >> 16: err |= __put_user(from->si_utime, &to->si_utime); err |= __put_user(from->si_stime, &to->si_stime); /* case __SI_RT: This is not generated by the kernel as of now. */ err |= __put_user(from->si_status, &to->si_status); default: err |= __put_user(from->si_uid, &to->si_uid); err |= __put_user(from->si_pid, &to->si_pid); break; } return err; }}/* Align macros */#define SF_ALIGNEDSZ (((sizeof(struct signal_sframe) + 7) & (~7)))#define NF_ALIGNEDSZ (((sizeof(struct new_signal_frame) + 7) & (~7)))#define RT_ALIGNEDSZ (((sizeof(struct rt_signal_frame) + 7) & (~7)))/* * atomically swap in the new signal mask, and wait for a signal. * This is really tricky on the Sparc, watch out... */asmlinkage void _sigpause_common(old_sigset_t set, struct pt_regs *regs){ sigset_t saveset; set &= _BLOCKABLE; spin_lock_irq(¤t->sigmask_lock); saveset = current->blocked; siginitset(¤t->blocked, set); recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); regs->pc = regs->npc; regs->npc += 4; /* Condition codes and return value where set here for sigpause, * and so got used by setup_frame, which again causes sigreturn() * to return -EINTR. */ while (1) { current->state = TASK_INTERRUPTIBLE; schedule(); /* * Return -EINTR and set condition code here, * so the interrupted system call actually returns * these. */ regs->psr |= PSR_C; regs->u_regs[UREG_I0] = EINTR; if (do_signal(&saveset, regs, 0, 0)) return; }}asmlinkage void do_sigpause(unsigned int set, struct pt_regs *regs){ _sigpause_common(set, regs);}asmlinkage void do_sigsuspend (struct pt_regs *regs){ _sigpause_common(regs->u_regs[UREG_I0], regs);}asmlinkage void do_rt_sigsuspend(sigset_t *uset, size_t sigsetsize, struct pt_regs *regs){ sigset_t oldset, set; /* XXX: Don't preclude handling different sized sigset_t's. */ if (sigsetsize != sizeof(sigset_t)) { regs->psr |= PSR_C; regs->u_regs[UREG_I0] = EINVAL; return; } if (copy_from_user(&set, uset, sizeof(set))) { regs->psr |= PSR_C; regs->u_regs[UREG_I0] = EFAULT; return; } sigdelsetmask(&set, ~_BLOCKABLE); spin_lock_irq(¤t->sigmask_lock); oldset = current->blocked; current->blocked = set; recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); regs->pc = regs->npc; regs->npc += 4; /* Condition codes and return value where set here for sigpause, * and so got used by setup_frame, which again causes sigreturn() * to return -EINTR. */ while (1) { current->state = TASK_INTERRUPTIBLE; schedule(); /* * Return -EINTR and set condition code here, * so the interrupted system call actually returns * these. */ regs->psr |= PSR_C; regs->u_regs[UREG_I0] = EINTR; if (do_signal(&oldset, regs, 0, 0)) return; }}static inline intrestore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t *fpu){ int err;#ifdef CONFIG_SMP if (current->flags & PF_USEDFPU) regs->psr &= ~PSR_EF;#else if (current == last_task_used_math) { last_task_used_math = 0; regs->psr &= ~PSR_EF; }#endif current->used_math = 1; current->flags &= ~PF_USEDFPU; if (verify_area (VERIFY_READ, fpu, sizeof(*fpu))) return -EFAULT; err = __copy_from_user(¤t->thread.float_regs[0], &fpu->si_float_regs[0], (sizeof(unsigned long) * 32)); err |= __get_user(current->thread.fsr, &fpu->si_fsr); err |= __get_user(current->thread.fpqdepth, &fpu->si_fpqdepth); if (current->thread.fpqdepth != 0) err |= __copy_from_user(¤t->thread.fpqueue[0], &fpu->si_fpqueue[0], ((sizeof(unsigned long) + (sizeof(unsigned long *)))*16)); return err;}static inline void do_new_sigreturn (struct pt_regs *regs){ struct new_signal_frame *sf; unsigned long up_psr, pc, npc; sigset_t set; __siginfo_fpu_t *fpu_save; int err; sf = (struct new_signal_frame *) regs->u_regs [UREG_FP]; /* 1. Make sure we are not getting garbage from the user */ if (verify_area (VERIFY_READ, sf, sizeof (*sf))) goto segv_and_exit; if (((uint) 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)); err |= __get_user(fpu_save, &sf->fpu_save); if (fpu_save) err |= restore_fpu_state(regs, fpu_save); /* 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); spin_lock_irq(¤t->sigmask_lock); current->blocked = set; recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); return;segv_and_exit: do_exit(SIGSEGV);}asmlinkage void do_sigreturn(struct pt_regs *regs){ struct sigcontext *scptr; unsigned long pc, npc, psr; sigset_t set; int err; synchronize_user_stack(); if (current->thread.new_signal) return do_new_sigreturn (regs); scptr = (struct sigcontext *) regs->u_regs[UREG_I0]; /* Check sanity of the user arg. */ if(verify_area(VERIFY_READ, scptr, sizeof(struct sigcontext)) || (((unsigned long) scptr) & 3)) goto segv_and_exit; err = __get_user(pc, &scptr->sigc_pc); err |= __get_user(npc, &scptr->sigc_npc); if((pc | npc) & 3) goto segv_and_exit; /* This is pretty much atomic, no amount locking would prevent * the races which exist anyways. */ err |= __get_user(set.sig[0], &scptr->sigc_mask); /* Note that scptr + 1 points to extramask */ err |= __copy_from_user(&set.sig[1], scptr + 1, (_NSIG_WORDS - 1) * sizeof(unsigned int)); if (err) goto segv_and_exit; sigdelsetmask(&set, ~_BLOCKABLE); spin_lock_irq(¤t->sigmask_lock); current->blocked = set; recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); regs->pc = pc; regs->npc = npc; err = __get_user(regs->u_regs[UREG_FP], &scptr->sigc_sp); err |= __get_user(regs->u_regs[UREG_I0], &scptr->sigc_o0); err |= __get_user(regs->u_regs[UREG_G1], &scptr->sigc_g1); /* User can only change condition codes in %psr. */ err |= __get_user(psr, &scptr->sigc_psr); if (err) goto segv_and_exit; regs->psr &= ~(PSR_ICC); regs->psr |= (psr & PSR_ICC); return;segv_and_exit: send_sig(SIGSEGV, current, 1);}asmlinkage void do_rt_sigreturn(struct pt_regs *regs){ struct rt_signal_frame *sf; unsigned int psr, pc, npc; __siginfo_fpu_t *fpu_save; sigset_t set; stack_t st; int err; synchronize_user_stack(); sf = (struct rt_signal_frame *) regs->u_regs[UREG_FP]; if(verify_area(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(®s->u_regs[UREG_G1], &sf->regs.u_regs[UREG_G1], 15*sizeof(u32)); regs->psr = (regs->psr & ~PSR_ICC) | (psr & PSR_ICC); err |= __get_user(fpu_save, &sf->fpu_save); if(fpu_save) 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. */ do_sigaltstack(&st, NULL, (unsigned long)sf); sigdelsetmask(&set, ~_BLOCKABLE); spin_lock_irq(¤t->sigmask_lock); current->blocked = set; recalc_sigpending(current); spin_unlock_irq(¤t->sigmask_lock); return;segv: send_sig(SIGSEGV, current, 1);}/* Checks if the fp is valid */static inline int invalid_frame_pointer (void *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 *get_sigframe(struct sigaction *sa, struct pt_regs *regs, unsigned long framesize){ unsigned long sp; sp = regs->u_regs[UREG_FP];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -