⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 signal.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	err |= __put_user(regs->hi, &sc->sc_mdhi);	err |= __put_user(regs->lo, &sc->sc_mdlo);	err |= __put_user(regs->cp0_cause, &sc->sc_cause);	err |= __put_user(regs->cp0_badvaddr, &sc->sc_badvaddr);	owned_fp = (current == last_task_used_math);	err |= __put_user(owned_fp, &sc->sc_ownedfp);	if (current->used_math) {	/* fp is active.  */		set_cp0_status(ST0_CU1, ST0_CU1);		err |= save_fp_context(sc);		last_task_used_math = NULL;		regs->cp0_status &= ~ST0_CU1;		current->used_math = 0;	}	return err;}/* * Determine which stack to use.. */static inline void *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size){	unsigned long sp;	/* Default to using normal stack */	sp = regs->regs[29];	/* This is the X/Open sanctioned signal stack switching.  */	if ((ka->sa.sa_flags & SA_ONSTACK) && ! on_sig_stack(sp))                sp = current->sas_ss_sp + current->sas_ss_size;	return (void *)((sp - frame_size) & ALMASK);}static void inlinesetup_frame(struct k_sigaction * ka, struct pt_regs *regs,            int signr, sigset_t *set){	struct sigframe *frame;	int err = 0;	frame = get_sigframe(ka, regs, sizeof(*frame));	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))		goto give_sigsegv;	/* Set up to return from userspace.  If provided, use a stub already	   in userspace.  */	if (ka->sa.sa_flags & SA_RESTORER)		regs->regs[31] = (unsigned long) ka->sa.sa_restorer;	else {		/*		 * Set up the return code ...		 *		 *         li      v0, __NR_sigreturn		 *         syscall		 */		err |= __put_user(0x24020000 + __NR_sigreturn,		                  frame->sf_code + 0);		err |= __put_user(0x0000000c                 ,		                  frame->sf_code + 1);		flush_cache_sigtramp((unsigned long) frame->sf_code);	}	err |= setup_sigcontext(regs, &frame->sf_sc);	err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));	if (err)		goto give_sigsegv;	/*	 * Arguments to signal handler:	 *	 *   a0 = signal number	 *   a1 = 0 (should be cause)	 *   a2 = pointer to struct sigcontext	 *	 * $25 and c0_epc point to the signal handler, $29 points to the	 * struct sigframe.	 */	regs->regs[ 4] = signr;	regs->regs[ 5] = 0;	regs->regs[ 6] = (unsigned long) &frame->sf_sc;	regs->regs[29] = (unsigned long) frame;	regs->regs[31] = (unsigned long) frame->sf_code;	regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;#if DEBUG_SIG	printk("SIG deliver (%s:%d): sp=0x%p pc=0x%p ra=0x%p\n",	       current->comm, current->pid, frame, regs->cp0_epc, frame->code);#endif        return;give_sigsegv:	if (signr == SIGSEGV)		ka->sa.sa_handler = SIG_DFL;	force_sig(SIGSEGV, current);}static void inlinesetup_rt_frame(struct k_sigaction * ka, struct pt_regs *regs,               int signr, sigset_t *set, siginfo_t *info){	struct rt_sigframe *frame;	int err = 0;	frame = get_sigframe(ka, regs, sizeof(*frame));	if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))		goto give_sigsegv;	/* Set up to return from userspace.  If provided, use a stub already	   in userspace.  */	if (ka->sa.sa_flags & SA_RESTORER)		regs->regs[31] = (unsigned long) ka->sa.sa_restorer;	else {		/*		 * Set up the return code ...		 *		 *         li      v0, __NR_sigreturn		 *         syscall		 */		err |= __put_user(0x24020000 + __NR_sigreturn,		                  frame->rs_code + 0);		err |= __put_user(0x0000000c                 ,		                  frame->rs_code + 1);		flush_cache_sigtramp((unsigned long) frame->rs_code);	}	/* Create siginfo.  */	err |= copy_siginfo_to_user(&frame->rs_info, info);	/* Create the ucontext.  */	err |= __put_user(0, &frame->rs_uc.uc_flags);	err |= __put_user(0, &frame->rs_uc.uc_link);	err |= __put_user((void *)current->sas_ss_sp,	                  &frame->rs_uc.uc_stack.ss_sp);	err |= __put_user(sas_ss_flags(regs->regs[29]),	                  &frame->rs_uc.uc_stack.ss_flags);	err |= __put_user(current->sas_ss_size,	                  &frame->rs_uc.uc_stack.ss_size);	err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);	err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));	if (err)		goto give_sigsegv;	/*	 * Arguments to signal handler:	 *	 *   a0 = signal number	 *   a1 = 0 (should be cause)	 *   a2 = pointer to ucontext	 *	 * $25 and c0_epc point to the signal handler, $29 points to	 * the struct rt_sigframe.	 */	regs->regs[ 4] = signr;	regs->regs[ 5] = (unsigned long) &frame->rs_info;	regs->regs[ 6] = (unsigned long) &frame->rs_uc;	regs->regs[29] = (unsigned long) frame;	regs->regs[31] = (unsigned long) frame->rs_code;	regs->cp0_epc = regs->regs[25] = (unsigned long) ka->sa.sa_handler;#if DEBUG_SIG	printk("SIG deliver (%s:%d): sp=0x%p pc=0x%p ra=0x%p\n",	       current->comm, current->pid, frame, regs->cp0_epc, frame->code);#endif	return;give_sigsegv:	if (signr == SIGSEGV)		ka->sa.sa_handler = SIG_DFL;	force_sig(SIGSEGV, current);}static inline voidhandle_signal(unsigned long sig, struct k_sigaction *ka,	siginfo_t *info, sigset_t *oldset, struct pt_regs * regs){	if (ka->sa.sa_flags & SA_SIGINFO)		setup_rt_frame(ka, regs, sig, oldset, info);	else		setup_frame(ka, regs, sig, oldset);	if (ka->sa.sa_flags & SA_ONESHOT)		ka->sa.sa_handler = SIG_DFL;	if (!(ka->sa.sa_flags & SA_NODEFER)) {		spin_lock_irq(&current->sigmask_lock);		sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);		sigaddset(&current->blocked,sig);		recalc_sigpending(current);		spin_unlock_irq(&current->sigmask_lock);	}}static inline voidsyscall_restart(struct pt_regs *regs, struct k_sigaction *ka){	switch(regs->regs[0]) {	case ERESTARTNOHAND:		regs->regs[2] = EINTR;		break;	case ERESTARTSYS:		if(!(ka->sa.sa_flags & SA_RESTART)) {			regs->regs[2] = EINTR;			break;		}	/* fallthrough */	case ERESTARTNOINTR:		/* Userland will reload $v0.  */		regs->regs[7] = regs->regs[26];		regs->cp0_epc -= 8;	}	regs->regs[0] = 0;		/* Don't deal with this again.  */}extern int do_irix_signal(sigset_t *oldset, struct pt_regs *regs);asmlinkage int do_signal(sigset_t *oldset, struct pt_regs *regs){	struct k_sigaction *ka;	siginfo_t info;#ifdef CONFIG_BINFMT_IRIX	if (current->personality != PER_LINUX)		return do_irix_signal(oldset, regs);#endif	if (!oldset)		oldset = &current->blocked;	for (;;) {		unsigned long signr;		spin_lock_irq(&current->sigmask_lock);		signr = dequeue_signal(&current->blocked, &info);		spin_unlock_irq(&current->sigmask_lock);		if (!signr)			break;		if ((current->ptrace & PT_PTRACED) && signr != SIGKILL) {			/* Let the debugger run.  */			current->exit_code = signr;			current->state = TASK_STOPPED;			notify_parent(current, SIGCHLD);			schedule();			/* We're back.  Did the debugger cancel the sig?  */			if (!(signr = current->exit_code))				continue;			current->exit_code = 0;			/* The debugger continued.  Ignore SIGSTOP.  */			if (signr == SIGSTOP)				continue;			/* Update the siginfo structure.  Is this good?  */			if (signr != info.si_signo) {				info.si_signo = signr;				info.si_errno = 0;				info.si_code = SI_USER;				info.si_pid = current->p_pptr->pid;				info.si_uid = current->p_pptr->uid;			}			/* If the (new) signal is now blocked, requeue it.  */			if (sigismember(&current->blocked, signr)) {				send_sig_info(signr, &info, current);				continue;			}		}		ka = &current->sig->action[signr-1];		if (ka->sa.sa_handler == SIG_IGN) {			if (signr != SIGCHLD)				continue;			/* Check for SIGCHLD: it's special.  */			while (sys_wait4(-1, NULL, WNOHANG, NULL) > 0)				/* nothing */;			continue;		}		if (ka->sa.sa_handler == SIG_DFL) {			int exit_code = signr;			/* Init gets no signals it doesn't want.  */			if (current->pid == 1)				continue;			switch (signr) {			case SIGCONT: case SIGCHLD: case SIGWINCH:				continue;			case SIGTSTP: case SIGTTIN: case SIGTTOU:				if (is_orphaned_pgrp(current->pgrp))					continue;				/* FALLTHRU */			case SIGSTOP:				current->state = TASK_STOPPED;				current->exit_code = signr;				if (!(current->p_pptr->sig->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDSTOP))					notify_parent(current, SIGCHLD);				schedule();				continue;			case SIGQUIT: case SIGILL: case SIGTRAP:			case SIGABRT: case SIGFPE: case SIGSEGV:			case SIGBUS: case SIGSYS: case SIGXCPU: case SIGXFSZ:				if (do_coredump(signr, regs))					exit_code |= 0x80;				/* FALLTHRU */			default:				sigaddset(&current->pending.signal, signr);				recalc_sigpending(current);				current->flags |= PF_SIGNALED;				do_exit(exit_code);				/* NOTREACHED */			}		}		if (regs->regs[0])			syscall_restart(regs, ka);		/* Whee!  Actually deliver the signal.  */		handle_signal(signr, ka, &info, oldset, regs);		return 1;	}	/*	 * Who's code doesn't conform to the restartable syscall convention	 * dies here!!!  The li instruction, a single machine instruction,	 * must directly be followed by the syscall instruction.	 */	if (regs->regs[0]) {		if (regs->regs[2] == ERESTARTNOHAND ||		    regs->regs[2] == ERESTARTSYS ||		    regs->regs[2] == ERESTARTNOINTR) {			regs->regs[7] = regs->regs[26];			regs->cp0_epc -= 8;		}	}	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -