signal.c
来自「LINUX 2.6.17.4的源码」· C语言 代码 · 共 1,126 行 · 第 1/3 页
C
1,126 行
/* $Id: signal.c,v 1.110 2002/02/08 03:57:14 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/tty.h>#include <linux/smp.h>#include <linux/smp_lock.h>#include <linux/binfmts.h> /* do_coredum */#include <linux/bitops.h>#include <asm/uaccess.h>#include <asm/ptrace.h>#include <asm/svr4.h>#include <asm/pgalloc.h>#include <asm/pgtable.h>#include <asm/cacheflush.h> /* flush_sig_insns */#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);/* 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 __user *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 __user *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 __user *fpu_save; unsigned int insns[2]; stack_t stack; unsigned int extra_size; /* Should be 0 */ __siginfo_fpu_t fpu_state;};/* 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)))static int _sigpause_common(old_sigset_t set){ set &= _BLOCKABLE; spin_lock_irq(¤t->sighand->siglock); current->saved_sigmask = current->blocked; siginitset(¤t->blocked, set); recalc_sigpending(); spin_unlock_irq(¤t->sighand->siglock); current->state = TASK_INTERRUPTIBLE; schedule(); set_thread_flag(TIF_RESTORE_SIGMASK); return -ERESTARTNOHAND;}asmlinkage int sys_sigpause(unsigned int set){ return _sigpause_common(set);}asmlinkage int sys_sigsuspend(old_sigset_t set){ return _sigpause_common(set);}static inline intrestore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu){ int err;#ifdef CONFIG_SMP if (test_tsk_thread_flag(current, TIF_USEDFPU)) regs->psr &= ~PSR_EF;#else if (current == last_task_used_math) { last_task_used_math = NULL; regs->psr &= ~PSR_EF; }#endif set_used_math(); clear_tsk_thread_flag(current, TIF_USEDFPU); if (!access_ok(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 __user *sf; unsigned long up_psr, pc, npc; sigset_t set; __siginfo_fpu_t __user *fpu_save; int err; sf = (struct new_signal_frame __user *) regs->u_regs[UREG_FP]; /* 1. Make sure we are not getting garbage from the user */ if (!access_ok(VERIFY_READ, sf, sizeof(*sf))) goto segv_and_exit; if (((unsigned long) 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->sighand->siglock); current->blocked = set; recalc_sigpending(); spin_unlock_irq(¤t->sighand->siglock); return;segv_and_exit: force_sig(SIGSEGV, current);}asmlinkage void do_sigreturn(struct pt_regs *regs){ struct sigcontext __user *scptr; unsigned long pc, npc, psr; sigset_t set; int err; /* Always make any pending restarted system calls return -EINTR */ current_thread_info()->restart_block.fn = do_no_restart_syscall; synchronize_user_stack(); if (current->thread.new_signal) { do_new_sigreturn(regs); return; } scptr = (struct sigcontext __user *) regs->u_regs[UREG_I0]; /* Check sanity of the user arg. */ if (!access_ok(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->sighand->siglock); current->blocked = set; recalc_sigpending(); spin_unlock_irq(¤t->sighand->siglock); 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: force_sig(SIGSEGV, current);}asmlinkage void do_rt_sigreturn(struct pt_regs *regs){ struct rt_signal_frame __user *sf; unsigned int psr, pc, npc; __siginfo_fpu_t __user *fpu_save; mm_segment_t old_fs; sigset_t set; stack_t st; int err; synchronize_user_stack(); sf = (struct rt_signal_frame __user *) regs->u_regs[UREG_FP]; if (!access_ok(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. */ old_fs = get_fs(); set_fs(KERNEL_DS); do_sigaltstack((const stack_t __user *) &st, NULL, (unsigned long)sf); set_fs(old_fs); sigdelsetmask(&set, ~_BLOCKABLE); spin_lock_irq(¤t->sighand->siglock); current->blocked = set; recalc_sigpending(); spin_unlock_irq(¤t->sighand->siglock); return;segv: force_sig(SIGSEGV, current);}/* Checks if the fp is valid */static inline int invalid_frame_pointer(void __user *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 __user *get_sigframe(struct sigaction *sa, struct pt_regs *regs, unsigned long framesize){ unsigned long sp; sp = regs->u_regs[UREG_FP]; /* This is the X/Open sanctioned signal stack switching. */ if (sa->sa_flags & SA_ONSTACK) { if (!on_sig_stack(sp) && !((current->sas_ss_sp + current->sas_ss_size) & 7)) sp = current->sas_ss_sp + current->sas_ss_size; } return (void __user *)(sp - framesize);}static inline voidsetup_frame(struct sigaction *sa, struct pt_regs *regs, int signr, sigset_t *oldset, siginfo_t *info){ struct signal_sframe __user *sframep; struct sigcontext __user *sc; int window = 0, err; unsigned long pc = regs->pc; unsigned long npc = regs->npc; struct thread_info *tp = current_thread_info(); void __user *sig_address; int sig_code; synchronize_user_stack(); sframep = (struct signal_sframe __user *) get_sigframe(sa, regs, SF_ALIGNEDSZ);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?