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

📄 signal.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	err |= __copy_to_user(&sc->sc_gr[12], &scr->pt.r12, 2*8);	/* r12-r13 */	err |= __copy_to_user(&sc->sc_gr[15], &scr->pt.r15, 8);		/* r15 */	err |= __put_user(scr->pt.cr_iip + ia64_psr(&scr->pt)->ri, &sc->sc_ip);	if (!(flags & IA64_SC_FLAG_IN_SYSCALL)) {		/* Copy scratch regs to sigcontext if the signal didn't interrupt a syscall. */		err |= __put_user(scr->pt.ar_ccv, &sc->sc_ar_ccv);		/* ar.ccv */		err |= __put_user(scr->pt.b7, &sc->sc_br[7]);			/* b7 */		err |= __put_user(scr->pt.r14, &sc->sc_gr[14]);			/* r14 */		err |= __copy_to_user(&sc->sc_ar25, &scr->pt.ar_csd, 2*8); /* ar.csd & ar.ssd */		err |= __copy_to_user(&sc->sc_gr[2], &scr->pt.r2, 2*8);		/* r2-r3 */		err |= __copy_to_user(&sc->sc_gr[16], &scr->pt.r16, 16*8);	/* r16-r31 */	}	return err;}/* * Check whether the register-backing store is already on the signal stack. */static inline intrbs_on_sig_stack (unsigned long bsp){	return (bsp - current->sas_ss_sp < current->sas_ss_size);}static longforce_sigsegv_info (int sig, void __user *addr){	unsigned long flags;	struct siginfo si;	if (sig == SIGSEGV) {		/*		 * Acquiring siglock around the sa_handler-update is almost		 * certainly overkill, but this isn't a		 * performance-critical path and I'd rather play it safe		 * here than having to debug a nasty race if and when		 * something changes in kernel/signal.c that would make it		 * no longer safe to modify sa_handler without holding the		 * lock.		 */		spin_lock_irqsave(&current->sighand->siglock, flags);		current->sighand->action[sig - 1].sa.sa_handler = SIG_DFL;		spin_unlock_irqrestore(&current->sighand->siglock, flags);	}	si.si_signo = SIGSEGV;	si.si_errno = 0;	si.si_code = SI_KERNEL;	si.si_pid = task_pid_vnr(current);	si.si_uid = current->uid;	si.si_addr = addr;	force_sig_info(SIGSEGV, &si, current);	return 0;}static longsetup_frame (int sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *set,	     struct sigscratch *scr){	extern char __kernel_sigtramp[];	unsigned long tramp_addr, new_rbs = 0, new_sp;	struct sigframe __user *frame;	long err;	new_sp = scr->pt.r12;	tramp_addr = (unsigned long) __kernel_sigtramp;	if ((ka->sa.sa_flags & SA_ONSTACK) && sas_ss_flags(new_sp) == 0) {		new_sp = current->sas_ss_sp + current->sas_ss_size;		/*		 * We need to check for the register stack being on the signal stack		 * separately, because it's switched separately (memory stack is switched		 * in the kernel, register stack is switched in the signal trampoline).		 */		if (!rbs_on_sig_stack(scr->pt.ar_bspstore))			new_rbs = (current->sas_ss_sp + sizeof(long) - 1) & ~(sizeof(long) - 1);	}	frame = (void __user *) ((new_sp - sizeof(*frame)) & -STACK_ALIGN);	if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))		return force_sigsegv_info(sig, frame);	err  = __put_user(sig, &frame->arg0);	err |= __put_user(&frame->info, &frame->arg1);	err |= __put_user(&frame->sc, &frame->arg2);	err |= __put_user(new_rbs, &frame->sc.sc_rbs_base);	err |= __put_user(0, &frame->sc.sc_loadrs);	/* initialize to zero */	err |= __put_user(ka->sa.sa_handler, &frame->handler);	err |= copy_siginfo_to_user(&frame->info, info);	err |= __put_user(current->sas_ss_sp, &frame->sc.sc_stack.ss_sp);	err |= __put_user(current->sas_ss_size, &frame->sc.sc_stack.ss_size);	err |= __put_user(sas_ss_flags(scr->pt.r12), &frame->sc.sc_stack.ss_flags);	err |= setup_sigcontext(&frame->sc, set, scr);	if (unlikely(err))		return force_sigsegv_info(sig, frame);	scr->pt.r12 = (unsigned long) frame - 16;	/* new stack pointer */	scr->pt.ar_fpsr = FPSR_DEFAULT;			/* reset fpsr for signal handler */	scr->pt.cr_iip = tramp_addr;	ia64_psr(&scr->pt)->ri = 0;			/* start executing in first slot */	ia64_psr(&scr->pt)->be = 0;			/* force little-endian byte-order */	/*	 * Force the interruption function mask to zero.  This has no effect when a	 * system-call got interrupted by a signal (since, in that case, scr->pt_cr_ifs is	 * ignored), but it has the desirable effect of making it possible to deliver a	 * signal with an incomplete register frame (which happens when a mandatory RSE	 * load faults).  Furthermore, it has no negative effect on the getting the user's	 * dirty partition preserved, because that's governed by scr->pt.loadrs.	 */	scr->pt.cr_ifs = (1UL << 63);	/*	 * Note: this affects only the NaT bits of the scratch regs (the ones saved in	 * pt_regs), which is exactly what we want.	 */	scr->scratch_unat = 0; /* ensure NaT bits of r12 is clear */#if DEBUG_SIG	printk("SIG deliver (%s:%d): sig=%d sp=%lx ip=%lx handler=%p\n",	       current->comm, current->pid, sig, scr->pt.r12, frame->sc.sc_ip, frame->handler);#endif	return 1;}static longhandle_signal (unsigned long sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *oldset,	       struct sigscratch *scr){	if (IS_IA32_PROCESS(&scr->pt)) {		/* send signal to IA-32 process */		if (!ia32_setup_frame1(sig, ka, info, oldset, &scr->pt))			return 0;	} else		/* send signal to IA-64 process */		if (!setup_frame(sig, ka, info, oldset, scr))			return 0;	spin_lock_irq(&current->sighand->siglock);	sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);	if (!(ka->sa.sa_flags & SA_NODEFER))		sigaddset(&current->blocked, sig);	recalc_sigpending();	spin_unlock_irq(&current->sighand->siglock);	return 1;}/* * Note that `init' is a special process: it doesn't get signals it doesn't want to * handle.  Thus you cannot kill init even with a SIGKILL even by mistake. */voidia64_do_signal (struct sigscratch *scr, long in_syscall){	struct k_sigaction ka;	sigset_t *oldset;	siginfo_t info;	long restart = in_syscall;	long errno = scr->pt.r8;#	define ERR_CODE(c)	(IS_IA32_PROCESS(&scr->pt) ? -(c) : (c))	/*	 * In the ia64_leave_kernel code path, we want the common case to go fast, which	 * is why we may in certain cases get here from kernel mode. Just return without	 * doing anything if so.	 */	if (!user_mode(&scr->pt))		return;	if (test_thread_flag(TIF_RESTORE_SIGMASK))		oldset = &current->saved_sigmask;	else		oldset = &current->blocked;	/*	 * This only loops in the rare cases of handle_signal() failing, in which case we	 * need to push through a forced SIGSEGV.	 */	while (1) {		int signr = get_signal_to_deliver(&info, &ka, &scr->pt, NULL);		/*		 * get_signal_to_deliver() may have run a debugger (via notify_parent())		 * and the debugger may have modified the state (e.g., to arrange for an		 * inferior call), thus it's important to check for restarting _after_		 * get_signal_to_deliver().		 */		if (IS_IA32_PROCESS(&scr->pt)) {			if (in_syscall) {				if (errno >= 0)					restart = 0;				else					errno = -errno;			}		} else if ((long) scr->pt.r10 != -1)			/*			 * A system calls has to be restarted only if one of the error codes			 * ERESTARTNOHAND, ERESTARTSYS, or ERESTARTNOINTR is returned.  If r10			 * isn't -1 then r8 doesn't hold an error code and we don't need to			 * restart the syscall, so we can clear the "restart" flag here.			 */			restart = 0;		if (signr <= 0)			break;		if (unlikely(restart)) {			switch (errno) {			      case ERESTART_RESTARTBLOCK:			      case ERESTARTNOHAND:				scr->pt.r8 = ERR_CODE(EINTR);				/* note: scr->pt.r10 is already -1 */				break;			      case ERESTARTSYS:				if ((ka.sa.sa_flags & SA_RESTART) == 0) {					scr->pt.r8 = ERR_CODE(EINTR);					/* note: scr->pt.r10 is already -1 */					break;				}			      case ERESTARTNOINTR:				if (IS_IA32_PROCESS(&scr->pt)) {					scr->pt.r8 = scr->pt.r1;					scr->pt.cr_iip -= 2;				} else					ia64_decrement_ip(&scr->pt);				restart = 0; /* don't restart twice if handle_signal() fails... */			}		}		/*		 * Whee!  Actually deliver the signal.  If the delivery failed, we need to		 * continue to iterate in this loop so we can deliver the SIGSEGV...		 */		if (handle_signal(signr, &ka, &info, oldset, scr)) {			/* a signal was successfully delivered; the saved			 * sigmask will have been stored in the signal frame,			 * and will be restored by sigreturn, so we can simply			 * clear the TIF_RESTORE_SIGMASK flag */			if (test_thread_flag(TIF_RESTORE_SIGMASK))				clear_thread_flag(TIF_RESTORE_SIGMASK);			return;		}	}	/* Did we come from a system call? */	if (restart) {		/* Restart the system call - no handlers present */		if (errno == ERESTARTNOHAND || errno == ERESTARTSYS || errno == ERESTARTNOINTR		    || errno == ERESTART_RESTARTBLOCK)		{			if (IS_IA32_PROCESS(&scr->pt)) {				scr->pt.r8 = scr->pt.r1;				scr->pt.cr_iip -= 2;				if (errno == ERESTART_RESTARTBLOCK)					scr->pt.r8 = 0;	/* x86 version of __NR_restart_syscall */			} else {				/*				 * Note: the syscall number is in r15 which is saved in				 * pt_regs so all we need to do here is adjust ip so that				 * the "break" instruction gets re-executed.				 */				ia64_decrement_ip(&scr->pt);				if (errno == ERESTART_RESTARTBLOCK)					scr->pt.r15 = __NR_restart_syscall;			}		}	}	/* if there's no signal to deliver, we just put the saved sigmask	 * back */	if (test_thread_flag(TIF_RESTORE_SIGMASK)) {		clear_thread_flag(TIF_RESTORE_SIGMASK);		sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);	}}

⌨️ 快捷键说明

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