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

📄 signal32.c

📁 是关于linux2.5.1的完全源码
💻 C
📖 第 1 页 / 共 4 页
字号:
		sr = (struct sigregs32*)(u64)sigctx.regs;		regs->gpr[3] = ret = sigctx.signal;		regs->gpr[4] = (unsigned long) sc;		regs->link = (unsigned long) &sr->tramp;		regs->nip = sigctx.handler;		if (get_user(prevsp, &sr->gp_regs[PT_R1])		    || put_user(prevsp, (unsigned int*) regs->gpr[1]))			goto badframe;	}  	PPCDBG(PPCDBG_SIGNAL, "sys32_sigreturn - normal exit returning %ld - pid=%ld current=%lx comm=%s \n", ret, current->pid, current, current->comm);	return ret;badframe:	PPCDBG(PPCDBG_SYS32NI, "sys32_sigreturn - badframe - pid=%ld current=%lx comm=%s \n", current->pid, current, current->comm);	do_exit(SIGSEGV);}	/* * Set up a signal frame. */static voidsetup_frame32(struct pt_regs *regs, struct sigregs32 *frame,            unsigned int newsp){	struct sigcontext32_struct *sc = (struct sigcontext32_struct *)(u64)newsp;	if (verify_area(VERIFY_WRITE, frame, sizeof(*frame)))		goto badframe;	if (regs->msr & MSR_FP)		giveup_fpu(current);	/***************************************************************/	/*                                                             */ 	/* Copy the register contents for the pt_regs structure on the */	/*   kernel stack to the elf_gregset_t32 structure on the user */	/*   stack. This is a copy of 64 bit register values to 32 bit */	/*   register values. The high order 32 bits of the 64 bit     */	/*   registers are not needed since a 32 bit application is    */	/*   running and the saved registers are the contents of the   */	/*   user registers at the time of a system call.              */	/*                                                             */	/* The values saved on the user stack will be restored into    */	/*  the registers during the signal return processing          */	/*                                                             */	/* Note the +1 is needed in order to get the lower 32 bits     */	/*  of 64 bit register                                         */	/***************************************************************/	if (__copy_to_user(&frame->gp_regs[0], (u32*)(&regs->gpr[0])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[1], (u32*)(&regs->gpr[1])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[2], (u32*)(&regs->gpr[2])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[3], (u32*)(&regs->gpr[3])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[4], (u32*)(&regs->gpr[4])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[5], (u32*)(&regs->gpr[5])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[6], (u32*)(&regs->gpr[6])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[7], (u32*)(&regs->gpr[7])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[8], (u32*)(&regs->gpr[8])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[9], (u32*)(&regs->gpr[9])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[10], (u32*)(&regs->gpr[10])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[11], (u32*)(&regs->gpr[11])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[12], (u32*)(&regs->gpr[12])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[13], (u32*)(&regs->gpr[13])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[14], (u32*)(&regs->gpr[14])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[15], (u32*)(&regs->gpr[15])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[16], (u32*)(&regs->gpr[16])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[17], (u32*)(&regs->gpr[17])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[18], (u32*)(&regs->gpr[18])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[19], (u32*)(&regs->gpr[19])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[20], (u32*)(&regs->gpr[20])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[21], (u32*)(&regs->gpr[21])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[22], (u32*)(&regs->gpr[22])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[23], (u32*)(&regs->gpr[23])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[24], (u32*)(&regs->gpr[24])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[25], (u32*)(&regs->gpr[25])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[26], (u32*)(&regs->gpr[26])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[27], (u32*)(&regs->gpr[27])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[28], (u32*)(&regs->gpr[28])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[29], (u32*)(&regs->gpr[29])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[30], (u32*)(&regs->gpr[30])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[31], (u32*)(&regs->gpr[31])+1, sizeof(u32))) 		goto badframe;  /*****************************************************************************/  /* Copy the non gpr registers to the user stack                              */  /*****************************************************************************/	if (__copy_to_user(&frame->gp_regs[PT_NIP], (u32*)(&regs->gpr[PT_NIP])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[PT_MSR], (u32*)(&regs->gpr[PT_MSR])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[PT_ORIG_R3], (u32*)(&regs->gpr[PT_ORIG_R3])+1,			      sizeof(u32))	    || __copy_to_user(&frame->gp_regs[PT_CTR], (u32*)(&regs->gpr[PT_CTR])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[PT_LNK], (u32*)(&regs->gpr[PT_LNK])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[PT_XER], (u32*)(&regs->gpr[PT_XER])+1, sizeof(u32))	    || __copy_to_user(&frame->gp_regs[PT_CCR], (u32*)(&regs->gpr[PT_CCR])+1, sizeof(u32))# if 0	    || __copy_to_user(&frame->gp_regs[PT_MQ], (u32*)(&regs->gpr[PT_MQ])+1, sizeof(u32))#endif	    || __copy_to_user(&frame->gp_regs[PT_RESULT], (u32*)(&regs->gpr[PT_RESULT])+1,			      sizeof(u32)))		goto badframe;	/*****************************************************************************/	/* Now copy the floating point registers onto the user stack                 */	/*                                                                           */	/* Also set up so on the completion of the signal handler, the sys_sigreturn */	/*   will get control to reset the stack                                     */	/*****************************************************************************/	if (__copy_to_user(&frame->fp_regs, current->thread.fpr,			   ELF_NFPREG * sizeof(double))	    || __put_user(0x38000000U + __NR_sigreturn, &frame->tramp[0])    /* li r0, __NR_sigreturn */	    || __put_user(0x44000002U, &frame->tramp[1]))   /* sc */		goto badframe;	flush_icache_range((unsigned long) &frame->tramp[0],			   (unsigned long) &frame->tramp[2]);	newsp -= __SIGNAL_FRAMESIZE32;	if (put_user(regs->gpr[1], (u32*)(u64)newsp)	    || get_user(regs->nip, &sc->handler)	    || get_user(regs->gpr[3], &sc->signal))		goto badframe;	regs->gpr[1] = newsp & 0xFFFFFFFF;	/**************************************************************/	/* first parameter to the signal handler is the signal number */	/*  - the value is in gpr3                                    */  	/* second parameter to the signal handler is the sigcontext   */	/*   - set the value into gpr4                                */ 	/**************************************************************/	regs->gpr[4] = (unsigned long) sc;	regs->link = (unsigned long) frame->tramp;	return; badframe:	udbg_printf("setup_frame32 - badframe in setup_frame, regs=%p frame=%p newsp=%lx\n", regs, frame, newsp);  PPCDBG_ENTER_DEBUGGER();#if DEBUG_SIG	printk("badframe in setup_frame32, regs=%p frame=%p newsp=%lx\n",	       regs, frame, newsp);#endif	do_exit(SIGSEGV);}/****************************************************************************//*  Start of RT signal support                                              *//*                                                                          *//*     sigset_t is 64 bits for rt signals                                   *//*                                                                          *//*  System Calls                                                            *//*       sigaction                sys32_rt_sigaction                        *//*       sigpending               sys32_rt_sigpending                       *//*       sigprocmask              sys32_rt_sigprocmask                      *//*       sigreturn                sys32_rt_sigreturn                        *//*       sigtimedwait             sys32_rt_sigtimedwait                     *//*       sigqueueinfo             sys32_rt_sigqueueinfo                     *//*       sigsuspend               sys32_rt_sigsuspend                       */ /*                                                                          *//*  Other routines                                                          *//*        setup_rt_frame32                                                  *//*        siginfo64to32                                                     *//*        siginfo32to64                                                     *//*                                                                          *//*                                                                          *//****************************************************************************/// This code executes after the rt signal handler in 32 bit mode has completed and //  returned  long sys32_rt_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5,			unsigned long r6, unsigned long r7, unsigned long r8,			struct pt_regs * regs){	struct rt_sigframe_32 *rt_stack_frame;	struct sigcontext32_struct sigctx;	struct sigregs32 *signalregs; 	int ret;	elf_gregset_t32 saved_regs;   /* an array of 32 bit register values */	sigset_t signal_set; 	stack_t stack;	unsigned int previous_stack;	ret = 0;	/* Adjust the inputted reg1 to point to the first rt signal frame */	rt_stack_frame = (struct rt_sigframe_32 *)(regs->gpr[1] + __SIGNAL_FRAMESIZE32);	/* Copy the information from the user stack  */	if (copy_from_user(&sigctx, &rt_stack_frame->uc.uc_mcontext,sizeof(sigctx))	    || copy_from_user(&signal_set, &rt_stack_frame->uc.uc_sigmask,sizeof(signal_set))	    || copy_from_user(&stack,&rt_stack_frame->uc.uc_stack,sizeof(stack)))	{		/* unable to copy from user storage */		goto badframe;	}	/* Unblock the signal that was processed 	 *   After a signal handler runs - 	 *     if the signal is blockable - the signal will be unblocked  	 *       ( sigkill and sigstop are not blockable)	 */	sigdelsetmask(&signal_set, ~_BLOCKABLE); 	/* update the current based on the sigmask found in the rt_stackframe */	spin_lock_irq(&current->sigmask_lock);	current->blocked = signal_set;	recalc_sigpending();	spin_unlock_irq(&current->sigmask_lock);	/* Set to point to the next rt_sigframe - this is used to determine whether this 	 *   is the last signal to process	 */	rt_stack_frame ++;	if (rt_stack_frame == (struct rt_sigframe_32 *)(u64)(sigctx.regs))	{		signalregs = (struct sigregs32 *) (u64)sigctx.regs;		/* If currently owning the floating point - give them up */		if (regs->msr & MSR_FP)		{			giveup_fpu(current);		}		if (copy_from_user(saved_regs,&signalregs->gp_regs,sizeof(signalregs->gp_regs))) 		{			goto badframe;		}		/**********************************************************************/		/* The saved reg structure in the frame is an elf_grepset_t32, it is  */		/*   a 32 bit register save of the registers in the pt_regs structure */		/*   that was stored on the kernel stack during the system call       */		/*   when the system call was interrupted for the signal. Only 32 bits*/		/*   are saved because the sigcontext contains a pointer to the regs  */		/*   and the sig context address is passed as a pointer to the signal */		/*   handler.                                                         */		/*                                                                    */		/* The entries in the elf_grepset have the same index as the elements */		/*   in the pt_regs structure.                                        */		/*                                                                    */		/**********************************************************************/		saved_regs[PT_MSR] = (regs->msr & ~MSR_USERCHANGE)			| (saved_regs[PT_MSR] & MSR_USERCHANGE);		regs->gpr[0] = (u64)(saved_regs[0]) & 0xFFFFFFFF;		regs->gpr[1] = (u64)(saved_regs[1]) & 0xFFFFFFFF;		/**********************************************************************/		/* Register 2 is the kernel toc - should be reset on any calls into   */		/*  the kernel                                                        */		/**********************************************************************/		regs->gpr[2] = (u64)(saved_regs[2]) & 0xFFFFFFFF; 		regs->gpr[3] = (u64)(saved_regs[3]) & 0xFFFFFFFF;		regs->gpr[4] = (u64)(saved_regs[4]) & 0xFFFFFFFF;		regs->gpr[5] = (u64)(saved_regs[5]) & 0xFFFFFFFF;		regs->gpr[6] = (u64)(saved_regs[6]) & 0xFFFFFFFF;		regs->gpr[7] = (u64)(saved_regs[7]) & 0xFFFFFFFF;		regs->gpr[8] = (u64)(saved_regs[8]) & 0xFFFFFFFF;		regs->gpr[9] = (u64)(saved_regs[9]) & 0xFFFFFFFF;		regs->gpr[10] = (u64)(saved_regs[10]) & 0xFFFFFFFF;		regs->gpr[11] = (u64)(saved_regs[11]) & 0xFFFFFFFF;		regs->gpr[12] = (u64)(saved_regs[12]) & 0xFFFFFFFF;		regs->gpr[13] = (u64)(saved_regs[13]) & 0xFFFFFFFF;		regs->gpr[14] = (u64)(saved_regs[14]) & 0xFFFFFFFF;		regs->gpr[15] = (u64)(saved_regs[15]) & 0xFFFFFFFF;		regs->gpr[16] = (u64)(saved_regs[16]) & 0xFFFFFFFF;		regs->gpr[17] = (u64)(saved_regs[17]) & 0xFFFFFFFF;		regs->gpr[18] = (u64)(saved_regs[18]) & 0xFFFFFFFF;		regs->gpr[19] = (u64)(saved_regs[19]) & 0xFFFFFFFF;		regs->gpr[20] = (u64)(saved_regs[20]) & 0xFFFFFFFF;		regs->gpr[21] = (u64)(saved_regs[21]) & 0xFFFFFFFF;		regs->gpr[22] = (u64)(saved_regs[22]) & 0xFFFFFFFF;		regs->gpr[23] = (u64)(saved_regs[23]) & 0xFFFFFFFF;		regs->gpr[24] = (u64)(saved_regs[24]) & 0xFFFFFFFF;		regs->gpr[25] = (u64)(saved_regs[25]) & 0xFFFFFFFF;		regs->gpr[26] = (u64)(saved_regs[26]) & 0xFFFFFFFF;		regs->gpr[27] = (u64)(saved_regs[27]) & 0xFFFFFFFF;		regs->gpr[28] = (u64)(saved_regs[28]) & 0xFFFFFFFF;		regs->gpr[29] = (u64)(saved_regs[29]) & 0xFFFFFFFF;		regs->gpr[30] = (u64)(saved_regs[30]) & 0xFFFFFFFF;		regs->gpr[31] = (u64)(saved_regs[31]) & 0xFFFFFFFF;		/****************************************************/		/*  restore the non gpr registers                   */		/****************************************************/		regs->msr = (u64)(saved_regs[PT_MSR]) & 0xFFFFFFFF;		regs->nip = (u64)(saved_regs[PT_NIP]) & 0xFFFFFFFF;		regs->orig_gpr3 = (u64)(saved_regs[PT_ORIG_R3]) & 0xFFFFFFFF; 		regs->ctr = (u64)(saved_regs[PT_CTR]) & 0xFFFFFFFF; 		regs->link = (u64)(saved_regs[PT_LNK]) & 0xFFFFFFFF; 		regs->xer = (u64)(saved_regs[PT_XER]) & 0xFFFFFFFF; 		regs->ccr = (u64)(saved_regs[PT_CCR]) & 0xFFFFFFFF;		/* regs->softe is left unchanged (like MSR.EE) */		/******************************************************/		/* the DAR and the DSISR are only relevant during a   */		/*   data or instruction storage interrupt. The value */		/*   will be set to zero.                             */		/******************************************************/		regs->dar = 0; 		regs->dsisr = 0;		regs->result = (u64)(saved_regs[PT_RESULT]) & 0xFFFFFFFF;		ret = regs->result;	}	else  /* more signals to go  */	{		udbg_printf("hey should not occur\n");		regs->gpr[1] = (u64)rt_stack_frame - __SIGNAL_FRAMESIZE32;		if (copy_from_user(&sigctx, &rt_stack_frame->uc.uc_mcontext,sizeof(sigctx)))		{			goto badframe;		}		signalregs = (struct sigregs32 *) (u64)sigctx.regs;		/* first parm to signal handler is the signal number */		regs->gpr[3] = ret = sigctx.signal;		/* second parm is a pointer to sig info */		get_user(regs->gpr[4], &rt_stack_frame->pinfo);		/* third parm is a pointer to the ucontext */		get_user(regs->gpr[5], &rt_stack_frame->puc);		/* fourth parm is the stack frame */		regs->gpr[6] = (u64)rt_stack_frame;		/* Set up link register to return to sigreturn when the */		/*  signal handler completes */		regs->link = (u64)&signalregs->tramp;		/* Set next instruction to the start fo the signal handler */		regs->nip = sigctx.handler;		/* Set the reg1 to look like a call to the signal handler */		if (get_user(previous_stack,&signalregs->gp_regs[PT_R1])		    || put_user(previous_stack, (unsigned long *)regs->gpr[1]))		{			goto badframe;		}	}	return ret; badframe:	do_exit(SIGSEGV);     }asmlinkage long sys32_rt_sigaction(int sig, const struct sigaction32 *act, struct sigaction32 *oact, size_t sigsetsize){	struct k_sigaction new_ka, old_ka;	int ret;	sigset32_t set32;	PPCDBG(PPCDBG_SIGNAL, "sys32_rt_sigaction - entered - sig=%x \n", sig);	/* XXX: Don't preclude handling different sized sigset_t's.  */	if (sigsetsize != sizeof(sigset32_t))		return -EINVAL;	if (act) {		ret = get_user((long)new_ka.sa.sa_handler, &act->sa_handler);		ret |= __copy_from_user(&set32, &act->sa_mask,					sizeof(sigset32_t));		switch (_NSIG_WORDS) {		case 4: new_ka.sa.sa_mask.sig[3] = set32.sig[6]				| (((long)set32.sig[7]) << 32);		case 3: new_ka.sa.sa_mask.sig[2] = set32.sig[4]				| (((long)set32.sig[5]) << 32);		case 2: new_ka.sa.sa_mask.sig[1] = set32.sig[2]				| (((long)set32.sig[3]) << 32);		case 1: new_ka.sa.sa_mask.sig[0] = set32.sig[0]				| (((long)set32.sig[1]) << 32);		}		ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);				if (ret)			return -EFAULT;

⌨️ 快捷键说明

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